1 /*
2 * Copyright (c) 2022 Würth Elektronik eiSos GmbH & Co. KG
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include "weplatform.h"
8
9 #include "weplatform_i2c.h"
10 #include "weplatform_spi.h"
11
12 /**
13 * @brief Read data starting from the addressed register
14 * @param[in] interface Sensor interface
15 * @param[in] regAdr The register address to read from
16 * @param[in] numBytesToRead Number of bytes to read
17 * @param[out] data The read data will be stored here
18 * @retval Error code
19 */
WE_ReadReg(WE_sensorInterface_t * interface,uint8_t regAdr,uint16_t numBytesToRead,uint8_t * data)20 inline int8_t WE_ReadReg(WE_sensorInterface_t *interface, uint8_t regAdr,
21 uint16_t numBytesToRead, uint8_t *data)
22 {
23 switch (interface->interfaceType) {
24 case WE_i2c:
25 return WE_ReadReg_I2C(interface, regAdr, numBytesToRead, data);
26
27 case WE_spi:
28 return WE_ReadReg_SPI(interface, regAdr, numBytesToRead, data);
29
30 default:
31 return WE_FAIL;
32 }
33 }
34
35 /**
36 * @brief Write data starting from the addressed register
37 * @param[in] interface Sensor interface
38 * @param[in] regAdr Address of register to be written
39 * @param[in] numBytesToWrite Number of bytes to write
40 * @param[in] data Data to be written
41 * @retval Error code
42 */
WE_WriteReg(WE_sensorInterface_t * interface,uint8_t regAdr,uint16_t numBytesToWrite,uint8_t * data)43 inline int8_t WE_WriteReg(WE_sensorInterface_t *interface, uint8_t regAdr,
44 uint16_t numBytesToWrite, uint8_t *data)
45 {
46 switch (interface->interfaceType) {
47 case WE_i2c:
48 return WE_WriteReg_I2C(interface, regAdr, numBytesToWrite, data);
49
50 case WE_spi:
51 return WE_WriteReg_SPI(interface, regAdr, numBytesToWrite, data);
52
53 default:
54 return WE_FAIL;
55 }
56 }
57