drivers/sensor: iis2dlpc: Add multi-instance support
Make this driver multi-instance and use the new API. Signed-off-by: Armando Visconti <armando.visconti@st.com>
This commit is contained in:
parent
8ccd506966
commit
45d0508bdf
5 changed files with 235 additions and 103 deletions
|
@ -35,7 +35,7 @@ static int iis2dlpc_set_range(const struct device *dev, uint8_t fs)
|
|||
{
|
||||
int err;
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
uint8_t shift_gain = 0U;
|
||||
|
||||
err = iis2dlpc_full_scale_set(iis2dlpc->ctx, fs);
|
||||
|
@ -179,7 +179,7 @@ static int iis2dlpc_sample_fetch(const struct device *dev,
|
|||
enum sensor_channel chan)
|
||||
{
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
uint8_t shift;
|
||||
int16_t buf[3];
|
||||
|
||||
|
@ -215,23 +215,16 @@ static const struct sensor_driver_api iis2dlpc_driver_api = {
|
|||
static int iis2dlpc_init_interface(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
|
||||
LOG_INF("bus name %s", cfg->bus_name);
|
||||
iis2dlpc->bus = device_get_binding(cfg->bus_name);
|
||||
if (!iis2dlpc->bus) {
|
||||
LOG_DBG("master bus not found: %s", cfg->bus_name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
iis2dlpc_spi_init(dev);
|
||||
#elif DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
iis2dlpc_i2c_init(dev);
|
||||
#else
|
||||
#error "BUS MACRO NOT DEFINED IN DTS"
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
return cfg->bus_init(dev);
|
||||
}
|
||||
|
||||
static int iis2dlpc_set_power_mode(struct iis2dlpc_data *iis2dlpc,
|
||||
|
@ -257,9 +250,11 @@ static int iis2dlpc_set_power_mode(struct iis2dlpc_data *iis2dlpc,
|
|||
static int iis2dlpc_init(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
uint8_t wai;
|
||||
|
||||
iis2dlpc->dev = dev;
|
||||
|
||||
if (iis2dlpc_init_interface(dev)) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
@ -385,28 +380,137 @@ static int iis2dlpc_init(const struct device *dev)
|
|||
return 0;
|
||||
}
|
||||
|
||||
const struct iis2dlpc_device_config iis2dlpc_cfg = {
|
||||
.bus_name = DT_INST_BUS_LABEL(0),
|
||||
.pm = DT_INST_PROP(0, power_mode),
|
||||
.range = DT_INST_PROP(0, range),
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
.int_gpio_port = DT_INST_GPIO_LABEL(0, drdy_gpios),
|
||||
.int_gpio_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
|
||||
.int_gpio_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
|
||||
.drdy_int = DT_INST_PROP(0, drdy_int),
|
||||
#if DT_NUM_INST_STATUS_OKAY(DT_DRV_COMPAT) == 0
|
||||
#warning "IIS2DLPC driver enabled without any devices"
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Device creation macro, shared by IIS2DLPC_DEFINE_SPI() and
|
||||
* IIS2DLPC_DEFINE_I2C().
|
||||
*/
|
||||
|
||||
#define IIS2DLPC_DEVICE_INIT(inst) \
|
||||
DEVICE_DT_INST_DEFINE(inst, \
|
||||
iis2dlpc_init, \
|
||||
device_pm_control_nop, \
|
||||
&iis2dlpc_data_##inst, \
|
||||
&iis2dlpc_config_##inst, \
|
||||
POST_KERNEL, \
|
||||
CONFIG_SENSOR_INIT_PRIORITY, \
|
||||
&iis2dlpc_driver_api);
|
||||
|
||||
/*
|
||||
* Instantiation macros used when a device is on a SPI bus.
|
||||
*/
|
||||
|
||||
#define IIS2DLPC_HAS_CS(inst) DT_INST_SPI_DEV_HAS_CS_GPIOS(inst)
|
||||
|
||||
#define IIS2DLPC_DATA_SPI_CS(inst) \
|
||||
{ .cs_ctrl = { \
|
||||
.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(inst), \
|
||||
.gpio_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(inst), \
|
||||
}, \
|
||||
}
|
||||
|
||||
#define IIS2DLPC_DATA_SPI(inst) \
|
||||
COND_CODE_1(IIS2DLPC_HAS_CS(inst), \
|
||||
(IIS2DLPC_DATA_SPI_CS(inst)), \
|
||||
({}))
|
||||
|
||||
#define IIS2DLPC_SPI_CS_PTR(inst) \
|
||||
COND_CODE_1(IIS2DLPC_HAS_CS(inst), \
|
||||
(&(iis2dlpc_data_##inst.cs_ctrl)), \
|
||||
(NULL))
|
||||
|
||||
#define IIS2DLPC_SPI_CS_LABEL(inst) \
|
||||
COND_CODE_1(IIS2DLPC_HAS_CS(inst), \
|
||||
(DT_INST_SPI_DEV_CS_GPIOS_LABEL(inst)), (NULL))
|
||||
|
||||
#define IIS2DLPC_SPI_CFG(inst) \
|
||||
(&(struct iis2dlpc_spi_cfg) { \
|
||||
.spi_conf = { \
|
||||
.frequency = \
|
||||
DT_INST_PROP(inst, spi_max_frequency), \
|
||||
.operation = (SPI_WORD_SET(8) | \
|
||||
SPI_OP_MODE_MASTER | \
|
||||
SPI_LINES_SINGLE | \
|
||||
SPI_MODE_CPOL | \
|
||||
SPI_MODE_CPHA), \
|
||||
.slave = DT_INST_REG_ADDR(inst), \
|
||||
.cs = IIS2DLPC_SPI_CS_PTR(inst), \
|
||||
}, \
|
||||
.cs_gpios_label = IIS2DLPC_SPI_CS_LABEL(inst), \
|
||||
})
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
.tap_mode = DT_INST_PROP(0, tap_mode),
|
||||
.tap_threshold = DT_INST_PROP(0, tap_threshold),
|
||||
.tap_shock = DT_INST_PROP(0, tap_shock),
|
||||
.tap_latency = DT_INST_PROP(0, tap_latency),
|
||||
.tap_quiet = DT_INST_PROP(0, tap_quiet),
|
||||
#define IIS2DLPC_CONFIG_TAP(inst) \
|
||||
.tap_mode = DT_INST_PROP(inst, tap_mode), \
|
||||
.tap_threshold = DT_INST_PROP(inst, tap_threshold), \
|
||||
.tap_shock = DT_INST_PROP(inst, tap_shock), \
|
||||
.tap_latency = DT_INST_PROP(inst, tap_latency), \
|
||||
.tap_quiet = DT_INST_PROP(inst, tap_quiet),
|
||||
#else
|
||||
#define IIS2DLPC_CONFIG_TAP(inst)
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
#define IIS2DLPC_CFG_IRQ(inst) \
|
||||
.irq_dev_name = DT_INST_GPIO_LABEL(inst, drdy_gpios), \
|
||||
.irq_pin = DT_INST_GPIO_PIN(inst, drdy_gpios), \
|
||||
.irq_flags = DT_INST_GPIO_FLAGS(inst, drdy_gpios), \
|
||||
.drdy_int = DT_INST_PROP(inst, drdy_int),
|
||||
#else
|
||||
#define IIS2DLPC_CFG_IRQ(inst)
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER */
|
||||
};
|
||||
|
||||
struct iis2dlpc_data iis2dlpc_data;
|
||||
#define IIS2DLPC_CONFIG_SPI(inst) \
|
||||
{ \
|
||||
.pm = DT_INST_PROP(inst, power_mode), \
|
||||
.range = DT_INST_PROP(inst, range), \
|
||||
.bus_name = DT_INST_BUS_LABEL(inst), \
|
||||
.bus_init = iis2dlpc_spi_init, \
|
||||
.bus_cfg = { .spi_cfg = IIS2DLPC_SPI_CFG(inst) }, \
|
||||
IIS2DLPC_CONFIG_TAP(inst) \
|
||||
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
|
||||
(IIS2DLPC_CFG_IRQ(inst)), ()) \
|
||||
}
|
||||
|
||||
DEVICE_DT_INST_DEFINE(0, iis2dlpc_init, device_pm_control_nop,
|
||||
&iis2dlpc_data, &iis2dlpc_cfg, POST_KERNEL,
|
||||
CONFIG_SENSOR_INIT_PRIORITY, &iis2dlpc_driver_api);
|
||||
#define IIS2DLPC_DEFINE_SPI(inst) \
|
||||
static struct iis2dlpc_data iis2dlpc_data_##inst = \
|
||||
IIS2DLPC_DATA_SPI(inst); \
|
||||
static const struct iis2dlpc_dev_config iis2dlpc_config_##inst =\
|
||||
IIS2DLPC_CONFIG_SPI(inst); \
|
||||
IIS2DLPC_DEVICE_INIT(inst)
|
||||
|
||||
/*
|
||||
* Instantiation macros used when a device is on an I2C bus.
|
||||
*/
|
||||
|
||||
#define IIS2DLPC_CONFIG_I2C(inst) \
|
||||
{ \
|
||||
.pm = DT_INST_PROP(inst, power_mode), \
|
||||
.range = DT_INST_PROP(inst, range), \
|
||||
.bus_name = DT_INST_BUS_LABEL(inst), \
|
||||
.bus_init = iis2dlpc_i2c_init, \
|
||||
.bus_cfg = { .i2c_slv_addr = DT_INST_REG_ADDR(inst), }, \
|
||||
IIS2DLPC_CONFIG_TAP(inst) \
|
||||
COND_CODE_1(DT_INST_NODE_HAS_PROP(inst, drdy_gpios), \
|
||||
(IIS2DLPC_CFG_IRQ(inst)), ()) \
|
||||
}
|
||||
|
||||
#define IIS2DLPC_DEFINE_I2C(inst) \
|
||||
static struct iis2dlpc_data iis2dlpc_data_##inst; \
|
||||
static const struct iis2dlpc_dev_config iis2dlpc_config_##inst =\
|
||||
IIS2DLPC_CONFIG_I2C(inst); \
|
||||
IIS2DLPC_DEVICE_INIT(inst)
|
||||
/*
|
||||
* Main instantiation macro. Use of COND_CODE_1() selects the right
|
||||
* bus-specific macro at preprocessor time.
|
||||
*/
|
||||
|
||||
#define IIS2DLPC_DEFINE(inst) \
|
||||
COND_CODE_1(DT_INST_ON_BUS(inst, spi), \
|
||||
(IIS2DLPC_DEFINE_SPI(inst)), \
|
||||
(IIS2DLPC_DEFINE_I2C(inst)))
|
||||
|
||||
DT_INST_FOREACH_STATUS_OKAY(IIS2DLPC_DEFINE)
|
||||
|
|
|
@ -11,12 +11,19 @@
|
|||
#ifndef ZEPHYR_DRIVERS_SENSOR_IIS2DLPC_IIS2DLPC_H_
|
||||
#define ZEPHYR_DRIVERS_SENSOR_IIS2DLPC_IIS2DLPC_H_
|
||||
|
||||
#include <drivers/spi.h>
|
||||
#include <drivers/gpio.h>
|
||||
#include <sys/util.h>
|
||||
#include <drivers/sensor.h>
|
||||
#include "iis2dlpc_reg.h"
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
#include <drivers/spi.h>
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
#include <drivers/i2c.h>
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c) */
|
||||
|
||||
union axis3bit16_t {
|
||||
int16_t i16bit[3];
|
||||
uint8_t u8bit[6];
|
||||
|
@ -46,22 +53,41 @@ union axis3bit16_t {
|
|||
#define IIS2DLPC_SHIFT_PM1 4
|
||||
#define IIS2DLPC_SHIFT_PMOTHER 2
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
struct iis2dlpc_spi_cfg {
|
||||
struct spi_config spi_conf;
|
||||
const char *cs_gpios_label;
|
||||
};
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
||||
|
||||
union iis2dlpc_bus_cfg {
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
uint16_t i2c_slv_addr;
|
||||
#endif
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
const struct iis2dlpc_spi_cfg *spi_cfg;
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
||||
};
|
||||
|
||||
/**
|
||||
* struct iis2dlpc_device_config - iis2dlpc hw configuration
|
||||
* struct iis2dlpc_dev_config - iis2dlpc hw configuration
|
||||
* @bus_name: Pointer to bus master identifier.
|
||||
* @pm: Power mode (lis2dh_powermode).
|
||||
* @int_gpio_port: Pointer to GPIO PORT identifier.
|
||||
* @int_gpio_pin: GPIO pin number connecter to sensor int pin.
|
||||
* @irq_dev_name: Pointer to GPIO PORT identifier.
|
||||
* @irq_pin: GPIO pin number connecter to sensor int pin.
|
||||
* @drdy_int: Sensor drdy int (int1/int2).
|
||||
*/
|
||||
struct iis2dlpc_device_config {
|
||||
struct iis2dlpc_dev_config {
|
||||
const char *bus_name;
|
||||
int (*bus_init)(const struct device *dev);
|
||||
const union iis2dlpc_bus_cfg bus_cfg;
|
||||
iis2dlpc_mode_t pm;
|
||||
uint8_t range;
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
const char *int_gpio_port;
|
||||
uint8_t int_gpio_pin;
|
||||
uint8_t int_gpio_flags;
|
||||
const char *irq_dev_name;
|
||||
gpio_pin_t irq_pin;
|
||||
gpio_flags_t irq_flags;
|
||||
uint8_t drdy_int;
|
||||
#ifdef CONFIG_IIS2DLPC_TAP
|
||||
uint8_t tap_mode;
|
||||
|
@ -75,6 +101,7 @@ struct iis2dlpc_device_config {
|
|||
|
||||
/* sensor data */
|
||||
struct iis2dlpc_data {
|
||||
const struct device *dev;
|
||||
const struct device *bus;
|
||||
int16_t acc[3];
|
||||
|
||||
|
@ -82,8 +109,15 @@ struct iis2dlpc_data {
|
|||
uint16_t gain;
|
||||
|
||||
stmdev_ctx_t *ctx;
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
stmdev_ctx_t ctx_i2c;
|
||||
#endif
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
stmdev_ctx_t ctx_spi;
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IIS2DLPC_TRIGGER
|
||||
const struct device *dev;
|
||||
const struct device *gpio;
|
||||
uint8_t gpio_pin;
|
||||
struct gpio_callback gpio_cb;
|
||||
|
@ -100,9 +134,9 @@ struct iis2dlpc_data {
|
|||
struct k_work work;
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER_GLOBAL_THREAD */
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER */
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(spi)
|
||||
struct spi_cs_control cs_ctrl;
|
||||
#endif
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
||||
};
|
||||
|
||||
int iis2dlpc_i2c_init(const struct device *dev);
|
||||
|
|
|
@ -11,41 +11,42 @@
|
|||
#define DT_DRV_COMPAT st_iis2dlpc
|
||||
|
||||
#include <string.h>
|
||||
#include <drivers/i2c.h>
|
||||
#include <logging/log.h>
|
||||
|
||||
#include "iis2dlpc.h"
|
||||
|
||||
#if DT_ANY_INST_ON_BUS_STATUS_OKAY(i2c)
|
||||
|
||||
static uint16_t iis2dlpc_i2c_slave_addr = DT_INST_REG_ADDR(0);
|
||||
|
||||
LOG_MODULE_DECLARE(IIS2DLPC, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static int iis2dlpc_i2c_read(struct iis2dlpc_data *data, uint8_t reg_addr,
|
||||
uint8_t *value, uint16_t len)
|
||||
{
|
||||
return i2c_burst_read(data->bus, iis2dlpc_i2c_slave_addr,
|
||||
const struct device *dev = data->dev;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
|
||||
return i2c_burst_read(data->bus, cfg->bus_cfg.i2c_slv_addr,
|
||||
reg_addr, value, len);
|
||||
}
|
||||
|
||||
static int iis2dlpc_i2c_write(struct iis2dlpc_data *data, uint8_t reg_addr,
|
||||
uint8_t *value, uint16_t len)
|
||||
{
|
||||
return i2c_burst_write(data->bus, iis2dlpc_i2c_slave_addr,
|
||||
const struct device *dev = data->dev;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
|
||||
return i2c_burst_write(data->bus, cfg->bus_cfg.i2c_slv_addr,
|
||||
reg_addr, value, len);
|
||||
}
|
||||
|
||||
stmdev_ctx_t iis2dlpc_i2c_ctx = {
|
||||
.read_reg = (stmdev_read_ptr) iis2dlpc_i2c_read,
|
||||
.write_reg = (stmdev_write_ptr) iis2dlpc_i2c_write,
|
||||
};
|
||||
|
||||
int iis2dlpc_i2c_init(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *data = dev->data;
|
||||
|
||||
data->ctx = &iis2dlpc_i2c_ctx;
|
||||
data->ctx_i2c.read_reg = (stmdev_read_ptr) iis2dlpc_i2c_read,
|
||||
data->ctx_i2c.write_reg = (stmdev_write_ptr) iis2dlpc_i2c_write,
|
||||
|
||||
data->ctx = &data->ctx_i2c;
|
||||
data->ctx->handle = data;
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -10,7 +10,6 @@
|
|||
|
||||
#define DT_DRV_COMPAT st_iis2dlpc
|
||||
|
||||
|
||||
#include <string.h>
|
||||
#include "iis2dlpc.h"
|
||||
#include <logging/log.h>
|
||||
|
@ -21,18 +20,12 @@
|
|||
|
||||
LOG_MODULE_DECLARE(IIS2DLPC, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static struct spi_config iis2dlpc_spi_conf = {
|
||||
.frequency = DT_INST_PROP(0, spi_max_frequency),
|
||||
.operation = (SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
|
||||
SPI_MODE_CPHA | SPI_WORD_SET(8) | SPI_LINES_SINGLE),
|
||||
.slave = DT_INST_REG_ADDR(0),
|
||||
.cs = NULL,
|
||||
};
|
||||
|
||||
static int iis2dlpc_spi_read(struct iis2dlpc_data *ctx, uint8_t reg,
|
||||
uint8_t *data, uint16_t len)
|
||||
static int iis2dlpc_spi_read(struct iis2dlpc_data *data, uint8_t reg,
|
||||
uint8_t *val, uint16_t len)
|
||||
{
|
||||
struct spi_config *spi_cfg = &iis2dlpc_spi_conf;
|
||||
const struct device *dev = data->dev;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
const struct spi_config *spi_cfg = &cfg->bus_cfg.spi_cfg->spi_conf;
|
||||
uint8_t buffer_tx[2] = { reg | IIS2DLPC_SPI_READ, 0 };
|
||||
const struct spi_buf tx_buf = {
|
||||
.buf = buffer_tx,
|
||||
|
@ -48,7 +41,7 @@ static int iis2dlpc_spi_read(struct iis2dlpc_data *ctx, uint8_t reg,
|
|||
.len = 1,
|
||||
},
|
||||
{
|
||||
.buf = data,
|
||||
.buf = val,
|
||||
.len = len,
|
||||
}
|
||||
};
|
||||
|
@ -57,17 +50,19 @@ static int iis2dlpc_spi_read(struct iis2dlpc_data *ctx, uint8_t reg,
|
|||
.count = 2
|
||||
};
|
||||
|
||||
if (spi_transceive(ctx->bus, spi_cfg, &tx, &rx)) {
|
||||
if (spi_transceive(data->bus, spi_cfg, &tx, &rx)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int iis2dlpc_spi_write(struct iis2dlpc_data *ctx, uint8_t reg,
|
||||
uint8_t *data, uint16_t len)
|
||||
static int iis2dlpc_spi_write(struct iis2dlpc_data *data, uint8_t reg,
|
||||
uint8_t *val, uint16_t len)
|
||||
{
|
||||
struct spi_config *spi_cfg = &iis2dlpc_spi_conf;
|
||||
const struct device *dev = data->dev;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
const struct spi_config *spi_cfg = &cfg->bus_cfg.spi_cfg->spi_conf;
|
||||
uint8_t buffer_tx[1] = { reg & ~IIS2DLPC_SPI_READ };
|
||||
const struct spi_buf tx_buf[2] = {
|
||||
{
|
||||
|
@ -75,7 +70,7 @@ static int iis2dlpc_spi_write(struct iis2dlpc_data *ctx, uint8_t reg,
|
|||
.len = 1,
|
||||
},
|
||||
{
|
||||
.buf = data,
|
||||
.buf = val,
|
||||
.len = len,
|
||||
}
|
||||
};
|
||||
|
@ -85,7 +80,7 @@ static int iis2dlpc_spi_write(struct iis2dlpc_data *ctx, uint8_t reg,
|
|||
};
|
||||
|
||||
|
||||
if (spi_write(ctx->bus, spi_cfg, &tx)) {
|
||||
if (spi_write(data->bus, spi_cfg, &tx)) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -100,30 +95,28 @@ stmdev_ctx_t iis2dlpc_spi_ctx = {
|
|||
int iis2dlpc_spi_init(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *data = dev->data;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
const struct iis2dlpc_spi_cfg *spi_cfg = cfg->bus_cfg.spi_cfg;
|
||||
|
||||
data->ctx = &iis2dlpc_spi_ctx;
|
||||
data->ctx_spi.read_reg = (stmdev_read_ptr) iis2dlpc_spi_read,
|
||||
data->ctx_spi.write_reg = (stmdev_write_ptr) iis2dlpc_spi_write,
|
||||
|
||||
data->ctx = &data->ctx_spi;
|
||||
data->ctx->handle = data;
|
||||
|
||||
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
|
||||
/* handle SPI CS thru GPIO if it is the case */
|
||||
data->cs_ctrl.gpio_dev = device_get_binding(
|
||||
DT_INST_SPI_DEV_CS_GPIOS_LABEL(0));
|
||||
if (!data->cs_ctrl.gpio_dev) {
|
||||
LOG_ERR("Unable to get GPIO SPI CS device");
|
||||
return -ENODEV;
|
||||
if (spi_cfg->cs_gpios_label != NULL) {
|
||||
/* handle SPI CS thru GPIO if it is the case */
|
||||
data->cs_ctrl.gpio_dev =
|
||||
device_get_binding(spi_cfg->cs_gpios_label);
|
||||
if (!data->cs_ctrl.gpio_dev) {
|
||||
LOG_ERR("Unable to get GPIO SPI CS device");
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
LOG_DBG("SPI GPIO CS configured on %s:%u",
|
||||
spi_cfg->cs_gpios_label, data->cs_ctrl.gpio_pin);
|
||||
}
|
||||
|
||||
data->cs_ctrl.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
|
||||
data->cs_ctrl.gpio_dt_flags = DT_INST_SPI_DEV_CS_GPIOS_FLAGS(0);
|
||||
data->cs_ctrl.delay = 0U;
|
||||
|
||||
iis2dlpc_spi_conf.cs = &data->cs_ctrl;
|
||||
|
||||
LOG_DBG("SPI GPIO CS configured on %s:%u",
|
||||
DT_INST_SPI_DEV_CS_GPIOS_LABEL(0),
|
||||
DT_INST_SPI_DEV_CS_GPIOS_PIN(0));
|
||||
#endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif /* DT_ANY_INST_ON_BUS_STATUS_OKAY(spi) */
|
||||
|
|
|
@ -25,7 +25,7 @@ LOG_MODULE_DECLARE(IIS2DLPC, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static int iis2dlpc_enable_int(const struct device *dev,
|
||||
enum sensor_trigger_type type, int enable)
|
||||
{
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
iis2dlpc_reg_t int_route;
|
||||
|
||||
|
@ -165,7 +165,7 @@ static int iis2dlpc_handle_double_tap_int(const struct device *dev)
|
|||
static void iis2dlpc_handle_interrupt(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
iis2dlpc_all_sources_t sources;
|
||||
|
||||
iis2dlpc_all_sources_get(iis2dlpc->ctx, &sources);
|
||||
|
@ -182,7 +182,7 @@ static void iis2dlpc_handle_interrupt(const struct device *dev)
|
|||
}
|
||||
#endif /* CONFIG_IIS2DLPC_TAP */
|
||||
|
||||
gpio_pin_interrupt_configure(iis2dlpc->gpio, cfg->int_gpio_pin,
|
||||
gpio_pin_interrupt_configure(iis2dlpc->gpio, cfg->irq_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
}
|
||||
|
||||
|
@ -229,14 +229,14 @@ static void iis2dlpc_work_cb(struct k_work *work)
|
|||
int iis2dlpc_init_interrupt(const struct device *dev)
|
||||
{
|
||||
struct iis2dlpc_data *iis2dlpc = dev->data;
|
||||
const struct iis2dlpc_device_config *cfg = dev->config;
|
||||
const struct iis2dlpc_dev_config *cfg = dev->config;
|
||||
int ret;
|
||||
|
||||
/* setup data ready gpio interrupt (INT1 or INT2) */
|
||||
iis2dlpc->gpio = device_get_binding(cfg->int_gpio_port);
|
||||
iis2dlpc->gpio = device_get_binding(cfg->irq_dev_name);
|
||||
if (iis2dlpc->gpio == NULL) {
|
||||
LOG_DBG("Cannot get pointer to %s device",
|
||||
cfg->int_gpio_port);
|
||||
cfg->irq_dev_name);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
@ -254,10 +254,10 @@ int iis2dlpc_init_interrupt(const struct device *dev)
|
|||
iis2dlpc->work.handler = iis2dlpc_work_cb;
|
||||
#endif /* CONFIG_IIS2DLPC_TRIGGER_OWN_THREAD */
|
||||
|
||||
iis2dlpc->gpio_pin = cfg->int_gpio_pin;
|
||||
iis2dlpc->gpio_pin = cfg->irq_pin;
|
||||
|
||||
ret = gpio_pin_configure(iis2dlpc->gpio, cfg->int_gpio_pin,
|
||||
GPIO_INPUT | cfg->int_gpio_flags);
|
||||
ret = gpio_pin_configure(iis2dlpc->gpio, cfg->irq_pin,
|
||||
GPIO_INPUT | cfg->irq_flags);
|
||||
if (ret < 0) {
|
||||
LOG_DBG("Could not configure gpio");
|
||||
return ret;
|
||||
|
@ -265,7 +265,7 @@ int iis2dlpc_init_interrupt(const struct device *dev)
|
|||
|
||||
gpio_init_callback(&iis2dlpc->gpio_cb,
|
||||
iis2dlpc_gpio_callback,
|
||||
BIT(cfg->int_gpio_pin));
|
||||
BIT(cfg->irq_pin));
|
||||
|
||||
if (gpio_add_callback(iis2dlpc->gpio, &iis2dlpc->gpio_cb) < 0) {
|
||||
LOG_DBG("Could not set gpio callback");
|
||||
|
@ -277,6 +277,6 @@ int iis2dlpc_init_interrupt(const struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
return gpio_pin_interrupt_configure(iis2dlpc->gpio, cfg->int_gpio_pin,
|
||||
return gpio_pin_interrupt_configure(iis2dlpc->gpio, cfg->irq_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue