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

3-axis magnetometer unit. No standalone GROVE unit exists for this chip; it is found built into some boards (e.g. classic M5Stack Core/Fire, paired with MPU6886) and as the auxiliary sensor of UnitBMI270 More...

#include <unit_bmm150.hpp>

Inheritance diagram for m5::unit::UnitBMM150:
m5::imu::IMUDataSource

Classes

struct  config_t
 Settings for begin() More...
 

Public Member Functions

 UnitBMM150 (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the I2C address the chip will answer on.
 
virtual ~UnitBMM150 ()
 Destructor.
 
virtual bool begin () override
 Begin the unit.
 
virtual void update (const bool force=false) override
 Update the unit.
 
Settings
config_t config () const
 Gets the configuration.
 
void config (const config_t &cfg)
 Set the configuration.
 
Setting (applies immediately)
bool writePreset (const bmm150::Preset preset)
 Write the accuracy/power preset (REG_REP_XY/REG_REP_Z)
 
bool writeRepetition (const uint8_t rep_xy, const uint8_t rep_z)
 Write the repetition (oversampling) registers directly.
 
bool readRepetition (uint8_t &rep_xy, uint8_t &rep_z)
 Read the repetition registers from the device (REG_REP_XY/REG_REP_Z)
 
bool writeDataRate (const bmm150::DataRate rate)
 Write the output data rate.
 
bool readDataRate (bmm150::DataRate &rate)
 Read the output data rate from the device (REG_OP_MODE bits[5:3])
 
Reset
bool softReset ()
 Soft reset (REG_POWER_CONTROL soft-reset bits, keeping the power control bit on), leaving the chip initialized but unconfigured and stopped.
 
Periodic measurement
bool startPeriodicMeasurement (const bmm150::DataRate rate, const bmm150::Preset preset)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
Power
bool sleep () override
 Put the chip into suspend mode (REG_POWER_CONTROL power bit cleared)
 
bool wakeup () override
 Bring the chip out of suspend.
 
IMUDataSource
virtual m5::imu::Capability imuSpec () const override
 Capability of this unit.
 
virtual m5::imu::Capability readImuRaw (m5::imu::imu_raw_data_t &out) override
 Read the latest raw IMU data.
 
virtual void imuConvertParam (m5::imu::imu_convert_param_t &out) const override
 Gets the conversion parameters for raw IMU data.
 

Protected Member Functions

bool start_periodic_measurement (const bmm150::DataRate rate, const bmm150::Preset preset)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (bmm150::Data &d)
 
bool write_repetition_unchecked (const uint8_t rep_xy, const uint8_t rep_z)
 
bool write_data_rate_unchecked (const bmm150::DataRate rate)
 
bool write_register8_verified (const uint8_t reg, const uint8_t val)
 
bool read_trim (bmm150::trim_t &trim)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitBMM150, bmm150::Data)
 

Detailed Description

3-axis magnetometer unit. No standalone GROVE unit exists for this chip; it is found built into some boards (e.g. classic M5Stack Core/Fire, paired with MPU6886) and as the auxiliary sensor of UnitBMI270

Constructor & Destructor Documentation

◆ UnitBMM150()

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

Construct with the I2C address the chip will answer on.

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

Member Function Documentation

◆ config() [1/2]

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

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

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

Set the configuration.

Parameters
[in]cfgConfiguration

◆ imuConvertParam()

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

Gets the conversion parameters for raw IMU data.

Parameters
[out]outConversion parameters

Implements m5::imu::IMUDataSource.

◆ imuSpec()

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

Capability of this unit.

Returns
Mag (no temperature output on this chip)

Implements m5::imu::IMUDataSource.

◆ readDataRate()

bool m5::unit::UnitBMM150::readDataRate ( bmm150::DataRate & rate)

Read the output data rate from the device (REG_OP_MODE bits[5:3])

Parameters
[out]rateData rate
Returns
True if successful

◆ readImuRaw()

Capability m5::unit::UnitBMM150::readImuRaw ( m5::imu::imu_raw_data_t & out)
overridevirtual

