Skip to content

Commit

Permalink
Merge pull request #10423 from ultrazar/patch-1
Browse files Browse the repository at this point in the history
Added IMUTemperature read function for ICM42605
  • Loading branch information
mmosca authored Nov 4, 2024
2 parents 78e1392 + a3afa3f commit df9b18f
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/main/drivers/accgyro/accgyro_icm42605.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@

#define ICM42605_RA_GYRO_DATA_X1 0x25
#define ICM42605_RA_ACCEL_DATA_X1 0x1F
#define ICM42605_RA_TEMP_DATA1 0x1D

#define ICM42605_RA_INT_CONFIG 0x14
#define ICM42605_INT1_MODE_PULSED (0 << 2)
Expand Down Expand Up @@ -321,6 +322,20 @@ static bool icm42605GyroRead(gyroDev_t *gyro)
return true;
}

static bool icm42605ReadTemperature(gyroDev_t *gyro, int16_t * temp)
{
uint8_t data[2];

const bool ack = busReadBuf(gyro->busDev, ICM42605_RA_TEMP_DATA1, data, 2);
if (!ack) {
return false;
}
// From datasheet: Temperature in Degrees Centigrade = (TEMP_DATA / 132.48) + 25
*temp = ( int16_val_big_endian(data, 0) / 13.248 ) + 250; // Temperature stored as degC*10

return true;
}

bool icm42605GyroDetect(gyroDev_t *gyro)
{
gyro->busDev = busDeviceInit(BUSTYPE_ANY, DEVHW_ICM42605, gyro->imuSensorToUse, OWNER_MPU);
Expand All @@ -340,7 +355,7 @@ bool icm42605GyroDetect(gyroDev_t *gyro)
gyro->initFn = icm42605AccAndGyroInit;
gyro->readFn = icm42605GyroRead;
gyro->intStatusFn = gyroCheckDataReady;
gyro->temperatureFn = NULL;
gyro->temperatureFn = icm42605ReadTemperature;
gyro->scale = 1.0f / 16.4f; // 16.4 dps/lsb scalefactor
gyro->gyroAlign = gyro->busDev->param;

Expand Down

0 comments on commit df9b18f

Please sign in to comment.