1 /* ST Microelectronics STMEMS hal i/f
2 *
3 * Copyright (c) 2021 STMicroelectronics
4 *
5 * SPDX-License-Identifier: Apache-2.0
6 *
7 * zephyrproject-rtos/modules/hal/st/sensor/stmemsc/
8 */
9
10 #include "stmemsc.h"
11
12 /* Enable address auto-increment on some stmemsc sensors */
13 #define STMEMSC_I2C_ADDR_AUTO_INCR BIT(7)
14
stmemsc_i2c_read(const struct i2c_dt_spec * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)15 int stmemsc_i2c_read(const struct i2c_dt_spec *stmemsc,
16 uint8_t reg_addr, uint8_t *value, uint8_t len)
17 {
18 return i2c_burst_read_dt(stmemsc, reg_addr, value, len);
19 }
20
stmemsc_i2c_write(const struct i2c_dt_spec * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)21 int stmemsc_i2c_write(const struct i2c_dt_spec *stmemsc,
22 uint8_t reg_addr, uint8_t *value, uint8_t len)
23 {
24 return i2c_burst_write_dt(stmemsc, reg_addr, value, len);
25 }
26
stmemsc_i2c_read_incr(const struct i2c_dt_spec * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)27 int stmemsc_i2c_read_incr(const struct i2c_dt_spec *stmemsc,
28 uint8_t reg_addr, uint8_t *value, uint8_t len)
29 {
30 reg_addr |= STMEMSC_I2C_ADDR_AUTO_INCR;
31 return stmemsc_i2c_read(stmemsc, reg_addr, value, len);
32 }
33
stmemsc_i2c_write_incr(const struct i2c_dt_spec * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)34 int stmemsc_i2c_write_incr(const struct i2c_dt_spec *stmemsc,
35 uint8_t reg_addr, uint8_t *value, uint8_t len)
36 {
37 reg_addr |= STMEMSC_I2C_ADDR_AUTO_INCR;
38 return stmemsc_i2c_write(stmemsc, reg_addr, value, len);
39 }
40