1 /* ST Microelectronics LPS22HH pressure and temperature sensor
2  *
3  * Copyright (c) 2019 STMicroelectronics
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  *
7  * Datasheet:
8  * https://www.st.com/resource/en/datasheet/lps22hh.pdf
9  */
10 
11 #ifndef ZEPHYR_DRIVERS_SENSOR_LPS22HH_LPS22HH_H_
12 #define ZEPHYR_DRIVERS_SENSOR_LPS22HH_LPS22HH_H_
13 
14 #include <stdint.h>
15 #include <stmemsc.h>
16 #include "lps22hh_reg.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 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c)
27 #include <zephyr/drivers/i3c.h>
28 #endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c) */
29 
30 struct lps22hh_config {
31 	stmdev_ctx_t ctx;
32 	union {
33 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
34 		const struct i2c_dt_spec i2c;
35 #endif
36 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
37 		const struct spi_dt_spec spi;
38 #endif
39 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c)
40 		struct i3c_device_desc **i3c;
41 #endif
42 	} stmemsc_cfg;
43 	uint8_t odr;
44 #ifdef CONFIG_LPS22HH_TRIGGER
45 	struct gpio_dt_spec gpio_int;
46 #endif
47 
48 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c)
49 	struct {
50 		const struct device *bus;
51 		const struct i3c_device_id dev_id;
52 	} i3c;
53 #endif
54 };
55 
56 struct lps22hh_data {
57 	int32_t sample_press;
58 	int16_t sample_temp;
59 
60 #ifdef CONFIG_LPS22HH_TRIGGER
61 	struct gpio_callback gpio_cb;
62 
63 	const struct sensor_trigger *data_ready_trigger;
64 	sensor_trigger_handler_t handler_drdy;
65 	const struct device *dev;
66 
67 #if defined(CONFIG_LPS22HH_TRIGGER_OWN_THREAD)
68 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_LPS22HH_THREAD_STACK_SIZE);
69 	struct k_thread thread;
70 	struct k_sem intr_sem;
71 #elif defined(CONFIG_LPS22HH_TRIGGER_GLOBAL_THREAD)
72 	struct k_work work;
73 #endif
74 
75 #endif /* CONFIG_LPS22HH_TRIGGER */
76 
77 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(i3c)
78 	struct i3c_device_desc *i3c_dev;
79 #endif
80 };
81 
82 #ifdef CONFIG_LPS22HH_TRIGGER
83 int lps22hh_trigger_set(const struct device *dev,
84 			const struct sensor_trigger *trig,
85 			sensor_trigger_handler_t handler);
86 
87 int lps22hh_init_interrupt(const struct device *dev);
88 #endif
89 
90 #endif /* ZEPHYR_DRIVERS_SENSOR_LPS22HH_LPS22HH_H_ */
91