Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added IMUTemperature read function for ICM42605 #10423

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading