zephyr/drivers/sensor/stmemsc/stmemsc_i2c.c
Armando Visconti 253cbfd0aa drivers/sensor: stmemsc: Add common i2c/spi read/write routines
Add common i2c/spi read/write routines for the benefit of those
ST sensor drivers who make use of the stmemsc HAL i/f.

Add generic stmemsc_cfg_i2c and stmemsc_cfg_spi structures which
contains all relevant information required by i2c/spi low level
routines, such as:

    - the pointer to the bus device
    - the I2C slave address (if instance is on I2C bus)
    - the spi_config structure (if istance is on SPI bus)

This level of abstraction allows the re-use of the i2c/spi read/write
routines among all stmemsc based sensor driver without the need to
reference the specific sensor data and or config structures.

The STMEMSC HAL source code is located here:
     zephyrproject-rtos/modules/hal/st/sensor/stmemsc/

Signed-off-by: Armando Visconti <armando.visconti@st.com>
2021-04-01 15:34:36 -05:00

25 lines
634 B
C

/* ST Microelectronics STMEMS hal i/f
*
* Copyright (c) 2021 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*
* zephyrproject-rtos/modules/hal/st/sensor/stmemsc/
*/
#include "stmemsc.h"
int stmemsc_i2c_read(const struct stmemsc_cfg_i2c *stmemsc,
uint8_t reg_addr, uint8_t *value, uint8_t len)
{
return i2c_burst_read(stmemsc->bus, stmemsc->i2c_slv_addr,
reg_addr, value, len);
}
int stmemsc_i2c_write(const struct stmemsc_cfg_i2c *stmemsc,
uint8_t reg_addr, uint8_t *value, uint8_t len)
{
return i2c_burst_write(stmemsc->bus, stmemsc->i2c_slv_addr,
reg_addr, value, len);
}