AMS Advanced Air Mobility Sensors UG
Loading...
Searching...
No Matches
CIcm20789Driver Class Reference
Inheritance diagram for CIcm20789Driver:
CSoftwareComponent< CIcm20789Driver, 2U >

Classes

struct  SCalibParam
 Compensation parameters of the pressure sensors. The parameters are retrieved from the sensor's internal memory. More...
 

Public Types

enum class  EIcmIds : uint8_t { eInvalid = 0 , eIcm1 , eIcm2 }
 ICM20789 chip instances supported by the driver. More...
 

Public Member Functions

void Init () override
 
bool IsInitialized () override
 
void PollPressureSensor ()
 Implements an iteration of cyclic data exchange with the pressure sensor.
 
void PollInertialSensor ()
 Implements an iteration of cyclic data exchange with the inertial sensor.
 
bool RequestInertialSensorDataDma ()
 Request IMU data in DMA mode. When reception is completed, received bytes can be processed in the interrupt handler.
 
bool RequestPressureSensorDataDma ()
 Request pressure data in DMA mode. When reception is completed, received bytes can be processed in the interrupt handler.
 
bool TriggerPressureMeasurement ()
 Trigger measuring sequence of the pressure sensor.
 
void ParseReceivedImuDataDma ()
 Parses IMU data received in DMA mode.
 
void ParseReceivedPressureDataDma ()
 Parses pressure data received in DMA mode.
 
void InvalidateImuOutputPort ()
 
void InvalidatePressureOutputPort ()
 
void HardReset ()
 Execute a hard-reset if the ICM chip hangs. Powers down the sensor, waits, then powers on and initializes it again. The function lowers priority of the calling task for the duration of the reset procedure. In re-initialization fails, then the function will keep on re-trying.
 
- Public Member Functions inherited from CSoftwareComponent< CIcm20789Driver, 2U >
 CSoftwareComponent (CSoftwareComponent &)=delete
 
 CSoftwareComponent (CSoftwareComponent &&)=delete
 
CSoftwareComponentoperator= (const CSoftwareComponent &orOther)=delete
 
CSoftwareComponentoperator= (CSoftwareComponent &&orOther)=delete
 
virtual void Init ()=0
 
virtual bool IsInitialized ()=0
 

Private Types

using EAccelDynamicRange = NIcm20789DriverConfig::EAccelDynamicRange
 
using EGyroDynamicRange = NIcm20789DriverConfig::EGyroDynamicRange
 

Private Member Functions

 CIcm20789Driver (CIcm20789Driver &)=delete
 
 CIcm20789Driver (CIcm20789Driver &&)=delete
 
CIcm20789Driveroperator= (const CIcm20789Driver &orOther)=delete
 
CIcm20789Driveroperator= (CIcm20789Driver &&orOther)=delete
 
 CIcm20789Driver ()=delete
 
 CIcm20789Driver (EIcmIds eIcmChipId)
 The only valid constructor.
 
bool getChipIDBaro (uint8_t &urId)
 Get the Chip ID value barometr part.
 
bool softResetBaro ()
 Request soft reset.
 
bool setLowNoiseModeBaro ()
 Request measurement temperature and pressure.
 
bool getOTPBaro ()
 Get the Trim Parameters structure.
 
bool getTemperatureAndPressure (float &frTemperature, float &frPressure)
 Get the Temperature And Pressure values.
 
void processDataBaro (uint32_t iPressData, uint32_t iTempData, float &frPressure, float &frTemperature)
 Processing the raw data.
 
bool getImuChipId (uint8_t &urId)
 Get the Chip ID value Gyro sensor part.
 
bool softResetImu ()
 Request soft reset.
 
bool setAccelerometerDynamicRange (EAccelDynamicRange eAccelDynamicRange)
 Set dynamic range for accelerometer.
 
bool setGyroscopeDynamicRange (EGyroDynamicRange eGyroDynamicRange)
 Set dynamic range for gyroscope.
 
bool enableAllImuAxes ()
 Enable axes.
 
bool setImuSampleRate ()
 Set Imu sample rate.
 
