Skip to content

Commit

Permalink
drivers: sensor: lis2de12: fix read accel via spi
Browse files Browse the repository at this point in the history
The lis2de12 sensor driver spi interface was calling spi read api.
This leads to a single byte operation on reading acceleration data
which is a multi byte operation. Fix it by adding a call to spi read
incr api instead. Added a length check to handle both single and multi
byte read properly.

Signed-off-by: Mayank Narang <[email protected]>
(cherry picked from commit 7b062f5)
  • Loading branch information
narangmayank authored and github-actions[bot] committed Jan 24, 2025
1 parent 2f0e67f commit 99a3a8e
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 2 deletions.
2 changes: 1 addition & 1 deletion drivers/sensor/st/lis2de12/lis2de12.c
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ static int lis2de12_init(const struct device *dev)

#define LIS2DE12_CONFIG_SPI(inst) \
{ \
STMEMSC_CTX_SPI(&lis2de12_config_##inst.stmemsc_cfg), \
STMEMSC_CTX_SPI_INCR(&lis2de12_config_##inst.stmemsc_cfg), \
.stmemsc_cfg = { \
.spi = SPI_DT_SPEC_INST_GET(inst, LIS2DE12_SPI_OP, 0), \
}, \
Expand Down
5 changes: 4 additions & 1 deletion drivers/sensor/st/stmemsc/stmemsc_spi.c
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ int stmemsc_spi_write(const struct spi_dt_spec *stmemsc,
int stmemsc_spi_read_incr(const struct spi_dt_spec *stmemsc,
uint8_t reg_addr, uint8_t *value, uint8_t len)
{
reg_addr |= STMEMSC_SPI_ADDR_AUTO_INCR;
if (len > 1) {
reg_addr |= STMEMSC_SPI_ADDR_AUTO_INCR;
}

return stmemsc_spi_read(stmemsc, reg_addr, value, len);
}

Expand Down

0 comments on commit 99a3a8e

Please sign in to comment.