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

Shared base for the TDK InvenSense MPU 6-axis family (accel + gyro + temp) More...

#include <unit_mpu6xxx.hpp>

Inheritance diagram for m5::unit::UnitMPU6xxx:
m5::imu::IMUDataSource m5::unit::UnitMPU6050 m5::unit::UnitMPU6500 m5::unit::UnitMPU6886 m5::unit::UnitMPU9250

Classes

struct  config_t
 Settings for begin() More...
 

Public Member Functions

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 mpu6886::AccelRange range)
 Write the accelerometer range.
 
bool writeGyroRange (const mpu6886::GyroRange range)
 Write the gyroscope range.
 
bool readAccelRange (mpu6886::AccelRange &range)
 Read the accelerometer range from the device (REG_ACCEL_CONFIG bits[4:3])
 
bool readGyroRange (mpu6886::GyroRange &range)
 Read the gyroscope range from the device (REG_GYRO_CONFIG bits[4:3])
 
Sampling (stop periodic measurement first)
bool writeSampleRateDiv (const uint8_t div)
 Write the sample rate divider.
 
bool readSampleRateDiv (uint8_t &div)
 Read the sample rate divider from the device (REG_SMPLRT_DIV)
 
bool writeDlpf (const mpu6886::Dlpf dlpf)
 Write the digital low-pass filter bandwidth.
 
bool readDlpf (mpu6886::Dlpf &dlpf)
 Read the digital low-pass filter bandwidth from the device (REG_CONFIG bits[2:0])
 
Reset
bool softReset ()
 Soft reset (REG_PWR_MGMT_1 DEVICE_RESET), leaving the chip initialized but unconfigured and stopped.
 
Periodic measurement
bool startPeriodicMeasurement (const mpu6886::AccelRange accel_range, const mpu6886::GyroRange gyro_range, const mpu6886::Dlpf dlpf, const uint8_t sample_rate_div)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool stopPeriodicMeasurement ()
 Stop periodic measurement.
 
Power
bool sleep () override
 Put the chip to sleep (REG_PWR_MGMT_1 SLEEP)
 
bool wakeup () override
 Wake 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

 UnitMPU6xxx (const uint8_t addr=DEFAULT_ADDRESS)
 Protected: UnitMPU6xxx is abstract, constructed only by concrete derived chips.
 
virtual bool start_periodic_measurement (const mpu6886::AccelRange accel_range, const mpu6886::GyroRange gyro_range, const mpu6886::Dlpf dlpf, const uint8_t sample_rate_div)
 Virtual: UnitMPU9250 layers its aux-bypass re-open on top (the config write here includes INT_PIN_CFG=0xC0, which closes the bypass)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (mpu6886::Data &d)
 
bool write_register8_verified (const uint8_t reg, const uint8_t val)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitMPU6xxx, mpu6886::Data)
 
Chip profile (overridden by each concrete derived chip)
virtual bool accepts_whoami (const uint8_t id) const =0
 Accepted WHO_AM_I id(s) for this chip; begin() rejects the device unless this returns true.
 
virtual float temperature_res () const =0
 Temperature conversion: degC per LSB (imu_convert_param_t::temp_res)
 
virtual float temperature_offset () const =0
 Temperature conversion: degC offset (imu_convert_param_t::temp_offset)
 

Detailed Description

Shared base for the TDK InvenSense MPU 6-axis family (accel + gyro + temp)

The accel/gyro register map, init sequence, and periodic read are identical across MPU6886/6050/6500 (and the MPU9250 accel/gyro die), so they all live here. The only per-chip differences – the accepted WHO_AM_I id and the temperature scale – are exposed as virtual hooks (accepts_whoami / temperature_res / temperature_offset) that thin derived classes override. Not instantiated directly; use UnitMPU6886 / UnitMPU6050 / UnitMPU6500 / UnitMPU9250.

Member Function Documentation

◆ accepts_whoami()

virtual bool m5::unit::UnitMPU6xxx::accepts_whoami ( const uint8_t id) const
protectedpure virtual

Accepted WHO_AM_I id(s) for this chip; begin() rejects the device unless this returns true.

Implemented in m5::unit::UnitMPU6050, m5::unit::UnitMPU6500, m5::unit::UnitMPU6886, and m5::unit::UnitMPU9250.

◆ begin()

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

Begin the unit.

Reimplemented in m5::unit::UnitMPU9250.

◆ config() [1/2]

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

Gets the configuration.

Returns
Current configuration

◆ config() [2/2]

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

Set the configuration.

Parameters
[in]cfgConfiguration

◆ imuConvertParam()

void m5::unit::UnitMPU6xxx::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::UnitMPU6xxx::imuSpec ( ) const
inlineoverridevirtual

Capability of this unit.

Returns
Accel | Gyro | Temp

Implements m5::imu::IMUDataSource.

◆ readAccelRange()

