Skip to content

Class daisy::Icm20948

template <typename Transport>

ClassList > daisy > Icm20948

Device support for ICM20948 IMU sensor. More...

  • #include <icm20948.h>

Classes

Type Name
struct Config
struct Icm20948Vect

Public Types

Type Name
enum Result
enum ak09916_data_rate_t
enum icm20948_accel_range_t
enum icm20948_gyro_range_t

Public Functions

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

Detailed Description

Author:

beserge

Date:

December 2021

Public Types Documentation

enum Result

enum daisy::Icm20948::Result {
    OK = 0,
    ERR
};

enum ak09916_data_rate_t

enum daisy::Icm20948::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
};

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


enum icm20948_accel_range_t

enum daisy::Icm20948::icm20948_accel_range_t {
    ICM20948_ACCEL_RANGE_2_G,
    ICM20948_ACCEL_RANGE_4_G,
    ICM20948_ACCEL_RANGE_8_G,
    ICM20948_ACCEL_RANGE_16_G
};

The accelerometer data range


enum icm20948_gyro_range_t

enum daisy::Icm20948::icm20948_gyro_range_t {
    ICM20948_GYRO_RANGE_250_DPS,
    ICM20948_GYRO_RANGE_500_DPS,
    ICM20948_GYRO_RANGE_1000_DPS,
    ICM20948_GYRO_RANGE_2000_DPS
};

The gyro data range


Public Functions Documentation

function AuxI2CBusSetupFailed

inline Result daisy::Icm20948::AuxI2CBusSetupFailed (
    void
) 

function AuxillaryRegisterTransaction

inline uint8_t daisy::Icm20948::AuxillaryRegisterTransaction (
    bool read,
    uint8_t slv_addr,
    uint8_t reg_addr,
    uint8_t value
) 

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

Parameters:

  • slv_addr the 7-bit I2C address of the slave device
  • reg_addr the register address to write to
  • value the value to write

Returns:

