Skip to content

Commit c269692

Browse files
trentp-igormbolivar-nordic
authored andcommitted
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 <[email protected]>
1 parent d611284 commit c269692

File tree

2 files changed

+4
-17
lines changed

2 files changed

+4
-17
lines changed

drivers/sensor/lsm6dso/lsm6dso.c

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -297,17 +297,12 @@ static int lsm6dso_sample_fetch_accel(const struct device *dev)
297297
const struct lsm6dso_config *cfg = dev->config;
298298
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
299299
struct lsm6dso_data *data = dev->data;
300-
int16_t buf[3];
301300

302-
if (lsm6dso_acceleration_raw_get(ctx, buf) < 0) {
301+
if (lsm6dso_acceleration_raw_get(ctx, data->acc) < 0) {
303302
LOG_DBG("Failed to read sample");
304303
return -EIO;
305304
}
306305

307-
data->acc[0] = sys_le16_to_cpu(buf[0]);
308-
data->acc[1] = sys_le16_to_cpu(buf[1]);
309-
data->acc[2] = sys_le16_to_cpu(buf[2]);
310-
311306
return 0;
312307
}
313308

@@ -316,17 +311,12 @@ static int lsm6dso_sample_fetch_gyro(const struct device *dev)
316311
const struct lsm6dso_config *cfg = dev->config;
317312
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
318313
struct lsm6dso_data *data = dev->data;
319-
int16_t buf[3];
320314

321-
if (lsm6dso_angular_rate_raw_get(ctx, buf) < 0) {
315+
if (lsm6dso_angular_rate_raw_get(ctx, data->gyro) < 0) {
322316
LOG_DBG("Failed to read sample");
323317
return -EIO;
324318
}
325319

326-
data->gyro[0] = sys_le16_to_cpu(buf[0]);
327-
data->gyro[1] = sys_le16_to_cpu(buf[1]);
328-
data->gyro[2] = sys_le16_to_cpu(buf[2]);
329-
330320
return 0;
331321
}
332322

@@ -336,15 +326,12 @@ static int lsm6dso_sample_fetch_temp(const struct device *dev)
336326
const struct lsm6dso_config *cfg = dev->config;
337327
stmdev_ctx_t *ctx = (stmdev_ctx_t *)&cfg->ctx;
338328
struct lsm6dso_data *data = dev->data;
339-
int16_t buf;
340329

341-
if (lsm6dso_temperature_raw_get(ctx, &buf) < 0) {
330+
if (lsm6dso_temperature_raw_get(ctx, &data->temp_sample) < 0) {
342331
LOG_DBG("Failed to read sample");
343332
return -EIO;
344333
}
345334

346-
data->temp_sample = sys_le16_to_cpu(buf);
347-
348335
return 0;
349336
}
350337
#endif

drivers/sensor/lsm6dso/lsm6dso.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ struct lsm6dso_data {
7979
int16_t gyro[3];
8080
uint32_t gyro_gain;
8181
#if defined(CONFIG_LSM6DSO_ENABLE_TEMP)
82-
int temp_sample;
82+
int16_t temp_sample;
8383
#endif
8484
#if defined(CONFIG_LSM6DSO_SENSORHUB)
8585
uint8_t ext_data[2][6];

0 commit comments

Comments
 (0)