From c269692b1d6d562dcde3c3ad422e75af4d5823ad Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Tue, 3 May 2022 19:33:17 -0700 Subject: [PATCH] drivers/sensor: lsm6dso: Remove LE to CPU conversions In ST HAL v2.00, the functions to get the raw sensors values, e.g. lsm6dso_acceleration_raw_get(), convert from little-endian to CPU. Previous versions of ST HAL didn't do this. The conversion here in the driver is converting a second time. It's not an issue on a LE system, the conversion is a no-op, but on a BE system it would be broken. Signed-off-by: Trent Piepho --- drivers/sensor/lsm6dso/lsm6dso.c | 19 +++---------------- drivers/sensor/lsm6dso/lsm6dso.h | 2 +- 2 files changed, 4 insertions(+), 17 deletions(-) diff --git a/drivers/sensor/lsm6dso/lsm6dso.c b/drivers/sensor/lsm6dso/lsm6dso.c index 6938579d1e9..7b6b0357c39 100644 --- a/drivers/sensor/lsm6dso/lsm6dso.c +++ b/drivers/sensor/lsm6dso/lsm6dso.c @@ -297,17 +297,12 @@ static int lsm6dso_sample_fetch_accel(const struct device *dev) const struct lsm6dso_config *cfg = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; struct lsm6dso_data *data = dev->data; - int16_t buf[3]; - if (lsm6dso_acceleration_raw_get(ctx, buf) < 0) { + if (lsm6dso_acceleration_raw_get(ctx, data->acc) < 0) { LOG_DBG("Failed to read sample"); return -EIO; } - data->acc[0] = sys_le16_to_cpu(buf[0]); - data->acc[1] = sys_le16_to_cpu(buf[1]); - data->acc[2] = sys_le16_to_cpu(buf[2]); - return 0; } @@ -316,17 +311,12 @@ static int lsm6dso_sample_fetch_gyro(const struct device *dev) const struct lsm6dso_config *cfg = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; struct lsm6dso_data *data = dev->data; - int16_t buf[3]; - if (lsm6dso_angular_rate_raw_get(ctx, buf) < 0) { + if (lsm6dso_angular_rate_raw_get(ctx, data->gyro) < 0) { LOG_DBG("Failed to read sample"); return -EIO; } - data->gyro[0] = sys_le16_to_cpu(buf[0]); - data->gyro[1] = sys_le16_to_cpu(buf[1]); - data->gyro[2] = sys_le16_to_cpu(buf[2]); - return 0; } @@ -336,15 +326,12 @@ static int lsm6dso_sample_fetch_temp(const struct device *dev) const struct lsm6dso_config *cfg = dev->config; stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx; struct lsm6dso_data *data = dev->data; - int16_t buf; - if (lsm6dso_temperature_raw_get(ctx, &buf) < 0) { + if (lsm6dso_temperature_raw_get(ctx, &data->temp_sample) < 0) { LOG_DBG("Failed to read sample"); return -EIO; } - data->temp_sample = sys_le16_to_cpu(buf); - return 0; } #endif diff --git a/drivers/sensor/lsm6dso/lsm6dso.h b/drivers/sensor/lsm6dso/lsm6dso.h index 1f69f54389a..336ebcdd475 100644 --- a/drivers/sensor/lsm6dso/lsm6dso.h +++ b/drivers/sensor/lsm6dso/lsm6dso.h @@ -79,7 +79,7 @@ struct lsm6dso_data { int16_t gyro[3]; uint32_t gyro_gain; #if defined(CONFIG_LSM6DSO_ENABLE_TEMP) - int temp_sample; + int16_t temp_sample; #endif #if defined(CONFIG_LSM6DSO_SENSORHUB) uint8_t ext_data[2][6];