From 0cfe9560d9805d22c2d4930840d3456b0119b9fb Mon Sep 17 00:00:00 2001 From: Trent Piepho Date: Tue, 20 Dec 2022 15:51:26 -0800 Subject: [PATCH] drivers/sensor: lsm6dso: Remove unneeded read/modify/write in shub read The code in the ST HAL does a read/modify/write to change the bits in the LSM6DSO_FUNC_CFG_ACCESS register that control which register bank is active. All the other bits in the register are defined as zero. It's possible to simply set the register to the desired value without reading the contents first. This bank switch needs to be done twice for every sensor read when the sensor hub is used. The driver as it is can not keep up with the higher update rates of the lsm6dso. So any speed increase in this code allows for a higher update rate as well as reduced latency. Previously, a read of the lsm6dso's accel and gyro on a 400 kHz I2C bus with a 3-axis magnetometer on the sensor hub takes 2.69 ms. This drops that to 2.26 ms. This is enough to support the 417 Hz ODR. Signed-off-by: Trent Piepho --- drivers/sensor/lsm6dso/lsm6dso_shub.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/sensor/lsm6dso/lsm6dso_shub.c b/drivers/sensor/lsm6dso/lsm6dso_shub.c index f4be9b1b25d..4226f694f38 100644 --- a/drivers/sensor/lsm6dso/lsm6dso_shub.c +++ b/drivers/sensor/lsm6dso/lsm6dso_shub.c @@ -441,11 +441,11 @@ static int lsm6dso_shub_wait_completed(stmdev_ctx_t *ctx) static inline void lsm6dso_shub_embedded_en(stmdev_ctx_t *ctx, bool on) { - if (on) { - (void) lsm6dso_mem_bank_set(ctx, LSM6DSO_SENSOR_HUB_BANK); - } else { - (void) lsm6dso_mem_bank_set(ctx, LSM6DSO_USER_BANK); - } + lsm6dso_func_cfg_access_t reg = { + .reg_access = on ? LSM6DSO_SENSOR_HUB_BANK : LSM6DSO_USER_BANK + }; + + lsm6dso_write_reg(ctx, LSM6DSO_FUNC_CFG_ACCESS, (uint8_t *)®, 1); k_busy_wait(150); }