2016-05-31 15:53:22 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2016 Intel Corporation
|
|
|
|
*
|
2017-01-19 09:01:01 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2016-05-31 15:53:22 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __SENSOR_MPU6050_H__
|
|
|
|
#define __SENSOR_MPU6050_H__
|
|
|
|
|
|
|
|
#include <device.h>
|
|
|
|
#include <gpio.h>
|
|
|
|
#include <misc/util.h>
|
Introduce new sized integer typedefs
This is a start to move away from the C99 {u}int{8,16,32,64}_t types to
Zephyr defined u{8,16,32,64}_t and s{8,16,32,64}_t. This allows Zephyr
to define the sized types in a consistent manor across all the
architectures we support and not conflict with what various compilers
and libc might do with regards to the C99 types.
We introduce <zephyr/types.h> as part of this and have it include
<stdint.h> for now until we transition all the code away from the C99
types.
We go with u{8,16,32,64}_t and s{8,16,32,64}_t as there are some
existing variables defined u8 & u16 as well as to be consistent with
Zephyr naming conventions.
Jira: ZEP-2051
Change-Id: I451fed0623b029d65866622e478225dfab2c0ca8
Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
2017-04-19 23:32:08 +08:00
|
|
|
#include <zephyr/types.h>
|
2016-05-31 15:53:22 +08:00
|
|
|
|
|
|
|
#define SYS_LOG_DOMAIN "MPU6050"
|
2016-10-06 00:49:41 +08:00
|
|
|
#define SYS_LOG_LEVEL CONFIG_SYS_LOG_SENSOR_LEVEL
|
2016-12-18 01:56:56 +08:00
|
|
|
#include <logging/sys_log.h>
|
2016-05-31 15:53:22 +08:00
|
|
|
|
|
|
|
#define MPU6050_REG_CHIP_ID 0x75
|
|
|
|
#define MPU6050_CHIP_ID 0x68
|
|
|
|
|
|
|
|
#define MPU6050_REG_GYRO_CFG 0x1B
|
|
|
|
#define MPU6050_GYRO_FS_SHIFT 3
|
|
|
|
|
|
|
|
#define MPU6050_REG_ACCEL_CFG 0x1C
|
|
|
|
#define MPU6050_ACCEL_FS_SHIFT 3
|
|
|
|
|
|
|
|
#define MPU6050_REG_INT_EN 0x38
|
|
|
|
#define MPU6050_DRDY_EN BIT(0)
|
|
|
|
|
|
|
|
#define MPU6050_REG_DATA_START 0x3B
|
|
|
|
|
|
|
|
#define MPU6050_REG_PWR_MGMT1 0x6B
|
|
|
|
#define MPU6050_SLEEP_EN BIT(6)
|
|
|
|
|
|
|
|
/* measured in degrees/sec x10 to avoid floating point */
|
2017-04-21 23:03:20 +08:00
|
|
|
static const u16_t mpu6050_gyro_sensitivity_x10[] = {
|
2016-05-31 15:53:22 +08:00
|
|
|
1310, 655, 328, 164
|
|
|
|
};
|
|
|
|
|
|
|
|
struct mpu6050_data {
|
|
|
|
struct device *i2c;
|
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
s16_t accel_x;
|
|
|
|
s16_t accel_y;
|
|
|
|
s16_t accel_z;
|
|
|
|
u16_t accel_sensitivity_shift;
|
2016-05-31 15:53:22 +08:00
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
s16_t temp;
|
2016-05-31 15:53:22 +08:00
|
|
|
|
2017-04-21 23:03:20 +08:00
|
|
|
s16_t gyro_x;
|
|
|
|
s16_t gyro_y;
|
|
|
|
s16_t gyro_z;
|
|
|
|
u16_t gyro_sensitivity_x10;
|
2016-05-31 15:53:22 +08:00
|
|
|
|
|
|
|
#ifdef CONFIG_MPU6050_TRIGGER
|
|
|
|
struct device *gpio;
|
|
|
|
struct gpio_callback gpio_cb;
|
|
|
|
|
|
|
|
struct sensor_trigger data_ready_trigger;
|
|
|
|
sensor_trigger_handler_t data_ready_handler;
|
|
|
|
|
2016-11-10 23:05:53 +08:00
|
|
|
#if defined(CONFIG_MPU6050_TRIGGER_OWN_THREAD)
|
2017-06-03 05:08:45 +08:00
|
|
|
K_THREAD_STACK_MEMBER(thread_stack, CONFIG_MPU6050_THREAD_STACK_SIZE);
|
2017-05-10 02:59:40 +08:00
|
|
|
struct k_thread thread;
|
2016-11-10 21:21:34 +08:00
|
|
|
struct k_sem gpio_sem;
|
2016-11-10 23:05:53 +08:00
|
|
|
#elif defined(CONFIG_MPU6050_TRIGGER_GLOBAL_THREAD)
|
2016-11-10 21:21:34 +08:00
|
|
|
struct k_work work;
|
2016-05-31 15:53:22 +08:00
|
|
|
struct device *dev;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* CONFIG_MPU6050_TRIGGER */
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef CONFIG_MPU6050_TRIGGER
|
|
|
|
int mpu6050_trigger_set(struct device *dev,
|
|
|
|
const struct sensor_trigger *trig,
|
|
|
|
sensor_trigger_handler_t handler);
|
|
|
|
|
|
|
|
int mpu6050_init_interrupt(struct device *dev);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* __SENSOR_MPU6050__ */
|