bool m5::unit::UnitMPU6xxx::readAccelRange ( mpu6886::AccelRange & range)

Read the accelerometer range from the device (REG_ACCEL_CONFIG bits[4:3])

Parameters
[out]rangeAccelerometer range
Returns
True if successful

◆ readDlpf()

bool m5::unit::UnitMPU6xxx::readDlpf ( mpu6886::Dlpf & dlpf)

Read the digital low-pass filter bandwidth from the device (REG_CONFIG bits[2:0])

Parameters
[out]dlpfFilter bandwidth
Returns
True if successful

◆ readGyroRange()

bool m5::unit::UnitMPU6xxx::readGyroRange ( mpu6886::GyroRange & range)

Read the gyroscope range from the device (REG_GYRO_CONFIG bits[4:3])

Parameters
[out]rangeGyroscope range
Returns
True if successful

◆ readImuRaw()

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

◆ readSampleRateDiv()

bool m5::unit::UnitMPU6xxx::readSampleRateDiv ( uint8_t & div)

Read the sample rate divider from the device (REG_SMPLRT_DIV)

Parameters
[out]divDivider
Returns
True if successful

◆ sleep()

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

Put the chip to sleep (REG_PWR_MGMT_1 SLEEP)

Returns
True if successful

Works while periodic measurement is running: it is stopped first, since a sleeping chip must not be polled. The SLEEP bit then halts sampling and drops the chip to its low-power state. Unlike softReset() the configuration is preserved.

Reimplemented from m5::imu::IMUDataSource.

◆ softReset()

bool m5::unit::UnitMPU6xxx::softReset ( )

Soft reset (REG_PWR_MGMT_1 DEVICE_RESET), 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

◆ start_periodic_measurement()

bool m5::unit::UnitMPU6xxx::start_periodic_measurement ( const mpu6886::AccelRange accel_range,
const mpu6886::GyroRange gyro_range,
const mpu6886::Dlpf dlpf,
const uint8_t sample_rate_div )
protectedvirtual

Virtual: UnitMPU9250 layers its aux-bypass re-open on top (the config write here includes INT_PIN_CFG=0xC0, which closes the bypass)

Reimplemented in m5::unit::UnitMPU9250.

◆ startPeriodicMeasurement() [1/2]

bool m5::unit::UnitMPU6xxx::startPeriodicMeasurement ( )

Start periodic measurement in the current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitMPU6xxx::startPeriodicMeasurement ( const mpu6886::AccelRange accel_range,
const mpu6886::GyroRange gyro_range,
const mpu6886::Dlpf dlpf,
const uint8_t sample_rate_div )

Start periodic measurement.

Parameters
accel_rangeAccelerometer range
gyro_rangeGyroscope range
dlpfGyro/temp low pass filter
sample_rate_divSample rate divider (ODR = 1000/(1+div) Hz)
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitMPU6xxx::stopPeriodicMeasurement ( )

Stop periodic measurement.

Returns
True if successful

◆ temperature_offset()

virtual float m5::unit::UnitMPU6xxx::temperature_offset ( ) const
protectedpure virtual

Temperature conversion: degC offset (imu_convert_param_t::temp_offset)

Implemented in m5::unit::UnitMPU6050, m5::unit::UnitMPU6500, and m5::unit::UnitMPU6886.

◆ temperature_res()

virtual float m5::unit::UnitMPU6xxx::temperature_res ( ) const
protectedpure virtual

Temperature conversion: degC per LSB (imu_convert_param_t::temp_res)

Implemented in m5::unit::UnitMPU6050, m5::unit::UnitMPU6500, and m5::unit::UnitMPU6886.

◆ update()

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

Wake the chip from sleep()

Returns
True if successful

Only clears SLEEP (by selecting the PLL clock) and waits for the sensors to start up – measurement stays stopped. Call startPeriodicMeasurement() to resume sampling. Harmless without a preceding sleep().

Reimplemented from m5::imu::IMUDataSource.

◆ writeAccelRange()

bool m5::unit::UnitMPU6xxx::writeAccelRange ( const mpu6886::AccelRange range)

Write the accelerometer range.

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

◆ writeDlpf()

bool m5::unit::UnitMPU6xxx::writeDlpf ( const mpu6886::Dlpf dlpf)

Write the digital low-pass filter bandwidth.

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

◆ writeGyroRange()

bool m5::unit::UnitMPU6xxx::writeGyroRange ( const mpu6886::GyroRange range)

Write the gyroscope range.

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

◆ writeSampleRateDiv()

bool m5::unit::UnitMPU6xxx::writeSampleRateDiv ( const uint8_t div)

Write the sample rate divider.

Parameters
[in]divDivider; the sample rate becomes 1kHz / (1 + div) with the DLPF enabled
Returns
True if successful
Note
The periodic measurement interval is derived from this, so it is updated too
Warning
During periodic measurement runs, an error is returned