1 /* ST Microelectronics IIS3DHHC accelerometer 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/iis3dhhc.pdf
9  */
10 
11 #ifndef ZEPHYR_DRIVERS_SENSOR_IIS3DHHC_IIS3DHHC_H_
12 #define ZEPHYR_DRIVERS_SENSOR_IIS3DHHC_IIS3DHHC_H_
13 
14 #include <stdint.h>
15 #include <zephyr/drivers/spi.h>
16 #include <zephyr/drivers/gpio.h>
17 #include <zephyr/drivers/sensor.h>
18 #include <zephyr/kernel.h>
19 #include <zephyr/types.h>
20 #include <zephyr/sys/util.h>
21 #include <stmemsc.h>
22 #include "iis3dhhc_reg.h"
23 
24 struct iis3dhhc_config {
25 	int (*bus_init)(const struct device *dev);
26 #ifdef CONFIG_IIS3DHHC_TRIGGER
27 	struct gpio_dt_spec int_gpio;
28 #endif
29 #if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
30 	struct spi_dt_spec spi;
31 #endif
32 };
33 
34 struct iis3dhhc_data {
35 	int16_t acc[3];
36 
37 	stmdev_ctx_t *ctx;
38 
39 #ifdef CONFIG_IIS3DHHC_TRIGGER
40 	struct gpio_callback gpio_cb;
41 
42 	sensor_trigger_handler_t handler_drdy;
43 	const struct sensor_trigger *trig_drdy;
44 	const struct device *dev;
45 
46 #if defined(CONFIG_IIS3DHHC_TRIGGER_OWN_THREAD)
47 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_IIS3DHHC_THREAD_STACK_SIZE);
48 	struct k_thread thread;
49 	struct k_sem gpio_sem;
50 #elif defined(CONFIG_IIS3DHHC_TRIGGER_GLOBAL_THREAD)
51 	struct k_work work;
52 #endif
53 
54 #endif /* CONFIG_IIS3DHHC_TRIGGER */
55 };
56 
57 int iis3dhhc_spi_init(const struct device *dev);
58 
59 #ifdef CONFIG_IIS3DHHC_TRIGGER
60 int iis3dhhc_trigger_set(const struct device *dev,
61 			 const struct sensor_trigger *trig,
62 			 sensor_trigger_handler_t handler);
63 
64 int iis3dhhc_init_interrupt(const struct device *dev);
65 #endif
66 
67 #endif /* ZEPHYR_DRIVERS_SENSOR_IIS3DHHC_IIS3DHHC_H_ */
68