M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
mag_detect.hpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2026 M5Stack Technology CO LTD
3 *
4 * SPDX-License-Identifier: MIT
5 */
17#ifndef M5_UNIT_IMU_IMU_MAG_DETECT_HPP
18#define M5_UNIT_IMU_IMU_MAG_DETECT_HPP
19
20#include <cstdint>
21
22namespace m5 {
23namespace unit {
24namespace imu {
25
27enum class MagKind : uint8_t {
28 None,
29 BMM150,
30 AK8963,
31 MAG3110,
32};
33
46template <class ReadReg>
48{
49 uint8_t id{};
50 if (read(static_cast<uint8_t>(0x0C), static_cast<uint8_t>(0x00), id) && id == 0x48) {
51 return MagKind::AK8963;
52 }
53 if (read(static_cast<uint8_t>(0x0E), static_cast<uint8_t>(0x07), id) && id == 0xC4) {
54 return MagKind::MAG3110;
55 }
56 if (read(static_cast<uint8_t>(0x10), static_cast<uint8_t>(0x40), id)) {
57 return MagKind::BMM150;
58 }
59 return MagKind::None;
60}
61
74template <class ReadReg, class WriteReg>
75bool enableAuxBypass(ReadReg read, WriteReg write)
76{
77 uint8_t id{};
78 if (!read(static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x75), id) || id != 0x71) {
79 return false; // not an MPU9250 -> nothing to bypass
80 }
81 uint8_t user_ctrl{};
82 if (!read(static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x6A), user_ctrl)) {
83 return false;
84 }
85 user_ctrl = static_cast<uint8_t>(user_ctrl & ~0x20); // clear I2C_MST_EN (bit5)
86 if (!write(static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x6A), user_ctrl)) {
87 return false;
88 }
89 if (!write(static_cast<uint8_t>(0x68), static_cast<uint8_t>(0x37), static_cast<uint8_t>(0x02))) {
90 return false; // INT_PIN_CFG BYPASS_EN (bit1)
91 }
92 return true;
93}
94
95} // namespace imu
96} // namespace unit
97} // namespace m5
98#endif
@ None
No accel/gyro responded (e.g. an IMU-less M5Stack Basic)
bool enableAuxBypass(ReadReg read, WriteReg write)
Open the MPU9250 I2C bypass so its internal AK8963 appears at 0x0C on the host bus.
Definition mag_detect.hpp:75
MagKind detectBuiltinMag(ReadReg read)
Probe the internal bus for a built-in magnetometer.
Definition mag_detect.hpp:47
MagKind
Which built-in magnetometer a classic M5Stack host carries.
Definition mag_detect.hpp:27
@ BMM150
Bosch BMM150 at 0x10.
@ MAG3110
NXP MAG3110 at 0x0E (original 2017 M5Stack Gray, paired with an MPU6050)
@ AK8963
AKM AK8963 (MPU9250-internal) at 0x0C.
Top level namespace of M5Stack.
Definition ahrs_controller.cpp:26
Unit-related namespace.