bool setImuFilter ()
 Set Imu Filter config.
 
bool imuSelfTest ()
 Perform a self test procedure for an IMU.
 
bool enableBypass ()
 Enable bypass.
 
uint8_t crc8 (uint8_t *upData, uint8_t uLen)
 Calculate CRC-8 for Barometer.
 
bool collectTestStatistics (bool bWithSelfTestFlag, int *ipGyroResult, int *ipAccelResult)
 Collect self-test statistics.
 
bool checkAccelSelfTest (int *ipMeanNormalTestValues, int *ipMeanSelfTestValues)
 check accel self test
 
bool checkGyroSelfTest (int *ipMeanNormalTestValues, int *ipMeanSelfTestValues)
 check gyro self test
 
bool i2cWrite (uint8_t uIicAddress, uint8_t *upData, uint8_t uLen)
 
bool i2cRead (uint8_t uIicAddress, uint8_t *upData, uint8_t uLen)
 
bool i2cReadOtp (uint8_t uIicAddress, uint8_t *upData, uint8_t uLen)
 
bool readFromImuRegisters (uint8_t uReg, uint8_t *upData, uint8_t uLen)
 
bool writeImuRegister (uint8_t uReg, uint8_t uData)
 
bool i2cWaitOnFlag (uint32_t Flag, FlagStatus Status, uint32_t Timeout, uint32_t Tickstart)
 
I2C_HandleTypeDef * getI2CHandle (EIcmIds eIcmChipId)
 Get an I2C handle corresponding to the chip.
 
uint16_t getShutdownPinId (EIcmIds eIcmChipId)
 Get ID of the shutdown pin for the ICM chip instance.
 
GPIO_TypeDef * getPortOfShutdownPin (EIcmIds eIcmChipId)
 Get GPIO port that the shutdown pin belongs to.
 

Static Private Member Functions

static CIcm20789DrivergetInstanceImpl (unsigned uInstanceIndex)
 
static void osDelayIfInitTaskCompleted (uint32_t uDelay)
 Delay the task if initialization was completed. The function does nothing if Init task is running and delays for the given number of milliseconds otherwise.
 
static bool hasSignalSaturated (int16_t iValue)
 Return true if 16bit integer signal saturated.
 

Private Attributes

const uint16_t kauSelfTestEquation [256]
 
SCalibParam oCalibParam_
 
uint8_t auImuDataBuffer_ [14]
 
uint8_t auPressureDataBuffer_ [9]
 
uint32_t uI2CBusErrorCounter_ { 0U }
 I2C bus error counter.
 
bool bIsInitialized_ { false }
 Sensor status after initialization.
 
const EIcmIds keSensorId_
 ID of the sensor corresponding to the driver instance.
 
const uint16_t kuShutdownPin_
 ID of the shutdown pin.
 
GPIO_TypeDef *const opkShutdownPinPort_
 GPIO port to which the shutdown pin belongs.
 
I2C_HandleTypeDef *const opkI2CHandle_
 Pointer to the I2C handle.
 

Static Private Attributes

static constexpr float skfTempScale_ {333.87F}
 A scale factor for converting raw temperature readings to degrees Celsius.
 
static constexpr float skfTempOffset_ {21.0F}
 An offset for converting raw temperature readings to degrees Celsius.
 
static constexpr EAccelDynamicRange skeAccelDynamicRange_ {EAccelDynamicRange::e8g}
 Configured accelerometer dynamic range.
 
static constexpr EGyroDynamicRange skeGyroDynamicRange_ {EGyroDynamicRange::e500dps}
 Configured gyroscope dynamic range.
 
static constexpr float skfAccelRawToMetersPerSecondSquared_
 
static constexpr float skfGyroRawToRadiansPerSecond_
 
static constexpr uint32_t skuMaxI2CBusErrorCounterToReset_ { 300U }
 Maximum bus error counter before the chip is reset.
 

Friends

class CSoftwareComponent< CIcm20789Driver, 2U >
 

Additional Inherited Members

