1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #ifndef ZEPHYR_DRIVERS_SENSOR_MPU6050_MPU6050_H_ 8 #define ZEPHYR_DRIVERS_SENSOR_MPU6050_MPU6050_H_ 9 10 #include <zephyr/device.h> 11 #include <zephyr/drivers/i2c.h> 12 #include <zephyr/drivers/gpio.h> 13 #include <zephyr/kernel.h> 14 #include <zephyr/sys/util.h> 15 #include <zephyr/types.h> 16 17 #define MPU6050_REG_CHIP_ID 0x75 18 #define MPU6050_CHIP_ID 0x68 19 #define MPU9250_CHIP_ID 0x71 20 21 #define MPU6050_REG_GYRO_CFG 0x1B 22 #define MPU6050_GYRO_FS_SHIFT 3 23 24 #define MPU6050_REG_ACCEL_CFG 0x1C 25 #define MPU6050_ACCEL_FS_SHIFT 3 26 27 #define MPU6050_REG_INT_EN 0x38 28 #define MPU6050_DRDY_EN BIT(0) 29 30 #define MPU6050_REG_DATA_START 0x3B 31 32 #define MPU6050_REG_PWR_MGMT1 0x6B 33 #define MPU6050_SLEEP_EN BIT(6) 34 35 /* measured in degrees/sec x10 to avoid floating point */ 36 static const uint16_t mpu6050_gyro_sensitivity_x10[] = { 37 1310, 655, 328, 164 38 }; 39 40 struct mpu6050_data { 41 int16_t accel_x; 42 int16_t accel_y; 43 int16_t accel_z; 44 uint16_t accel_sensitivity_shift; 45 46 int16_t temp; 47 48 int16_t gyro_x; 49 int16_t gyro_y; 50 int16_t gyro_z; 51 uint16_t gyro_sensitivity_x10; 52 53 #ifdef CONFIG_MPU6050_TRIGGER 54 const struct device *dev; 55 struct gpio_callback gpio_cb; 56 57 const struct sensor_trigger *data_ready_trigger; 58 sensor_trigger_handler_t data_ready_handler; 59 60 #if defined(CONFIG_MPU6050_TRIGGER_OWN_THREAD) 61 K_KERNEL_STACK_MEMBER(thread_stack, CONFIG_MPU6050_THREAD_STACK_SIZE); 62 struct k_thread thread; 63 struct k_sem gpio_sem; 64 #elif defined(CONFIG_MPU6050_TRIGGER_GLOBAL_THREAD) 65 struct k_work work; 66 #endif 67 68 #endif /* CONFIG_MPU6050_TRIGGER */ 69 }; 70 71 struct mpu6050_config { 72 struct i2c_dt_spec i2c; 73 #ifdef CONFIG_MPU6050_TRIGGER 74 struct gpio_dt_spec int_gpio; 75 #endif /* CONFIG_MPU6050_TRIGGER */ 76 }; 77 78 #ifdef CONFIG_MPU6050_TRIGGER 79 int mpu6050_trigger_set(const struct device *dev, 80 const struct sensor_trigger *trig, 81 sensor_trigger_handler_t handler); 82 83 int mpu6050_init_interrupt(const struct device *dev); 84 #endif 85 86 #endif /* __SENSOR_MPU6050__ */ 87