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

drivers: sensor: bmi08x: fix temperature interface and trigger setting #82405

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
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
31 changes: 28 additions & 3 deletions drivers/sensor/bosch/bmi08x/bmi08x_accel.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,16 +454,41 @@ static int bmi08x_temp_channel_get(const struct device *dev, struct sensor_value
{
uint16_t temp_raw = 0U;
int32_t temp_micro = 0;
int16_t temp_int11 = 0;
int ret;

ret = bmi08x_accel_word_read(dev, BMI08X_REG_TEMP_MSB, &temp_raw);
if (ret < 0) {
if (!ret) {
temp_int11 = (temp_raw & 0xFF) << 3;
} else {
ttwards marked this conversation as resolved.
Show resolved Hide resolved
LOG_ERR("Error reading BMI08X_REG_TEMP_MSB. (err %d)", ret);
return ret;
}

/* the scale is 1/2^5/LSB = 31250 micro degrees */
temp_micro = BMI08X_TEMP_OFFSET * 1000000ULL + temp_raw * 31250ULL;
if (temp_raw == 0x80) {
/* temperature invalid */
ttwards marked this conversation as resolved.
Show resolved Hide resolved
LOG_ERR("BMI08X returned invalid temperature.");
return -ENODATA;
}

ret = bmi08x_accel_word_read(dev, BMI08X_REG_TEMP_LSB, &temp_raw);
if (!ret) {
temp_int11 |= (temp_raw & 0xE0) >> 5;
} else {
ttwards marked this conversation as resolved.
Show resolved Hide resolved
LOG_ERR("Error reading BMI08X_REG_TEMP_LSB. (err %d)", ret);
return ret;
}
/*
* int11 type ranges in [-1024, 1023]
* the 11st bit declares +/-
* if larger than 1023, it is negative.
*/
if (temp_int11 > 1023) {
ttwards marked this conversation as resolved.
Show resolved Hide resolved
temp_int11 -= 2048;
}
/* the value ranges in [-504, 496] */
/* the scale is 0.125°C/LSB = 125 micro degrees */
temp_micro = temp_int11 * 125 + 23 * 1000000;
val->val1 = temp_micro / 1000000ULL;
val->val2 = temp_micro % 1000000ULL;

Expand Down
2 changes: 1 addition & 1 deletion drivers/sensor/bosch/bmi08x/bmi08x_accel_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ int bmi08x_trigger_set_acc(const struct device *dev, const struct sensor_trigger
struct bmi08x_accel_data *data = dev->data;

if ((trig->chan == SENSOR_CHAN_ACCEL_XYZ) && (trig->type == SENSOR_TRIG_DATA_READY)) {
data->handler_drdy_acc = handler;
data->drdy_trig_acc = trig;
data->handler_drdy_acc = handler;
return 0;
}

Expand Down
2 changes: 1 addition & 1 deletion drivers/sensor/bosch/bmi08x/bmi08x_gyro_trigger.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ int bmi08x_trigger_set_gyr(const struct device *dev, const struct sensor_trigger
struct bmi08x_gyro_data *data = dev->data;

if ((trig->chan == SENSOR_CHAN_GYRO_XYZ) && (trig->type == SENSOR_TRIG_DATA_READY)) {
data->handler_drdy_gyr = handler;
data->drdy_trig_gyr = trig;
data->handler_drdy_gyr = handler;
return 0;
}

Expand Down
Loading