drivers: sensor: st: Convert to new DT_INST macros

Convert older DT_INST_ macro use the new include/devicetree.h
DT_INST macro APIs.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2020-03-26 16:47:47 -05:00 committed by Maureen Helm
commit e268368fd4
54 changed files with 442 additions and 354 deletions

View file

@ -8,6 +8,8 @@
* https://www.st.com/resource/en/datasheet/lsm6dso.pdf
*/
#define DT_DRV_COMPAT st_lsm6dso
#include <drivers/sensor.h>
#include <kernel.h>
#include <device.h>
@ -749,32 +751,32 @@ static int lsm6dso_init_chip(struct device *dev)
static struct lsm6dso_data lsm6dso_data;
static const struct lsm6dso_config lsm6dso_config = {
.bus_name = DT_INST_0_ST_LSM6DSO_BUS_NAME,
#if defined(DT_ST_LSM6DSO_BUS_SPI)
.bus_name = DT_INST_BUS_LABEL(0),
#if DT_ANY_INST_ON_BUS(spi)
.bus_init = lsm6dso_spi_init,
.spi_conf.frequency = DT_INST_0_ST_LSM6DSO_SPI_MAX_FREQUENCY,
.spi_conf.frequency = DT_INST_PROP(0, spi_max_frequency),
.spi_conf.operation = (SPI_OP_MODE_MASTER | SPI_MODE_CPOL |
SPI_MODE_CPHA | SPI_WORD_SET(8) |
SPI_LINES_SINGLE),
.spi_conf.slave = DT_INST_0_ST_LSM6DSO_BASE_ADDRESS,
#if defined(DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER)
.gpio_cs_port = DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER,
.cs_gpio = DT_INST_0_ST_LSM6DSO_CS_GPIOS_PIN,
.spi_conf.slave = DT_INST_REG_ADDR(0),
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
.gpio_cs_port = DT_INST_SPI_DEV_CS_GPIOS_LABEL(0),
.cs_gpio = DT_INST_SPI_DEV_CS_GPIOS_PIN(0),
.spi_conf.cs = &lsm6dso_data.cs_ctrl,
#else
.spi_conf.cs = NULL,
#endif
#elif defined(DT_ST_LSM6DSO_BUS_I2C)
#elif DT_ANY_INST_ON_BUS(i2c)
.bus_init = lsm6dso_i2c_init,
.i2c_slv_addr = DT_INST_0_ST_LSM6DSO_BASE_ADDRESS,
.i2c_slv_addr = DT_INST_REG_ADDR(0),
#else
#error "BUS MACRO NOT DEFINED IN DTS"
#endif
#ifdef CONFIG_LSM6DSO_TRIGGER
.int_gpio_port = DT_INST_0_ST_LSM6DSO_IRQ_GPIOS_CONTROLLER,
.int_gpio_pin = DT_INST_0_ST_LSM6DSO_IRQ_GPIOS_PIN,
.int_gpio_flags = DT_INST_0_ST_LSM6DSO_IRQ_GPIOS_FLAGS,
.int_gpio_port = DT_INST_GPIO_LABEL(0, irq_gpios),
.int_gpio_pin = DT_INST_GPIO_PIN(0, irq_gpios),
.int_gpio_flags = DT_INST_GPIO_FLAGS(0, irq_gpios),
#if defined(CONFIG_LSM6DSO_INT_PIN_1)
.int_pin = 1,
#elif defined(CONFIG_LSM6DSO_INT_PIN_2)
@ -823,6 +825,6 @@ static int lsm6dso_init(struct device *dev)
static struct lsm6dso_data lsm6dso_data;
DEVICE_AND_API_INIT(lsm6dso, DT_INST_0_ST_LSM6DSO_LABEL, lsm6dso_init,
DEVICE_AND_API_INIT(lsm6dso, DT_INST_LABEL(0), lsm6dso_init,
&lsm6dso_data, &lsm6dso_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &lsm6dso_api_funcs);

View file

@ -100,15 +100,15 @@ struct lsm6dso_config {
u8_t int_gpio_flags;
u8_t int_pin;
#endif /* CONFIG_LSM6DSO_TRIGGER */
#ifdef DT_ST_LSM6DSO_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
u16_t i2c_slv_addr;
#elif DT_ST_LSM6DSO_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
struct spi_config spi_conf;
#if defined(DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const char *gpio_cs_port;
u8_t cs_gpio;
#endif /* DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER */
#endif /* DT_ST_LSM6DSO_BUS_I2C */
#endif /* DT_INST_SPI_DEV_HAS_CS_GPIOS(0) */
#endif /* DT_ANY_INST_ON_BUS(i2c) */
};
union samples {
@ -159,9 +159,9 @@ struct lsm6dso_data {
stmdev_ctx_t *ctx;
#ifdef DT_ST_LSM6DSO_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
stmdev_ctx_t ctx_i2c;
#elif DT_ST_LSM6DSO_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
stmdev_ctx_t ctx_spi;
#endif
@ -187,7 +187,7 @@ struct lsm6dso_data {
#endif
#endif /* CONFIG_LSM6DSO_TRIGGER */
#if defined(DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
struct spi_cs_control cs_ctrl;
#endif
};

View file

@ -8,13 +8,15 @@
* https://www.st.com/resource/en/datasheet/lsm6dso.pdf
*/
#define DT_DRV_COMPAT st_lsm6dso
#include <string.h>
#include <drivers/i2c.h>
#include <logging/log.h>
#include "lsm6dso.h"
#ifdef DT_ST_LSM6DSO_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
LOG_MODULE_DECLARE(LSM6DSO, CONFIG_SENSOR_LOG_LEVEL);
@ -50,4 +52,4 @@ int lsm6dso_i2c_init(struct device *dev)
return 0;
}
#endif /* DT_ST_LSM6DSO_BUS_I2C */
#endif /* DT_ANY_INST_ON_BUS(i2c) */

View file

@ -8,11 +8,13 @@
* https://www.st.com/resource/en/datasheet/lsm6dso.pdf
*/
#define DT_DRV_COMPAT st_lsm6dso
#include <string.h>
#include "lsm6dso.h"
#include <logging/log.h>
#ifdef DT_ST_LSM6DSO_BUS_SPI
#if DT_ANY_INST_ON_BUS(spi)
#define LSM6DSO_SPI_READ (1 << 7)
@ -104,7 +106,7 @@ int lsm6dso_spi_init(struct device *dev)
data->ctx = &data->ctx_spi;
data->ctx->handle = dev;
#if defined(DT_INST_0_ST_LSM6DSO_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const struct lsm6dso_config *cfg = dev->config->config_info;
/* handle SPI CS thru GPIO if it is the case */
@ -123,4 +125,4 @@ int lsm6dso_spi_init(struct device *dev)
return 0;
}
#endif /* DT_ST_LSM6DSO_BUS_SPI */
#endif /* DT_ANY_INST_ON_BUS(spi) */