M5Unified
MPU6886_Class.hpp
Go to the documentation of this file.
1 // Copyright (c) M5Stack. All rights reserved.
2 // Licensed under the MIT license. See LICENSE file in the project root for full license information.
3 
4 #ifndef __M5_MPU6886_CLASS_H__
5 #define __M5_MPU6886_CLASS_H__
6 
7 #include "IMU_Base.hpp"
8 
9 namespace m5
10 {
11  class MPU6886_Class : public IMU_Base
12  {
13  public:
14  static constexpr const std::uint8_t DEV_ID_MPU6886 = 0x19;
15  static constexpr const std::uint8_t DEV_ID_MPU6050 = 0x68;
16  static constexpr const std::uint8_t DEV_ID_MPU9250 = 0x71;
17 
18  static constexpr const std::uint8_t REG_WHOAMI = 0x75;
19  static constexpr const std::uint8_t REG_ACCEL_INTEL_CTRL = 0x69;
20  static constexpr const std::uint8_t REG_SMPLRT_DIV = 0x19;
21  static constexpr const std::uint8_t REG_INT_PIN_CFG = 0x37;
22  static constexpr const std::uint8_t REG_INT_ENABLE = 0x38;
23  static constexpr const std::uint8_t REG_ACCEL_XOUT_H = 0x3B;
24  static constexpr const std::uint8_t REG_ACCEL_XOUT_L = 0x3C;
25  static constexpr const std::uint8_t REG_ACCEL_YOUT_H = 0x3D;
26  static constexpr const std::uint8_t REG_ACCEL_YOUT_L = 0x3E;
27  static constexpr const std::uint8_t REG_ACCEL_ZOUT_H = 0x3F;
28  static constexpr const std::uint8_t REG_ACCEL_ZOUT_L = 0x40;
29 
30  static constexpr const std::uint8_t REG_TEMP_OUT_H = 0x41;
31  static constexpr const std::uint8_t REG_TEMP_OUT_L = 0x42;
32 
33  static constexpr const std::uint8_t REG_GYRO_XOUT_H = 0x43;
34  static constexpr const std::uint8_t REG_GYRO_XOUT_L = 0x44;
35  static constexpr const std::uint8_t REG_GYRO_YOUT_H = 0x45;
36  static constexpr const std::uint8_t REG_GYRO_YOUT_L = 0x46;
37  static constexpr const std::uint8_t REG_GYRO_ZOUT_H = 0x47;
38  static constexpr const std::uint8_t REG_GYRO_ZOUT_L = 0x48;
39 
40  static constexpr const std::uint8_t REG_USER_CTRL = 0x6A;
41  static constexpr const std::uint8_t REG_PWR_MGMT_1 = 0x6B;
42  static constexpr const std::uint8_t REG_PWR_MGMT_2 = 0x6C;
43  static constexpr const std::uint8_t REG_CONFIG = 0x1A;
44  static constexpr const std::uint8_t REG_GYRO_CONFIG = 0x1B;
45  static constexpr const std::uint8_t REG_ACCEL_CONFIG = 0x1C;
46  static constexpr const std::uint8_t REG_ACCEL_CONFIG2 = 0x1D;
47  static constexpr const std::uint8_t REG_LP_MODE_CFG = 0x1E;
48  static constexpr const std::uint8_t REG_FIFO_EN = 0x23;
49 
50  static constexpr const std::uint8_t REG_FIFO_COUNTH = 0x72;
51  static constexpr const std::uint8_t REG_FIFO_R_W = 0x74;
52 
53  enum Ascale
54  { AFS_2G = 0
58  };
59 
60  enum Gscale
61  { GFS_250DPS = 0
65  };
66 
67  enum Fodr
68  { ODR_1kHz = 0
69  , ODR_500Hz = 1
70  // , ODR_333Hz = 2
71  , ODR_250Hz = 3
72  , ODR_200Hz = 4
73  // , ODR_166Hz = 5
74  // , ODR_143Hz = 6
75  , ODR_125Hz = 7
76  // , ODR_111Hz = 8
77  , ODR_100Hz = 9
78  , ODR_50Hz = 19
79  , ODR_10Hz = 99
80  };
81 
82  static constexpr std::uint8_t DEFAULT_ADDRESS = 0x68;
83 
84  virtual ~MPU6886_Class();
85  MPU6886_Class(std::uint8_t i2c_addr = DEFAULT_ADDRESS, std::uint32_t freq = 400000, I2C_Class* i2c = &In_I2C);
86 
87  imu_spec_t begin(I2C_Class* i2c = nullptr) override;
88  imu_spec_t getImuRawData(imu_raw_data_t* data) const override;
90  bool getTempAdc(int16_t* adc) const override;
91 /*
92  bool getAccelAdc(std::int16_t* ax, std::int16_t* ay, std::int16_t* az) const override;
93  bool getGyroAdc(std::int16_t* gx, std::int16_t* gy, std::int16_t* gz) const override;
94  bool getAccel(float* ax, float* ay, float* az) const override;
95  bool getGyro(float* gx, float* gy, float* gz) const override;
96  bool getTemp(float* t) const override;
97 //*/
98  void enableFIFO(Fodr output_data_rate);
99  // void disableFIFO(void);
100 
101  bool setGyroAdcOffset(std::int16_t gx, std::int16_t gy, std::int16_t gz);
102  bool setINTPinActiveLogic(bool level) override;
103 
104  std::uint8_t whoAmI(void) const { return _device_id; }
105 
106  protected:
107  void setGyroFsr(Gscale scale);
108  void setAccelFsr(Ascale scale);
109 
110  bool _fifo_en;
111  float _aRes, _gRes;
114  std::uint8_t _device_id = 0;
115  };
116 }
117 
118 #endif
static constexpr const std::uint8_t REG_GYRO_ZOUT_L
static constexpr const std::uint8_t REG_LP_MODE_CFG
static constexpr const std::uint8_t DEV_ID_MPU9250
imu_spec_t begin(I2C_Class *i2c=nullptr) override
static constexpr const std::uint8_t REG_ACCEL_ZOUT_H
static constexpr const std::uint8_t REG_PWR_MGMT_1
static constexpr const std::uint8_t DEV_ID_MPU6050
static constexpr const std::uint8_t DEV_ID_MPU6886
static constexpr const std::uint8_t REG_FIFO_EN
static constexpr const std::uint8_t REG_GYRO_XOUT_L
static constexpr const std::uint8_t REG_ACCEL_XOUT_L
bool setGyroAdcOffset(std::int16_t gx, std::int16_t gy, std::int16_t gz)
static constexpr const std::uint8_t REG_FIFO_COUNTH
static constexpr const std::uint8_t REG_GYRO_CONFIG
static constexpr const std::uint8_t REG_GYRO_ZOUT_H
virtual ~MPU6886_Class()
static constexpr const std::uint8_t REG_GYRO_YOUT_L
static constexpr std::uint8_t DEFAULT_ADDRESS
static constexpr const std::uint8_t REG_ACCEL_YOUT_H
static constexpr const std::uint8_t REG_SMPLRT_DIV
static constexpr const std::uint8_t REG_CONFIG
static constexpr const std::uint8_t REG_ACCEL_CONFIG2
static constexpr const std::uint8_t REG_TEMP_OUT_L
static constexpr const std::uint8_t REG_ACCEL_INTEL_CTRL
std::uint8_t _device_id
static constexpr const std::uint8_t REG_PWR_MGMT_2
static constexpr const std::uint8_t REG_WHOAMI
imu_spec_t getImuRawData(imu_raw_data_t *data) const override
static constexpr const std::uint8_t REG_FIFO_R_W
MPU6886_Class(std::uint8_t i2c_addr=DEFAULT_ADDRESS, std::uint32_t freq=400000, I2C_Class *i2c=&In_I2C)
static constexpr const std::uint8_t REG_ACCEL_CONFIG
std::uint8_t whoAmI(void) const
void setAccelFsr(Ascale scale)
static constexpr const std::uint8_t REG_INT_PIN_CFG
static constexpr const std::uint8_t REG_GYRO_XOUT_H
static constexpr const std::uint8_t REG_ACCEL_ZOUT_L
bool setINTPinActiveLogic(bool level) override
static constexpr const std::uint8_t REG_TEMP_OUT_H
static constexpr const std::uint8_t REG_ACCEL_XOUT_H
static constexpr const std::uint8_t REG_INT_ENABLE
void enableFIFO(Fodr output_data_rate)
static constexpr const std::uint8_t REG_USER_CTRL
static constexpr const std::uint8_t REG_ACCEL_YOUT_L
void getConvertParam(imu_convert_param_t *param) const
void setGyroFsr(Gscale scale)
bool getTempAdc(int16_t *adc) const override
static constexpr const std::uint8_t REG_GYRO_YOUT_H
Definition: M5Unified.cpp:48
I2C_Class In_I2C
for internal I2C device
Definition: I2C_Class.cpp:10