- Static Public Member Functions inherited from CSoftwareComponent< CIcm20789Driver, 2U >
static CIcm20789DriverGetInstance (unsigned uInstanceIndex=0U)
 
- Static Public Attributes inherited from CSoftwareComponent< CIcm20789Driver, 2U >
static constexpr unsigned skuInstanceCount_
 
- Protected Member Functions inherited from CSoftwareComponent< CIcm20789Driver, 2U >
 CSoftwareComponent ()=default
 
 ~CSoftwareComponent ()=default
 

Member Typedef Documentation

◆ EAccelDynamicRange

◆ EGyroDynamicRange

Member Enumeration Documentation

◆ EIcmIds

enum class CIcm20789Driver::EIcmIds : uint8_t
strong

ICM20789 chip instances supported by the driver.

Enumerator
eInvalid 

Invalid ICM chip.

eIcm1 

The first ICM20789.

eIcm2 

The second ICM20789.

Constructor & Destructor Documentation

◆ CIcm20789Driver() [1/4]

CIcm20789Driver::CIcm20789Driver ( CIcm20789Driver )
privatedelete

◆ CIcm20789Driver() [2/4]

CIcm20789Driver::CIcm20789Driver ( CIcm20789Driver &&  )
privatedelete

◆ CIcm20789Driver() [3/4]

CIcm20789Driver::CIcm20789Driver ( )
privatedelete

◆ CIcm20789Driver() [4/4]

CIcm20789Driver::CIcm20789Driver ( EIcmIds  eIcmChipId)
private

The only valid constructor.

Parameters
eIcmChipIdAn ID of the ICM20789 chip to instantiate a driver for.

Member Function Documentation

◆ checkAccelSelfTest()

bool CIcm20789Driver::checkAccelSelfTest ( int *  ipMeanNormalTestValues,
int *  ipMeanSelfTestValues 
)
private

check accel self test

Parameters
[in]ipMeanNormalTestValuesaverage value of normal test.
[in]ipMeanSelfTestValuesaverage value of self test
Returns
True – success, false – failure.

◆ checkGyroSelfTest()

bool CIcm20789Driver::checkGyroSelfTest ( int *  ipMeanNormalTestValues,
int *  ipMeanSelfTestValues 
)
private

check gyro self test

Parameters
[in]ipMeanNormalTestValuesaverage value of normal test.
[in]ipMeanSelfTestValuesaverage value of self test
Returns
True – success, false – failure.

◆ collectTestStatistics()

bool CIcm20789Driver::collectTestStatistics ( bool  bWithSelfTestFlag,
int *  ipGyroResult,
int *  ipAccelResult 
)
private

Collect self-test statistics.

Parameters
bWithSelfTestFlagRun test with self-test enabled flag
ipGyroResultTest statistics of a gyroscope
ipAccelResultTest statistics of an accelerometer
Returns
True – success. false – failure

◆ crc8()

uint8_t CIcm20789Driver::crc8 ( uint8_t *  upData,
uint8_t  uLen 
)
private

Calculate CRC-8 for Barometer.

Parameters
upData- pointer on data
uLen- length of data
Returns
CRC

◆ enableAllImuAxes()

bool CIcm20789Driver::enableAllImuAxes ( )
private

Enable axes.

Returns
True – success, false – failure.

◆ enableBypass()

bool CIcm20789Driver::enableBypass ( )
private

Enable bypass.

Returns
True – success, false – failure.

◆ getChipIDBaro()

bool CIcm20789Driver::getChipIDBaro ( uint8_t &  urId)
private

Get the Chip ID value barometr part.

Parameters
urIdreference to the ID variable
Returns
True – success, false – failure.

◆ getI2CHandle()

I2C_HandleTypeDef * CIcm20789Driver::getI2CHandle ( EIcmIds  eIcmChipId)
private

Get an I2C handle corresponding to the chip.

Parameters
eIcmChipIdAn ID of the ICM20789 chip.
Returns
nullptr if an ID is invalid, a pointer to a valid bus handle otherwise.

◆ getImuChipId()

