libDaisy
Hardware Library for Daisy
Loading...
Searching...
No Matches
daisy::Icm20948< Transport > Class Template Reference

Device support for ICM20948 IMU sensor. More...

Detailed Description

template<typename Transport>
class daisy::Icm20948< Transport >

Device support for ICM20948 IMU sensor.

Author
beserge
Date
December 2021

#include <icm20948.h>

Classes

struct  Config
 
struct  Icm20948Vect
 

Public Types

enum  icm20948_accel_range_t { ICM20948_ACCEL_RANGE_2_G , ICM20948_ACCEL_RANGE_4_G , ICM20948_ACCEL_RANGE_8_G , ICM20948_ACCEL_RANGE_16_G }
 
enum  icm20948_gyro_range_t { ICM20948_GYRO_RANGE_250_DPS , ICM20948_GYRO_RANGE_500_DPS , ICM20948_GYRO_RANGE_1000_DPS , ICM20948_GYRO_RANGE_2000_DPS }
 
enum  ak09916_data_rate_t {
  AK09916_MAG_DATARATE_SHUTDOWN = 0x0 , AK09916_MAG_DATARATE_SINGLE = 0x1 , AK09916_MAG_DATARATE_10_HZ = 0x2 , AK09916_MAG_DATARATE_20_HZ = 0x4 ,
  AK09916_MAG_DATARATE_50_HZ = 0x6 , AK09916_MAG_DATARATE_100_HZ = 0x8
}
 
enum  Result { OK = 0 , ERR }
 

Public Member Functions

 Icm20948 ()
 
 ~Icm20948 ()
 
Result Init (Config config)
 
void Reset ()
 
uint8_t GetMagId ()
 
Result SetupMag ()
 
uint8_t ReadMagRegister (uint8_t mag_reg_addr)
 
bool WriteMagRegister (uint8_t mag_reg_addr, uint8_t value)
 
void ScaleValues ()
 
void SetAccelRateDivisor (uint16_t new_accel_divisor)
 
icm20948_accel_range_t GetAccelRange ()
 
uint8_t ReadAccelRange ()
 
void WriteAccelRange (uint8_t new_accel_range)
 
void SetAccelRange (icm20948_accel_range_t new_accel_range)
 
void SetGyroRateDivisor (uint8_t new_gyro_divisor)
 
icm20948_gyro_range_t GetGyroRange ()
 
void SetGyroRange (icm20948_gyro_range_t new_gyro_range)
 
void WriteGyroRange (uint8_t new_gyro_range)
 
uint8_t ReadGyroRange ()
 
ak09916_data_rate_t GetMagDataRate ()
 
bool SetMagDataRate (ak09916_data_rate_t rate)
 
void SetBank (uint8_t bank_number)
 
uint8_t ReadExternalRegister (uint8_t slv_addr, uint8_t reg_addr)
 
