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 
stmemsc_i3c_read(void * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)12 int stmemsc_i3c_read(void *stmemsc,
13 		     uint8_t reg_addr, uint8_t *value, uint8_t len)
14 {
15 	struct i3c_device_desc *target = **(struct i3c_device_desc ***)stmemsc;
16 
17 	return i3c_burst_read(target, reg_addr, value, len);
18 }
19 
stmemsc_i3c_write(void * stmemsc,uint8_t reg_addr,uint8_t * value,uint8_t len)20 int stmemsc_i3c_write(void *stmemsc,
21 		      uint8_t reg_addr, uint8_t *value, uint8_t len)
22 {
23 	struct i3c_device_desc *target = **(struct i3c_device_desc ***)stmemsc;
24 	uint8_t buf[CONFIG_STMEMSC_I3C_I2C_WRITE_BUFFER_SIZE];
25 
26 	__ASSERT_NO_MSG(len <= sizeof(buf) - 1);
27 
28 	buf[0] = reg_addr;
29 	memcpy(&buf[1], value, len);
30 
31 	return i3c_write(target, buf, len + 1);
32 }
33