Read the latest raw IMU data.

Parameters
[out]outRaw IMU data
Returns
Capability of the data actually stored in out (None if no data available)

Implements m5::imu::IMUDataSource.

◆ readRepetition()

bool m5::unit::UnitBMM150::readRepetition ( uint8_t & rep_xy,
uint8_t & rep_z )

Read the repetition registers from the device (REG_REP_XY/REG_REP_Z)

Parameters
[out]rep_xyREG_REP_XY value
[out]rep_zREG_REP_Z value
Returns
True if successful

◆ sleep()

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

Put the chip into suspend mode (REG_POWER_CONTROL power bit cleared)

Returns
True if successful

Works while periodic measurement is running: it is stopped first, since a suspended chip must not be polled. Suspend is the BMM150's lowest power state.

Warning
Suspend resets the register map, so the measurement settings do not survive it; startPeriodicMeasurement() re-applies the preset and data rate.

Reimplemented from m5::imu::IMUDataSource.

◆ softReset()

bool m5::unit::UnitBMM150::softReset ( )

Soft reset (REG_POWER_CONTROL soft-reset bits, keeping the power control bit on), leaving the chip initialized but unconfigured and stopped.

Returns
True if successful
Warning
During periodic measurements, an error is returned; call stopPeriodicMeasurement() first
All settings revert to the chip defaults; call startPeriodicMeasurement(...) to reconfigure and resume measurement

◆ startPeriodicMeasurement() [1/2]

bool m5::unit::UnitBMM150::startPeriodicMeasurement ( )

Start periodic measurement in the current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitBMM150::startPeriodicMeasurement ( const bmm150::DataRate rate,
const bmm150::Preset preset )

Start periodic measurement.

Parameters
rateOutput data rate
presetAccuracy/power preset (controls REG_REP_XY/REG_REP_Z)
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitBMM150::stopPeriodicMeasurement ( )

Stop periodic measurement.

Returns
True if successful

◆ update()

void m5::unit::UnitBMM150::update ( const bool force = false)
overridevirtual

Update the unit.

Parameters
[in]forceForces an update if true, even if not time for periodic measurement

◆ wakeup()

bool m5::unit::UnitBMM150::wakeup ( )
overridevirtual

Bring the chip out of suspend.

Returns
True if successful

Sets the power bit and waits for the chip to reach sleep mode, where its registers are writable again – measurement stays stopped. Call startPeriodicMeasurement() to reconfigure and resume sampling. Harmless without a preceding sleep().

Reimplemented from m5::imu::IMUDataSource.

◆ writeDataRate()

bool m5::unit::UnitBMM150::writeDataRate ( const bmm150::DataRate rate)

Write the output data rate.

Parameters
[in]rateData rate
Returns
True if successful, false if the current repetitions cannot keep up with the new rate
Warning
During periodic measurement runs, an error is returned

◆ writePreset()

bool m5::unit::UnitBMM150::writePreset ( const bmm150::Preset preset)

Write the accuracy/power preset (REG_REP_XY/REG_REP_Z)

Parameters
[in]presetPreset
Returns
True if successful, false if the preset cannot keep up with the current data rate
Note
Convenience wrapper around writeRepetition() with the preset's repetition values
Warning
During periodic measurement runs, an error is returned

◆ writeRepetition()

bool m5::unit::UnitBMM150::writeRepetition ( const uint8_t rep_xy,
const uint8_t rep_z )

Write the repetition (oversampling) registers directly.

Parameters
[in]rep_xyREG_REP_XY value; the sensor performs 1 + 2*rep_xy repetitions on X/Y
[in]rep_zREG_REP_Z value; the sensor performs 1 + rep_z repetitions on Z
Returns
True if successful, false if the repetitions cannot keep up with the current data rate

The four presets are only Bosch's recommendations – both registers accept any 8bit value. More repetitions means less noise but a longer measurement, so the pair is rejected when it cannot finish inside one output period (bmm150::repetition_fits()); raise it here by slowing the rate first. Register values, not repetition counts, because nXY can only be odd

Warning
During periodic measurement runs, an error is returned