bool WriteExternalRegister (uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
 
uint8_t AuxillaryRegisterTransaction (bool read, uint8_t slv_addr, uint8_t reg_addr, uint8_t value)
 
void Process ()
 
Icm20948Vect GetAccelVect ()
 
Icm20948Vect GetGyroVect ()
 
Icm20948Vect GetMagVect ()
 
float GetTemp ()
 
uint8_t Read8 (uint8_t reg)
 
void Write8 (uint8_t reg, uint8_t value)
 
void Write16 (uint8_t reg, uint16_t value)
 
void ReadReg (uint8_t reg, uint8_t *buff, uint8_t size)
 
uint8_t ReadBits (uint8_t reg, uint8_t bits, uint8_t shift)
 
void WriteBits (uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
 
void SetI2CBypass (bool bypass_i2c)
 
Result EnableI2CMaster (bool enable_i2c_master)
 
Result ConfigureI2CMaster (void)
 
void ResetI2CMaster (void)
 
Result AuxI2CBusSetupFailed (void)
 
Result GetTransportError ()
 

Member Enumeration Documentation

◆ ak09916_data_rate_t

Data rates/modes for the embedded AsahiKASEI AK09916 3-axis magnetometer

Enumerator
AK09916_MAG_DATARATE_SHUTDOWN 

Stops measurement updates.

AK09916_MAG_DATARATE_SINGLE 

Takes a single measurement then switches to AK09916_MAG_DATARATE_SHUTDOWN

AK09916_MAG_DATARATE_10_HZ 

updates at 10Hz

AK09916_MAG_DATARATE_20_HZ 

updates at 20Hz

AK09916_MAG_DATARATE_50_HZ 

updates at 50Hz

AK09916_MAG_DATARATE_100_HZ 

updates at 100Hz

◆ icm20948_accel_range_t

The accelerometer data range

Enumerator
ICM20948_ACCEL_RANGE_2_G 
ICM20948_ACCEL_RANGE_4_G 
ICM20948_ACCEL_RANGE_8_G 
ICM20948_ACCEL_RANGE_16_G 

◆ icm20948_gyro_range_t

The gyro data range

Enumerator
ICM20948_GYRO_RANGE_250_DPS 
ICM20948_GYRO_RANGE_500_DPS 
ICM20948_GYRO_RANGE_1000_DPS 
ICM20948_GYRO_RANGE_2000_DPS 

◆ Result

Enumerator
OK 
ERR 

Constructor & Destructor Documentation

◆ Icm20948()

template<typename Transport >
daisy::Icm20948< Transport >::Icm20948 ( )
inline

◆ ~Icm20948()

template<typename Transport >
daisy::Icm20948< Transport >::~Icm20948 ( )
inline

Member Function Documentation

◆ AuxI2CBusSetupFailed()

template<typename Transport >
Result daisy::Icm20948< Transport >::AuxI2CBusSetupFailed ( void  )
inline

◆ AuxillaryRegisterTransaction()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::AuxillaryRegisterTransaction ( bool  read,
uint8_t  slv_addr,
uint8_t  reg_addr,
uint8_t  value 
)
inline

Read / Write a single byte to a given register address for an I2C slave device on the auxiliary I2C bus

Parameters
slv_addrthe 7-bit I2C address of the slave device
reg_addrthe register address to write to
valuethe value to write
Returns
Read value ( if it's a read operation ), else true or false

◆ ConfigureI2CMaster()

template<typename Transport >
Result daisy::Icm20948< Transport >::ConfigureI2CMaster ( void  )
inline

Set the I2C clock rate for the auxillary I2C bus to 345.60kHz and disable repeated start

Returns
true: success false: failure

◆ EnableI2CMaster()

template<typename Transport >
Result daisy::Icm20948< Transport >::EnableI2CMaster ( bool  enable_i2c_master)
inline

Enable or disable the I2C mastercontroller

Parameters
enable_i2c_mastertrue: enable false: disable
Returns
true: success false: error

◆ GetAccelRange()

template<typename Transport >
icm20948_accel_range_t daisy::Icm20948< Transport >::GetAccelRange ( )
inline

Get the accelerometer's measurement range.

Returns
The accelerometer's measurement range (icm20948_accel_range_t).

◆ GetAccelVect()

template<typename Transport >
Icm20948Vect daisy::Icm20948< Transport >::GetAccelVect ( )
inline

◆ GetGyroRange()

template<typename Transport >
icm20948_gyro_range_t daisy::Icm20948< Transport >::GetGyroRange ( )
inline

Get the gyro's measurement range.

Returns
The gyro's measurement range (icm20948_gyro_range_t).

◆ GetGyroVect()

template<typename Transport >
Icm20948Vect daisy::Icm20948< Transport >::GetGyroVect ( )
inline

◆ GetMagDataRate()

template<typename Transport >
ak09916_data_rate_t daisy::Icm20948< Transport >::GetMagDataRate ( )
inline

Get the current magnetometer measurement rate

Returns
ak09916_data_rate_t the current rate

◆ GetMagId()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::GetMagId ( )
inline

◆ GetMagVect()

template<typename Transport >
Icm20948Vect daisy::Icm20948< Transport >::GetMagVect ( )
inline

◆ GetTemp()

template<typename Transport >
float daisy::Icm20948< Transport >::GetTemp ( )
inline

◆ GetTransportError()

template<typename Transport >
Result daisy::Icm20948< Transport >::GetTransportError ( )
inline

Get and reset the transport error flag

Returns
Whether the transport has errored since the last check

◆ Init()

template<typename Transport >
Result daisy::Icm20948< Transport >::Init ( Config  config)
inline

Initialize the Icm20948 device

Parameters
configConfiguration settings

◆ Process()

template<typename Transport >
void daisy::Icm20948< Transport >::Process ( )
inline

Updates the measurement data for all sensors simultaneously

◆ Read8()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::Read8 ( uint8_t  reg)
inline

Reads an 8 bit value

Parameters
regthe register address to read from
Returns
the data uint8_t read from the device

◆ ReadAccelRange()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::ReadAccelRange ( )
inline

Get the accelerometer's measurement range.

Returns
The accelerometer's measurement range (icm20x_accel_range_t).

◆ ReadBits()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::ReadBits ( uint8_t  reg,
uint8_t  bits,
uint8_t  shift 
)
inline

◆ ReadExternalRegister()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::ReadExternalRegister ( uint8_t  slv_addr,
uint8_t  reg_addr 
)
inline

Read a single byte from a given register address for an I2C slave device on the auxiliary I2C bus

Parameters
slv_addrthe 7-bit I2C address of the slave device
reg_addrthe register address to read from
Returns
the requested register value

◆ ReadGyroRange()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::ReadGyroRange ( )
inline

Get the gyro's measurement range.

Returns
The gyro's measurement range (icm20x_gyro_range_t).

◆ ReadMagRegister()

template<typename Transport >
uint8_t daisy::Icm20948< Transport >::ReadMagRegister ( uint8_t  mag_reg_addr)
inline
Parameters
slv_addr
mag_reg_addr
num_finished_checks
Returns
uint8_t

◆ ReadReg()

template<typename Transport >
void daisy::Icm20948< Transport >::ReadReg ( uint8_t  reg,
uint8_t buff,
uint8_t  size 
)
inline

Read from a reg address a defined number of bytes

◆ Reset()

template<typename Transport >
void daisy::Icm20948< Transport >::Reset ( )
inline

Reset the internal registers and restores the default settings

◆ ResetI2CMaster()

template<typename Transport >
void daisy::Icm20948< Transport >::ResetI2CMaster ( void  )
inline

Reset the I2C master

◆ ScaleValues()

template<typename Transport >
void daisy::Icm20948< Transport >::ScaleValues ( )
inline

◆ SetAccelRange()

template<typename Transport >
void daisy::Icm20948< Transport >::SetAccelRange ( icm20948_accel_range_t  new_accel_range)
inline

Sets the accelerometer's measurement range.

Parameters
new_accel_rangeMeasurement range to be set. Must be an icm20948_accel_range_t.

◆ SetAccelRateDivisor()

template<typename Transport >
void daisy::Icm20948< Transport >::SetAccelRateDivisor ( uint16_t  new_accel_divisor)
inline

Sets the accelerometer's data rate divisor.

Parameters
new_accel_divisorThe accelerometer's data rate divisor (uint16_t). This 12-bit value must be <= 4095

◆ SetBank()

template<typename Transport >
void daisy::Icm20948< Transport >::SetBank ( uint8_t  bank_number)
inline

Sets register bank.

Parameters
bank_numberThe bank to set to active

◆ SetGyroRange()

template<typename Transport >
void daisy::Icm20948< Transport >::SetGyroRange ( icm20948_gyro_range_t  new_gyro_range)
inline

Sets the gyro's measurement range.

Parameters
new_gyro_rangeMeasurement range to be set. Must be an icm20948_gyro_range_t.

◆ SetGyroRateDivisor()

template<typename Transport >
void daisy::Icm20948< Transport >::SetGyroRateDivisor ( uint8_t  new_gyro_divisor)
inline

Sets the gyro's data rate divisor.

Parameters
new_gyro_divisorThe gyro's data rate divisor (uint8_t).

◆ SetI2CBypass()

template<typename Transport >
void daisy::Icm20948< Transport >::SetI2CBypass ( bool  bypass_i2c)
inline

Sets the bypass status of the I2C master bus support.

Parameters
bypass_i2cSet to true to bypass the internal I2C master circuitry, connecting the external I2C bus to the main I2C bus. Set to false to re-connect

◆ SetMagDataRate()

template<typename Transport >
bool daisy::Icm20948< Transport >::SetMagDataRate ( ak09916_data_rate_t  rate)
inline

Set the magnetometer measurement rate

Parameters
rateThe rate to set.
Returns
true: success false: failure

◆ SetupMag()

template<typename Transport >
Result daisy::Icm20948< Transport >::SetupMag ( )
inline

◆ Write16()

template<typename Transport >
void daisy::Icm20948< Transport >::Write16 ( uint8_t  reg,
uint16_t  value 
)
inline

Writes a 16 bit value MSB first

Parameters
regthe register address to write to
valuethe value to write to the register

◆ Write8()

template<typename Transport >
void daisy::Icm20948< Transport >::Write8 ( uint8_t  reg,
uint8_t  value 
)
inline

Writes an 8 bit value

Parameters
regthe register address to write to
valuethe value to write to the register

◆ WriteAccelRange()

template<typename Transport >
void daisy::Icm20948< Transport >::WriteAccelRange ( uint8_t  new_accel_range)
inline

Sets the accelerometer's measurement range.

Parameters
new_accel_rangeMeasurement range to be set. Must be an icm20x_accel_range_t.

◆ WriteBits()

template<typename Transport >
void daisy::Icm20948< Transport >::WriteBits ( uint8_t  reg,
uint8_t  data,
uint8_t  bits,
uint8_t  shift 
)
inline

◆ WriteExternalRegister()

template<typename Transport >
bool daisy::Icm20948< Transport >::WriteExternalRegister ( uint8_t  slv_addr,
uint8_t  reg_addr,
uint8_t  value 
)
inline

Write a single byte to a given register address for an I2C slave device on the auxiliary I2C bus

Parameters
slv_addrthe 7-bit I2C address of the slave device
reg_addrthe register address to write to
valuethe value to write
Returns
true
false

◆ WriteGyroRange()

template<typename Transport >
void daisy::Icm20948< Transport >::WriteGyroRange ( uint8_t  new_gyro_range)
inline

Sets the gyro's measurement range.

Parameters
new_gyro_rangeMeasurement range to be set. Must be an icm20x_gyro_range_t.

◆ WriteMagRegister()

template<typename Transport >
bool daisy::Icm20948< Transport >::WriteMagRegister ( uint8_t  mag_reg_addr,
uint8_t  value 
)
inline

The documentation for this class was generated from the following file: