M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
mag_detect.hpp File Reference

Framework-agnostic detection of a classic M5Stack built-in magnetometer. More...

#include <cstdint>

Go to the source code of this file.

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Enumerations

enum class  m5::unit::imu::MagKind : uint8_t { None , BMM150 , AK8963 , MAG3110 }
 Which built-in magnetometer a classic M5Stack host carries. More...
 

Functions

template<class ReadReg >
MagKind m5::unit::imu::detectBuiltinMag (ReadReg read)
 Probe the internal bus for a built-in magnetometer.
 
template<class ReadReg , class WriteReg >
bool m5::unit::imu::enableAuxBypass (ReadReg read, WriteReg write)
 Open the MPU9250 I2C bypass so its internal AK8963 appears at 0x0C on the host bus.
 

Detailed Description

Framework-agnostic detection of a classic M5Stack built-in magnetometer.

Classic M5Stack hosts (Basic/Gray/Fire and StickC) carry a version-dependent magnetometer that M5.getBoard() cannot distinguish: a BMM150 at 0x10 (SH200Q/MPU6886 generations) or the AK8963 embedded in an MPU9250 at 0x0C (original generation). These helpers probe the bus via injected callbacks so src/ stays independent of M5Unified / Arduino Wire (same pattern as m5::unit::bmi270::detectAddress). Note: m5::unit::imu here is distinct from the m5::imu namespace that holds the AHRS types.

Enumeration Type Documentation

◆ MagKind

enum class m5::unit::imu::MagKind : uint8_t
strong

Which built-in magnetometer a classic M5Stack host carries.

Enumerator
None 

No magnetometer responded (e.g. an IMU-less M5Stack Basic)

BMM150 

Bosch BMM150 at 0x10.

AK8963 

AKM AK8963 (MPU9250-internal) at 0x0C.

MAG3110 

NXP MAG3110 at 0x0E (original 2017 M5Stack Gray, paired with an MPU6050)

Function Documentation

◆ detectBuiltinMag()

template<class ReadReg >
MagKind m5::unit::imu::detectBuiltinMag ( ReadReg read)

Probe the internal bus for a built-in magnetometer.

Template Parameters
ReadRegCallable bool(uint8_t addr, uint8_t reg, uint8_t& out) returning true on ACK
Parameters
readThe bus read callable
Returns
The detected magnetometer kind

AK8963 (0x0C) and MAG3110 (0x0E) are checked first by their definitive WHO_AM_I ids (0x48 / 0xC4, readable any time; distinct addresses so no conflict). BMM150 is then detected by presence at 0x10: its CHIP_ID reads 0x00 while the chip is suspended (power-on default), so an ACK at 0x10 is treated as BMM150 (UnitBMM150::begin() does the authoritative CHIP_ID check after powering the chip). MAG3110 sits directly on the bus (no bypass); for AK8963 to be visible at 0x0C behind an MPU9250, call enableAuxBypass() first.

◆ enableAuxBypass()

template<class ReadReg , class WriteReg >
bool m5::unit::imu::enableAuxBypass ( ReadReg read,
WriteReg write )

Open the MPU9250 I2C bypass so its internal AK8963 appears at 0x0C on the host bus.

Template Parameters
ReadRegCallable bool(uint8_t addr, uint8_t reg, uint8_t& out)
WriteRegCallable bool(uint8_t addr, uint8_t reg, uint8_t val)
Parameters
readThe bus read callable
writeThe bus write callable
Returns
true if an MPU9250 was found and bypass enabled; false if no MPU9250 (a BMM150-direct board, or no IMU) – in which case no registers are written

Only the MPU9250 hides its magnetometer behind an aux I2C master; MPU6886/BMM150 boards expose the mag directly, so this is a no-op there. Requires the host IMU to not be concurrently owned (run with M5.config().internal_imu = false).