bool CIcm20789Driver::getImuChipId ( uint8_t &  urId)
private

Get the Chip ID value Gyro sensor part.

Returns
True – success, false – failure.

◆ getInstanceImpl()

CIcm20789Driver & CIcm20789Driver::getInstanceImpl ( unsigned  uInstanceIndex)
staticprivate

◆ getOTPBaro()

bool CIcm20789Driver::getOTPBaro ( )
private

Get the Trim Parameters structure.

Returns
True – success, false – failure.

◆ getPortOfShutdownPin()

GPIO_TypeDef * CIcm20789Driver::getPortOfShutdownPin ( EIcmIds  eIcmChipId)
private

Get GPIO port that the shutdown pin belongs to.

◆ getShutdownPinId()

uint16_t CIcm20789Driver::getShutdownPinId ( EIcmIds  eIcmChipId)
private

Get ID of the shutdown pin for the ICM chip instance.

◆ getTemperatureAndPressure()

bool CIcm20789Driver::getTemperatureAndPressure ( float &  frTemperature,
float &  frPressure 
)
private

Get the Temperature And Pressure values.

Parameters
frTemperaturereference to the temperature variable
frPressurereference to the pressure variable
Returns
True – success, false – failure.

◆ HardReset()

void CIcm20789Driver::HardReset ( )

Execute a hard-reset if the ICM chip hangs. Powers down the sensor, waits, then powers on and initializes it again. The function lowers priority of the calling task for the duration of the reset procedure. In re-initialization fails, then the function will keep on re-trying.

◆ hasSignalSaturated()

static bool CIcm20789Driver::hasSignalSaturated ( int16_t  iValue)
inlinestaticprivate

Return true if 16bit integer signal saturated.

◆ i2cRead()

bool CIcm20789Driver::i2cRead ( uint8_t  uIicAddress,
uint8_t *  upData,
uint8_t  uLen 
)
private

Read via I2C.

Parameters
uIicAddressDevice address to read from.
upDataA pointer to output data buffer.
uLenNumber of bytes to read.
Returns
True – success, false – failure.

◆ i2cReadOtp()

bool CIcm20789Driver::i2cReadOtp ( uint8_t  uIicAddress,
uint8_t *  upData,
uint8_t  uLen 
)
private

Read via I2C. The function uses increased timeout value.

Parameters
uIicAddressDevice address to read from.
upDataA pointer to output data buffer.
uLenNumber of bytes to read.
Returns
True – success, false – failure.

◆ i2cWaitOnFlag()

bool CIcm20789Driver::i2cWaitOnFlag ( uint32_t  Flag,
FlagStatus  Status,
uint32_t  Timeout,
uint32_t  Tickstart 
)
private

Checks the status and waits till I2C bus flags are ready

Parameters
Flagspecifies the I2C flag to check.
StatusThe new Flag status (SET or RESET).
TimeoutTimeout duration
TickstartTick start value
Returns
True – success, false – failure.

◆ i2cWrite()

bool CIcm20789Driver::i2cWrite ( uint8_t  uIicAddress,
uint8_t *  upData,
uint8_t  uLen 
)
private

Write via I2C.

Parameters
uIicAddressDevice address
upDataPointer do data buffer to be written
uLenNumber of bytes to write
Returns
True – success, false – failure.

◆ imuSelfTest()

bool CIcm20789Driver::imuSelfTest ( )
private

Perform a self test procedure for an IMU.

Returns
True – self test successful and passed, false – otherwise.

◆ Init()

void CIcm20789Driver::Init ( )
overridevirtual

Initialize the software component.

Implements CSoftwareComponent< CIcm20789Driver, 2U >.

◆ InvalidateImuOutputPort()

void CIcm20789Driver::InvalidateImuOutputPort ( )

Writes default invalid data to IMU output port.

◆ InvalidatePressureOutputPort()

void CIcm20789Driver::InvalidatePressureOutputPort ( )

Writes default invalid data to pressure output port.

◆ IsInitialized()

bool CIcm20789Driver::IsInitialized ( )
overridevirtual

Get initialization status of the software component.

