M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
unit_mpu6886_data.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
10#ifndef M5_UNIT_IMU_UNIT_UNIT_MPU6886_DATA_HPP
11#define M5_UNIT_IMU_UNIT_UNIT_MPU6886_DATA_HPP
12
13#include <array>
14#include <cstdint>
15
16namespace m5 {
17namespace unit {
18namespace mpu6886 {
19
24enum class AccelRange : uint8_t {
25 G2,
26 G4,
27 G8,
28 G16,
29};
30
35enum class GyroRange : uint8_t {
36 DPS250,
37 DPS500,
38 DPS1000,
39 DPS2000,
40};
41
46enum class Dlpf : uint8_t {
47 BW250,
48 BW176,
49 BW92,
50 BW41,
51 BW20,
52 BW10,
53 BW5,
54 BW3281,
55};
56
58constexpr float accel_res(const AccelRange r)
59{
60 return (2.0f * (1 << static_cast<uint8_t>(r))) / 32768;
61}
63constexpr float gyro_res(const GyroRange r)
64{
65 return (250.0f * (1 << static_cast<uint8_t>(r))) / 32768;
66}
67
72struct Data {
73 std::array<uint8_t, 14> raw{};
74
78 inline int16_t accel_x() const
79 {
80 return static_cast<int16_t>((raw[0] << 8) | raw[1]);
81 }
83 inline int16_t accel_y() const
84 {
85 return static_cast<int16_t>((raw[2] << 8) | raw[3]);
86 }
88 inline int16_t accel_z() const
89 {
90 return static_cast<int16_t>((raw[4] << 8) | raw[5]);
91 }
93 inline int16_t temp_adc() const
94 {
95 return static_cast<int16_t>((raw[6] << 8) | raw[7]);
96 }
98 inline int16_t gyro_x() const
99 {
100 return static_cast<int16_t>((raw[8] << 8) | raw[9]);
101 }
103 inline int16_t gyro_y() const
104 {
105 return static_cast<int16_t>((raw[10] << 8) | raw[11]);
106 }
108 inline int16_t gyro_z() const
109 {
110 return static_cast<int16_t>((raw[12] << 8) | raw[13]);
111 }
113
115 inline float temperature() const
116 {
117 return temp_adc() / 326.8f + 25.0f;
118 }
119};
120
121} // namespace mpu6886
122} // namespace unit
123} // namespace m5
124#endif
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
Unit-related namespace.
One measurement (14 bytes burst from REG_ACCEL_XOUT_H, big-endian)
Definition unit_mpu6886_data.hpp:72
int16_t accel_x() const
Raw accelerometer X.
Definition unit_mpu6886_data.hpp:78
int16_t temp_adc() const
Raw temperature ADC.
Definition unit_mpu6886_data.hpp:93
int16_t gyro_x() const
Raw gyroscope X.
Definition unit_mpu6886_data.hpp:98
float temperature() const
Temperature in degC (T = adc/326.8 + 25.0)
Definition unit_mpu6886_data.hpp:115
int16_t accel_y() const
Raw accelerometer Y.
Definition unit_mpu6886_data.hpp:83
int16_t gyro_y() const
Raw gyroscope Y.
Definition unit_mpu6886_data.hpp:103
int16_t gyro_z() const
Raw gyroscope Z.
Definition unit_mpu6886_data.hpp:108
int16_t accel_z() const
Raw accelerometer Z.
Definition unit_mpu6886_data.hpp:88
std::array< uint8_t, 14 > raw
[0..5] accel, [6..7] temp, [8..13] gyro
Definition unit_mpu6886_data.hpp:73
AccelRange
Accelerometer full scale range (register value = enum << 3)
Definition unit_mpu6886_data.hpp:24
GyroRange
Gyroscope full scale range (register value = enum << 3)
Definition unit_mpu6886_data.hpp:35
Dlpf
Gyro/temp digital low pass filter (REG_CONFIG reg DLPF_CFG, valid when FCHOICE_B=00)
Definition unit_mpu6886_data.hpp:46
@ BW250
250Hz (gyro output 8kHz)
@ BW3281
3281Hz (8kHz)