-
Notifications
You must be signed in to change notification settings - Fork 0
/
mpu6050.h
94 lines (80 loc) · 2.92 KB
/
mpu6050.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* File: mpu6050.h
* Author: luizg
*
* Created on 8 de Dezembro de 2018, 23:57
*/
#ifndef MPU6050_H
#define MPU6050_H
#include "system.h"
#define MPU6050_ADDRESS (0xD0)
#define MPU6050_REG_CONFIG (0x1A)
#define MPU6050_REG_GYRO_CONFIG (0x1B) // Gyroscope Configuration
#define MPU6050_REG_ACCEL_CONFIG (0x1C) // Accelerometer Configuration
#define MPU6050_REG_INT_PIN_CFG (0x37) // INT Pin. Bypass Enable Configuration
#define MPU6050_REG_INT_ENABLE (0x38) // INT Enable
#define MPU6050_REG_INT_STATUS (0x3A)
#define MPU6050_REG_ACCEL_XOUT_H (0x3B)
#define MPU6050_REG_ACCEL_XOUT_L (0x3C)
#define MPU6050_REG_ACCEL_YOUT_H (0x3D)
#define MPU6050_REG_ACCEL_YOUT_L (0x3E)
#define MPU6050_REG_ACCEL_ZOUT_H (0x3F)
#define MPU6050_REG_ACCEL_ZOUT_L (0x40)
#define MPU6050_REG_TEMP_OUT_H (0x41)
#define MPU6050_REG_TEMP_OUT_L (0x42)
#define MPU6050_REG_GYRO_XOUT_H (0x43)
#define MPU6050_REG_GYRO_XOUT_L (0x44)
#define MPU6050_REG_GYRO_YOUT_H (0x45)
#define MPU6050_REG_GYRO_YOUT_L (0x46)
#define MPU6050_REG_GYRO_ZOUT_H (0x47)
#define MPU6050_REG_GYRO_ZOUT_L (0x48)
#define MPU6050_REG_MOT_DETECT_STATUS (0x61)
#define MPU6050_REG_MOT_DETECT_CTRL (0x69)
#define MPU6050_REG_USER_CTRL (0x6A) // User Control
#define MPU6050_REG_PWR_MGMT_1 (0x6B) // Power Management 1
#define MPU6050_REG_WHO_AM_I (0x75) // Who Am I
typedef struct { float x, y, z; } vec3f;
typedef struct {
float dpsPerDigit;
float rangePerDigit;
} mpu_data_t;
typedef enum
{
MPU6050_CLOCK_KEEP_RESET = 0b111,
MPU6050_CLOCK_EXTERNAL_19MHZ = 0b101,
MPU6050_CLOCK_EXTERNAL_32KHZ = 0b100,
MPU6050_CLOCK_PLL_ZGYRO = 0b011,
MPU6050_CLOCK_PLL_YGYRO = 0b010,
MPU6050_CLOCK_PLL_XGYRO = 0b001,
MPU6050_CLOCK_INTERNAL_8MHZ = 0b000
} mpu6050_clockSource_t;
typedef enum
{
MPU6050_SCALE_2000DPS = 0b11,
MPU6050_SCALE_1000DPS = 0b10,
MPU6050_SCALE_500DPS = 0b01,
MPU6050_SCALE_250DPS = 0b00
} mpu6050_dps_t;
typedef enum
{
MPU6050_RANGE_16G = 0b11,
MPU6050_RANGE_8G = 0b10,
MPU6050_RANGE_4G = 0b01,
MPU6050_RANGE_2G = 0b00,
} mpu6050_range_t;
mpu_data_t MPU;
int MPU_Init(mpu6050_range_t range, mpu6050_dps_t scale);
void MPU_GetGyro(vec3f* out);
void MPU_GetAccel(vec3f* out);
void MPU_SetClockSource(mpu6050_clockSource_t source);
void MPU_SetScale(mpu6050_dps_t scale);
void MPU_SetRange(mpu6050_range_t range);
void MPU_SetSleepEnabled(byte state);
//<editor-fold desc="I2C Helpers" defaultstate="collapsed">
byte MPU_ReadRegister(byte reg);
void MPU_WriteRegister(byte reg, byte value);
int MPU_ReadRegister16(byte reg);
void MPU_WriteRegister16(byte reg, int value);
void MPU_WriteRegisterBit(byte reg, byte pos, byte state);
//</editor-fold>
#endif /* MPU6050_H */