Returns
True – the component is initialized, false otherwise.

Implements CSoftwareComponent< CIcm20789Driver, 2U >.

◆ operator=() [1/2]

CIcm20789Driver & CIcm20789Driver::operator= ( CIcm20789Driver &&  orOther)
privatedelete

◆ operator=() [2/2]

CIcm20789Driver & CIcm20789Driver::operator= ( const CIcm20789Driver orOther)
privatedelete

◆ osDelayIfInitTaskCompleted()

static void CIcm20789Driver::osDelayIfInitTaskCompleted ( uint32_t  uDelay)
inlinestaticprivate

Delay the task if initialization was completed. The function does nothing if Init task is running and delays for the given number of milliseconds otherwise.

Parameters
uDelayDelay duration in [ms].

◆ ParseReceivedImuDataDma()

void CIcm20789Driver::ParseReceivedImuDataDma ( )

Parses IMU data received in DMA mode.

◆ ParseReceivedPressureDataDma()

void CIcm20789Driver::ParseReceivedPressureDataDma ( )

Parses pressure data received in DMA mode.

◆ PollInertialSensor()

void CIcm20789Driver::PollInertialSensor ( )

Implements an iteration of cyclic data exchange with the inertial sensor.

◆ PollPressureSensor()

void CIcm20789Driver::PollPressureSensor ( )

Implements an iteration of cyclic data exchange with the pressure sensor.

◆ processDataBaro()

void CIcm20789Driver::processDataBaro ( uint32_t  iPressData,
uint32_t  iTempData,
float &  frPressure,
float &  frTemperature 
)
private

Processing the raw data.

Parameters
iPressData- Raw pressure data from sensor
iTempData- Raw temperature data from sensor
frTemperaturereference to the temperature variable
frPressurereference to the pressure variable

◆ readFromImuRegisters()

bool CIcm20789Driver::readFromImuRegisters ( uint8_t  uReg,
uint8_t *  upData,
uint8_t  uLen 
)
private

Read data from registers of the IMU starting from the specified address.

Parameters
uRegRegister address to start the read from
upDataPointer to the output data buffer
uLenNumber of bytes to read
Returns
True – success, false – failure.

◆ RequestInertialSensorDataDma()

bool CIcm20789Driver::RequestInertialSensorDataDma ( )

Request IMU data in DMA mode. When reception is completed, received bytes can be processed in the interrupt handler.

Returns
Status of the DMA request, true – OK, false otherwise.

◆ RequestPressureSensorDataDma()

bool CIcm20789Driver::RequestPressureSensorDataDma ( )

Request pressure data in DMA mode. When reception is completed, received bytes can be processed in the interrupt handler.

Returns
Status of the DMA request, true – OK, false otherwise.

◆ setAccelerometerDynamicRange()

bool CIcm20789Driver::setAccelerometerDynamicRange ( EAccelDynamicRange  eAccelDynamicRange)
private

Set dynamic range for accelerometer.

Returns
True – success, false – failure.

◆ setGyroscopeDynamicRange()

bool CIcm20789Driver::setGyroscopeDynamicRange ( EGyroDynamicRange  eGyroDynamicRange)
private

Set dynamic range for gyroscope.

Returns
True – success, false – failure.

◆ setImuFilter()

bool CIcm20789Driver::setImuFilter ( )
private

Set Imu Filter config.

Returns
True – success, false – failure.

◆ setImuSampleRate()

bool CIcm20789Driver::setImuSampleRate ( )
private

Set Imu sample rate.

Returns
True – success, false – failure.

◆ setLowNoiseModeBaro()

bool CIcm20789Driver::setLowNoiseModeBaro ( )
private

Request measurement temperature and pressure.

Returns
True – success, false – failure.

◆ softResetBaro()

bool CIcm20789Driver::softResetBaro ( )
private

Request soft reset.

Returns
True – success, false – failure.

◆ softResetImu()

bool CIcm20789Driver::softResetImu ( )
private

Request soft reset.

Returns
True – success, false – failure.

◆ TriggerPressureMeasurement()

