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

Senodia SH200Q 6-axis IMU (accel + gyro + temp). No standalone GROVE unit exists; it is the built-in IMU of the earliest (2019.3) M5StickC and of the 2019.7 M5Stack Fire (there paired with a discrete BMM150 magnetometer), on the internal I2C bus at 0x6C. More...

#include <unit_sh200q.hpp>

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

Classes

struct  config_t
 Settings for begin() More...
 

Public Member Functions

 UnitSH200Q (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the I2C address the chip will answer on.
 
virtual ~UnitSH200Q ()
 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 sh200q::AccelRange range)
 Write the accelerometer range.
 
bool writeGyroRange (const sh200q::GyroRange range)
 Write the gyroscope range.
 
bool readAccelRange (sh200q::AccelRange &range)
 Read the accelerometer range from the device (REG_ACC_RANGE bits[1:0])
 
bool readGyroRange (sh200q::GyroRange &range)
 Read the gyroscope range from the device (REG_GYRO_RANGE bits[2:0])
 
Output data rate (stop periodic measurement first)
bool writeAccelOdr (const sh200q::AccelOdr odr)
 Write the accelerometer output data rate.
 
bool writeGyroOdr (const sh200q::GyroOdr odr)
 Write the gyroscope output data rate.
 
bool readAccelOdr (sh200q::AccelOdr &odr)
 Read the accelerometer output data rate from the device (REG_ACC_CONFIG bits[4:3])
 
bool readGyroOdr (sh200q::GyroOdr &odr)
 Read the gyroscope output data rate from the device (REG_GYRO_CONFIG bits[3:1])
 
Reset
bool softReset ()
 Soft reset (the undocumented ADC/init reset dance inherited from the original library), leaving the chip initialized but unconfigured and stopped.
 
Periodic measurement
bool startPeriodicMeasurement (const sh200q::AccelRange accel_range, const sh200q::GyroRange gyro_range, const sh200q::AccelOdr accel_odr, const sh200q::GyroOdr gyro_odr, const sh200q::GyroDlpf gyro_dlpf)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool stopPeriodicMeasurement ()
 Mark periodic measurement as stopped (bookkeeping only; the chip stays running – call sleep() to power-down for actual quiescence)
 
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.
 
- Public Member Functions inherited from m5::imu::IMUDataSource
virtual bool sleep ()
 Put the device into its lowest reversible power state.
 
virtual bool wakeup ()
 Bring the device back from sleep()
 

Protected Member Functions

bool start_periodic_measurement (const sh200q::AccelRange accel_range, const sh200q::GyroRange gyro_range, const sh200q::AccelOdr accel_odr, const sh200q::GyroOdr gyro_odr, const sh200q::GyroDlpf gyro_dlpf)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (sh200q::Data &d)
 
bool write_register8_verified (const uint8_t reg, const uint8_t val)
 
bool toggle_register_bits (const uint8_t reg, const uint8_t bits)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitSH200Q, sh200q::Data)
 

Detailed Description

Senodia SH200Q 6-axis IMU (accel + gyro + temp). No standalone GROVE unit exists; it is the built-in IMU of the earliest (2019.3) M5StickC and of the 2019.7 M5Stack Fire (there paired with a discrete BMM150 magnetometer), on the internal I2C bus at 0x6C.

Warning
Field reports (and the chip's EOL status) suggest the gyroscope output is of poor quality (large per-axis zero offsets) and that the accel and gyro axis systems may not even agree with each other or with the datasheet – verify the orientation on hardware and expect to need gyro zero-offset calibration. The accelerometer is the dependable half of this chip.

Constructor & Destructor Documentation

◆ UnitSH200Q()

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

◆ imuConvertParam()

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

Gets the conversion parameters for raw IMU data.

Parameters
[out]outDestination for the scale factors this driver applies

Implements m5::imu::IMUDataSource.

◆ imuSpec()

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

Capability of this unit.

Returns
Accel | Gyro | Temp

Implements m5::imu::IMUDataSource.

◆ readAccelOdr()

bool m5::unit::UnitSH200Q::readAccelOdr ( sh200q::AccelOdr & odr)

Read the accelerometer output data rate from the device (REG_ACC_CONFIG bits[4:3])

Parameters
[out]odrAccelerometer output data rate
Returns
True if successful

◆ readAccelRange()

bool m5::unit::UnitSH200Q::readAccelRange ( sh200q::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::UnitSH200Q::readGyroOdr ( sh200q::GyroOdr & odr)

Read the gyroscope output data rate from the device (REG_GYRO_CONFIG bits[3:1])

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

◆ readGyroRange()

bool m5::unit::UnitSH200Q::readGyroRange ( sh200q::GyroRange & range)

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

Parameters
[out]rangeGyroscope range
Returns
True if successful

◆ readImuRaw()

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

Read the latest raw IMU data.

Parameters
[out]outDestination buffer filled with the most recent sample
Returns
Capability of the sample (which axes were populated)

Implements m5::imu::IMUDataSource.

◆ softReset()

bool m5::unit::UnitSH200Q::softReset ( )

Soft reset (the undocumented ADC/init reset dance inherited from the original library), 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()

bool m5::unit::UnitSH200Q::startPeriodicMeasurement ( const sh200q::AccelRange accel_range,
const sh200q::GyroRange gyro_range,
const sh200q::AccelOdr accel_odr,
const sh200q::GyroOdr gyro_odr,
const sh200q::GyroDlpf gyro_dlpf )

Start periodic measurement.

Parameters
accel_rangeAccelerometer range
gyro_rangeGyroscope range
accel_odrAccelerometer output data rate
gyro_odrGyroscope output data rate (also paces the periodic measurement)
gyro_dlpfGyro low pass filter
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitSH200Q::stopPeriodicMeasurement ( )

Mark periodic measurement as stopped (bookkeeping only; the chip stays running – call sleep() to power-down for actual quiescence)

Returns
True on success

◆ update()

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

Update the unit.

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

◆ writeAccelOdr()

bool m5::unit::UnitSH200Q::writeAccelOdr ( const sh200q::AccelOdr odr)

Write the accelerometer output data rate.

Parameters
[in]odrAccelerometer output data rate
Returns
True if successful
Note
The rate occupies REG_ACC_CONFIG bits[4:3]; the filter bits around it are rewritten with the driver's fixed base value
Warning
During periodic measurement runs, an error is returned

◆ writeAccelRange()

bool m5::unit::UnitSH200Q::writeAccelRange ( const sh200q::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::UnitSH200Q::writeGyroOdr ( const sh200q::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::UnitSH200Q::writeGyroRange ( const sh200q::GyroRange range)

Write the gyroscope range.

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