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 #ifndef ZEPHYR_DRIVERS_SENSOR_STMEMSC_STMEMSC_H_
11 #define ZEPHYR_DRIVERS_SENSOR_STMEMSC_STMEMSC_H_
12
13 #include <zephyr/kernel.h>
14 #include <zephyr/drivers/i2c.h>
15 #include <zephyr/drivers/i3c.h>
16 #include <zephyr/drivers/spi.h>
17
18
stmemsc_mdelay(uint32_t millisec)19 static inline void stmemsc_mdelay(uint32_t millisec)
20 {
21 k_msleep(millisec);
22 }
23
24 #ifdef CONFIG_I2C
25 /*
26 * Populate the stmdev_ctx_t structure pointed by stmdev_ctx_ptr with
27 * stmemsc i2c APIs.
28 */
29 #define STMEMSC_CTX_I2C(stmdev_ctx_ptr) \
30 .ctx = { \
31 .read_reg = (stmdev_read_ptr) stmemsc_i2c_read, \
32 .write_reg = (stmdev_write_ptr) stmemsc_i2c_write, \
33 .mdelay = (stmdev_mdelay_ptr) stmemsc_mdelay, \
34 .handle = (void *)stmdev_ctx_ptr \
35 }
36
37 int stmemsc_i2c_read(const struct i2c_dt_spec *stmemsc,
38 uint8_t reg_addr, uint8_t *value, uint8_t len);
39 int stmemsc_i2c_write(const struct i2c_dt_spec *stmemsc,
40 uint8_t reg_addr, uint8_t *value, uint8_t len);
41 #endif
42
43 #ifdef CONFIG_I3C
44 /*
45 * Populate the stmdev_ctx_t structure pointed by stmdev_ctx_ptr with
46 * stmemsc i3c APIs.
47 */
48 #define STMEMSC_CTX_I3C(stmdev_ctx_ptr) \
49 .ctx = { \
50 .read_reg = (stmdev_read_ptr) stmemsc_i3c_read, \
51 .write_reg = (stmdev_write_ptr) stmemsc_i3c_write, \
52 .mdelay = (stmdev_mdelay_ptr) stmemsc_mdelay, \
53 .handle = (void *)stmdev_ctx_ptr \
54 }
55
56 int stmemsc_i3c_read(void *stmemsc,
57 uint8_t reg_addr, uint8_t *value, uint8_t len);
58 int stmemsc_i3c_write(void *stmemsc,
59 uint8_t reg_addr, uint8_t *value, uint8_t len);
60 #endif
61
62 #ifdef CONFIG_SPI
63 /*
64 * Populate the stmdev_ctx_t structure pointed by stmdev_ctx_ptr with
65 * stmemsc spi APIs.
66 */
67 #define STMEMSC_CTX_SPI(stmdev_ctx_ptr) \
68 .ctx = { \
69 .read_reg = (stmdev_read_ptr) stmemsc_spi_read, \
70 .write_reg = (stmdev_write_ptr) stmemsc_spi_write, \
71 .mdelay = (stmdev_mdelay_ptr) stmemsc_mdelay, \
72 .handle = (void *)stmdev_ctx_ptr \
73 }
74
75 int stmemsc_spi_read(const struct spi_dt_spec *stmemsc,
76 uint8_t reg_addr, uint8_t *value, uint8_t len);
77 int stmemsc_spi_write(const struct spi_dt_spec *stmemsc,
78 uint8_t reg_addr, uint8_t *value, uint8_t len);
79 #endif
80 #endif /* ZEPHYR_DRIVERS_SENSOR_STMEMSC_STMEMSC_H_ */
81