bool CIcm20789Driver::TriggerPressureMeasurement ( )

Trigger measuring sequence of the pressure sensor.

Returns
True – success, false – failure.

◆ writeImuRegister()

bool CIcm20789Driver::writeImuRegister ( uint8_t  uReg,
uint8_t  uData 
)
private

Write a byte to IMU's register

Parameters
uRegRegister address
uDataA value to write
Returns
True – success, false – failure.

Friends And Related Function Documentation

◆ CSoftwareComponent< CIcm20789Driver, 2U >

friend class CSoftwareComponent< CIcm20789Driver, 2U >
friend

Member Data Documentation

◆ auImuDataBuffer_

uint8_t CIcm20789Driver::auImuDataBuffer_[14]
private

◆ auPressureDataBuffer_

uint8_t CIcm20789Driver::auPressureDataBuffer_[9]
private

◆ bIsInitialized_

bool CIcm20789Driver::bIsInitialized_ { false }
private

Sensor status after initialization.

◆ kauSelfTestEquation

const uint16_t CIcm20789Driver::kauSelfTestEquation[256]
private

◆ keSensorId_

const EIcmIds CIcm20789Driver::keSensorId_
private

ID of the sensor corresponding to the driver instance.

◆ kuShutdownPin_

const uint16_t CIcm20789Driver::kuShutdownPin_
private

ID of the shutdown pin.

◆ oCalibParam_

SCalibParam CIcm20789Driver::oCalibParam_
private

◆ opkI2CHandle_

I2C_HandleTypeDef* const CIcm20789Driver::opkI2CHandle_
private

Pointer to the I2C handle.

◆ opkShutdownPinPort_

GPIO_TypeDef* const CIcm20789Driver::opkShutdownPinPort_
private

GPIO port to which the shutdown pin belongs.

◆ skeAccelDynamicRange_

constexpr EAccelDynamicRange CIcm20789Driver::skeAccelDynamicRange_ {EAccelDynamicRange::e8g}
staticconstexprprivate

Configured accelerometer dynamic range.

◆ skeGyroDynamicRange_

constexpr EGyroDynamicRange CIcm20789Driver::skeGyroDynamicRange_ {EGyroDynamicRange::e500dps}
staticconstexprprivate

Configured gyroscope dynamic range.

◆ skfAccelRawToMetersPerSecondSquared_

constexpr float CIcm20789Driver::skfAccelRawToMetersPerSecondSquared_
staticconstexprprivate
Initial value:
* NIcm20789DriverConfig::getAccelerometerRangeInG<skeAccelDynamicRange_>())
/ static_cast<float>(std::numeric_limits<int16_t>::max())}
static constexpr float skfGravity
Gravity constant from "ICAO Standard Atmosphere".
Definition: CGeoConstants.h:21

◆ skfGyroRawToRadiansPerSecond_

constexpr float CIcm20789Driver::skfGyroRawToRadiansPerSecond_
staticconstexprprivate
Initial value:
* NIcm20789DriverConfig::getGyroscopeRangeInDegreesPerSecond<skeGyroDynamicRange_>())
/ static_cast<float>(std::numeric_limits<int16_t>::max())}
static constexpr float skfPi_
Definition of float pi.
Definition: CMathConstants.h:16

◆ skfTempOffset_

constexpr float CIcm20789Driver::skfTempOffset_ {21.0F}
staticconstexprprivate

An offset for converting raw temperature readings to degrees Celsius.

◆ skfTempScale_

constexpr float CIcm20789Driver::skfTempScale_ {333.87F}
staticconstexprprivate

A scale factor for converting raw temperature readings to degrees Celsius.

◆ skuMaxI2CBusErrorCounterToReset_

constexpr uint32_t CIcm20789Driver::skuMaxI2CBusErrorCounterToReset_ { 300U }
staticconstexprprivate

Maximum bus error counter before the chip is reset.

◆ uI2CBusErrorCounter_

uint32_t CIcm20789Driver::uI2CBusErrorCounter_ { 0U }
private

I2C bus error counter.


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