Read value ( if it's a read operation ), else true or false


function ConfigureI2CMaster

inline Result daisy::Icm20948::ConfigureI2CMaster (
    void
) 

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

Returns:

true: success false: failure


function EnableI2CMaster

inline Result daisy::Icm20948::EnableI2CMaster (
    bool enable_i2c_master
) 

Enable or disable the I2C mastercontroller

Parameters:

  • enable_i2c_master true: enable false: disable

Returns:

true: success false: error


function GetAccelRange

inline icm20948_accel_range_t daisy::Icm20948::GetAccelRange () 

Get the accelerometer's measurement range.

Returns:

The accelerometer's measurement range (icm20948_accel_range_t).


function GetAccelVect

inline Icm20948Vect daisy::Icm20948::GetAccelVect () 

function GetGyroRange

inline icm20948_gyro_range_t daisy::Icm20948::GetGyroRange () 

Get the gyro's measurement range.

Returns:

The gyro's measurement range (icm20948_gyro_range_t).


function GetGyroVect

inline Icm20948Vect daisy::Icm20948::GetGyroVect () 

function GetMagDataRate

inline ak09916_data_rate_t daisy::Icm20948::GetMagDataRate () 

Get the current magnetometer measurement rate

Returns:

ak09916_data_rate_t the current rate


function GetMagId

inline uint8_t daisy::Icm20948::GetMagId () 

function GetMagVect

inline Icm20948Vect daisy::Icm20948::GetMagVect () 

function GetTemp

inline float daisy::Icm20948::GetTemp () 

function GetTransportError

inline Result daisy::Icm20948::GetTransportError () 

Get and reset the transport error flag

Returns:

Whether the transport has errored since the last check


function Icm20948

inline daisy::Icm20948::Icm20948 () 

function Init

inline Result daisy::Icm20948::Init (
    Config config
) 

Initialize the Icm20948 device

Parameters:

  • config Configuration settings

function Process

inline void daisy::Icm20948::Process () 

Updates the measurement data for all sensors simultaneously


function Read8

inline uint8_t daisy::Icm20948::Read8 (
    uint8_t reg
) 

Reads an 8 bit value

Parameters:

  • reg the register address to read from

Returns:

the data uint8_t read from the device


function ReadAccelRange

inline uint8_t daisy::Icm20948::ReadAccelRange () 

Get the accelerometer's measurement range.

Returns:

The accelerometer's measurement range (icm20x_accel_range_t).


function ReadBits

inline uint8_t daisy::Icm20948::ReadBits (
    uint8_t reg,
    uint8_t bits,
    uint8_t shift
) 

function ReadExternalRegister

inline uint8_t daisy::Icm20948::ReadExternalRegister (
    uint8_t slv_addr,
    uint8_t reg_addr
) 

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

Parameters:

  • slv_addr the 7-bit I2C address of the slave device
  • reg_addr the register address to read from

Returns:

the requested register value


function ReadGyroRange

inline uint8_t daisy::Icm20948::ReadGyroRange () 

Get the gyro's measurement range.

Returns:

The gyro's measurement range (icm20x_gyro_range_t).


function ReadMagRegister

inline uint8_t daisy::Icm20948::ReadMagRegister (
    uint8_t mag_reg_addr
) 

Parameters:

  • slv_addr
  • mag_reg_addr
  • num_finished_checks

Returns:

uint8_t


function ReadReg

inline void daisy::Icm20948::ReadReg (
    uint8_t reg,
    uint8_t * buff,
    uint8_t size
) 

Read from a reg address a defined number of bytes


function Reset

inline void daisy::Icm20948::Reset () 

Reset the internal registers and restores the default settings


function ResetI2CMaster

inline void daisy::Icm20948::ResetI2CMaster (
    void
) 

Reset the I2C master


function ScaleValues

inline void daisy::Icm20948::ScaleValues () 

function SetAccelRange

inline void daisy::Icm20948::SetAccelRange (
    icm20948_accel_range_t new_accel_range
) 

Sets the accelerometer's measurement range.

Parameters:

  • new_accel_range Measurement range to be set. Must be an icm20948_accel_range_t.

function SetAccelRateDivisor

inline void daisy::Icm20948::SetAccelRateDivisor (
    uint16_t new_accel_divisor
) 

Sets the accelerometer's data rate divisor.

Parameters:

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

function SetBank

inline void daisy::Icm20948::SetBank (
    uint8_t bank_number
) 

Sets register bank.

Parameters:

  • bank_number The bank to set to active

function SetGyroRange

inline void daisy::Icm20948::SetGyroRange (
    icm20948_gyro_range_t new_gyro_range
) 

Sets the gyro's measurement range.

Parameters:

  • new_gyro_range Measurement range to be set. Must be an icm20948_gyro_range_t.

function SetGyroRateDivisor

inline void daisy::Icm20948::SetGyroRateDivisor (
    uint8_t new_gyro_divisor
) 

Sets the gyro's data rate divisor.

Parameters:

  • new_gyro_divisor The gyro's data rate divisor (uint8_t).

function SetI2CBypass

inline void daisy::Icm20948::SetI2CBypass (
    bool bypass_i2c
) 

Sets the bypass status of the I2C master bus support.

Parameters:

  • bypass_i2c Set 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

function SetMagDataRate

inline bool daisy::Icm20948::SetMagDataRate (
    ak09916_data_rate_t rate
) 

Set the magnetometer measurement rate

Parameters:

  • rate The rate to set.

Returns:

true: success false: failure


function SetupMag

inline Result daisy::Icm20948::SetupMag () 

function Write16

inline void daisy::Icm20948::Write16 (
    uint8_t reg,
    uint16_t value
) 

Writes a 16 bit value MSB first

Parameters:

  • reg the register address to write to
  • value the value to write to the register

function Write8

inline void daisy::Icm20948::Write8 (
    uint8_t reg,
    uint8_t value
) 

Writes an 8 bit value

Parameters:

  • reg the register address to write to
  • value the value to write to the register

function WriteAccelRange

inline void daisy::Icm20948::WriteAccelRange (
    uint8_t new_accel_range
) 

Sets the accelerometer's measurement range.

Parameters:

  • new_accel_range Measurement range to be set. Must be an icm20x_accel_range_t.

function WriteBits

inline void daisy::Icm20948::WriteBits (
    uint8_t reg,
    uint8_t data,
    uint8_t bits,
    uint8_t shift
) 

function WriteExternalRegister

inline bool daisy::Icm20948::WriteExternalRegister (
    uint8_t slv_addr,
    uint8_t reg_addr,
    uint8_t value
) 

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

Parameters:

  • slv_addr the 7-bit I2C address of the slave device
  • reg_addr the register address to write to
  • value the value to write

Returns:

true

Returns:

false


function WriteGyroRange

inline void daisy::Icm20948::WriteGyroRange (
    uint8_t new_gyro_range
) 

Sets the gyro's measurement range.

Parameters:

  • new_gyro_range Measurement range to be set. Must be an icm20x_gyro_range_t.

function WriteMagRegister

inline bool daisy::Icm20948::WriteMagRegister (
    uint8_t mag_reg_addr,
    uint8_t value
) 

function ~Icm20948

inline daisy::Icm20948::~Icm20948 () 


The documentation for this class was generated from the following file external-docs/libDaisy/src/dev/icm20948.h