|
M5Unit-IMU 0.0.2 git rev:e5b00aa
|
Shared base for the TDK InvenSense MPU 6-axis family (accel + gyro + temp) More...
#include <unit_mpu6xxx.hpp>
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) | |
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.
|
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.
|
overridevirtual |
Begin the unit.
Reimplemented in m5::unit::UnitMPU9250.
|
inline |
Gets the configuration.
|
inline |
Set the configuration.
| [in] | cfg | Configuration |
|
overridevirtual |
Gets the conversion parameters for raw IMU data.
| [out] | out | Conversion parameters |
Implements m5::imu::IMUDataSource.
|
inlineoverridevirtual |
| bool m5::unit::UnitMPU6xxx::readAccelRange | ( | mpu6886::AccelRange & | range | ) |
Read the accelerometer range from the device (REG_ACCEL_CONFIG bits[4:3])
| [out] | range | Accelerometer range |
| bool m5::unit::UnitMPU6xxx::readDlpf | ( | mpu6886::Dlpf & | dlpf | ) |
Read the digital low-pass filter bandwidth from the device (REG_CONFIG bits[2:0])
| [out] | dlpf | Filter bandwidth |
| bool m5::unit::UnitMPU6xxx::readGyroRange | ( | mpu6886::GyroRange & | range | ) |
Read the gyroscope range from the device (REG_GYRO_CONFIG bits[4:3])
| [out] | range | Gyroscope range |
|
overridevirtual |
Read the latest raw IMU data.
| [out] | out | Raw IMU data |
Implements m5::imu::IMUDataSource.
| bool m5::unit::UnitMPU6xxx::readSampleRateDiv | ( | uint8_t & | div | ) |
Read the sample rate divider from the device (REG_SMPLRT_DIV)
| [out] | div | Divider |
|
overridevirtual |
Put the chip to sleep (REG_PWR_MGMT_1 SLEEP)
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.
| bool m5::unit::UnitMPU6xxx::softReset | ( | ) |
Soft reset (REG_PWR_MGMT_1 DEVICE_RESET), leaving the chip initialized but unconfigured and stopped.
|
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.
| bool m5::unit::UnitMPU6xxx::startPeriodicMeasurement | ( | ) |
Start periodic measurement in the current settings.
| 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.
| accel_range | Accelerometer range |
| gyro_range | Gyroscope range |
| dlpf | Gyro/temp low pass filter |
| sample_rate_div | Sample rate divider (ODR = 1000/(1+div) Hz) |
| bool m5::unit::UnitMPU6xxx::stopPeriodicMeasurement | ( | ) |
Stop periodic measurement.
|
protectedpure virtual |
Temperature conversion: degC offset (imu_convert_param_t::temp_offset)
Implemented in m5::unit::UnitMPU6050, m5::unit::UnitMPU6500, and m5::unit::UnitMPU6886.
|
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.
|
overridevirtual |
Update the unit.
| [in] | force | Forces an update if true, even if not time for periodic measurement |
|
overridevirtual |
Wake the chip from sleep()
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.
| bool m5::unit::UnitMPU6xxx::writeAccelRange | ( | const mpu6886::AccelRange | range | ) |
Write the accelerometer range.
| [in] | range | Accelerometer range |
| bool m5::unit::UnitMPU6xxx::writeDlpf | ( | const mpu6886::Dlpf | dlpf | ) |
Write the digital low-pass filter bandwidth.
| [in] | dlpf | Filter bandwidth |
| bool m5::unit::UnitMPU6xxx::writeGyroRange | ( | const mpu6886::GyroRange | range | ) |
Write the gyroscope range.
| [in] | range | Gyroscope range |
| bool m5::unit::UnitMPU6xxx::writeSampleRateDiv | ( | const uint8_t | div | ) |
Write the sample rate divider.
| [in] | div | Divider; the sample rate becomes 1kHz / (1 + div) with the DLPF enabled |