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

3-axis magnetometer unit. No standalone GROVE unit exists; it is the magnetometer embedded in the MPU9250 found on early classic M5Stack Core/Fire boards, reachable at 0x0C once the MPU9250's I2C bypass is enabled (see m5::unit::imu::enableAuxBypass) More...

#include <unit_ak8963.hpp>

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

Classes

struct  config_t
 Settings for begin() More...
 

Public Member Functions

 UnitAK8963 (const uint8_t addr=DEFAULT_ADDRESS)
 Construct with the I2C address the chip will answer on.
 
virtual ~UnitAK8963 ()
 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.
 
Reset
bool softReset ()
 Soft reset (REG_CNTL2 SRST), leaving the chip initialized but unconfigured and stopped.
 
Measurement setting (stop periodic measurement first)
bool writeMeasurementMode (const ak8963::MeasurementMode mode, const ak8963::OutputBit bit)
 Write the continuous measurement rate and output bit width.
 
bool readMeasurementMode (ak8963::MeasurementMode &mode, ak8963::OutputBit &bit) const
 Read the continuous measurement rate and output bit width.
 
Periodic measurement
bool startPeriodicMeasurement (const ak8963::MeasurementMode mode, const ak8963::OutputBit bit)
 Start periodic measurement.
 
bool startPeriodicMeasurement ()
 Start periodic measurement in the current settings.
 
bool stopPeriodicMeasurement ()
 Mark periodic measurement as stopped (bookkeeping only; the chip stays in its current mode – call sleep() to power-down for actual quiescence)
 
Power
bool sleep () override
 Enter power-down mode (REG_CNTL1 mode 0)
 
bool wakeup () override
 Leave power-down.
 
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

bool start_periodic_measurement (const ak8963::MeasurementMode mode, const ak8963::OutputBit bit)
 
bool start_periodic_measurement ()
 
bool stop_periodic_measurement ()
 
bool read_measurement (ak8963::Data &d)
 
bool read_sensitivity (std::array< uint8_t, 3 > &asa)
 
 M5_UNIT_COMPONENT_PERIODIC_MEASUREMENT_ADAPTER_HPP_BUILDER (UnitAK8963, ak8963::Data)
 

Detailed Description

3-axis magnetometer unit. No standalone GROVE unit exists; it is the magnetometer embedded in the MPU9250 found on early classic M5Stack Core/Fire boards, reachable at 0x0C once the MPU9250's I2C bypass is enabled (see m5::unit::imu::enableAuxBypass)

Constructor & Destructor Documentation

◆ UnitAK8963()

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

Capability of this unit.

Returns
Mag (no temperature output on this chip)

Implements m5::imu::IMUDataSource.

◆ readImuRaw()

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

◆ readMeasurementMode()

bool m5::unit::UnitAK8963::readMeasurementMode ( ak8963::MeasurementMode & mode,
ak8963::OutputBit & bit ) const

Read the continuous measurement rate and output bit width.

Parameters
[out]modeContinuous measurement rate
[out]bitOutput bit width
Returns
True if successful
Note
Returns the setting this unit measures with, not a register read: REG_CNTL1 holds power-down whenever measurement is stopped, so the chip cannot answer this while idle

◆ sleep()

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

Enter power-down mode (REG_CNTL1 mode 0)

Returns
True if successful

Works while periodic measurement is running: it is stopped first, since a powered-down chip must not be polled. Power-down is the AK8963's only low-power state.

Reimplemented from m5::imu::IMUDataSource.

◆ softReset()

bool m5::unit::UnitAK8963::softReset ( )

Soft reset (REG_CNTL2 SRST), 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::UnitAK8963::startPeriodicMeasurement ( )

Start periodic measurement in the current settings.

Returns
True if successful

◆ startPeriodicMeasurement() [2/2]

bool m5::unit::UnitAK8963::startPeriodicMeasurement ( const ak8963::MeasurementMode mode,
const ak8963::OutputBit bit )

Start periodic measurement.

Parameters
[in]modeContinuous measurement rate
[in]bitOutput bit width
Returns
True if successful

◆ stopPeriodicMeasurement()

bool m5::unit::UnitAK8963::stopPeriodicMeasurement ( )

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

Returns
True on success

◆ update()

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

Leave power-down.

Returns
True (always)

No-op by design: on the AK8963 power-down is also the state every mode change has to pass through, so there is nothing to undo here. Call startPeriodicMeasurement() to re-enter continuous measurement.

Reimplemented from m5::imu::IMUDataSource.

◆ writeMeasurementMode()

bool m5::unit::UnitAK8963::writeMeasurementMode ( const ak8963::MeasurementMode mode,
const ak8963::OutputBit bit )

Write the continuous measurement rate and output bit width.

Parameters
[in]modeContinuous measurement rate
[in]bitOutput bit width
Returns
True if successful

Applied to the chip by the next startPeriodicMeasurement(), along with the periodic measurement interval. Entering a continuous mode is measuring on this chip, so there is no way to park the setting in REG_CNTL1 while stopped – what this does write is the power-down every mode transition has to pass through

Warning
Fails while periodic measurement is running