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

6-axis (accel + gyro) IMU unit. CoreS3/AtomS3R built-in More...

#include <unit_bmi270.hpp>

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

Classes

struct  config_t
 Settings for begin() More...
 

Public Member Functions

 UnitBMI270 (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the I2C address the chip will answer on.
 
virtual ~UnitBMI270 ()
 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.
 
Range setting (stop periodic measurement first)
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])
 
Output data rate (stop periodic measurement first)
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])
 
Reset
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.
 
Periodic measurement
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.
 
Power
bool sleep () override
 Suspend the chip (REG_PWR_CTRL off, REG_PWR_CONF adv_power_save)
 
bool wakeup () override
 Resume the chip from sleep()
 
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

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)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (bmi270::Data &d)
 
virtual bool read_sensor_burst (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

6-axis (accel + gyro) IMU unit. CoreS3/AtomS3R built-in

Note
Accel/gyro/temp only. The chip's auxiliary (AUX) interface, which can drive an on-chip BMM150 magnetometer, is deliberately left untouched here – use UnitBMI270AuxBMM150 on the boards that wire one to it (CoreS3, AtomS3R, Mini IMU-Pro). Enabling it is not always safe: on UnitDoF9/UnitDoF10 the AUX pins share the main I2C bus, and switching the interface on makes the BMI270 a second bus master, locking the bus until the unit is power-cycled

Constructor & Destructor Documentation

◆ UnitBMI270()

m5::unit::UnitBMI270::UnitBMI270 ( 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

◆ begin()

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

Begin the unit.

Reimplemented in m5::unit::UnitBMI270AuxBMM150.

◆ config() [1/2]

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

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

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

Set the configuration.

Parameters
[in]cfgConfiguration

◆ imuConvertParam()

void m5::unit::UnitBMI270::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.

Reimplemented in m5::unit::UnitBMI270AuxBMM150.

◆ imuSpec()

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

Capability of this unit.

Returns
Accel | Gyro | Temp. This class leaves the AUX interface alone, so never Mag – see UnitBMI270AuxBMM150 for the boards that wire a magnetometer to it

Implements m5::imu::IMUDataSource.

Reimplemented in m5::unit::UnitBMI270AuxBMM150.

◆ read_sensor_burst()

bool m5::unit::UnitBMI270::read_sensor_burst ( bmi270::Data & d)
protectedvirtual

Reimplemented in m5::unit::UnitBMI270AuxBMM150.

◆ readAccelODR()

bool m5::unit::UnitBMI270::readAccelODR ( bmi270::AccelODR & odr)

Read the accelerometer output data rate from the device (REG_ACC_CONF bits[3:0])

Parameters
[out]odrAccelerometer output data rate
Returns
True if successful, false if the register holds a reserved (unmapped) value

◆ readAccelRange()

bool m5::unit::UnitBMI270::readAccelRange ( bmi270::AccelRange & range)

Read the accelerometer range from the device (REG_ACC_RANGE bits[1:0])

Parameters
[out]rangeAccelerometer range
Returns
True if successful

◆ readGyroODR()

bool m5::unit::UnitBMI270::readGyroODR ( bmi270::GyroODR & odr)

Read the gyroscope output data rate from the device (REG_GYR_CONF bits[3:0])

Parameters
[out]odrGyroscope output data rate
Returns
True if successful, false if the register holds a reserved (unmapped) value

◆ readGyroRange()

bool m5::unit::UnitBMI270::readGyroRange ( bmi270::GyroRange & range)

Read the gyroscope range from the device (REG_GYR_RANGE bits[2:0])

Parameters
[out]rangeGyroscope range
Returns
True if successful, false if the register holds a reserved (unmapped) value

◆ readImuRaw()

Capability m5::unit::UnitBMI270::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.

◆ sleep()

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

Suspend the chip (REG_PWR_CTRL off, REG_PWR_CONF adv_power_save)

Returns
True if successful

Works while periodic measurement is running: it is stopped first, since a suspended chip must not be polled. Then accel/gyro/temp are powered down and advanced power save is enabled. The uploaded configuration file survives suspend – unlike softReset(), which requires the full post-reset initialization again.

Reimplemented from m5::imu::IMUDataSource.

Reimplemented in m5::unit::UnitBMI270AuxBMM150.

◆ softReset()

bool m5::unit::UnitBMI270::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.

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::UnitBMI270::startPeriodicMeasurement ( )

Start periodic measurement in the current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitBMI270::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.

Parameters
accel_rangeAccelerometer range
gyro_rangeGyroscope range
accel_odrAccelerometer output data rate
gyro_odrGyroscope output data rate (periodic measurement interval is derived from this)
accel_filter_perfAccelerometer filter performance mode
accel_bwpAccelerometer bandwidth parameter
gyro_filter_perfGyroscope filter performance mode
gyro_bwpGyroscope bandwidth parameter
Returns
True if successful, false if accel_bwp is reserved in accel_filter_perf (bmi270::bwp_fits())
Note
Every field of REG_ACC_CONF/REG_GYR_CONF is an argument so that starting never depends on config_t, which only begin() reads
UnitBMI270AuxBMM150 overrides this to also (re)probe and configure its AUX BMM150

◆ stopPeriodicMeasurement()

bool m5::unit::UnitBMI270::stopPeriodicMeasurement ( )

Stop periodic measurement.

Returns
True if successful

◆ update()

void m5::unit::UnitBMI270::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::UnitBMI270::wakeup ( )
overridevirtual

Resume the chip from sleep()

Returns
True if successful

Leaves advanced power save (configuration writes are ignored while it is active) and powers accel/gyro/temp back on – measurement stays stopped. Call startPeriodicMeasurement() to resume sampling. Harmless without a preceding sleep().

Reimplemented from m5::imu::IMUDataSource.

◆ writeAccelODR()

bool m5::unit::UnitBMI270::writeAccelODR ( const bmi270::AccelODR odr)

Write the accelerometer output data rate.

Parameters
[in]odrAccelerometer output data rate
Returns
True if successful
Note
config_t::accel_filter_perf and config_t::accel_bwp share REG_ACC_CONF with the rate and are rewritten from the configuration along with it
Warning
During periodic measurement runs, an error is returned

◆ writeAccelRange()

bool m5::unit::UnitBMI270::writeAccelRange ( const bmi270::AccelRange range)

Write the accelerometer range.

Parameters
[in]rangeAccelerometer range
Returns
True if successful
Warning
During periodic measurement runs, an error is returned

◆ writeGyroODR()

bool m5::unit::UnitBMI270::writeGyroODR ( const bmi270::GyroODR odr)

Write the gyroscope output data rate.

Parameters
[in]odrGyroscope output data rate
Returns
True if successful
Note
The periodic measurement interval is derived from this rate, so it is updated too
Warning
During periodic measurement runs, an error is returned

◆ writeGyroRange()

bool m5::unit::UnitBMI270::writeGyroRange ( const bmi270::GyroRange range)

Write the gyroscope range.

Parameters
[in]rangeGyroscope range
Returns
True if successful
Warning
During periodic measurement runs, an error is returned