1 /*
2  * Copyright (c) 2025 Würth Elektronik eiSos GmbH & Co. KG
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_2521020222501_WSEN_TIDS_2521020222501_H_
8 #define ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_2521020222501_WSEN_TIDS_2521020222501_H_
9 
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/drivers/sensor.h>
12 
13 #include <weplatform.h>
14 
15 #include "WSEN_TIDS_2521020222501_hal.h"
16 #include <zephyr/drivers/sensor/wsen_tids_2521020222501.h>
17 
18 #include <zephyr/drivers/i2c.h>
19 
20 struct tids_2521020222501_data {
21 	/* WE sensor interface configuration */
22 	WE_sensorInterface_t sensor_interface;
23 
24 	/* Last temperature sample */
25 	int16_t temperature;
26 
27 	uint8_t sensor_odr;
28 
29 #ifdef CONFIG_WSEN_TIDS_2521020222501_TRIGGER
30 	const struct device *dev;
31 
32 	/* Callback for high/low limit interrupts */
33 	struct gpio_callback interrupt_cb;
34 
35 	int32_t sensor_high_threshold;
36 	int32_t sensor_low_threshold;
37 
38 	sensor_trigger_handler_t temperature_high_handler;
39 	sensor_trigger_handler_t temperature_low_handler;
40 
41 	const struct sensor_trigger *temperature_high_trigger;
42 	const struct sensor_trigger *temperature_low_trigger;
43 
44 #if defined(CONFIG_WSEN_TIDS_2521020222501_TRIGGER_OWN_THREAD)
45 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_WSEN_TIDS_2521020222501_THREAD_STACK_SIZE);
46 	struct k_thread thread;
47 	struct k_sem sem;
48 #elif defined(CONFIG_WSEN_TIDS_2521020222501_TRIGGER_GLOBAL_THREAD)
49 	struct k_work work;
50 #endif
51 #endif /* CONFIG_WSEN_TIDS_2521020222501_TRIGGER */
52 };
53 
54 struct tids_2521020222501_config {
55 	union {
56 		const struct i2c_dt_spec i2c;
57 	} bus_cfg;
58 
59 	/* Output data rate */
60 	const uint8_t odr;
61 
62 #ifdef CONFIG_WSEN_TIDS_2521020222501_TRIGGER
63 	/* Interrupt pin used for high and low limit interrupt events */
64 	const struct gpio_dt_spec interrupt_gpio;
65 
66 	/* High temperature interrupt threshold */
67 	const int32_t high_threshold;
68 
69 	/* Low temperature interrupt threshold */
70 	const int32_t low_threshold;
71 #endif
72 };
73 
74 #ifdef CONFIG_WSEN_TIDS_2521020222501_TRIGGER
75 int tids_2521020222501_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
76 				   sensor_trigger_handler_t handler);
77 
78 int tids_2521020222501_threshold_upper_set(const struct device *dev,
79 					   const struct sensor_value *thresh_value);
80 
81 int tids_2521020222501_threshold_upper_get(const struct device *dev,
82 					   struct sensor_value *thresh_value);
83 
84 int tids_2521020222501_threshold_lower_set(const struct device *dev,
85 					   const struct sensor_value *thresh_value);
86 
87 int tids_2521020222501_threshold_lower_get(const struct device *dev,
88 					   struct sensor_value *thresh_value);
89 
90 int tids_2521020222501_init_interrupt(const struct device *dev);
91 #endif
92 
93 int tids_2521020222501_i2c_init(const struct device *dev);
94 
95 #endif /* ZEPHYR_DRIVERS_SENSOR_WSEN_TIDS_2521020222501_WSEN_TIDS_2521020222501_H_ */
96