Skip to content

daisy::Icm20948

Module: External

Device support for ICM20948 IMU sensor. More...

#include <icm20948.h>

Public Classes

Name
struct Config
struct Icm20948Vect

Public Types

Name
enum icm20948_accel_range_t
enum icm20948_gyro_range_t
enum ak09916_data_rate_t
enum Result

Public Functions

Name
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()

Detailed Description

template <typename Transport >
class daisy::Icm20948;

Device support for ICM20948 IMU sensor.

Author: beserge

Date: December 2021

Public Types Documentation

enum icm20948_accel_range_t

Enumerator Value Description
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

Enumerator Value Description
ICM20948_GYRO_RANGE_250_DPS
ICM20948_GYRO_RANGE_500_DPS
ICM20948_GYRO_RANGE_1000_DPS
ICM20948_GYRO_RANGE_2000_DPS

The gyro data range

enum ak09916_data_rate_t

Enumerator Value Description
AK09916_MAG_DATARATE_SHUTDOWN 0x0 Stops measurement updates.
AK09916_MAG_DATARATE_SINGLE 0x1 Takes a single measurement then switches to AK09916_MAG_DATARATE_SHUTDOWN
AK09916_MAG_DATARATE_10_HZ 0x2 updates at 10Hz
AK09916_MAG_DATARATE_20_HZ 0x4 updates at 20Hz
AK09916_MAG_DATARATE_50_HZ 0x6 updates at 50Hz
AK09916_MAG_DATARATE_100_HZ 0x8 updates at 100Hz

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

enum Result

Enumerator Value Description
OK 0
ERR

Public Functions Documentation

function Icm20948

inline Icm20948()

function ~Icm20948

inline ~Icm20948()

function Init

inline Result Init(
    Config config
)

Parameters:

  • config Configuration settings

Initialize the Icm20948 device


function Reset

inline void Reset()

Reset the internal registers and restores the default settings


function GetMagId

inline uint8_t GetMagId()

function SetupMag

inline Result SetupMag()

function ReadMagRegister

inline uint8_t ReadMagRegister(
    uint8_t mag_reg_addr
)

Parameters:

  • slv_addr
  • mag_reg_addr
  • num_finished_checks

Return: uint8_t


function WriteMagRegister

inline bool WriteMagRegister(
    uint8_t mag_reg_addr,
    uint8_t value
)

function ScaleValues

inline void ScaleValues()

function SetAccelRateDivisor

inline void SetAccelRateDivisor(
    uint16_t new_accel_divisor
)

Parameters:

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

Sets the accelerometer's data rate divisor.


function GetAccelRange

inline icm20948_accel_range_t GetAccelRange()

Return: The accelerometer's measurement range (icm20948_accel_range_t).

Get the accelerometer's measurement range.


function ReadAccelRange

inline uint8_t ReadAccelRange()

Return: The accelerometer's measurement range (icm20x_accel_range_t).

Get the accelerometer's measurement range.


function WriteAccelRange

inline void WriteAccelRange(
    uint8_t new_accel_range
)

Parameters:

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

Sets the accelerometer's measurement range.


function SetAccelRange

inline void SetAccelRange(
    icm20948_accel_range_t new_accel_range
)

Parameters:

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

Sets the accelerometer's measurement range.


function SetGyroRateDivisor

inline void SetGyroRateDivisor(
    uint8_t new_gyro_divisor
)

Parameters:

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

Sets the gyro's data rate divisor.


function GetGyroRange

inline icm20948_gyro_range_t GetGyroRange()

Return: The gyro's measurement range (icm20948_gyro_range_t).

Get the gyro's measurement range.


function SetGyroRange

inline void SetGyroRange(
    icm20948_gyro_range_t new_gyro_range
)

Parameters:

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

Sets the gyro's measurement range.


function WriteGyroRange

inline void WriteGyroRange(
    uint8_t new_gyro_range
)

Parameters:

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

Sets the gyro's measurement range.


function ReadGyroRange

inline uint8_t ReadGyroRange()

Return: The gyro's measurement range (icm20x_gyro_range_t).

Get the gyro's measurement range.


function GetMagDataRate

inline ak09916_data_rate_t GetMagDataRate()

Return: ak09916_data_rate_t the current rate

Get the current magnetometer measurement rate


function SetMagDataRate

inline bool SetMagDataRate(
    ak09916_data_rate_t rate
)

Parameters:

  • rate The rate to set.

Return: true: success false: failure

Set the magnetometer measurement rate


function SetBank

inline void SetBank(
    uint8_t bank_number
)

Parameters:

  • bank_number The bank to set to active

Sets register bank.


function ReadExternalRegister

inline uint8_t ReadExternalRegister(
    uint8_t slv_addr,
    uint8_t reg_addr
)

Parameters:

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

Return: the requested register value

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


function WriteExternalRegister

inline bool WriteExternalRegister(
    uint8_t slv_addr,
    uint8_t reg_addr,
    uint8_t value
)

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

Return:

  • true
  • false

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


function AuxillaryRegisterTransaction

inline uint8_t AuxillaryRegisterTransaction(
    bool read,
    uint8_t slv_addr,
    uint8_t reg_addr,
    uint8_t value
)

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

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

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


function Process

inline void Process()

Updates the measurement data for all sensors simultaneously


function GetAccelVect

inline Icm20948Vect GetAccelVect()

function GetGyroVect

inline Icm20948Vect GetGyroVect()

function GetMagVect

inline Icm20948Vect GetMagVect()

function GetTemp

inline float GetTemp()

function Read8

inline uint8_t Read8(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the data uint8_t read from the device

Reads an 8 bit value


function Write8

inline void Write8(
    uint8_t reg,
    uint8_t value
)

Parameters:

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

Writes an 8 bit value


function Write16

inline void Write16(
    uint8_t reg,
    uint16_t value
)

Parameters:

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

Writes a 16 bit value MSB first


function ReadReg

inline void ReadReg(
    uint8_t reg,
    uint8_t * buff,
    uint8_t size
)

Read from a reg address a defined number of bytes


function ReadBits

inline uint8_t ReadBits(
    uint8_t reg,
    uint8_t bits,
    uint8_t shift
)

function WriteBits

inline void WriteBits(
    uint8_t reg,
    uint8_t data,
    uint8_t bits,
    uint8_t shift
)

function SetI2CBypass

inline void SetI2CBypass(
    bool bypass_i2c
)

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

Sets the bypass status of the I2C master bus support.


function EnableI2CMaster

inline Result EnableI2CMaster(
    bool enable_i2c_master
)

Parameters:

  • enable_i2c_master true: enable false: disable

Return: true: success false: error

Enable or disable the I2C mastercontroller


function ConfigureI2CMaster

inline Result ConfigureI2CMaster(
    void 
)

Return: true: success false: failure

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


function ResetI2CMaster

inline void ResetI2CMaster(
    void 
)

Reset the I2C master


function AuxI2CBusSetupFailed

inline Result AuxI2CBusSetupFailed(
    void 
)

function GetTransportError

inline Result GetTransportError()

Return: Whether the transport has errored since the last check

Get and reset the transport error flag

---

Updated on 2024-01-03 at 19:41:01 +0000