24 #include "native_gecko.h"
37 static void gpioInterrupt( uint8_t pin );
57 static float gyroSampleRate;
58 static float accelSampleRate;
59 static bool dataReady;
60 static uint32_t IMU_interruptCount = 0;
61 static uint32_t IMU_isDataReadyQueryCount = 0;
62 static uint32_t IMU_isDataReadyTrueCount = 0;
87 float gyroBiasScaled[3];
96 printf(
"IMU init..." );
99 printf(
"Failed! status = %08Xh\r\n", status );
108 printf(
"IMU device ID = %02Xh\r\n", devid );
112 printf(
"IMU gyro calibration..." );
115 printf(
"Failed! status = %08Xh\r\n", status );
120 printf(
"Gyroscope bias (deg/s) : " );
121 printf(
"gx: % 6.4f, gy: % 6.4f, gz: % 6.4f\r\n", gyroBiasScaled[0], gyroBiasScaled[1], gyroBiasScaled[2] );
200 printf(
"IMU sample rate set to %f Hz (accel), %f Hz (gyro)\r\n", accelSampleRate, gyroSampleRate );
280 ovec[1] = (int16_t) ( 100.0f * IMU_RAD_TO_DEG_FACTOR * fuseObj.
orientation[1] );
281 ovec[2] = (int16_t) ( 100.0f * IMU_RAD_TO_DEG_FACTOR * fuseObj.
orientation[2] );
300 gvec[0] = (int16_t) ( 100.0f * fuseObj.
gVector[0] );
301 gvec[1] = (int16_t) ( 100.0f * fuseObj.
gVector[1] );
302 gvec[2] = (int16_t) ( 100.0f * fuseObj.
gVector[2] );
458 IMU_isDataReadyQueryCount++;
461 IMU_isDataReadyTrueCount++;
536 static void gpioInterrupt( uint8_t pin )
540 IMU_interruptCount++;
543 gecko_external_signal( 1 );
Structure to store the sensor fusion data.
bool IMU_isDataReadyFlag(void)
Checks if there is new accel/gyro data available for read. In case of ver 0.3.0 and older of the PIC ...
void IMU_config(float sampleRate)
Configures the IMU.
uint32_t ICM20648_deInit(void)
De-initializes the ICM20648 sensor by disconnecting the supply and SPI lines.
#define ICM20648_GYRO_FULLSCALE_250DPS
uint32_t ICM20648_interruptEnable(bool dataReadyEnable, bool womEnable)
Enables or disables the interrupts in the ICM20648 chip.
bool BOARD_picIsLegacyIntCtrl(void)
Checks if the legacy interrupt control method should be used.
void UTIL_delay(uint32_t ms)
Delays number of msTick Systicks (1 ms)
Driver for the Invensense ICM20648 6-axis motion sensor.
CMSIS Cortex-M Peripheral Access Layer for Silicon Laboratories microcontroller devices.
#define ICM20648_GYRO_BW_51HZ
uint32_t ICM20648_gyroDataRead(float *gyro)
Reads the raw gyroscope value and converts to deg/sec value based on the actual resolution.
void GPIOINT_CallbackRegister(uint8_t pin, GPIOINT_IrqCallbackPtr_t callbackPtr)
Registers user callback for given pin number.
uint32_t BOARD_picWriteReg(uint8_t reg, uint8_t value)
Writes a register in the IO expander.
uint32_t ICM20648_gyroBandwidthSet(uint8_t gyroBw)
Sets the bandwidth of the gyroscope.
#define BOARD_PIC_INT_WAKE_PORT
uint32_t ICM20648_lowPowerModeEnter(bool enAccel, bool enGyro, bool enTemp)
Enables or disables the sensors in low power mode in the ICM20648 chip.
uint8_t IMU_getState(void)
Returns IMU state.
float ICM20648_gyroSampleRateSet(float sampleRate)
Sets the sample rate of the accelerometer.
void IMU_getGyroData(float gvec[3])
Retrieves the raw gyroscope data from the IMU.
uint32_t BOARD_imuEnableIRQ(bool enable)
Enables or disables the accelerometer and gyroscope GPIO interrupt.
void IMU_fuseAccelerometerSetSampleRate(IMU_SensorFusion *f, float rate)
Sets the accelerometer sample rate in the IMU_SensorFusion structure.
void IMU_update(void)
Gets a new set of data from the accel and gyro sensor and updates the fusion calculation.
void IMU_getAccelerometerData(float avec[3])
Retrieves the raw acceleration data from the IMU.
uint32_t IMU_gyroCalibrate(void)
Performs gyroscope calibration to cancel gyro bias.
Utility Functions for the Thunderboard Sense.
void IMU_gyroGet(int16_t gvec[3])
Retrieves the processed gyroscope data.
void IMU_fuseReset(IMU_SensorFusion *f)
Clears the values of the sensor fusion object.
uint32_t IMU_init(void)
Initializes and calibrates the IMU.
Inertial Measurement Unit DCM matrix related routines.
#define BOARD_PIC_REG_INT_CLEAR
uint32_t ICM20648_init(void)
Initializes the ICM20648 sensor. Enables the power supply and SPI lines, sets up the host SPI control...
#define IMU_STATE_CALIBRATING
uint32_t ICM20648_accelDataRead(float *accel)
Reads the raw acceleration value and converts to g value based on the actual resolution.
void IMU_clearDataReadyFlag(void)
Clears the IMU data ready flag. In case of ver 0.3.0 and older of the PIC firmware the interrupt regi...
#define IMU_STATE_INITIALIZING
void IMU_getGyroCorrectionAngles(float acorr[3])
Retrieves the processed gyroscope correction angles.
uint32_t ICM20648_interruptStatusRead(uint32_t *intStatus)
Reads the interrupt status registers of the ICM20648 chip.
void IMU_accelerationGet(int16_t avec[3])
Retrieves the processed acceleration data.
bool IMU_isDataReady(void)
Checks if there is new accel/gyro data available for read.
void IMU_fuseNew(IMU_SensorFusion *f)
Initializes a new IMU_SensorFusion structure.
void GPIOINT_Init(void)
Initialization of GPIOINT module.
#define ICM20648_ACCEL_FULLSCALE_2G
uint32_t ICM20648_gyroFullscaleSet(uint8_t gyroFs)
Sets the full scale value of the gyroscope.
float ICM20648_accelSampleRateSet(float sampleRate)
Sets the sample rate of the gyroscope.
bool ICM20648_isDataReady(void)
Checks if new data is available for read.
uint32_t ICM20648_sensorEnable(bool accel, bool gyro, bool temp)
Enables or disables the sensors in the ICM20648 chip.
uint32_t ICM20648_getDeviceID(uint8_t *devID)
Reads the device ID of the ICM20648.
#define BOARD_PIC_INT_WAKE_PIN
uint32_t ICM20648_accelFullscaleSet(uint8_t accelFs)
Sets the full scale value of the accelerometer.
void IMU_fuseUpdate(IMU_SensorFusion *f)
Updates the fusion calculation.
#define ICM20648_ACCEL_BW_1210HZ
uint32_t aAccumulatorCount
#define IMU_RAD_TO_DEG_FACTOR
__STATIC_INLINE unsigned int GPIO_PinInGet(GPIO_Port_TypeDef port, unsigned int pin)
Read the pad value for a single pin in a GPIO port.
void IMU_fuseGyroSetSampleRate(IMU_SensorFusion *f, float rate)
Sets the gyro sample rate and related values in the IMU_SensorFusion structure.
BOARD module header file.
uint32_t ICM20648_gyroCalibrate(float *gyroBiasScaled)
Gyroscope calibration function. Reads the gyroscope values while the device is at rest and in level...
void IMU_reset(void)
Resets the fusion calculation.
#define IMU_STATE_DISABLED
void IMU_orientationGet(int16_t ovec[3])
Retrieves the processed orientation data.
uint32_t IMU_deInit(void)
De-initializes the IMU chip.
uint32_t ICM20648_accelBandwidthSet(uint8_t accelBw)
Sets the bandwidth of the accelerometer.