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_PADS_2511020213301_WSEN_PADS_2511020213301_H_
8 #define ZEPHYR_DRIVERS_SENSOR_WSEN_PADS_2511020213301_WSEN_PADS_2511020213301_H_
9 
10 #include <zephyr/drivers/gpio.h>
11 #include <zephyr/drivers/sensor.h>
12 
13 #include <weplatform.h>
14 
15 #include "WSEN_PADS_2511020213301_hal.h"
16 #include <zephyr/drivers/sensor/wsen_pads_2511020213301.h>
17 
18 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
19 #include <zephyr/drivers/spi.h>
20 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
21 
22 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
23 #include <zephyr/drivers/i2c.h>
24 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
25 
26 struct pads_2511020213301_data {
27 	/* WE sensor interface configuration */
28 	WE_sensorInterface_t sensor_interface;
29 
30 	/* Last pressure sample */
31 	int32_t pressure;
32 
33 	/* Last temperature sample */
34 	int16_t temperature;
35 
36 	PADS_outputDataRate_t sensor_odr;
37 
38 #ifdef CONFIG_WSEN_PADS_2511020213301_TRIGGER
39 	const struct device *dev;
40 
41 	struct gpio_callback interrupt_cb;
42 
43 #ifdef CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD
44 	sensor_trigger_handler_t pressure_high_trigger_handler;
45 	sensor_trigger_handler_t pressure_low_trigger_handler;
46 	const struct sensor_trigger *pressure_high_trigger;
47 	const struct sensor_trigger *pressure_low_trigger;
48 #else
49 	sensor_trigger_handler_t data_ready_trigger_handler;
50 	const struct sensor_trigger *data_ready_trigger;
51 #endif /*  CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD */
52 
53 #if defined(CONFIG_WSEN_PADS_2511020213301_TRIGGER_OWN_THREAD)
54 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_WSEN_PADS_2511020213301_THREAD_STACK_SIZE);
55 	struct k_thread thread;
56 	struct k_sem sem;
57 #elif defined(CONFIG_WSEN_PADS_2511020213301_TRIGGER_GLOBAL_THREAD)
58 	struct k_work work;
59 #endif
60 #endif /* CONFIG_WSEN_PADS_2511020213301_TRIGGER */
61 };
62 
63 struct pads_2511020213301_config {
64 	union {
65 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
66 		const struct i2c_dt_spec i2c;
67 #endif
68 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
69 		const struct spi_dt_spec spi;
70 #endif
71 	} bus_cfg;
72 
73 	/* Output data rate */
74 	const PADS_outputDataRate_t odr;
75 
76 	const PADS_powerMode_t configuration;
77 
78 	const PADS_state_t alpf;
79 
80 	const PADS_filterConf_t alpf_configuration;
81 #ifdef CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD
82 	const uint16_t threshold;
83 #endif /*  CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD */
84 #ifdef CONFIG_WSEN_PADS_2511020213301_TRIGGER
85 	/* Interrupt pin */
86 	const struct gpio_dt_spec interrupt_gpio;
87 #endif /* CONFIG_WSEN_PADS_2511020213301_TRIGGER */
88 };
89 
90 #ifdef CONFIG_WSEN_PADS_2511020213301_TRIGGER
91 int pads_2511020213301_trigger_set(const struct device *dev, const struct sensor_trigger *trig,
92 				   sensor_trigger_handler_t handler);
93 
94 int pads_2511020213301_init_interrupt(const struct device *dev);
95 
96 #ifdef CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD
97 int pads_2511020213301_threshold_set(const struct device *dev,
98 				     const struct sensor_value *threshold);
99 
100 int pads_2511020213301_threshold_get(const struct device *dev, struct sensor_value *threshold);
101 
102 int pads_2511020213301_reference_point_set(const struct device *dev,
103 					   const struct sensor_value *reference_point);
104 
105 int pads_2511020213301_reference_point_get(const struct device *dev,
106 					   struct sensor_value *reference_point);
107 
108 #endif /* CONFIG_WSEN_PADS_2511020213301_PRESSURE_THRESHOLD */
109 #endif /* CONFIG_WSEN_PADS_2511020213301_TRIGGER */
110 
111 int pads_2511020213301_spi_init(const struct device *dev);
112 int pads_2511020213301_i2c_init(const struct device *dev);
113 
114 #endif /* ZEPHYR_DRIVERS_SENSOR_WSEN_PADS_2511020213301_WSEN_PADS_2511020213301_H_ */
115