M5Unit-IMU 0.0.2 git rev:e5b00aa
Loading...
Searching...
No Matches
m5::unit::UnitBMI270AuxBMM150 Class Reference

BMI270 that switches on its auxiliary (AUX) interface and drives a BMM150 through it. More...

#include <unit_bmi270_aux_bmm150.hpp>

Inheritance diagram for m5::unit::UnitBMI270AuxBMM150:
m5::unit::UnitBMI270 m5::imu::IMUDataSource

Classes

struct  config_t
 Settings for begin(), extending the base with the magnetometer's own. More...
 

Public Member Functions

 UnitBMI270AuxBMM150 (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the BMI270's I2C address (the AUX BMM150 sits behind the bridge)
 
virtual ~UnitBMI270AuxBMM150 ()
 Destructor.
 
virtual bool begin () override
 Seed the magnetometer's live state from config_t, then run the base begin()
 
bool sleep () override
 Suspend the chip, parking the AUX BMM150 first.
 
Settings
config_t config () const
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
IMUDataSource
virtual m5::imu::Capability imuSpec () const override
 Capability of this unit.
 
virtual void imuConvertParam (m5::imu::imu_convert_param_t &out) const override
 Gets the conversion parameters for raw IMU data.
 
AUX magnetometer setting (stop periodic measurement first)
bool writeAuxMagPreset (const bmm150::Preset preset)
 Write the accuracy/power preset of the AUX BMM150.
 
bool writeAuxMagRepetition (const uint8_t rep_xy, const uint8_t rep_z)
 Write the repetition (oversampling) of the AUX BMM150.
 
bool readAuxMagRepetition (uint8_t &rep_xy, uint8_t &rep_z) const
 Read the repetition (oversampling) the AUX BMM150 is configured with.
 
- Public Member Functions inherited from m5::unit::UnitBMI270
 UnitBMI270 (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the I2C address the chip will answer on.
 
virtual ~UnitBMI270 ()
 Destructor.
 
virtual void update (const bool force=false) override
 Update the unit.
 
config_t config () const
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
bool writeAccelRange (const bmi270::AccelRange range)
 Write the accelerometer range.
 
bool writeGyroRange (const bmi270::GyroRange range)
 Write the gyroscope range.
 
bool readAccelRange (bmi270::AccelRange &range)
 Read the accelerometer range from the device (REG_ACC_RANGE bits[1:0])
 
bool readGyroRange (bmi270::GyroRange &range)
 Read the gyroscope range from the device (REG_GYR_RANGE bits[2:0])
 
bool writeAccelODR (const bmi270::AccelODR odr)
 Write the accelerometer output data rate.
 
bool writeGyroODR (const bmi270::GyroODR odr)
 Write the gyroscope output data rate.
 
bool readAccelODR (bmi270::AccelODR &odr)
 Read the accelerometer output data rate from the device (REG_ACC_CONF bits[3:0])
 
bool readGyroODR (bmi270::GyroODR &odr)
 Read the gyroscope output data rate from the device (REG_GYR_CONF bits[3:0])
 
bool softReset ()
 Soft reset (REG_CMD CMD_SOFTRESET), then re-run the mandatory post-reset initialization (config blob re-upload), leaving the chip initialized but unconfigured and stopped.
 
bool startPeriodicMeasurement (const bmi270::AccelRange accel_range, const bmi270::GyroRange gyro_range, const bmi270::AccelODR accel_odr, const bmi270::GyroODR gyro_odr, const bmi270::FilterPerf accel_filter_perf, const bmi270::AccelBwp accel_bwp, const bmi270::FilterPerf gyro_filter_perf, const bmi270::GyroBwp gyro_bwp)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
bool wakeup () override
 Resume the chip from sleep()
 
virtual m5::imu::Capability readImuRaw (m5::imu::imu_raw_data_t &out) override
 Read the latest raw IMU data.
 

Protected Types

enum class  AuxDetect : uint8_t { Unknown , Absent , Present }
 

Protected Member Functions

virtual bool start_periodic_measurement (const bmi270::AccelRange accel_range, const bmi270::GyroRange gyro_range, const bmi270::AccelODR accel_odr, const bmi270::GyroODR gyro_odr, const bmi270::FilterPerf accel_filter_perf, const bmi270::AccelBwp accel_bwp, const bmi270::FilterPerf gyro_filter_perf, const bmi270::GyroBwp gyro_bwp) override
 
virtual bool read_sensor_burst (bmi270::Data &d) override
 One 20 byte burst covering mag + accel + gyro, instead of the base's 12 byte accel/gyro read.
 
bool setup_aux_bmm150 ()
 
bool aux_enter_setup_mode ()
 
bool aux_detect_bmm150 ()
 
bool aux_enter_data_mode ()
 
bool aux_wait_ready ()
 
bool aux_write_register8 (const uint8_t reg, const uint8_t val)
 
bool aux_read_register8 (const uint8_t reg, uint8_t &out)
 
bool aux_read_burst8 (const uint8_t bmm150_reg, std::array< uint8_t, 8 > &out)
 
bool aux_read_trim (bmm150::trim_t &trim)
 
- Protected Member Functions inherited from m5::unit::UnitBMI270
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (bmi270::Data &d)
 
bool write_register8_verified (const uint8_t reg, const uint8_t val)
 
bool read_register8_quiet (const uint8_t reg, uint8_t &out)
 
bool recover_wedged_interface (const uint8_t id)
 
bool upload_config ()
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitBMI270, bmi270::Data)
 

Detailed Description

BMI270 that switches on its auxiliary (AUX) interface and drives a BMM150 through it.

The BMI270's AUX interface is a general-purpose I2C master built into the chip – the datasheet calls it a "master interface hub for 1 I2C AUX sensor (e.g. ext. magnetometer, pressure)". This class implements one specific target, a Bosch BMM150: it addresses 0x10, checks for chip ID 0x32, reads that part's factory trim and drives its repetition/opmode registers. The name records that choice, since a different AUX target would need a different driver.

Which class to instantiate is a property of the board, not of the chip:

  • This class turns the interface on and probes for the BMM150. CoreS3 / AtomS3R / Mini IMU-Pro (U171) wire one there. Built-in IMUs in general should use it – the probe adapts to whatever the host actually carries, with no board table to keep up to date.
  • The plain UnitBMI270 never touches the interface. Use it where the wiring makes enabling it unsafe or pointless: on UnitDoF9 / UnitDoF10 the AUX pins are tied to the main I2C bus, so enabling them turns the BMI270 into a second bus master and the bus locks up until the unit is power-cycled; on UnitDoF6 there is simply no magnetometer.

Naming a chip here does not promise one is present – that is only known at runtime. On a host without a BMM150 (Capsule, StickS3, Core2 v1.3, ...) the probe finds nothing, the interface is switched back off, and the unit runs as a plain 6-axis BMI270. imuSpec() reports Mag only once a BMM150 has actually answered.

Note
The BMM350 in UnitDoF9 / UnitDoF10 / Unit BMM350 (U231) sits on the main bus, not on this interface, and is driven by UnitBMM350 instead
The bridge polls the BMM150 at a fixed 25Hz – the only rate the BMI270's aux_odr field and the BMM150's normal mode both offer – which bounds its usable oversampling; see config_t::aux_mag_preset

Member Enumeration Documentation

◆ AuxDetect

enum class m5::unit::UnitBMI270AuxBMM150::AuxDetect : uint8_t
strongprotected

Whether this board carries a BMM150 on the interface. Answered once, then remembered: re-running the detection below on every start costs a BMM150 soft reset plus three trim bursts, and the answer cannot change while the unit stays powered

Enumerator
Unknown 

Not probed yet, or invalidated by begin()/sleep()

Absent 

Nothing answered on the interface; it is left switched off.

Present 

A BMM150 answered and _mag_trim holds its factory trim.

Constructor & Destructor Documentation

◆ UnitBMI270AuxBMM150()

m5::unit::UnitBMI270AuxBMM150::UnitBMI270AuxBMM150 ( const uint8_t addr = DEFAULT_ADDRESS)
explicit

Construct with the BMI270's I2C address (the AUX BMM150 sits behind the bridge)

Parameters
[in]addrI2C address (defaults to the chip's factory address)

Member Function Documentation

◆ begin()

bool m5::unit::UnitBMI270AuxBMM150::begin ( )
overridevirtual

Seed the magnetometer's live state from config_t, then run the base begin()

Reimplemented from m5::unit::UnitBMI270.

◆ config() [1/2]

config_t m5::unit::UnitBMI270AuxBMM150::config ( ) const
inline

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

void m5::unit::UnitBMI270AuxBMM150::config ( const config_t & cfg)
inline

Set the configuration.

Parameters
[in]cfgConfiguration
Note
The inherited fields stay in the base's own storage, so reading them back through a UnitBMI270 reference always agrees with what was set here

◆ imuConvertParam()

void m5::unit::UnitBMI270AuxBMM150::imuConvertParam ( m5::imu::imu_convert_param_t & out) const
overridevirtual

Gets the conversion parameters for raw IMU data.

Parameters
[out]outConversion parameters

Reimplemented from m5::unit::UnitBMI270.

◆ imuSpec()

virtual m5::imu::Capability m5::unit::UnitBMI270AuxBMM150::imuSpec ( ) const
inlineoverridevirtual

Capability of this unit.

Returns
Accel | Gyro | Temp, plus Mag once an AUX BMM150 has been detected in startPeriodicMeasurement()

Reimplemented from m5::unit::UnitBMI270.

◆ read_sensor_burst()

bool m5::unit::UnitBMI270AuxBMM150::read_sensor_burst ( bmi270::Data & d)
overrideprotectedvirtual

One 20 byte burst covering mag + accel + gyro, instead of the base's 12 byte accel/gyro read.

Reimplemented from m5::unit::UnitBMI270.

◆ readAuxMagRepetition()

bool m5::unit::UnitBMI270AuxBMM150::readAuxMagRepetition ( uint8_t & rep_xy,
uint8_t & rep_z ) const

Read the repetition (oversampling) the AUX BMM150 is configured with.

Parameters
[out]rep_xyValue of REG_REP_XY
[out]rep_zValue of REG_REP_Z
Returns
True if successful
Note
Returns the value this unit applies to the magnetometer, not a fresh register read: the BMM150 is only reachable while the bridge is in setup mode, which periodic measurement is not

◆ sleep()

bool m5::unit::UnitBMI270AuxBMM150::sleep ( )
overridevirtual

Suspend the chip, parking the AUX BMM150 first.

Returns
True if successful

The magnetometer keeps running on its own once the bridge is gone, so it is put into its own suspend mode before the BMI270 powers down. Otherwise identical to UnitBMI270::sleep()

Reimplemented from m5::unit::UnitBMI270.

◆ start_periodic_measurement()

bool m5::unit::UnitBMI270AuxBMM150::start_periodic_measurement ( const bmi270::AccelRange accel_range,
const bmi270::GyroRange gyro_range,
const bmi270::AccelODR accel_odr,
const bmi270::GyroODR gyro_odr,
const bmi270::FilterPerf accel_filter_perf,
const bmi270::AccelBwp accel_bwp,
const bmi270::FilterPerf gyro_filter_perf,
const bmi270::GyroBwp gyro_bwp )
overrideprotectedvirtual

Reimplemented from m5::unit::UnitBMI270.

◆ writeAuxMagPreset()

bool m5::unit::UnitBMI270AuxBMM150::writeAuxMagPreset ( const bmm150::Preset preset)

Write the accuracy/power preset of the AUX BMM150.

Parameters
[in]presetPreset
Returns
True if successful
Note
Convenience wrapper around writeAuxMagRepetition() with the preset's repetition values

◆ writeAuxMagRepetition()

bool m5::unit::UnitBMI270AuxBMM150::writeAuxMagRepetition ( const uint8_t rep_xy,
const uint8_t rep_z )

Write the repetition (oversampling) of the AUX BMM150.

Parameters
[in]rep_xyValue of REG_REP_XY (repetitions = 1 + 2 * rep_xy)
[in]rep_zValue of REG_REP_Z (repetitions = 1 + rep_z)
Returns
True if successful
Warning
Fails while periodic measurement is running, and fails for a pair the bridge's fixed 25Hz poll cannot complete in time (bmm150::repetition_fits()); unlike a stand-alone UnitBMM150 there is no slower rate to fall back on, so the ceiling here is absolute
Note
The value is applied to the magnetometer by the next startPeriodicMeasurement(). While measurement is stopped the bridge is not in a state where the BMM150's registers can be reached, so nothing is written to it here