1 /*
2  * Copyright (c) 2020 TDK Invensense
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_ICM42605_ICM42605_H_
8 #define ZEPHYR_DRIVERS_SENSOR_ICM42605_ICM42605_H_
9 
10 #include <zephyr/device.h>
11 #include <zephyr/drivers/gpio.h>
12 #include <zephyr/drivers/spi.h>
13 #include <zephyr/kernel.h>
14 #include <zephyr/sys/util.h>
15 #include <zephyr/types.h>
16 
17 #include "icm42605_reg.h"
18 
19 typedef void (*tap_fetch_t)(const struct device *dev);
20 int icm42605_tap_fetch(const struct device *dev);
21 
22 struct icm42605_data {
23 	uint8_t fifo_data[HARDWARE_FIFO_SIZE];
24 
25 	int16_t accel_x;
26 	int16_t accel_y;
27 	int16_t accel_z;
28 	uint16_t accel_sensitivity_shift;
29 	uint16_t accel_hz;
30 	uint16_t accel_sf;
31 
32 	int16_t temp;
33 
34 	int16_t gyro_x;
35 	int16_t gyro_y;
36 	int16_t gyro_z;
37 	uint16_t gyro_sensitivity_x10;
38 	uint16_t gyro_hz;
39 	uint16_t gyro_sf;
40 
41 	bool accel_en;
42 	bool gyro_en;
43 	bool tap_en;
44 
45 	bool sensor_started;
46 
47 	const struct device *dev;
48 	struct gpio_callback gpio_cb;
49 
50 	const struct sensor_trigger *data_ready_trigger;
51 	sensor_trigger_handler_t data_ready_handler;
52 
53 	const struct sensor_trigger *tap_trigger;
54 	sensor_trigger_handler_t tap_handler;
55 
56 	const struct sensor_trigger *double_tap_trigger;
57 	sensor_trigger_handler_t double_tap_handler;
58 
59 #ifdef CONFIG_ICM42605_TRIGGER
60 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_ICM42605_THREAD_STACK_SIZE);
61 	struct k_thread thread;
62 	struct k_sem gpio_sem;
63 #endif
64 };
65 
66 struct icm42605_config {
67 	struct spi_dt_spec spi;
68 	struct gpio_dt_spec gpio_int;
69 	uint16_t accel_hz;
70 	uint16_t gyro_hz;
71 	uint16_t accel_fs;
72 	uint16_t gyro_fs;
73 };
74 
75 int icm42605_trigger_set(const struct device *dev,
76 			 const struct sensor_trigger *trig,
77 			 sensor_trigger_handler_t handler);
78 
79 int icm42605_init_interrupt(const struct device *dev);
80 
81 #endif /* __SENSOR_ICM42605__ */
82