zephyr/drivers/sensor/iis2iclx/iis2iclx_spi.c
Armando Visconti aae2161542 drivers/sensor: iis2iclx: avoid using both ctx_i2c and ctx_spi
The STMEMSC HAL i/f requires every driver using it to define
for each instance a stmdev_ctx_t structure, which is used to
export the hardware specific APIs to handle i2c and spi busses
operations. Since this structure is bus agnostic, there is no
need to declare it twice for both i2c and spi. Instead, declare
only one structure, which will be populated either with i2c APIs
or with spi APIs according to where that particular instance is
declared inside the DT.

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

33 lines
846 B
C

/* ST Microelectronics IIS2ICLX 2-axis accelerometer sensor driver
*
* Copyright (c) 2020 STMicroelectronics
*
* SPDX-License-Identifier: Apache-2.0
*
* Datasheet:
* https://www.st.com/resource/en/datasheet/iis2iclx.pdf
*/
#define DT_DRV_COMPAT st_iis2iclx
#include "iis2iclx.h"
#include <logging/log.h>
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
LOG_MODULE_DECLARE(IIS2ICLX, CONFIG_SENSOR_LOG_LEVEL);
int iis2iclx_spi_init(const struct device *dev)
{
struct iis2iclx_data *data = dev->data;
const struct iis2iclx_config *cfg = dev->config;
/* Use generic stmemsc routine for read/write SPI bus */
data->ctx.read_reg = (stmdev_read_ptr) stmemsc_spi_read;
data->ctx.write_reg = (stmdev_write_ptr) stmemsc_spi_write;
data->ctx.handle = (void *)&cfg->stmemsc_cfg.spi;
return 0;
}
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */