1 /*
2  * Copyright (c) 2021, Nordic Semiconductor ASA
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_DRIVERS_SENSOR_MPU9250_MPU9250_H_
8 #define ZEPHYR_DRIVERS_SENSOR_MPU9250_MPU9250_H_
9 
10 #include <stdint.h>
11 #include <zephyr/device.h>
12 #include <zephyr/drivers/gpio.h>
13 #include <zephyr/drivers/i2c.h>
14 #include <zephyr/drivers/sensor.h>
15 #include <zephyr/kernel.h>
16 
17 struct mpu9250_data {
18 	int16_t accel_x;
19 	int16_t accel_y;
20 	int16_t accel_z;
21 	uint16_t accel_sensitivity_shift;
22 
23 	int16_t temp;
24 
25 	int16_t gyro_x;
26 	int16_t gyro_y;
27 	int16_t gyro_z;
28 	uint16_t gyro_sensitivity_x10;
29 
30 #ifdef CONFIG_MPU9250_MAGN_EN
31 	int16_t magn_x;
32 	int16_t magn_scale_x;
33 	int16_t magn_y;
34 	int16_t magn_scale_y;
35 	int16_t magn_z;
36 	int16_t magn_scale_z;
37 	uint8_t magn_st2;
38 #endif
39 
40 #ifdef CONFIG_MPU9250_TRIGGER
41 	const struct device *dev;
42 	struct gpio_callback gpio_cb;
43 
44 	const struct sensor_trigger *data_ready_trigger;
45 	sensor_trigger_handler_t data_ready_handler;
46 
47 #if defined(CONFIG_MPU9250_TRIGGER_OWN_THREAD)
48 	K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_MPU9250_THREAD_STACK_SIZE);
49 	struct k_thread thread;
50 	struct k_sem gpio_sem;
51 #elif defined(CONFIG_MPU9250_TRIGGER_GLOBAL_THREAD)
52 	struct k_work work;
53 #endif
54 
55 #endif /* CONFIG_MPU9250_TRIGGER */
56 };
57 
58 struct mpu9250_config {
59 	const struct i2c_dt_spec i2c;
60 	uint8_t gyro_sr_div;
61 	uint8_t gyro_dlpf;
62 	uint8_t gyro_fs;
63 	uint8_t accel_fs;
64 	uint8_t accel_dlpf;
65 #ifdef CONFIG_MPU9250_TRIGGER
66 	const struct gpio_dt_spec int_pin;
67 #endif /* CONFIG_MPU9250_TRIGGER */
68 };
69 
70 #ifdef CONFIG_MPU9250_TRIGGER
71 int mpu9250_trigger_set(const struct device *dev,
72 			const struct sensor_trigger *trig,
73 			sensor_trigger_handler_t handler);
74 
75 int mpu9250_init_interrupt(const struct device *dev);
76 #endif
77 
78 #endif /* ZEPHYR_DRIVERS_SENSOR_MPU9250_MPU9250_H_ */
79