1 /* ST Microelectronics STTS22H temperature sensor
2  *
3  * Copyright (c) 2024 STMicroelectronics
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Datasheet:
8  * https://www.st.com/resource/en/datasheet/stts22h.pdf
9  */
10 
11 #ifndef ZEPHYR_DRIVERS_SENSOR_STTS22H_STTS22H_H_
12 #define ZEPHYR_DRIVERS_SENSOR_STTS22H_STTS22H_H_
13 
14 #include <zephyr/drivers/sensor.h>
15 #include <zephyr/types.h>
16 #include <zephyr/drivers/gpio.h>
17 #include <zephyr/sys/util.h>
18 #include <stmemsc.h>
19 #include "stts22h_reg.h"
20 
21 #include <zephyr/drivers/i2c.h>
22 
23 struct stts22h_config {
24 	stmdev_ctx_t ctx;
25 	const struct i2c_dt_spec i2c;
26 #ifdef CONFIG_STTS22H_TRIGGER
27 	const struct gpio_dt_spec int_gpio;
28 #endif
29 	uint8_t temp_hi;
30 	uint8_t temp_lo;
31 	uint8_t odr;
32 };
33 
34 struct stts22h_data {
35 	const struct device *dev;
36 	int16_t sample_temp;
37 
38 #ifdef CONFIG_STTS22H_TRIGGER
39 	struct gpio_callback gpio_cb;
40 
41 	const struct sensor_trigger *thsld_trigger;
42 	sensor_trigger_handler_t thsld_handler;
43 
44 #if defined(CONFIG_STTS22H_TRIGGER_OWN_THREAD)
45 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_STTS22H_THREAD_STACK_SIZE);
46 	struct k_thread thread;
47 	struct k_sem gpio_sem;
48 #elif defined(CONFIG_STTS22H_TRIGGER_GLOBAL_THREAD)
49 	struct k_work work;
50 #endif
51 
52 #endif /* CONFIG_STTS22H_TRIGGER */
53 };
54 
55 #ifdef CONFIG_STTS22H_TRIGGER
56 int stts22h_trigger_set(const struct device *dev,
57 			const struct sensor_trigger *trig,
58 			sensor_trigger_handler_t handler);
59 
60 int stts22h_init_interrupt(const struct device *dev);
61 #endif
62 
63 #endif /* ZEPHYR_DRIVERS_SENSOR_STTS22H_STTS22H_H_ */
64