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>
|
|
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) |
| |
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
◆ UnitBMM150()
| m5::unit::UnitBMM150::UnitBMM150 |
( |
const uint8_t | addr = DEFAULT_ADDRESS | ) |
|
|
explicit |
Construct with the I2C address the chip will answer on.
- Parameters
-
| [in] | addr | I2C address (defaults to the chip's factory address) |
◆ 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
-
◆ imuConvertParam()
Gets the conversion parameters for raw IMU data.
- Parameters
-
| [out] | out | Conversion parameters |
Implements m5::imu::IMUDataSource.
◆ imuSpec()
◆ readDataRate()
Read the output data rate from the device (REG_OP_MODE bits[5:3])
- Parameters
-
- Returns
- True if successful
◆ readImuRaw()
Read the latest raw IMU data.
- Parameters
-
- 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_xy | REG_REP_XY value |
| [out] | rep_z | REG_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]
Start periodic measurement.
- Parameters
-
| rate | Output data rate |
| preset | Accuracy/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] | force | Forces 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()
Write the output data rate.
- Parameters
-
- 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()
Write the accuracy/power preset (REG_REP_XY/REG_REP_Z)
- Parameters
-
- 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_xy | REG_REP_XY value; the sensor performs 1 + 2*rep_xy repetitions on X/Y |
| [in] | rep_z | REG_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