10#ifndef M5_UNIT_IMU_UNIT_UNIT_MAG3110_DATA_HPP
11#define M5_UNIT_IMU_UNIT_UNIT_MAG3110_DATA_HPP
57constexpr uint32_t OUTPUT_RATE_MHZ[8] = {80000, 40000, 20000, 10000, 5000, 2500, 1250, 630};
64 return OUTPUT_RATE_MHZ[
static_cast<uint8_t
>(rate)] >>
static_cast<uint8_t
>(os);
77 return static_cast<uint8_t
>((
static_cast<uint8_t
>(rate) << 5) | (
static_cast<uint8_t
>(os) << 3) | 0x01);
81constexpr float RAW_UT_PER_LSB{0.10f};
83constexpr float OUTPUT_LSB_PER_UT{16.0f};
93 std::array<uint8_t, 7>
raw{};
98 return (
raw[0] & 0x08) != 0;
103 return static_cast<int16_t
>((
raw[1] << 8) |
raw[2]);
108 return static_cast<int16_t
>((
raw[3] << 8) |
raw[4]);
113 return static_cast<int16_t
>((
raw[5] << 8) |
raw[6]);
119 return rescale(
x_raw());
124 return rescale(
y_raw());
129 return rescale(
z_raw());
133 static inline int32_t rescale(
const int16_t raw_axis)
136 return static_cast<int32_t
>(lroundf(raw_axis * RAW_UT_PER_LSB * OUTPUT_LSB_PER_UT));
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
One MAG3110 sample: a 7-byte burst from DR_STATUS (0x00)
Definition unit_mag3110_data.hpp:92
int16_t y_raw() const
Raw Y.
Definition unit_mag3110_data.hpp:106
int16_t z_raw() const
Raw Z.
Definition unit_mag3110_data.hpp:111
int32_t adj_z() const
Z rescaled to the library-wide 16 LSB/µT.
Definition unit_mag3110_data.hpp:127
int16_t x_raw() const
Raw X (big-endian, signed 16bit)
Definition unit_mag3110_data.hpp:101
int32_t adj_x() const
X rescaled to the library-wide 16 LSB/µT.
Definition unit_mag3110_data.hpp:117
int32_t adj_y() const
Y rescaled to the library-wide 16 LSB/µT.
Definition unit_mag3110_data.hpp:122
std::array< uint8_t, 7 > raw
DR_STATUS + X/Y/Z (big-endian)
Definition unit_mag3110_data.hpp:93
bool drdy() const
Data ready (DR_STATUS bit3 ZYXDR: new data on one or more axes)
Definition unit_mag3110_data.hpp:96
constexpr uint8_t ctrl_reg1_active(const DataRate rate, const OverSampling os)
REG_CTRL_REG1 value entering continuous ACTIVE measurement (FR and TM left at 0)
Definition unit_mag3110_data.hpp:75
constexpr uint32_t output_rate_mhz(const DataRate rate, const OverSampling os)
Effective output rate in milli-Hz.
Definition unit_mag3110_data.hpp:62
DataRate
Output data rate select (REG_CTRL_REG1 DR[7:5])
Definition unit_mag3110_data.hpp:28
@ Rate80Hz
80Hz at X16 (ADC 1280Hz, 900µA)
@ Rate40Hz
40Hz at X16 (ADC 640Hz, 550µA)
@ Rate0_63Hz
0.63Hz at X16 (ADC 80Hz, 8.6µA)
@ Rate1_25Hz
1.25Hz at X16 (ADC 80Hz, 17.2µA)
@ Rate2_5Hz
2.5Hz at X16 (ADC 80Hz, 34.4µA)
@ Rate5Hz
5Hz at X16 (ADC 80Hz, 68.8µA)
OverSampling
Over sampling ratio (REG_CTRL_REG1 OS[4:3])
Definition unit_mag3110_data.hpp:47