drivers: sensors: 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-30 10:08:08 -05:00 committed by Maureen Helm
commit 9872dc16b5
66 changed files with 491 additions and 399 deletions

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT adi_adt7420
#include <device.h>
#include <drivers/i2c.h>
#include <sys/byteorder.h>
@ -216,15 +218,15 @@ static int adt7420_init(struct device *dev)
static struct adt7420_data adt7420_driver;
static const struct adt7420_dev_config adt7420_config = {
.i2c_port = DT_INST_0_ADI_ADT7420_BUS_NAME,
.i2c_addr = DT_INST_0_ADI_ADT7420_BASE_ADDRESS,
.i2c_port = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
#ifdef CONFIG_ADT7420_TRIGGER
.int_pin = DT_INST_0_ADI_ADT7420_INT_GPIOS_PIN,
.int_flags = DT_INST_0_ADI_ADT7420_INT_GPIOS_FLAGS,
.int_name = DT_INST_0_ADI_ADT7420_INT_GPIOS_CONTROLLER,
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
.int_name = DT_INST_GPIO_LABEL(0, int_gpios),
#endif
};
DEVICE_AND_API_INIT(adt7420, DT_INST_0_ADI_ADT7420_LABEL, adt7420_init, &adt7420_driver,
DEVICE_AND_API_INIT(adt7420, DT_INST_LABEL(0), adt7420_init, &adt7420_driver,
&adt7420_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&adt7420_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT adi_adxl345
#include <drivers/sensor.h>
#include <init.h>
#include <drivers/gpio.h>
@ -183,10 +185,10 @@ static int adxl345_init(struct device *dev)
static struct adxl345_dev_data adxl345_data;
static const struct adxl345_dev_config adxl345_config = {
.i2c_master_name = DT_INST_0_ADI_ADXL345_BUS_NAME,
.i2c_addr = DT_INST_0_ADI_ADXL345_BASE_ADDRESS,
.i2c_master_name = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
};
DEVICE_AND_API_INIT(adxl345, DT_INST_0_ADI_ADXL345_LABEL, adxl345_init,
DEVICE_AND_API_INIT(adxl345, DT_INST_LABEL(0), adxl345_init,
&adxl345_data, &adxl345_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &adxl345_api_funcs);

View file

@ -1,10 +1,13 @@
/* adxl362.c - ADXL362 Three-Axis Digital Accelerometers */
/*
* Copyright (c) 2017 IpTronix S.r.l.
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT adi_adxl362
#include <kernel.h>
#include <string.h>
#include <drivers/sensor.h>
@ -733,7 +736,7 @@ static int adxl362_init(struct device *dev)
data->spi_cfg.frequency = config->spi_max_frequency;
data->spi_cfg.slave = config->spi_slave;
#if defined(DT_INST_0_ADI_ADXL362_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
data->adxl362_cs_ctrl.gpio_dev =
device_get_binding(config->gpio_cs_port);
if (!data->adxl362_cs_ctrl.gpio_dev) {
@ -784,20 +787,20 @@ static int adxl362_init(struct device *dev)
}
static const struct adxl362_config adxl362_config = {
.spi_name = DT_INST_0_ADI_ADXL362_BUS_NAME,
.spi_slave = DT_INST_0_ADI_ADXL362_BASE_ADDRESS,
.spi_max_frequency = DT_INST_0_ADI_ADXL362_SPI_MAX_FREQUENCY,
#if defined(DT_INST_0_ADI_ADXL362_CS_GPIOS_CONTROLLER)
.gpio_cs_port = DT_INST_0_ADI_ADXL362_CS_GPIOS_CONTROLLER,
.cs_gpio = DT_INST_0_ADI_ADXL362_CS_GPIOS_PIN,
.spi_name = DT_INST_BUS_LABEL(0),
.spi_slave = DT_INST_REG_ADDR(0),
.spi_max_frequency = DT_INST_PROP(0, spi_max_frequency),
#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),
#endif
#if defined(CONFIG_ADXL362_TRIGGER)
.gpio_port = DT_INST_0_ADI_ADXL362_INT1_GPIOS_CONTROLLER,
.int_gpio = DT_INST_0_ADI_ADXL362_INT1_GPIOS_PIN,
.int_flags = DT_INST_0_ADI_ADXL362_INT1_GPIOS_FLAGS,
.gpio_port = DT_INST_GPIO_LABEL(0, int1_gpios),
.int_gpio = DT_INST_GPIO_PIN(0, int1_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int1_gpios),
#endif
};
DEVICE_AND_API_INIT(adxl362, DT_INST_0_ADI_ADXL362_LABEL, adxl362_init,
DEVICE_AND_API_INIT(adxl362, DT_INST_LABEL(0), adxl362_init,
&adxl362_data, &adxl362_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &adxl362_api_funcs);

View file

@ -174,7 +174,7 @@ struct adxl362_config {
char *spi_name;
u32_t spi_max_frequency;
u16_t spi_slave;
#if defined(DT_INST_0_ADI_ADXL362_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const char *gpio_cs_port;
gpio_pin_t cs_gpio;
#endif
@ -190,7 +190,7 @@ struct adxl362_config {
struct adxl362_data {
struct device *spi;
struct spi_config spi_cfg;
#if defined(DT_INST_0_ADI_ADXL362_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
struct spi_cs_control adxl362_cs_ctrl;
#endif
s16_t acc_x;

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT adi_adxl372
#include <kernel.h>
#include <string.h>
#include <drivers/sensor.h>
@ -897,7 +899,7 @@ static int adxl372_init(struct device *dev)
data->spi_cfg.frequency = cfg->spi_max_frequency;
data->spi_cfg.slave = cfg->spi_slave;
#if defined(DT_INST_0_ADI_ADXL372_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
/* handle SPI CS thru GPIO if it is the case */
data->adxl372_cs_ctrl.gpio_dev = device_get_binding(cfg->gpio_cs_port);
@ -924,22 +926,22 @@ static struct adxl372_data adxl372_data;
static const struct adxl372_dev_config adxl372_config = {
#ifdef CONFIG_ADXL372_I2C
.i2c_port = DT_INST_0_ADI_ADXL372_BUS_NAME,
.i2c_addr = DT_INST_0_ADI_ADXL372_BASE_ADDRESS,
.i2c_port = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
#endif
#ifdef CONFIG_ADXL372_SPI
.spi_port = DT_INST_0_ADI_ADXL372_BUS_NAME,
.spi_slave = DT_INST_0_ADI_ADXL372_BASE_ADDRESS,
.spi_max_frequency = DT_INST_0_ADI_ADXL372_SPI_MAX_FREQUENCY,
#ifdef DT_INST_0_ADI_ADXL372_CS_GPIOS_CONTROLLER
.gpio_cs_port = DT_INST_0_ADI_ADXL372_CS_GPIOS_CONTROLLER,
.cs_gpio = DT_INST_0_ADI_ADXL372_CS_GPIOS_PIN,
.spi_port = DT_INST_BUS_LABEL(0),
.spi_slave = DT_INST_REG_ADDR(0),
.spi_max_frequency = DT_INST_PROP(0, spi_max_frequency),
#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),
#endif
#endif
#ifdef CONFIG_ADXL372_TRIGGER
.gpio_port = DT_INST_0_ADI_ADXL372_INT1_GPIOS_CONTROLLER,
.int_gpio = DT_INST_0_ADI_ADXL372_INT1_GPIOS_PIN,
.int_flags = DT_INST_0_ADI_ADXL372_INT1_GPIOS_FLAGS,
.gpio_port = DT_INST_GPIO_LABEL(0, int1_gpios),
.int_gpio = DT_INST_GPIO_PIN(0, int1_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int1_gpios),
#endif
.max_peak_detect_mode = IS_ENABLED(CONFIG_ADXL372_PEAK_DETECT_MODE),
@ -1011,6 +1013,6 @@ static const struct adxl372_dev_config adxl372_config = {
.op_mode = ADXL372_FULL_BW_MEASUREMENT,
};
DEVICE_AND_API_INIT(adxl372, DT_INST_0_ADI_ADXL372_LABEL, adxl372_init,
DEVICE_AND_API_INIT(adxl372, DT_INST_LABEL(0), adxl372_init,
&adxl372_data, &adxl372_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &adxl372_api_funcs);

View file

@ -282,7 +282,7 @@ struct adxl372_data {
struct device *bus;
#ifdef CONFIG_ADXL372_SPI
struct spi_config spi_cfg;
#if defined(DT_INST_0_ADI_ADXL372_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
struct spi_cs_control adxl372_cs_ctrl;
#endif
#endif
@ -318,7 +318,7 @@ struct adxl372_dev_config {
const char *spi_port;
u16_t spi_slave;
u32_t spi_max_frequency;
#if defined(DT_INST_0_ADI_ADXL372_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
const char *gpio_cs_port;
gpio_pin_t cs_gpio;
#endif

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT asahi_kasei_ak8975
#include <device.h>
#include <drivers/i2c.h>
#include <kernel.h>
@ -25,7 +27,7 @@ static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
if (i2c_reg_write_byte(drv_data->i2c,
DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
AK8975_REG_CNTL, AK8975_MODE_MEASURE) < 0) {
LOG_ERR("Failed to start measurement.");
return -EIO;
@ -34,7 +36,7 @@ static int ak8975_sample_fetch(struct device *dev, enum sensor_channel chan)
k_busy_wait(AK8975_MEASURE_TIME_US);
if (i2c_burst_read(drv_data->i2c,
DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
AK8975_REG_DATA_START, buf, 6) < 0) {
LOG_ERR("Failed to read sample data.");
return -EIO;
@ -94,14 +96,14 @@ static int ak8975_read_adjustment_data(struct ak8975_data *drv_data)
u8_t buf[3];
if (i2c_reg_write_byte(drv_data->i2c,
DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
AK8975_REG_CNTL, AK8975_MODE_FUSE_ACCESS) < 0) {
LOG_ERR("Failed to set chip in fuse access mode.");
return -EIO;
}
if (i2c_burst_read(drv_data->i2c,
DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
AK8975_REG_ADJ_DATA_START, buf, 3) < 0) {
LOG_ERR("Failed to read adjustment data.");
return -EIO;
@ -120,14 +122,14 @@ int ak8975_init(struct device *dev)
u8_t id;
drv_data->i2c =
device_get_binding(DT_INST_0_ASAHI_KASEI_AK8975_BUS_NAME);
device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_ASAHI_KASEI_AK8975_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
#ifdef DT_INST_0_INVENSENSE_MPU9150
#if DT_HAS_NODE(DT_INST(0, invensense_mpu9150))
/* wake up MPU9150 chip */
if (i2c_reg_update_byte(drv_data->i2c, MPU9150_I2C_ADDR,
MPU9150_REG_PWR_MGMT1, MPU9150_SLEEP_EN,
@ -147,7 +149,7 @@ int ak8975_init(struct device *dev)
/* check chip ID */
if (i2c_reg_read_byte(drv_data->i2c,
DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
AK8975_REG_CHIP_ID, &id) < 0) {
LOG_ERR("Failed to read chip ID.");
return -EIO;
@ -167,7 +169,7 @@ int ak8975_init(struct device *dev)
struct ak8975_data ak8975_data;
DEVICE_AND_API_INIT(ak8975, DT_INST_0_ASAHI_KASEI_AK8975_LABEL, ak8975_init,
DEVICE_AND_API_INIT(ak8975, DT_INST_LABEL(0), ak8975_init,
&ak8975_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&ak8975_driver_api);

View file

@ -23,14 +23,12 @@
#define AK8975_MEASURE_TIME_US 9000
#define AK8975_MICRO_GAUSS_PER_BIT 3000
#ifdef DT_INST_0_INVENSENSE_MPU9150_BASE_ADDRESS
#if DT_INST_0_ASAHI_KASEI_AK8975_BASE_ADDRESS != 0x0C
#if DT_NODE_HAS_PROP(DT_INST(0, invensense_mpu9150), reg)
#if DT_REG_ADDR(DT_INST(0, asahi_kasei_ak8975)) != 0x0C
#error "I2C address must be 0x0C when AK8975 is part of a MPU9150 chip"
#endif
#ifdef DT_INST_0_INVENSENSE_MPU9150
#define MPU9150_I2C_ADDR DT_INST_0_INVENSENSE_MPU9150_BASE_ADDRESS
#endif
#define MPU9150_I2C_ADDR DT_REG_ADDR(DT_INST(0, invensense_mpu9150))
#define MPU9150_REG_BYPASS_CFG 0x37
#define MPU9150_I2C_BYPASS_EN BIT(1)
@ -38,7 +36,7 @@
#define MPU9150_REG_PWR_MGMT1 0x6B
#define MPU9150_SLEEP_EN BIT(6)
#endif /* DT_INST_0_INVENSENSE_MPU9150 */
#endif /* DT_NODE_HAS_PROP(DT_INST(0, invensense_mpu9150), reg) */
struct ak8975_data {

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT panasonic_amg88xx
#include <string.h>
#include <device.h>
#include <drivers/i2c.h>
@ -141,16 +143,16 @@ static const struct sensor_driver_api amg88xx_driver_api = {
};
static const struct amg88xx_config amg88xx_config = {
.i2c_name = DT_INST_0_PANASONIC_AMG88XX_BUS_NAME,
.i2c_address = DT_INST_0_PANASONIC_AMG88XX_BASE_ADDRESS,
.i2c_name = DT_INST_BUS_LABEL(0),
.i2c_address = DT_INST_REG_ADDR(0),
#ifdef CONFIG_AMG88XX_TRIGGER
.gpio_name = DT_INST_0_PANASONIC_AMG88XX_INT_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_PANASONIC_AMG88XX_INT_GPIOS_PIN,
.gpio_flags = DT_INST_0_PANASONIC_AMG88XX_INT_GPIOS_FLAGS,
.gpio_name = DT_INST_GPIO_LABEL(0, int_gpios),
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
#endif
};
DEVICE_AND_API_INIT(amg88xx, DT_INST_0_PANASONIC_AMG88XX_LABEL, amg88xx_init,
DEVICE_AND_API_INIT(amg88xx, DT_INST_LABEL(0), amg88xx_init,
&amg88xx_driver, &amg88xx_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&amg88xx_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ams_iaqcore
#include <device.h>
#include <drivers/i2c.h>
#include <kernel.h>
@ -33,7 +35,7 @@ static int iaqcore_sample_fetch(struct device *dev, enum sensor_channel chan)
for (tries = 0; tries < CONFIG_IAQ_CORE_MAX_READ_RETRIES; tries++) {
ret = i2c_transfer(drv_data->i2c, &msg, 1,
DT_INST_0_AMS_IAQCORE_BASE_ADDRESS);
DT_INST_REG_ADDR(0));
if (ret < 0) {
LOG_ERR("Failed to read registers data [%d].", ret);
return -EIO;
@ -99,10 +101,10 @@ static int iaq_core_init(struct device *dev)
{
struct iaq_core_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_AMS_IAQCORE_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_AMS_IAQCORE_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -111,6 +113,6 @@ static int iaq_core_init(struct device *dev)
static struct iaq_core_data iaq_core_driver;
DEVICE_AND_API_INIT(iaq_core, DT_INST_0_AMS_IAQCORE_LABEL, iaq_core_init,
DEVICE_AND_API_INIT(iaq_core, DT_INST_LABEL(0), iaq_core_init,
&iaq_core_driver, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &iaq_core_driver_api);

View file

@ -5,6 +5,8 @@
*SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT avago_apds9960
/* @file
* @brief driver for APDS9960 ALS/RGB/gesture/proximity sensor
*/
@ -490,11 +492,11 @@ static const struct sensor_driver_api apds9960_driver_api = {
};
static const struct apds9960_config apds9960_config = {
.i2c_name = DT_INST_0_AVAGO_APDS9960_BUS_NAME,
.i2c_address = DT_INST_0_AVAGO_APDS9960_BASE_ADDRESS,
.gpio_name = DT_INST_0_AVAGO_APDS9960_INT_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_AVAGO_APDS9960_INT_GPIOS_PIN,
.gpio_flags = DT_INST_0_AVAGO_APDS9960_INT_GPIOS_FLAGS,
.i2c_name = DT_INST_BUS_LABEL(0),
.i2c_address = DT_INST_REG_ADDR(0),
.gpio_name = DT_INST_GPIO_LABEL(0, int_gpios),
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
#if CONFIG_APDS9960_PGAIN_8X
.pgain = APDS9960_PGAIN_8X,
#elif CONFIG_APDS9960_PGAIN_4X
@ -540,11 +542,11 @@ static const struct apds9960_config apds9960_config = {
static struct apds9960_data apds9960_data;
#ifndef CONFIG_DEVICE_POWER_MANAGEMENT
DEVICE_AND_API_INIT(apds9960, DT_INST_0_AVAGO_APDS9960_LABEL, &apds9960_init,
DEVICE_AND_API_INIT(apds9960, DT_INST_LABEL(0), &apds9960_init,
&apds9960_data, &apds9960_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &apds9960_driver_api);
#else
DEVICE_DEFINE(apds9960, DT_INST_0_AVAGO_APDS9960_LABEL, apds9960_init,
DEVICE_DEFINE(apds9960, DT_INST_LABEL(0), apds9960_init,
apds9960_device_ctrl, &apds9960_data, &apds9960_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &apds9960_driver_api);
#endif

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bma280
#include <drivers/i2c.h>
#include <init.h>
#include <drivers/sensor.h>
@ -116,10 +118,10 @@ int bma280_init(struct device *dev)
struct bma280_data *drv_data = dev->driver_data;
u8_t id = 0U;
drv_data->i2c = device_get_binding(DT_INST_0_BOSCH_BMA280_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Could not get pointer to %s device",
DT_INST_0_BOSCH_BMA280_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -160,7 +162,7 @@ int bma280_init(struct device *dev)
struct bma280_data bma280_driver;
DEVICE_AND_API_INIT(bma280, DT_INST_0_BOSCH_BMA280_LABEL,
DEVICE_AND_API_INIT(bma280, DT_INST_LABEL(0),
bma280_init, &bma280_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&bma280_driver_api);

View file

@ -12,10 +12,10 @@
#include <zephyr/types.h>
#include <drivers/gpio.h>
#define BMA280_I2C_ADDRESS DT_INST_0_BOSCH_BMA280_BASE_ADDRESS
#define BMA280_I2C_ADDRESS DT_INST_REG_ADDR(0)
#define BMA280_REG_CHIP_ID 0x00
#if DT_INST_0_BOSCH_BMA280_IS_BMC150
#if DT_INST_PROP(0, is_bmc150)
#define BMA280_CHIP_ID 0xFA
#else
#define BMA280_CHIP_ID 0xFB
@ -96,7 +96,7 @@
#define BMA280_REG_ACCEL_Y_LSB 0x4
#define BMA280_REG_ACCEL_Z_LSB 0x6
#if DT_INST_0_BOSCH_BMA280_IS_BMC150
#if DT_INST_PROP(0, is_bmc150)
#define BMA280_ACCEL_LSB_BITS 4
#define BMA280_ACCEL_LSB_SHIFT 4
#else

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bma280
#include <device.h>
#include <drivers/i2c.h>
#include <sys/util.h>
@ -21,7 +23,7 @@ static inline void setup_int1(struct device *dev,
struct bma280_data *data = dev->driver_data;
gpio_pin_interrupt_configure(data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int1_gpios),
(enable
? GPIO_INT_EDGE_TO_ACTIVE
: GPIO_INT_DISABLE));
@ -222,21 +224,21 @@ int bma280_init_interrupt(struct device *dev)
/* setup data ready gpio interrupt */
drv_data->gpio =
device_get_binding(DT_INST_0_BOSCH_BMA280_INT1_GPIOS_CONTROLLER);
device_get_binding(DT_INST_GPIO_LABEL(0, int1_gpios));
if (drv_data->gpio == NULL) {
LOG_DBG("Cannot get pointer to %s device",
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, int1_gpios));
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN,
DT_INST_0_BOSCH_BMA280_INT1_GPIOS_FLAGS
DT_INST_GPIO_PIN(0, int1_gpios),
DT_INST_GPIO_FLAGS(0, int1_gpios)
| GPIO_INPUT);
gpio_init_callback(&drv_data->gpio_cb,
bma280_gpio_callback,
BIT(DT_INST_0_BOSCH_BMA280_INT1_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, int1_gpios)));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_DBG("Could not set gpio callback");

View file

@ -9,6 +9,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bmc150_magn
#include <drivers/sensor.h>
#include <kernel.h>
#include <device.h>
@ -595,16 +597,16 @@ static int bmc150_magn_init(struct device *dev)
static const struct bmc150_magn_config bmc150_magn_config = {
#if defined(CONFIG_BMC150_MAGN_TRIGGER_DRDY)
.gpio_drdy_dev_name = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_CONTROLLER,
.gpio_drdy_int_pin = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_PIN,
.gpio_drdy_int_flags = DT_INST_0_BOSCH_BMC150_MAGN_DRDY_GPIOS_FLAGS,
.gpio_drdy_dev_name = DT_INST_GPIO_LABEL(0, drdy_gpios),
.gpio_drdy_int_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
.gpio_drdy_int_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
#endif
.i2c_master_dev_name = DT_INST_0_BOSCH_BMC150_MAGN_BUS_NAME,
.i2c_master_dev_name = DT_INST_BUS_LABEL(0),
.i2c_slave_addr = BMC150_MAGN_I2C_ADDR,
};
static struct bmc150_magn_data bmc150_magn_data;
DEVICE_AND_API_INIT(bmc150_magn, DT_INST_0_BOSCH_BMC150_MAGN_LABEL, bmc150_magn_init,
DEVICE_AND_API_INIT(bmc150_magn, DT_INST_LABEL(0), bmc150_magn_init,
&bmc150_magn_data, &bmc150_magn_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &bmc150_magn_api_funcs);

View file

@ -73,7 +73,7 @@
#define BMC150_MAGN_MASK_DRDY_LATCHING BIT(1)
#define BMC150_MAGN_MASK_DRDY_INT3_POLARITY BIT(0)
#define BMC150_MAGN_I2C_ADDR DT_INST_0_BOSCH_BMC150_MAGN_BASE_ADDRESS
#define BMC150_MAGN_I2C_ADDR DT_INST_REG_ADDR(0)
#if defined(CONFIG_BMC150_MAGN_SAMPLING_REP_XY) || \
defined(CONFIG_BMC150_MAGN_SAMPLING_REP_Z)

View file

@ -7,6 +7,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bme280
#include <kernel.h>
#include <drivers/sensor.h>
#include <init.h>
@ -14,9 +16,9 @@
#include <sys/byteorder.h>
#include <sys/__assert.h>
#ifdef DT_BOSCH_BME280_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
#include <drivers/i2c.h>
#elif defined DT_BOSCH_BME280_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
#include <drivers/spi.h>
#endif
#include <logging/log.h>
@ -29,10 +31,10 @@ static int bm280_reg_read(struct bme280_data *data,
u8_t start, u8_t *buf, int size)
{
#ifdef DT_BOSCH_BME280_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
return i2c_burst_read(data->i2c_master, data->i2c_slave_addr,
start, buf, size);
#elif defined DT_BOSCH_BME280_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
u8_t addr;
const struct spi_buf tx_buf = {
.buf = &addr,
@ -72,10 +74,10 @@ static int bm280_reg_read(struct bme280_data *data,
static int bm280_reg_write(struct bme280_data *data, u8_t reg, u8_t val)
{
#ifdef DT_BOSCH_BME280_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
return i2c_reg_write_byte(data->i2c_master, data->i2c_slave_addr,
reg, val);
#elif defined DT_BOSCH_BME280_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
u8_t cmd[2] = { reg & 0x7F, val };
const struct spi_buf tx_buf = {
.buf = cmd,
@ -347,34 +349,34 @@ static int bme280_chip_init(struct device *dev)
return 0;
}
#ifdef DT_BOSCH_BME280_BUS_SPI
#if DT_ANY_INST_ON_BUS(spi)
static inline int bme280_spi_init(struct bme280_data *data)
{
data->spi = device_get_binding(DT_INST_0_BOSCH_BME280_BUS_NAME);
data->spi = device_get_binding(DT_INST_BUS_LABEL(0));
if (!data->spi) {
LOG_DBG("spi device not found: %s",
DT_INST_0_BOSCH_BME280_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
data->spi_cfg.operation = SPI_WORD_SET(8) | SPI_TRANSFER_MSB |
SPI_MODE_CPOL | SPI_MODE_CPHA;
data->spi_cfg.frequency = DT_INST_0_BOSCH_BME280_SPI_MAX_FREQUENCY;
data->spi_cfg.slave = DT_INST_0_BOSCH_BME280_BASE_ADDRESS;
data->spi_cfg.frequency = DT_INST_PROP(0, spi_max_frequency);
data->spi_cfg.slave = DT_INST_REG_ADDR(0);
#if defined(DT_INST_0_BOSCH_BME280_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
data->spi_cs_control.gpio_dev =
device_get_binding(DT_INST_0_BOSCH_BME280_CS_GPIOS_CONTROLLER);
device_get_binding(DT_INST_SPI_DEV_CS_GPIOS_LABEL(0));
if (!data->spi_cs_control.gpio_dev) {
LOG_ERR("Unable to get GPIO SPI CS device");
return -ENODEV;
}
data->spi_cs_control.gpio_pin = DT_INST_0_BOSCH_BME280_CS_GPIOS_PIN;
data->spi_cs_control.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
data->spi_cs_control.delay = 0U;
data->spi_cfg.cs = &data->spi_cs_control;
#endif /* DT_INST_0_BOSCH_BME280_CS_GPIOS_CONTROLLER */
#endif /* DT_INST_SPI_DEV_HAS_CS_GPIOS(0) */
return 0;
}
@ -384,19 +386,19 @@ int bme280_init(struct device *dev)
{
struct bme280_data *data = dev->driver_data;
#ifdef DT_BOSCH_BME280_BUS_I2C
data->i2c_master = device_get_binding(DT_INST_0_BOSCH_BME280_BUS_NAME);
#if DT_ANY_INST_ON_BUS(i2c)
data->i2c_master = device_get_binding(DT_INST_BUS_LABEL(0));
if (!data->i2c_master) {
LOG_DBG("i2c master not found: %s",
DT_INST_0_BOSCH_BME280_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
data->i2c_slave_addr = DT_INST_0_BOSCH_BME280_BASE_ADDRESS;
#elif defined DT_BOSCH_BME280_BUS_SPI
data->i2c_slave_addr = DT_INST_REG_ADDR(0);
#elif DT_ANY_INST_ON_BUS(spi)
if (bme280_spi_init(data) < 0) {
LOG_DBG("spi master not found: %s",
DT_INST_0_BOSCH_BME280_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
#endif
@ -410,6 +412,6 @@ int bme280_init(struct device *dev)
static struct bme280_data bme280_data;
DEVICE_AND_API_INIT(bme280, DT_INST_0_BOSCH_BME280_LABEL, bme280_init, &bme280_data,
DEVICE_AND_API_INIT(bme280, DT_INST_LABEL(0), bme280_init, &bme280_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&bme280_api_funcs);

View file

@ -109,13 +109,13 @@
BME280_SPI_3W_DISABLE)
struct bme280_data {
#ifdef DT_BOSCH_BME280_BUS_I2C
#if DT_ANY_INST_ON_BUS(i2c)
struct device *i2c_master;
u16_t i2c_slave_addr;
#elif defined DT_BOSCH_BME280_BUS_SPI
#elif DT_ANY_INST_ON_BUS(spi)
struct device *spi;
struct spi_config spi_cfg;
#if defined(DT_INST_0_BOSCH_BME280_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
struct spi_cs_control spi_cs_control;
#endif
#else

View file

@ -10,6 +10,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bme680
#include "bme680.h"
#include <drivers/gpio.h>
#include <drivers/i2c.h>
@ -401,14 +403,14 @@ static int bme680_init(struct device *dev)
struct bme680_data *data = dev->driver_data;
data->i2c_master = device_get_binding(
DT_INST_0_BOSCH_BME680_BUS_NAME);
DT_INST_BUS_LABEL(0));
if (!data->i2c_master) {
LOG_ERR("I2C master not found: %s",
DT_INST_0_BOSCH_BME680_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
data->i2c_slave_addr = DT_INST_0_BOSCH_BME680_BASE_ADDRESS;
data->i2c_slave_addr = DT_INST_REG_ADDR(0);
if (bme680_chip_init(dev) < 0) {
return -EINVAL;
@ -424,6 +426,6 @@ static const struct sensor_driver_api bme680_api_funcs = {
static struct bme680_data bme680_data;
DEVICE_AND_API_INIT(bme680, DT_INST_0_BOSCH_BME680_LABEL, bme680_init, &bme680_data,
DEVICE_AND_API_INIT(bme680, DT_INST_LABEL(0), bme680_init, &bme680_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&bme680_api_funcs);

View file

@ -8,6 +8,8 @@
* http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMG160-DS000-09.pdf
*/
#define DT_DRV_COMPAT bosch_bmg160
#include <init.h>
#include <drivers/sensor.h>
#include <sys/byteorder.h>
@ -328,17 +330,17 @@ int bmg160_init(struct device *dev)
}
const struct bmg160_device_config bmg160_config = {
.i2c_port = DT_INST_0_BOSCH_BMG160_BUS_NAME,
.i2c_addr = DT_INST_0_BOSCH_BMG160_BASE_ADDRESS,
.i2c_port = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
.i2c_speed = BMG160_BUS_SPEED,
#ifdef CONFIG_BMG160_TRIGGER
.int_pin = DT_INST_0_BOSCH_BMG160_INT_GPIOS_PIN,
.int_flags = DT_INST_0_BOSCH_BMG160_INT_GPIOS_FLAGS,
.gpio_port = DT_INST_0_BOSCH_BMG160_INT_GPIOS_CONTROLLER,
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
.gpio_port = DT_INST_GPIO_LABEL(0, int_gpios),
#endif
};
DEVICE_AND_API_INIT(bmg160, DT_INST_0_BOSCH_BMG160_LABEL, bmg160_init,
DEVICE_AND_API_INIT(bmg160, DT_INST_LABEL(0), bmg160_init,
&bmg160_data,
&bmg160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&bmg160_api);

View file

@ -8,6 +8,8 @@
* http://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BMI160-DS000-07.pdf
*/
#define DT_DRV_COMPAT bosch_bmi160
#include <init.h>
#include <drivers/sensor.h>
#include <sys/byteorder.h>
@ -795,16 +797,16 @@ int bmi160_init(struct device *dev)
u8_t val = 0U;
s32_t acc_range, gyr_range;
bmi160->spi = device_get_binding(DT_INST_0_BOSCH_BMI160_BUS_NAME);
bmi160->spi = device_get_binding(DT_INST_BUS_LABEL(0));
if (!bmi160->spi) {
LOG_DBG("SPI master controller not found: %s.",
DT_INST_0_BOSCH_BMI160_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
bmi160->spi_cfg.operation = SPI_WORD_SET(8);
bmi160->spi_cfg.frequency = DT_INST_0_BOSCH_BMI160_SPI_MAX_FREQUENCY;
bmi160->spi_cfg.slave = DT_INST_0_BOSCH_BMI160_BASE_ADDRESS;
bmi160->spi_cfg.frequency = DT_INST_PROP(0, spi_max_frequency);
bmi160->spi_cfg.slave = DT_INST_REG_ADDR(0);
/* reboot the chip */
if (bmi160_byte_write(dev, BMI160_REG_CMD, BMI160_CMD_SOFT_RESET) < 0) {
@ -899,14 +901,14 @@ int bmi160_init(struct device *dev)
const struct bmi160_device_config bmi160_config = {
#if defined(CONFIG_BMI160_TRIGGER)
.gpio_port = DT_INST_0_BOSCH_BMI160_INT_GPIOS_CONTROLLER,
.int_pin = DT_INST_0_BOSCH_BMI160_INT_GPIOS_PIN,
.int_flags = DT_INST_0_BOSCH_BMI160_INT_GPIOS_FLAGS,
.gpio_port = DT_INST_GPIO_LABEL(0, int_gpios),
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
#endif
};
DEVICE_AND_API_INIT(bmi160, DT_INST_0_BOSCH_BMI160_LABEL, bmi160_init, &bmi160_data,
DEVICE_AND_API_INIT(bmi160, DT_INST_LABEL(0), bmi160_init, &bmi160_data,
&bmi160_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&bmi160_api);

View file

@ -6,6 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT bosch_bmm150
#include <logging/log.h>
#include "bmm150.h"
@ -598,12 +600,12 @@ static int bmm150_init(struct device *dev)
}
static const struct bmm150_config bmm150_config = {
.i2c_master_dev_name = DT_INST_0_BOSCH_BMM150_BUS_NAME,
.i2c_master_dev_name = DT_INST_BUS_LABEL(0),
.i2c_slave_addr = BMM150_I2C_ADDR,
};
static struct bmm150_data bmm150_data;
DEVICE_AND_API_INIT(bmm150, DT_INST_0_BOSCH_BMM150_LABEL, bmm150_init,
DEVICE_AND_API_INIT(bmm150, DT_INST_LABEL(0), bmm150_init,
&bmm150_data, &bmm150_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &bmm150_api_funcs);

View file

@ -82,7 +82,7 @@
#define BMM150_MASK_DRDY_LATCHING BIT(1)
#define BMM150_MASK_DRDY_INT3_POLARITY BIT(0)
#define BMM150_I2C_ADDR DT_INST_0_BOSCH_BMM150_BASE_ADDRESS
#define BMM150_I2C_ADDR DT_INST_REG_ADDR(0)
#if defined(CONFIG_BMM150_SAMPLING_REP_XY) || \
defined(CONFIG_BMM150_SAMPLING_REP_Z)

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ams_ccs811
#include <device.h>
#include <drivers/gpio.h>
#include <drivers/i2c.h>
@ -17,12 +19,12 @@
#include "ccs811.h"
#define WAKE_PIN DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN
#define RESET_PIN DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN
#define WAKE_PIN DT_INST_GPIO_PIN(0, wake_gpios)
#define RESET_PIN DT_INST_GPIO_PIN(0, reset_gpios)
LOG_MODULE_REGISTER(CCS811, CONFIG_SENSOR_LOG_LEVEL);
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, wake_gpios)
static void set_wake(struct ccs811_data *drv_data, bool enable)
{
gpio_pin_set(drv_data->wake_gpio, WAKE_PIN, enable);
@ -45,7 +47,7 @@ static int fetch_status(struct device *i2c)
u8_t status;
int rv;
if (i2c_reg_read_byte(i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
if (i2c_reg_read_byte(i2c, DT_INST_REG_ADDR(0),
CCS811_REG_STATUS, &status) < 0) {
LOG_ERR("Failed to read Status register");
return -EIO;
@ -55,7 +57,7 @@ static int fetch_status(struct device *i2c)
if (status & CCS811_STATUS_ERROR) {
u8_t error_id;
if (i2c_reg_read_byte(i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
if (i2c_reg_read_byte(i2c, DT_INST_REG_ADDR(0),
CCS811_REG_ERROR_ID, &error_id) < 0) {
LOG_ERR("Failed to read ERROR_ID register");
return -EIO;
@ -92,12 +94,12 @@ int ccs811_configver_fetch(struct device *dev,
set_wake(drv_data, true);
cmd = CCS811_REG_HW_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
&ptr->hw_version, sizeof(ptr->hw_version));
if (rc == 0) {
cmd = CCS811_REG_FW_BOOT_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
(u8_t *)&ptr->fw_boot_version,
sizeof(ptr->fw_boot_version));
@ -106,7 +108,7 @@ int ccs811_configver_fetch(struct device *dev,
if (rc == 0) {
cmd = CCS811_REG_FW_APP_VERSION;
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
(u8_t *)&ptr->fw_app_version,
sizeof(ptr->fw_app_version));
@ -133,7 +135,7 @@ int ccs811_baseline_fetch(struct device *dev)
set_wake(drv_data, true);
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
(u8_t *)&baseline, sizeof(baseline));
set_wake(drv_data, false);
@ -154,7 +156,7 @@ int ccs811_baseline_update(struct device *dev,
buf[0] = CCS811_REG_BASELINE;
memcpy(buf + 1, &baseline, sizeof(baseline));
set_wake(drv_data, true);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_0_AMS_CCS811_BASE_ADDRESS);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_REG_ADDR(0));
set_wake(drv_data, false);
return rc;
}
@ -222,7 +224,7 @@ int ccs811_envdata_update(struct device *dev,
}
set_wake(drv_data, true);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_0_AMS_CCS811_BASE_ADDRESS);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_REG_ADDR(0));
set_wake(drv_data, false);
return rc;
}
@ -237,7 +239,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
unsigned int status;
set_wake(drv_data, true);
rc = i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
(u8_t *)buf, sizeof(buf));
set_wake(drv_data, false);
@ -346,7 +348,7 @@ static int switch_to_app_mode(struct device *i2c)
buf = CCS811_REG_APP_START;
/* Set the device to application mode */
if (i2c_write(i2c, &buf, 1, DT_INST_0_AMS_CCS811_BASE_ADDRESS) < 0) {
if (i2c_write(i2c, &buf, 1, DT_INST_REG_ADDR(0)) < 0) {
LOG_ERR("Failed to set Application mode");
return -EIO;
}
@ -388,7 +390,7 @@ int ccs811_mutate_meas_mode(struct device *dev,
if (mode != drv_data->mode) {
set_wake(drv_data, true);
rc = i2c_reg_write_byte(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
rc = i2c_reg_write_byte(drv_data->i2c, DT_INST_REG_ADDR(0),
CCS811_REG_MEAS_MODE,
mode);
LOG_DBG("CCS811 meas mode change %02x to %02x got %d",
@ -420,7 +422,7 @@ int ccs811_set_thresholds(struct device *dev)
int rc;
set_wake(drv_data, true);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_0_AMS_CCS811_BASE_ADDRESS);
rc = i2c_write(drv_data->i2c, buf, sizeof(buf), DT_INST_REG_ADDR(0));
set_wake(drv_data, false);
return rc;
}
@ -437,18 +439,18 @@ static int ccs811_init(struct device *dev)
u8_t hw_id;
*drv_data = (struct ccs811_data){ 0 };
drv_data->i2c = device_get_binding(DT_INST_0_AMS_CCS811_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_AMS_CCS811_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
drv_data->wake_gpio = device_get_binding(DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
#if DT_INST_NODE_HAS_PROP(0, wake_gpios)
drv_data->wake_gpio = device_get_binding(DT_INST_GPIO_LABEL(0, wake_gpios));
if (drv_data->wake_gpio == NULL) {
LOG_ERR("Failed to get pointer to WAKE device: %s",
DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, wake_gpios));
return -EINVAL;
}
@ -459,30 +461,30 @@ static int ccs811_init(struct device *dev)
*/
gpio_pin_configure(drv_data->wake_gpio, WAKE_PIN,
GPIO_OUTPUT_INACTIVE
| DT_INST_0_AMS_CCS811_WAKE_GPIOS_FLAGS);
| DT_INST_GPIO_FLAGS(0, wake_gpios));
set_wake(drv_data, true);
k_msleep(1);
#endif
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
drv_data->reset_gpio = device_get_binding(DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER);
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
drv_data->reset_gpio = device_get_binding(DT_INST_GPIO_LABEL(0, reset_gpios));
if (drv_data->reset_gpio == NULL) {
LOG_ERR("Failed to get pointer to RESET device: %s",
DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, reset_gpios));
return -EINVAL;
}
gpio_pin_configure(drv_data->reset_gpio, RESET_PIN,
GPIO_OUTPUT_ACTIVE
| DT_INST_0_AMS_CCS811_RESET_GPIOS_FLAGS);
| DT_INST_GPIO_FLAGS(0, reset_gpios));
k_msleep(1);
#endif
#ifdef DT_INST_0_AMS_CCS811_IRQ_GPIOS_CONTROLLER
drv_data->irq_gpio = device_get_binding(DT_INST_0_AMS_CCS811_IRQ_GPIOS_CONTROLLER);
#if DT_INST_NODE_HAS_PROP(0, irq_gpios)
drv_data->irq_gpio = device_get_binding(DT_INST_GPIO_LABEL(0, irq_gpios));
if (drv_data->irq_gpio == NULL) {
LOG_ERR("Failed to get pointer to INT device: %s",
DT_INST_0_AMS_CCS811_IRQ_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, irq_gpios));
return -EINVAL;
}
#endif
@ -491,7 +493,7 @@ static int ccs811_init(struct device *dev)
* and validating any errors or configuration inconsistencies
* after a reset that left the device running.
*/
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
gpio_pin_set(drv_data->reset_gpio, RESET_PIN, 1);
k_busy_wait(15); /* t_RESET */
gpio_pin_set(drv_data->reset_gpio, RESET_PIN, 0);
@ -502,7 +504,7 @@ static int ccs811_init(struct device *dev)
};
if (i2c_write(drv_data->i2c, reset_seq, sizeof(reset_seq),
DT_INST_0_AMS_CCS811_BASE_ADDRESS) < 0) {
DT_INST_REG_ADDR(0)) < 0) {
LOG_ERR("Failed to issue SW reset");
ret = -EIO;
goto out;
@ -518,7 +520,7 @@ static int ccs811_init(struct device *dev)
}
/* Check Hardware ID */
if (i2c_reg_read_byte(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
if (i2c_reg_read_byte(drv_data->i2c, DT_INST_REG_ADDR(0),
CCS811_REG_HW_ID, &hw_id) < 0) {
LOG_ERR("Failed to read Hardware ID register");
ret = -EIO;
@ -533,7 +535,7 @@ static int ccs811_init(struct device *dev)
/* Check application firmware version (first byte) */
cmd = CCS811_REG_FW_APP_VERSION;
if (i2c_write_read(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
if (i2c_write_read(drv_data->i2c, DT_INST_REG_ADDR(0),
&cmd, sizeof(cmd),
&fw_ver, sizeof(fw_ver)) < 0) {
LOG_ERR("Failed to read App Firmware Version register");
@ -555,7 +557,7 @@ static int ccs811_init(struct device *dev)
#elif defined(CONFIG_CCS811_DRIVE_MODE_4)
meas_mode = CCS811_MODE_IAQ_250MSEC;
#endif
if (i2c_reg_write_byte(drv_data->i2c, DT_INST_0_AMS_CCS811_BASE_ADDRESS,
if (i2c_reg_write_byte(drv_data->i2c, DT_INST_REG_ADDR(0),
CCS811_REG_MEAS_MODE,
meas_mode) < 0) {
LOG_ERR("Failed to set Measurement mode");
@ -590,6 +592,6 @@ out:
static struct ccs811_data ccs811_driver;
DEVICE_AND_API_INIT(ccs811, DT_INST_0_AMS_CCS811_LABEL, ccs811_init, &ccs811_driver,
DEVICE_AND_API_INIT(ccs811, DT_INST_LABEL(0), ccs811_init, &ccs811_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&ccs811_driver_api);

View file

@ -49,7 +49,7 @@
struct ccs811_data {
struct device *i2c;
#ifdef DT_INST_0_AMS_CCS811_IRQ_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, irq_gpios)
struct device *irq_gpio;
#ifdef CONFIG_CCS811_TRIGGER
struct device *dev;
@ -72,10 +72,10 @@ struct ccs811_data {
u16_t co2_m2h;
#endif /* CONFIG_CCS811_TRIGGER */
#endif
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, reset_gpios)
struct device *reset_gpio;
#endif
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, wake_gpios)
struct device *wake_gpio;
#endif
struct ccs811_result_type result;

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ams_ccs811
#include <drivers/sensor.h>
#include "ccs811.h"
@ -11,7 +13,7 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(CCS811);
#define IRQ_PIN DT_INST_0_AMS_CCS811_IRQ_GPIOS_PIN
#define IRQ_PIN DT_INST_GPIO_PIN(0, irq_gpios)
int ccs811_attr_set(struct device *dev,
enum sensor_channel chan,
@ -173,7 +175,7 @@ int ccs811_init_interrupt(struct device *dev)
drv_data->dev = dev;
gpio_pin_configure(drv_data->irq_gpio, IRQ_PIN,
GPIO_INPUT | DT_INST_0_AMS_CCS811_IRQ_GPIOS_FLAGS);
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, irq_gpios));
gpio_init_callback(&drv_data->gpio_cb, gpio_callback, BIT(IRQ_PIN));

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT aosong_dht
#include <device.h>
#include <drivers/gpio.h>
#include <sys/byteorder.h>
@ -172,7 +174,7 @@ static int dht_channel_get(struct device *dev,
|| chan == SENSOR_CHAN_HUMIDITY);
/* see data calculation example from datasheet */
if (IS_ENABLED(DT_INST_0_AOSONG_DHT_DHT22)) {
if (IS_ENABLED(DT_INST_PROP(0, dht22))) {
/*
* use both integral and decimal data bytes; resulted
* 16bit data has a resolution of 0.1 units
@ -239,11 +241,11 @@ static int dht_init(struct device *dev)
static struct dht_data dht_data;
static const struct dht_config dht_config = {
.ctrl = DT_INST_0_AOSONG_DHT_DIO_GPIOS_CONTROLLER,
.flags = DT_INST_0_AOSONG_DHT_DIO_GPIOS_FLAGS,
.pin = DT_INST_0_AOSONG_DHT_DIO_GPIOS_PIN,
.ctrl = DT_INST_GPIO_LABEL(0, dio_gpios),
.flags = DT_INST_GPIO_FLAGS(0, dio_gpios),
.pin = DT_INST_GPIO_PIN(0, dio_gpios),
};
DEVICE_AND_API_INIT(dht_dev, DT_INST_0_AOSONG_DHT_LABEL, &dht_init,
DEVICE_AND_API_INIT(dht_dev, DT_INST_LABEL(0), &dht_init,
&dht_data, &dht_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &dht_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ams_ens210
#include <device.h>
#include <drivers/i2c.h>
#include <kernel.h>
@ -51,7 +53,7 @@ static int ens210_measure(struct device *i2c_dev, enum sensor_channel chan)
/* Start measuring */
ret = i2c_reg_write_byte(i2c_dev,
DT_INST_0_AMS_ENS210_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
ENS210_REG_SENS_START, *(u8_t *)&sense_start);
if (ret < 0) {
@ -64,7 +66,7 @@ static int ens210_measure(struct device *i2c_dev, enum sensor_channel chan)
do {
k_sleep(K_MSEC(2));
ret = i2c_reg_read_byte(i2c_dev,
DT_INST_0_AMS_ENS210_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
ENS210_REG_SENS_START, &buf);
if (ret < 0) {
@ -100,7 +102,7 @@ static int ens210_sample_fetch(struct device *dev, enum sensor_channel chan)
#endif /* Single shot mode */
for (cnt = 0; cnt <= CONFIG_ENS210_MAX_READ_RETRIES; cnt++) {
ret = i2c_burst_read(drv_data->i2c, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_burst_read(drv_data->i2c, DT_INST_REG_ADDR(0),
ENS210_REG_T_VAL, (u8_t *)&data, sizeof(data));
if (ret < 0) {
LOG_ERR("Failed to read data");
@ -194,7 +196,7 @@ static int ens210_sys_reset(struct device *i2c_dev)
};
int ret;
ret = i2c_reg_write_byte(i2c_dev, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_reg_write_byte(i2c_dev, DT_INST_REG_ADDR(0),
ENS210_REG_SYS_CTRL, *(u8_t *)&sys_ctrl);
if (ret < 0) {
LOG_ERR("Failed to set SYS_CTRL to 0x%x", *(u8_t *)&sys_ctrl);
@ -210,7 +212,7 @@ static int ens210_sys_enable(struct device *i2c_dev, u8_t low_power)
};
int ret;
ret = i2c_reg_write_byte(i2c_dev, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_reg_write_byte(i2c_dev, DT_INST_REG_ADDR(0),
ENS210_REG_SYS_CTRL, *(u8_t *)&sys_ctrl);
if (ret < 0) {
LOG_ERR("Failed to set SYS_CTRL to 0x%x", *(u8_t *)&sys_ctrl);
@ -225,7 +227,7 @@ static int ens210_wait_boot(struct device *i2c_dev)
struct ens210_sys_stat sys_stat;
for (cnt = 0; cnt <= CONFIG_ENS210_MAX_STAT_RETRIES; cnt++) {
ret = i2c_reg_read_byte(i2c_dev, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_reg_read_byte(i2c_dev, DT_INST_REG_ADDR(0),
ENS210_REG_SYS_STAT,
(u8_t *)&sys_stat);
@ -280,10 +282,10 @@ static int ens210_init(struct device *dev)
int ret;
u16_t part_id;
drv_data->i2c = device_get_binding(DT_INST_0_AMS_ENS210_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_AMS_ENS210_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -296,7 +298,7 @@ static int ens210_init(struct device *dev)
/* Check Hardware ID. This is only possible after device is ready
* and active
*/
ret = i2c_burst_read(drv_data->i2c, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_burst_read(drv_data->i2c, DT_INST_REG_ADDR(0),
ENS210_REG_PART_ID, (u8_t *)&part_id,
sizeof(part_id));
if (ret < 0) {
@ -316,7 +318,7 @@ static int ens210_init(struct device *dev)
}
/* Set measurement mode*/
ret = i2c_reg_write_byte(drv_data->i2c, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_reg_write_byte(drv_data->i2c, DT_INST_REG_ADDR(0),
ENS210_REG_SENS_RUN, *(u8_t *)&sense_run);
if (ret < 0) {
LOG_ERR("Failed to set SENS_RUN to 0x%x",
@ -327,7 +329,7 @@ static int ens210_init(struct device *dev)
#if defined(CONFIG_ENS210_TEMPERATURE_CONTINUOUS) \
|| defined(CONFIG_ENS210_HUMIDITY_CONTINUOUS)
/* Start measuring */
ret = i2c_reg_write_byte(drv_data->i2c, DT_INST_0_AMS_ENS210_BASE_ADDRESS,
ret = i2c_reg_write_byte(drv_data->i2c, DT_INST_REG_ADDR(0),
ENS210_REG_SENS_START, *(u8_t *)&sense_start);
if (ret < 0) {
LOG_ERR("Failed to set SENS_START to 0x%x",
@ -340,6 +342,6 @@ static int ens210_init(struct device *dev)
static struct ens210_data ens210_driver;
DEVICE_AND_API_INIT(ens210, DT_INST_0_AMS_ENS210_LABEL, ens210_init, &ens210_driver,
DEVICE_AND_API_INIT(ens210, DT_INST_LABEL(0), ens210_init, &ens210_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&en210_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT nxp_fxas21002
#include "fxas21002.h"
#include <sys/util.h>
#include <sys/__assert.h>
@ -284,27 +286,27 @@ static const struct sensor_driver_api fxas21002_driver_api = {
};
static const struct fxas21002_config fxas21002_config = {
.i2c_name = DT_INST_0_NXP_FXAS21002_BUS_NAME,
.i2c_address = DT_INST_0_NXP_FXAS21002_BASE_ADDRESS,
.i2c_name = DT_INST_BUS_LABEL(0),
.i2c_address = DT_INST_REG_ADDR(0),
.whoami = CONFIG_FXAS21002_WHOAMI,
.range = CONFIG_FXAS21002_RANGE,
.dr = CONFIG_FXAS21002_DR,
#ifdef CONFIG_FXAS21002_TRIGGER
#ifdef CONFIG_FXAS21002_DRDY_INT1
.gpio_name = DT_INST_0_NXP_FXAS21002_INT1_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_NXP_FXAS21002_INT1_GPIOS_PIN,
.gpio_flags = DT_INST_0_NXP_FXAS21002_INT1_GPIOS_FLAGS,
.gpio_name = DT_INST_GPIO_LABEL(0, int1_gpios),
.gpio_pin = DT_INST_GPIO_PIN(0, int1_gpios),
.gpio_flags = DT_INST_GPIO_FLAGS(0, int1_gpios),
#else
.gpio_name = DT_INST_0_NXP_FXAS21002_INT2_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_NXP_FXAS21002_INT2_GPIOS_PIN,
.gpio_flags = DT_INST_0_NXP_FXAS21002_INT2_GPIOS_FLAGS,
.gpio_name = DT_INST_GPIO_LABEL(0, int2_gpios),
.gpio_pin = DT_INST_GPIO_PIN(0, int2_gpios),
.gpio_flags = DT_INST_GPIO_FLAGS(0, int2_gpios),
#endif
#endif
};
static struct fxas21002_data fxas21002_data;
DEVICE_AND_API_INIT(fxas21002, DT_INST_0_NXP_FXAS21002_LABEL, fxas21002_init,
DEVICE_AND_API_INIT(fxas21002, DT_INST_LABEL(0), fxas21002_init,
&fxas21002_data, &fxas21002_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&fxas21002_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT grove_light
#include <drivers/adc.h>
#include <device.h>
#include <math.h>
@ -113,10 +115,10 @@ static int gls_init(struct device *dev)
static struct gls_data gls_data;
static const struct gls_config gls_cfg = {
.adc_label = DT_INST_0_GROVE_LIGHT_IO_CHANNELS_CONTROLLER,
.adc_channel = DT_INST_0_GROVE_LIGHT_IO_CHANNELS_INPUT,
.adc_label = DT_INST_IO_CHANNELS_LABEL(0),
.adc_channel = DT_INST_IO_CHANNELS_INPUT(0),
};
DEVICE_AND_API_INIT(gls_dev, DT_INST_0_GROVE_LIGHT_LABEL, &gls_init,
DEVICE_AND_API_INIT(gls_dev, DT_INST_LABEL(0), &gls_init,
&gls_data, &gls_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&gls_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT grove_temperature
#include <drivers/adc.h>
#include <device.h>
#include <math.h>
@ -115,13 +117,13 @@ static int gts_init(struct device *dev)
static struct gts_data gts_data;
static const struct gts_config gts_cfg = {
.adc_label = DT_INST_0_GROVE_TEMPERATURE_IO_CHANNELS_CONTROLLER,
.b_const = (IS_ENABLED(DT_INST_0_GROVE_TEMPERATURE_V1P0)
.adc_label = DT_INST_IO_CHANNELS_LABEL(0),
.b_const = (IS_ENABLED(DT_INST_PROP(0, v1p0))
? 3975
: 4250),
.adc_channel = DT_INST_0_GROVE_TEMPERATURE_IO_CHANNELS_INPUT,
.adc_channel = DT_INST_IO_CHANNELS_INPUT(0),
};
DEVICE_AND_API_INIT(gts_dev, DT_INST_0_GROVE_TEMPERATURE_LABEL, &gts_init,
DEVICE_AND_API_INIT(gts_dev, DT_INST_LABEL(0), &gts_init,
&gts_data, &gts_cfg, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&gts_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT honeywell_hmc5883l
#include <drivers/i2c.h>
#include <init.h>
#include <sys/__assert.h>
@ -60,7 +62,7 @@ static int hmc5883l_sample_fetch(struct device *dev, enum sensor_channel chan)
/* fetch magnetometer sample */
if (i2c_burst_read(drv_data->i2c,
DT_INST_0_HONEYWELL_HMC5883L_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
HMC5883L_REG_DATA_START, (u8_t *)buf, 6) < 0) {
LOG_ERR("Failed to fetch megnetometer sample.");
return -EIO;
@ -87,16 +89,16 @@ int hmc5883l_init(struct device *dev)
u8_t chip_cfg[3], id[3], idx;
drv_data->i2c = device_get_binding(
DT_INST_0_HONEYWELL_HMC5883L_BUS_NAME);
DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device.",
DT_INST_0_HONEYWELL_HMC5883L_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
/* check chip ID */
if (i2c_burst_read(drv_data->i2c,
DT_INST_0_HONEYWELL_HMC5883L_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
HMC5883L_REG_CHIP_ID, id, 3) < 0) {
LOG_ERR("Failed to read chip ID.");
return -EIO;
@ -140,7 +142,7 @@ int hmc5883l_init(struct device *dev)
chip_cfg[2] = HMC5883L_MODE_CONTINUOUS;
if (i2c_burst_write(drv_data->i2c,
DT_INST_0_HONEYWELL_HMC5883L_BASE_ADDRESS,
DT_INST_REG_ADDR(0),
HMC5883L_REG_CONFIG_A, chip_cfg, 3) < 0) {
LOG_ERR("Failed to configure chip.");
return -EIO;
@ -158,6 +160,6 @@ int hmc5883l_init(struct device *dev)
struct hmc5883l_data hmc5883l_driver;
DEVICE_AND_API_INIT(hmc5883l, DT_INST_0_HONEYWELL_HMC5883L_LABEL,
DEVICE_AND_API_INIT(hmc5883l, DT_INST_LABEL(0),
hmc5883l_init, &hmc5883l_driver, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &hmc5883l_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT honeywell_hmc5883l
#include <device.h>
#include <drivers/i2c.h>
#include <sys/__assert.h>
@ -24,7 +26,7 @@ int hmc5883l_trigger_set(struct device *dev,
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_DISABLE);
drv_data->data_ready_handler = handler;
@ -35,7 +37,7 @@ int hmc5883l_trigger_set(struct device *dev,
drv_data->data_ready_trigger = *trig;
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
return 0;
@ -50,7 +52,7 @@ static void hmc5883l_gpio_callback(struct device *dev,
ARG_UNUSED(pins);
gpio_pin_interrupt_configure(dev,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_DISABLE);
#if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD)
@ -71,7 +73,7 @@ static void hmc5883l_thread_cb(void *arg)
}
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
}
@ -106,21 +108,21 @@ int hmc5883l_init_interrupt(struct device *dev)
/* setup data ready gpio interrupt */
drv_data->gpio = device_get_binding(
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, int_gpios));
if (drv_data->gpio == NULL) {
LOG_ERR("Failed to get pointer to %s device.",
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, int_gpios));
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INPUT |
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_FLAGS);
DT_INST_GPIO_FLAGS(0, int_gpios));
gpio_init_callback(&drv_data->gpio_cb,
hmc5883l_gpio_callback,
BIT(DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_ERR("Failed to set gpio callback.");
@ -141,7 +143,7 @@ int hmc5883l_init_interrupt(struct device *dev)
#endif
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
return 0;

View file

@ -8,6 +8,8 @@
* http://www.hoperf.com/upload/sensor/HP206C_DataSheet_EN_V2.0.pdf
*/
#define DT_DRV_COMPAT hoperf_hp206c
#include <init.h>
#include <drivers/sensor.h>
#include <drivers/i2c.h>
@ -284,7 +286,7 @@ static int hp206c_init(struct device *dev)
{
struct hp206c_device_data *hp206c = dev->driver_data;
hp206c->i2c = device_get_binding(DT_INST_0_HOPERF_HP206C_BUS_NAME);
hp206c->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (!hp206c->i2c) {
LOG_ERR("I2C master controller not found!");
return -EINVAL;
@ -314,7 +316,7 @@ static int hp206c_init(struct device *dev)
static struct hp206c_device_data hp206c_data;
DEVICE_AND_API_INIT(hp206c, DT_INST_0_HOPERF_HP206C_LABEL,
DEVICE_AND_API_INIT(hp206c, DT_INST_LABEL(0),
hp206c_init, &hp206c_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&hp206c_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT st_hts221
#include <drivers/i2c.h>
#include <init.h>
#include <sys/__assert.h>
@ -177,15 +179,15 @@ int hts221_init(struct device *dev)
static struct hts221_data hts221_driver;
static const struct hts221_config hts221_cfg = {
.i2c_bus = DT_INST_0_ST_HTS221_BUS_NAME,
.i2c_addr = DT_INST_0_ST_HTS221_BASE_ADDRESS,
.i2c_bus = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
#ifdef CONFIG_HTS221_TRIGGER
.drdy_pin = DT_INST_0_ST_HTS221_DRDY_GPIOS_PIN,
.drdy_flags = DT_INST_0_ST_HTS221_DRDY_GPIOS_FLAGS,
.drdy_controller = DT_INST_0_ST_HTS221_DRDY_GPIOS_CONTROLLER,
.drdy_pin = DT_INST_GPIO_PIN(0, drdy_gpios),
.drdy_flags = DT_INST_GPIO_FLAGS(0, drdy_gpios),
.drdy_controller = DT_INST_GPIO_LABEL(0, drdy_gpios),
#endif /* CONFIG_HTS221_TRIGGER */
};
DEVICE_AND_API_INIT(hts221, DT_INST_0_ST_HTS221_LABEL, hts221_init,
DEVICE_AND_API_INIT(hts221, DT_INST_LABEL(0), hts221_init,
&hts221_driver, &hts221_cfg, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &hts221_driver_api);

View file

@ -6,6 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT isil_isl29035
#include <kernel.h>
#include <init.h>
#include <drivers/i2c.h>
@ -74,7 +76,7 @@ static int isl29035_init(struct device *dev)
{
struct isl29035_driver_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_ISIL_ISL29035_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get I2C device.");
return -EINVAL;
@ -141,6 +143,6 @@ static int isl29035_init(struct device *dev)
struct isl29035_driver_data isl29035_data;
DEVICE_AND_API_INIT(isl29035_dev, DT_INST_0_ISIL_ISL29035_LABEL, &isl29035_init,
DEVICE_AND_API_INIT(isl29035_dev, DT_INST_LABEL(0), &isl29035_init,
&isl29035_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &isl29035_api);

View file

@ -14,7 +14,7 @@
#include <drivers/sensor.h>
#include <drivers/gpio.h>
#define ISL29035_I2C_ADDRESS DT_INST_0_ISIL_ISL29035_BASE_ADDRESS
#define ISL29035_I2C_ADDRESS DT_INST_REG_ADDR(0)
#define ISL29035_COMMAND_I_REG 0x00
#define ISL29035_OPMODE_SHIFT 5

View file

@ -6,6 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT isil_isl29035
#include <drivers/i2c.h>
#include <sys/util.h>
#include <kernel.h>
@ -24,7 +26,7 @@ static inline void setup_int(struct isl29035_driver_data *drv_data,
: GPIO_INT_DISABLE;
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
flags);
}
@ -152,7 +154,7 @@ int isl29035_trigger_set(struct device *dev,
/* enable interrupt callback */
setup_int(drv_data, true);
if (gpio_pin_get(drv_data->gpio,
DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN) > 0) {
DT_INST_GPIO_PIN(0, int_gpios)) > 0) {
handle_int(drv_data);
}
@ -174,18 +176,18 @@ int isl29035_init_interrupt(struct device *dev)
/* setup gpio interrupt */
drv_data->gpio =
device_get_binding(DT_INST_0_ISIL_ISL29035_INT_GPIOS_CONTROLLER);
device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
if (drv_data->gpio == NULL) {
LOG_DBG("Failed to get GPIO device.");
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN,
GPIO_INPUT | DT_INST_0_ISIL_ISL29035_INT_GPIOS_FLAGS);
gpio_pin_configure(drv_data->gpio, DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, int_gpios));
gpio_init_callback(&drv_data->gpio_cb,
isl29035_gpio_callback,
BIT(DT_INST_0_ISIL_ISL29035_INT_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_DBG("Failed to set gpio callback.");

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT max_max30101
#include <logging/log.h>
#include "max30101.h"
@ -204,8 +206,8 @@ static int max30101_init(struct device *dev)
}
static struct max30101_config max30101_config = {
.i2c_label = DT_INST_0_MAX_MAX30101_BUS_NAME,
.i2c_addr = DT_INST_0_MAX_MAX30101_BASE_ADDRESS,
.i2c_label = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
.fifo = (CONFIG_MAX30101_SMP_AVE << MAX30101_FIFO_CFG_SMP_AVE_SHIFT) |
#ifdef CONFIG_MAX30101_FIFO_ROLLOVER_EN
MAX30101_FIFO_CFG_ROLLOVER_EN_MASK |
@ -244,7 +246,7 @@ static struct max30101_config max30101_config = {
static struct max30101_data max30101_data;
DEVICE_AND_API_INIT(max30101, DT_INST_0_MAX_MAX30101_LABEL, max30101_init,
DEVICE_AND_API_INIT(max30101, DT_INST_LABEL(0), max30101_init,
&max30101_data, &max30101_config,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&max30101_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT maxim_max44009
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
@ -171,10 +173,10 @@ int max44009_init(struct device *dev)
{
struct max44009_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_MAXIM_MAX44009_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
DT_INST_0_MAXIM_MAX44009_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -183,6 +185,6 @@ int max44009_init(struct device *dev)
static struct max44009_data max44009_drv_data;
DEVICE_AND_API_INIT(max44009, DT_INST_0_MAXIM_MAX44009_LABEL, max44009_init,
DEVICE_AND_API_INIT(max44009, DT_INST_LABEL(0), max44009_init,
&max44009_drv_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &max44009_driver_api);

View file

@ -9,7 +9,7 @@
#include <sys/util.h>
#define MAX44009_I2C_ADDRESS DT_INST_0_MAXIM_MAX44009_BASE_ADDRESS
#define MAX44009_I2C_ADDRESS DT_INST_REG_ADDR(0)
#define MAX44009_SAMPLING_CONTROL_BIT BIT(7)
#define MAX44009_CONTINUOUS_SAMPLING BIT(7)

View file

@ -3,6 +3,9 @@
*
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT microchip_xec_tach
#include <errno.h>
#include <device.h>
#include <drivers/sensor.h>
@ -114,13 +117,13 @@ static const struct sensor_driver_api tach_xec_driver_api = {
#define TACH_XEC_DEVICE(id) \
static const struct tach_xec_config tach_xec_dev_config##id = { \
.base_address = \
DT_INST_##id##_MICROCHIP_XEC_TACH_BASE_ADDRESS, \
DT_INST_REG_ADDR(id), \
}; \
\
static struct tach_xec_data tach_xec_dev_data##id; \
\
DEVICE_AND_API_INIT(tach##id, \
DT_INST_##id##_MICROCHIP_XEC_TACH_LABEL, \
DT_INST_LABEL(id), \
tach_xec_init, \
&tach_xec_dev_data##id, \
&tach_xec_dev_config##id, \
@ -128,18 +131,4 @@ static const struct sensor_driver_api tach_xec_driver_api = {
CONFIG_SENSOR_INIT_PRIORITY, \
&tach_xec_driver_api) \
#ifdef DT_INST_0_MICROCHIP_XEC_TACH
TACH_XEC_DEVICE(0);
#endif
#ifdef DT_INST_1_MICROCHIP_XEC_TACH
TACH_XEC_DEVICE(1);
#endif
#ifdef DT_INST_2_MICROCHIP_XEC_TACH
TACH_XEC_DEVICE(2);
#endif
#ifdef DT_INST_3_MICROCHIP_XEC_TACH
TACH_XEC_DEVICE(3);
#endif
DT_INST_FOREACH(TACH_XEC_DEVICE)

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT microchip_mcp9808
#include <errno.h>
#include <kernel.h>
@ -88,15 +90,15 @@ int mcp9808_init(struct device *dev)
static struct mcp9808_data mcp9808_data;
static const struct mcp9808_config mcp9808_cfg = {
.i2c_bus = DT_INST_0_MICROCHIP_MCP9808_BUS_NAME,
.i2c_addr = DT_INST_0_MICROCHIP_MCP9808_BASE_ADDRESS,
.i2c_bus = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
#ifdef CONFIG_MCP9808_TRIGGER
.alert_pin = DT_INST_0_MICROCHIP_MCP9808_INT_GPIOS_PIN,
.alert_flags = DT_INST_0_MICROCHIP_MCP9808_INT_GPIOS_FLAGS,
.alert_controller = DT_INST_0_MICROCHIP_MCP9808_INT_GPIOS_CONTROLLER,
.alert_pin = DT_INST_GPIO_PIN(0, int_gpios),
.alert_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
.alert_controller = DT_INST_GPIO_LABEL(0, int_gpios),
#endif /* CONFIG_MCP9808_TRIGGER */
};
DEVICE_AND_API_INIT(mcp9808, DT_INST_0_MICROCHIP_MCP9808_LABEL, mcp9808_init,
DEVICE_AND_API_INIT(mcp9808, DT_INST_LABEL(0), mcp9808_init,
&mcp9808_data, &mcp9808_cfg, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &mcp9808_api_funcs);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT invensense_mpu6050
#include <drivers/i2c.h>
#include <init.h>
#include <sys/byteorder.h>
@ -225,16 +227,16 @@ int mpu6050_init(struct device *dev)
static struct mpu6050_data mpu6050_driver;
static const struct mpu6050_config mpu6050_cfg = {
.i2c_label = DT_INST_0_INVENSENSE_MPU6050_BUS_NAME,
.i2c_addr = DT_INST_0_INVENSENSE_MPU6050_BASE_ADDRESS,
.i2c_label = DT_INST_BUS_LABEL(0),
.i2c_addr = DT_INST_REG_ADDR(0),
#ifdef CONFIG_MPU6050_TRIGGER
.int_pin = DT_INST_0_INVENSENSE_MPU6050_INT_GPIOS_PIN,
.int_flags = DT_INST_0_INVENSENSE_MPU6050_INT_GPIOS_FLAGS,
.int_label = DT_INST_0_INVENSENSE_MPU6050_INT_GPIOS_CONTROLLER,
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
.int_label = DT_INST_GPIO_LABEL(0, int_gpios),
#endif /* CONFIG_MPU6050_TRIGGER */
};
DEVICE_AND_API_INIT(mpu6050, DT_INST_0_INVENSENSE_MPU6050_LABEL,
DEVICE_AND_API_INIT(mpu6050, DT_INST_LABEL(0),
mpu6050_init, &mpu6050_driver, &mpu6050_cfg,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&mpu6050_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT meas_ms5607
#include <init.h>
#include <kernel.h>
#include <sys/byteorder.h>
@ -221,7 +223,7 @@ static int ms5607_attr_set(struct device *dev, enum sensor_channel chan,
}
static const struct ms5607_config ms5607_config = {
.ms5607_device_name = DT_INST_0_MEAS_MS5607_BUS_NAME,
.ms5607_device_name = DT_INST_BUS_LABEL(0),
};
static int ms5607_init(struct device *dev)
@ -237,7 +239,7 @@ static int ms5607_init(struct device *dev)
return -EINVAL;
}
#ifdef DT_MEAS_MS5607_BUS_SPI
#if DT_ANY_INST_ON_BUS(spi)
ms5607_spi_init(dev);
#else
BUILD_ASSERT(1, "I2c interface not implemented yet");
@ -325,7 +327,7 @@ static const struct sensor_driver_api ms5607_api_funcs = {
static struct ms5607_data ms5607_data;
DEVICE_AND_API_INIT(ms5607,
DT_INST_0_MEAS_MS5607_LABEL,
DT_INST_LABEL(0),
ms5607_init,
&ms5607_data,
&ms5607_config,

View file

@ -61,7 +61,7 @@
#define MS5607_TEMP_OVER_DEFAULT 2048
#endif
#ifdef DT_MEAS_MS5607_BUS_SPI
#if DT_ANY_INST_ON_BUS(spi)
int ms5607_spi_init(struct device *dev);
#else
/* I2c Interface not implemented yet */

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT meas_ms5607
#include <string.h>
#include <drivers/spi.h>
#include <sys/byteorder.h>
@ -13,21 +15,21 @@
#include <logging/log.h>
LOG_MODULE_DECLARE(ms5607);
#ifdef DT_MEAS_MS5607_BUS_SPI
#if DT_ANY_INST_ON_BUS(spi)
#if defined(DT_INST_0_MEAS_MS5607_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
static struct spi_cs_control ms5607_cs_ctrl;
#endif
#define SPI_CS NULL
static struct spi_config ms5607_spi_conf = {
.frequency = DT_INST_0_MEAS_MS5607_SPI_MAX_FREQUENCY,
.frequency = DT_INST_PROP(0, spi_max_frequency),
.operation = (SPI_OP_MODE_MASTER | SPI_WORD_SET(8) |
SPI_MODE_CPOL | SPI_MODE_CPHA |
SPI_TRANSFER_MSB |
SPI_LINES_SINGLE),
.slave = DT_INST_0_MEAS_MS5607_BASE_ADDRESS,
.slave = DT_INST_REG_ADDR(0),
.cs = SPI_CS,
};
@ -170,22 +172,22 @@ int ms5607_spi_init(struct device *dev)
data->tf = &ms5607_spi_transfer_function;
#if defined(DT_INST_0_MEAS_MS5607_CS_GPIOS_CONTROLLER)
#if DT_INST_SPI_DEV_HAS_CS_GPIOS(0)
ms5607_cs_ctrl.gpio_dev = device_get_binding(
DT_INST_0_MEAS_MS5607_CS_GPIOS_CONTROLLER);
DT_INST_SPI_DEV_CS_GPIOS_LABEL(0));
if (!ms5607_cs_ctrl.gpio_dev) {
LOG_ERR("Unable to get GPIO SPI CS device");
return -ENODEV;
}
ms5607_cs_ctrl.gpio_pin = DT_INST_0_MEAS_MS5607_CS_GPIOS_PIN;
ms5607_cs_ctrl.gpio_pin = DT_INST_SPI_DEV_CS_GPIOS_PIN(0);
ms5607_cs_ctrl.delay = 0U;
ms5607_spi_conf.cs = &ms5607_cs_ctrl;
LOG_DBG("SPI GPIO CS configured on %s:%u",
DT_INST_0_MEAS_MS5607_CS_GPIOS_CONTROLLER,
DT_INST_0_MEAS_MS5607_CS_GPIOS_PIN);
DT_INST_SPI_DEV_CS_GPIOS_LABEL(0),
DT_INST_SPI_DEV_CS_GPIOS_PIN(0));
#endif
return 0;
}

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT meas_ms5837
#include <init.h>
#include <kernel.h>
#include <sys/byteorder.h>
@ -259,7 +261,7 @@ static int ms5837_init(struct device *dev)
data->i2c_master = device_get_binding(cfg->i2c_name);
if (data->i2c_master == NULL) {
LOG_ERR("i2c master %s not found",
DT_INST_0_MEAS_MS5837_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -317,10 +319,10 @@ static int ms5837_init(struct device *dev)
static struct ms5837_data ms5837_data;
static const struct ms5837_config ms5837_config = {
.i2c_name = DT_INST_0_MEAS_MS5837_BUS_NAME,
.i2c_address = DT_INST_0_MEAS_MS5837_BASE_ADDRESS
.i2c_name = DT_INST_BUS_LABEL(0),
.i2c_address = DT_INST_REG_ADDR(0)
};
DEVICE_AND_API_INIT(ms5837, DT_INST_0_MEAS_MS5837_LABEL, ms5837_init, &ms5837_data,
DEVICE_AND_API_INIT(ms5837, DT_INST_LABEL(0), ms5837_init, &ms5837_data,
&ms5837_config, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&ms5837_api_funcs);

View file

@ -5,6 +5,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT nordic_nrf_temp
#include <device.h>
#include <drivers/sensor.h>
#include <drivers/clock_control.h>
@ -111,17 +113,17 @@ static int temp_nrf5_init(struct device *dev)
/* A null clk_dev indicates sensor has not been initialized */
data->clk_dev =
device_get_binding(DT_INST_0_NORDIC_NRF_CLOCK_LABEL);
device_get_binding(DT_LABEL(DT_INST(0, nordic_nrf_clock)));
__ASSERT_NO_MSG(data->clk_dev);
k_sem_init(&data->device_sync_sem, 0, UINT_MAX);
IRQ_CONNECT(
DT_INST_0_NORDIC_NRF_TEMP_IRQ_0,
DT_INST_0_NORDIC_NRF_TEMP_IRQ_0_PRIORITY,
DT_INST_IRQN(0),
DT_INST_IRQ(0, priority),
temp_nrf5_isr,
DEVICE_GET(temp_nrf5),
0);
irq_enable(DT_INST_0_NORDIC_NRF_TEMP_IRQ_0);
irq_enable(DT_INST_IRQN(0));
nrf_temp_int_enable(NRF_TEMP, NRF_TEMP_INT_DATARDY_MASK);
@ -131,7 +133,7 @@ static int temp_nrf5_init(struct device *dev)
static struct temp_nrf5_data temp_nrf5_driver;
DEVICE_AND_API_INIT(temp_nrf5,
DT_INST_0_NORDIC_NRF_TEMP_LABEL,
DT_INST_LABEL(0),
temp_nrf5_init,
&temp_nrf5_driver,
NULL,

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT nxp_kinetis_temperature
#include <device.h>
#include <drivers/sensor.h>
#include <drivers/adc.h>
@ -158,9 +160,9 @@ static int temp_kinetis_init(struct device *dev)
return 0;
}
#ifdef DT_INST_0_NXP_KINETIS_TEMPERATURE
BUILD_ASSERT(DT_INST_0_NXP_KINETIS_TEMPERATURE_SENSOR_IO_CHANNELS_INPUT <
DT_INST_0_NXP_KINETIS_TEMPERATURE_BANDGAP_IO_CHANNELS_INPUT,
#if DT_HAS_DRV_INST(0)
BUILD_ASSERT(DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, sensor) <
DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, bandgap),
"This driver assumes sensor ADC channel to come before "
"bandgap ADC channel");
@ -168,20 +170,20 @@ static struct temp_kinetis_data temp_kinetis_data_0;
static const struct temp_kinetis_config temp_kinetis_config_0 = {
.adc_dev_name =
DT_INST_0_NXP_KINETIS_TEMPERATURE_IO_CHANNELS_CONTROLLER_0,
DT_INST_IO_CHANNELS_LABEL_BY_IDX(0, 0),
.sensor_adc_ch =
DT_INST_0_NXP_KINETIS_TEMPERATURE_SENSOR_IO_CHANNELS_INPUT,
DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, sensor),
.bandgap_adc_ch =
DT_INST_0_NXP_KINETIS_TEMPERATURE_BANDGAP_IO_CHANNELS_INPUT,
.bandgap_mv = DT_INST_0_NXP_KINETIS_TEMPERATURE_BANDGAP_VOLTAGE / 1000,
.vtemp25_mv = DT_INST_0_NXP_KINETIS_TEMPERATURE_VTEMP25 / 1000,
.slope_cold_uv = DT_INST_0_NXP_KINETIS_TEMPERATURE_SENSOR_SLOPE_COLD,
.slope_hot_uv = DT_INST_0_NXP_KINETIS_TEMPERATURE_SENSOR_SLOPE_HOT,
DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, bandgap),
.bandgap_mv = DT_INST_PROP(0, bandgap_voltage) / 1000,
.vtemp25_mv = DT_INST_PROP(0, vtemp25) / 1000,
.slope_cold_uv = DT_INST_PROP(0, sensor_slope_cold),
.slope_hot_uv = DT_INST_PROP(0, sensor_slope_hot),
.adc_seq = {
.options = NULL,
.channels =
BIT(DT_INST_0_NXP_KINETIS_TEMPERATURE_SENSOR_IO_CHANNELS_INPUT) |
BIT(DT_INST_0_NXP_KINETIS_TEMPERATURE_BANDGAP_IO_CHANNELS_INPUT),
BIT(DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, sensor)) |
BIT(DT_INST_IO_CHANNELS_INPUT_BY_NAME(0, bandgap)),
.buffer = &temp_kinetis_data_0.buffer,
.buffer_size = sizeof(temp_kinetis_data_0.buffer),
.resolution = CONFIG_TEMP_KINETIS_RESOLUTION,
@ -190,10 +192,10 @@ static const struct temp_kinetis_config temp_kinetis_config_0 = {
},
};
DEVICE_AND_API_INIT(temp_kinetis, DT_INST_0_NXP_KINETIS_TEMPERATURE_LABEL,
DEVICE_AND_API_INIT(temp_kinetis, DT_INST_LABEL(0),
temp_kinetis_init, &temp_kinetis_data_0,
&temp_kinetis_config_0, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY,
&temp_kinetis_driver_api);
#endif /* DT_INST_0_NXP_KINETIS_TEMPERATURE */
#endif /* DT_HAS_DRV_INST(0) */

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_opt3001
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
@ -19,7 +21,7 @@ static int opt3001_reg_read(struct opt3001_data *drv_data, u8_t reg,
{
u8_t value[2];
if (i2c_burst_read(drv_data->i2c, DT_INST_0_TI_OPT3001_BASE_ADDRESS,
if (i2c_burst_read(drv_data->i2c, DT_INST_REG_ADDR(0),
reg, value, 2) != 0) {
return -EIO;
}
@ -40,7 +42,7 @@ static int opt3001_reg_write(struct opt3001_data *drv_data, u8_t reg,
u8_t tx_buf[3] = { reg, new_value[0], new_value[1] };
return i2c_write(drv_data->i2c, tx_buf, sizeof(tx_buf),
DT_INST_0_TI_OPT3001_BASE_ADDRESS);
DT_INST_REG_ADDR(0));
}
static int opt3001_reg_update(struct opt3001_data *drv_data, u8_t reg,
@ -113,10 +115,10 @@ static int opt3001_chip_init(struct device *dev)
struct opt3001_data *drv_data = dev->driver_data;
u16_t value;
drv_data->i2c = device_get_binding(DT_INST_0_TI_OPT3001_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_TI_OPT3001_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -161,6 +163,6 @@ int opt3001_init(struct device *dev)
static struct opt3001_data opt3001_drv_data;
DEVICE_AND_API_INIT(opt3001, DT_INST_0_TI_OPT3001_LABEL, opt3001_init,
DEVICE_AND_API_INIT(opt3001, DT_INST_LABEL(0), opt3001_init,
&opt3001_drv_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &opt3001_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT plantower_pms7003
/* sensor pms7003.c - Driver for plantower PMS7003 sensor
* PMS7003 product: http://www.plantower.com/en/content/?110.html
* PMS7003 spec: http://aqicn.org/air/view/sensor/spec/pms7003.pdf
@ -166,11 +168,11 @@ static int pms7003_init(struct device *dev)
{
struct pms7003_data *drv_data = dev->driver_data;
drv_data->uart_dev = device_get_binding(DT_INST_0_PLANTOWER_PMS7003_BUS_NAME);
drv_data->uart_dev = device_get_binding(DT_INST_BUS_LABEL(0));
if (!drv_data->uart_dev) {
LOG_DBG("uart device is not found: %s",
DT_INST_0_PLANTOWER_PMS7003_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -179,6 +181,6 @@ static int pms7003_init(struct device *dev)
static struct pms7003_data pms7003_data;
DEVICE_AND_API_INIT(gts_dev, DT_INST_0_PLANTOWER_PMS7003_LABEL, &pms7003_init,
DEVICE_AND_API_INIT(gts_dev, DT_INST_LABEL(0), &pms7003_init,
&pms7003_data, NULL, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &pms7003_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT sensirion_sht3xd
#include <device.h>
#include <drivers/i2c.h>
#include <kernel.h>
@ -225,18 +227,18 @@ static int sht3xd_init(struct device *dev)
struct sht3xd_data sht3xd0_driver;
static const struct sht3xd_config sht3xd0_cfg = {
.bus_name = DT_INST_0_SENSIRION_SHT3XD_BUS_NAME,
.bus_name = DT_INST_BUS_LABEL(0),
#ifdef CONFIG_SHT3XD_TRIGGER
.alert_gpio_name = DT_INST_0_SENSIRION_SHT3XD_ALERT_GPIOS_CONTROLLER,
.alert_gpio_name = DT_INST_GPIO_LABEL(0, alert_gpios),
#endif
.base_address = DT_INST_0_SENSIRION_SHT3XD_BASE_ADDRESS,
.base_address = DT_INST_REG_ADDR(0),
#ifdef CONFIG_SHT3XD_TRIGGER
.alert_pin = DT_INST_0_SENSIRION_SHT3XD_ALERT_GPIOS_PIN,
.alert_flags = DT_INST_0_SENSIRION_SHT3XD_ALERT_GPIOS_FLAGS,
.alert_pin = DT_INST_GPIO_PIN(0, alert_gpios),
.alert_flags = DT_INST_GPIO_FLAGS(0, alert_gpios),
#endif
};
DEVICE_AND_API_INIT(sht3xd0, DT_INST_0_SENSIRION_SHT3XD_LABEL,
DEVICE_AND_API_INIT(sht3xd0, DT_INST_LABEL(0),
sht3xd_init, &sht3xd0_driver, &sht3xd0_cfg,
POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&sht3xd_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT silabs_si7006
#include <drivers/sensor.h>
#include <kernel.h>
#include <device.h>
@ -37,7 +39,7 @@ static int si7006_get_humidity(struct device *i2c_dev,
int retval;
u8_t hum[2];
retval = i2c_burst_read(i2c_dev, DT_INST_0_SILABS_SI7006_BASE_ADDRESS,
retval = i2c_burst_read(i2c_dev, DT_INST_REG_ADDR(0),
SI7006_MEAS_REL_HUMIDITY_MASTER_MODE, hum, sizeof(hum));
if (retval == 0) {
@ -61,7 +63,7 @@ static int si7006_get_temperature(struct device *i2c_dev,
u8_t temp[2];
int retval;
retval = i2c_burst_read(i2c_dev, DT_INST_0_SILABS_SI7006_BASE_ADDRESS,
retval = i2c_burst_read(i2c_dev, DT_INST_REG_ADDR(0),
SI7006_MEAS_TEMP_MASTER_MODE, temp, sizeof(temp));
if (retval == 0) {
@ -144,7 +146,7 @@ static int si7006_init(struct device *dev)
struct si7006_data *drv_data = dev->driver_data;
drv_data->i2c_dev = device_get_binding(
DT_INST_0_SILABS_SI7006_BUS_NAME);
DT_INST_BUS_LABEL(0));
if (!drv_data->i2c_dev) {
LOG_ERR("i2c master not found.");
@ -158,5 +160,5 @@ static int si7006_init(struct device *dev)
static struct si7006_data si_data;
DEVICE_AND_API_INIT(si7006, DT_INST_0_SILABS_SI7006_LABEL, si7006_init,
DEVICE_AND_API_INIT(si7006, DT_INST_LABEL(0), si7006_init,
&si_data, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &si7006_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT silabs_si7060
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
@ -24,7 +26,7 @@ static int si7060_reg_read(struct si7060_data *drv_data, u8_t reg,
u8_t *val)
{
if (i2c_reg_read_byte(drv_data->i2c_dev,
DT_INST_0_SILABS_SI7060_BASE_ADDRESS, reg, val)) {
DT_INST_REG_ADDR(0), reg, val)) {
return -EIO;
}
@ -35,7 +37,7 @@ static int si7060_reg_write(struct si7060_data *drv_data, u8_t reg,
u8_t val)
{
return i2c_reg_write_byte(drv_data->i2c_dev,
DT_INST_0_SILABS_SI7060_BASE_ADDRESS, reg, val);
DT_INST_REG_ADDR(0), reg, val);
}
static int si7060_sample_fetch(struct device *dev, enum sensor_channel chan)
@ -98,11 +100,11 @@ static int si7060_chip_init(struct device *dev)
u8_t value;
drv_data->i2c_dev = device_get_binding(
DT_INST_0_SILABS_SI7060_BUS_NAME);
DT_INST_BUS_LABEL(0));
if (!drv_data->i2c_dev) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_SILABS_SI7060_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -130,5 +132,5 @@ static int si7060_init(struct device *dev)
static struct si7060_data si_data;
DEVICE_AND_API_INIT(si7060, DT_INST_0_SILABS_SI7060_LABEL, si7060_init,
DEVICE_AND_API_INIT(si7060, DT_INST_LABEL(0), si7060_init,
&si_data, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &si7060_api);

View file

@ -6,6 +6,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT semtech_sx9500
#include <errno.h>
#include <kernel.h>
@ -110,14 +112,14 @@ int sx9500_init(struct device *dev)
{
struct sx9500_data *data = dev->driver_data;
data->i2c_master = device_get_binding(DT_INST_0_SEMTECH_SX9500_BUS_NAME);
data->i2c_master = device_get_binding(DT_INST_BUS_LABEL(0));
if (!data->i2c_master) {
LOG_DBG("sx9500: i2c master not found: %s",
DT_INST_0_SEMTECH_SX9500_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
data->i2c_slave_addr = DT_INST_0_SEMTECH_SX9500_BASE_ADDRESS;
data->i2c_slave_addr = DT_INST_REG_ADDR(0);
if (sx9500_init_chip(dev) < 0) {
LOG_DBG("sx9500: failed to initialize chip");
@ -134,6 +136,6 @@ int sx9500_init(struct device *dev)
struct sx9500_data sx9500_data;
DEVICE_AND_API_INIT(sx9500, DT_INST_0_SEMTECH_SX9500_LABEL, sx9500_init, &sx9500_data,
DEVICE_AND_API_INIT(sx9500, DT_INST_LABEL(0), sx9500_init, &sx9500_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&sx9500_api_funcs);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT semtech_sx9500
#include <errno.h>
#include <kernel.h>
@ -157,22 +159,22 @@ int sx9500_setup_interrupt(struct device *dev)
data->dev = dev;
#endif
gpio = device_get_binding(DT_INST_0_SEMTECH_SX9500_INT_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
if (!gpio) {
LOG_DBG("sx9500: gpio controller %s not found",
DT_INST_0_SEMTECH_SX9500_INT_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, int_gpios));
return -EINVAL;
}
gpio_pin_configure(gpio, DT_INST_0_SEMTECH_SX9500_INT_GPIOS_PIN,
GPIO_INPUT | DT_INST_0_SEMTECH_SX9500_INT_GPIOS_FLAGS);
gpio_pin_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, int_gpios));
gpio_init_callback(&data->gpio_cb,
sx9500_gpio_cb,
BIT(DT_INST_0_SEMTECH_SX9500_INT_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
gpio_add_callback(gpio, &data->gpio_cb);
gpio_pin_interrupt_configure(gpio, DT_INST_0_SEMTECH_SX9500_INT_GPIOS_PIN,
gpio_pin_interrupt_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
#ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT hoperf_th02
#include <kernel.h>
#include <device.h>
#include <drivers/i2c.h>
@ -126,10 +128,10 @@ static int th02_init(struct device *dev)
{
struct th02_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_HOPERF_TH02_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_HOPERF_TH02_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -138,6 +140,6 @@ static int th02_init(struct device *dev)
static struct th02_data th02_driver;
DEVICE_AND_API_INIT(th02, DT_INST_0_HOPERF_TH02_LABEL, th02_init, &th02_driver,
DEVICE_AND_API_INIT(th02, DT_INST_LABEL(0), th02_init, &th02_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&th02_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_hdc
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/gpio.h>
@ -17,7 +19,7 @@
LOG_MODULE_REGISTER(TI_HDC, CONFIG_SENSOR_LOG_LEVEL);
#if defined(DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER)
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
static void ti_hdc_gpio_callback(struct device *dev,
struct gpio_callback *cb, u32_t pins)
{
@ -27,7 +29,7 @@ static void ti_hdc_gpio_callback(struct device *dev,
ARG_UNUSED(pins);
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_TI_HDC_DRDY_GPIOS_PIN,
DT_INST_GPIO_PIN(0, drdy_gpios),
GPIO_INT_DISABLE);
k_sem_give(&drv_data->data_sem);
}
@ -40,27 +42,27 @@ static int ti_hdc_sample_fetch(struct device *dev, enum sensor_channel chan)
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
#if defined(DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER)
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_TI_HDC_DRDY_GPIOS_PIN,
DT_INST_GPIO_PIN(0, drdy_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
#endif
buf[0] = TI_HDC_REG_TEMP;
if (i2c_write(drv_data->i2c, buf, 1,
DT_INST_0_TI_HDC_BASE_ADDRESS) < 0) {
DT_INST_REG_ADDR(0)) < 0) {
LOG_DBG("Failed to write address pointer");
return -EIO;
}
#if defined(DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER)
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
k_sem_take(&drv_data->data_sem, K_FOREVER);
#else
/* wait for the conversion to finish */
k_msleep(HDC_CONVERSION_TIME);
#endif
if (i2c_read(drv_data->i2c, buf, 4, DT_INST_0_TI_HDC_BASE_ADDRESS) < 0) {
if (i2c_read(drv_data->i2c, buf, 4, DT_INST_REG_ADDR(0)) < 0) {
LOG_DBG("Failed to read sample data");
return -EIO;
}
@ -121,44 +123,44 @@ static int ti_hdc_init(struct device *dev)
struct ti_hdc_data *drv_data = dev->driver_data;
u16_t tmp;
drv_data->i2c = device_get_binding(DT_INST_0_TI_HDC_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
DT_INST_0_TI_HDC_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
if (read16(drv_data->i2c, DT_INST_0_TI_HDC_BASE_ADDRESS,
if (read16(drv_data->i2c, DT_INST_REG_ADDR(0),
TI_HDC_REG_MANUFID) != TI_HDC_MANUFID) {
LOG_ERR("Failed to get correct manufacturer ID");
return -EINVAL;
}
tmp = read16(drv_data->i2c, DT_INST_0_TI_HDC_BASE_ADDRESS,
tmp = read16(drv_data->i2c, DT_INST_REG_ADDR(0),
TI_HDC_REG_DEVICEID);
if (tmp != TI_HDC1000_DEVID && tmp != TI_HDC1050_DEVID) {
LOG_ERR("Unsupported device ID");
return -EINVAL;
}
#if defined(DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER)
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
k_sem_init(&drv_data->data_sem, 0, UINT_MAX);
/* setup data ready gpio interrupt */
drv_data->gpio = device_get_binding(
DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, drdy_gpios));
if (drv_data->gpio == NULL) {
LOG_DBG("Failed to get pointer to %s device",
DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, drdy_gpios));
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, DT_INST_0_TI_HDC_DRDY_GPIOS_PIN,
GPIO_INPUT | DT_INST_0_TI_HDC_DRDY_GPIOS_FLAGS);
gpio_pin_configure(drv_data->gpio, DT_INST_GPIO_PIN(0, drdy_gpios),
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, drdy_gpios));
gpio_init_callback(&drv_data->gpio_cb,
ti_hdc_gpio_callback,
BIT(DT_INST_0_TI_HDC_DRDY_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, drdy_gpios)));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_DBG("Failed to set GPIO callback");
@ -166,7 +168,7 @@ static int ti_hdc_init(struct device *dev)
}
gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_TI_HDC_DRDY_GPIOS_PIN,
DT_INST_GPIO_PIN(0, drdy_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
#endif
@ -177,6 +179,6 @@ static int ti_hdc_init(struct device *dev)
static struct ti_hdc_data ti_hdc_data;
DEVICE_AND_API_INIT(ti_hdc, DT_INST_0_TI_HDC_LABEL, ti_hdc_init, &ti_hdc_data,
DEVICE_AND_API_INIT(ti_hdc, DT_INST_LABEL(0), ti_hdc_init, &ti_hdc_data,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&ti_hdc_driver_api);

View file

@ -26,11 +26,11 @@ struct ti_hdc_data {
u16_t t_sample;
u16_t rh_sample;
#if defined(DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER)
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
struct device *gpio;
struct gpio_callback gpio_cb;
struct k_sem data_sem;
#endif /* DT_INST_0_TI_HDC_DRDY_GPIOS_CONTROLLER */
#endif /* DT_INST_NODE_HAS_PROP(0, drdy_gpios) */
};
#endif

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_tmp007
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/gpio.h>
@ -107,10 +109,10 @@ int tmp007_init(struct device *dev)
{
struct tmp007_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP007_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
DT_INST_0_TI_TMP007_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -126,7 +128,7 @@ int tmp007_init(struct device *dev)
struct tmp007_data tmp007_driver;
DEVICE_AND_API_INIT(tmp007, DT_INST_0_TI_TMP007_LABEL, tmp007_init,
DEVICE_AND_API_INIT(tmp007, DT_INST_LABEL(0), tmp007_init,
&tmp007_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&tmp007_driver_api);

View file

@ -11,7 +11,7 @@
#include <drivers/gpio.h>
#include <sys/util.h>
#define TMP007_I2C_ADDRESS DT_INST_0_TI_TMP007_BASE_ADDRESS
#define TMP007_I2C_ADDRESS DT_INST_REG_ADDR(0)
#define TMP007_REG_CONFIG 0x02
#define TMP007_ALERT_EN_BIT BIT(8)

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_tmp007
#include <device.h>
#include <drivers/gpio.h>
#include <sys/util.h>
@ -23,7 +25,7 @@ static inline void setup_int(struct device *dev,
struct tmp007_data *data = dev->driver_data;
gpio_pin_interrupt_configure(data->gpio,
DT_INST_0_TI_TMP007_INT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, int_gpios),
enable
? GPIO_INT_LEVEL_ACTIVE
: GPIO_INT_DISABLE);
@ -158,20 +160,20 @@ int tmp007_init_interrupt(struct device *dev)
drv_data->dev = dev;
/* setup gpio interrupt */
drv_data->gpio = device_get_binding(DT_INST_0_TI_TMP007_INT_GPIOS_CONTROLLER);
drv_data->gpio = device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
if (drv_data->gpio == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
DT_INST_0_TI_TMP007_INT_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, int_gpios));
return -EINVAL;
}
gpio_pin_configure(drv_data->gpio, DT_INST_0_TI_TMP007_INT_GPIOS_PIN,
DT_INST_0_TI_TMP007_INT_GPIOS_FLAGS
gpio_pin_configure(drv_data->gpio, DT_INST_GPIO_PIN(0, int_gpios),
DT_INST_GPIO_FLAGS(0, int_gpios)
| GPIO_INT_LEVEL_ACTIVE);
gpio_init_callback(&drv_data->gpio_cb,
tmp007_gpio_callback,
BIT(DT_INST_0_TI_TMP007_INT_GPIOS_PIN));
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
LOG_DBG("Failed to set gpio callback!");

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_tmp112
#include <device.h>
#include <drivers/i2c.h>
#include <sys/byteorder.h>
@ -15,7 +17,7 @@
LOG_MODULE_REGISTER(TMP112, CONFIG_SENSOR_LOG_LEVEL);
#define TMP112_I2C_ADDRESS DT_INST_0_TI_TMP112_BASE_ADDRESS
#define TMP112_I2C_ADDRESS DT_INST_REG_ADDR(0)
#define TMP112_REG_TEMPERATURE 0x00
#define TMP112_D0_BIT BIT(0)
@ -195,10 +197,10 @@ int tmp112_init(struct device *dev)
{
struct tmp112_data *drv_data = dev->driver_data;
drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP112_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_DBG("Failed to get pointer to %s device!",
DT_INST_0_TI_TMP112_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -207,5 +209,5 @@ int tmp112_init(struct device *dev)
static struct tmp112_data tmp112_driver;
DEVICE_AND_API_INIT(tmp112, DT_INST_0_TI_TMP112_LABEL, tmp112_init, &tmp112_driver,
DEVICE_AND_API_INIT(tmp112, DT_INST_LABEL(0), tmp112_init, &tmp112_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, &tmp112_driver_api);

View file

@ -4,6 +4,8 @@
* SPDX-License-Identifier: Apache-2.0
*/
#define DT_DRV_COMPAT ti_tmp116
#include <device.h>
#include <drivers/i2c.h>
#include <drivers/sensor.h>
@ -47,13 +49,13 @@ static inline int tmp116_device_id_check(struct device *dev)
if (tmp116_reg_read(dev, TMP116_REG_DEVICE_ID, &value) != 0) {
LOG_ERR("%s: Failed to get Device ID register!",
DT_INST_0_TI_TMP116_LABEL);
DT_INST_LABEL(0));
return -EIO;
}
if ((value != TMP116_DEVICE_ID) && (value != TMP117_DEVICE_ID)) {
LOG_ERR("%s: Failed to match the device IDs!",
DT_INST_0_TI_TMP116_LABEL);
DT_INST_LABEL(0));
return -EINVAL;
}
@ -76,7 +78,7 @@ static int tmp116_sample_fetch(struct device *dev, enum sensor_channel chan)
rc = tmp116_reg_read(dev, TMP116_REG_TEMP, &value);
if (rc < 0) {
LOG_ERR("%s: Failed to read from TEMP register!",
DT_INST_0_TI_TMP116_LABEL);
DT_INST_LABEL(0));
return rc;
}
@ -118,10 +120,10 @@ static int tmp116_init(struct device *dev)
int rc;
/* Bind to the I2C bus that the sensor is connected */
drv_data->i2c = device_get_binding(DT_INST_0_TI_TMP116_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (!drv_data->i2c) {
LOG_ERR("Cannot bind to %s device!",
DT_INST_0_TI_TMP116_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
@ -137,9 +139,9 @@ static int tmp116_init(struct device *dev)
static struct tmp116_data tmp116_data;
static const struct tmp116_dev_config tmp116_config = {
.i2c_addr = DT_INST_0_TI_TMP116_BASE_ADDRESS,
.i2c_addr = DT_INST_REG_ADDR(0),
};
DEVICE_AND_API_INIT(hdc1080, DT_INST_0_TI_TMP116_LABEL, tmp116_init,
DEVICE_AND_API_INIT(hdc1080, DT_INST_LABEL(0), tmp116_init,
&tmp116_data, &tmp116_config, POST_KERNEL,
CONFIG_SENSOR_INIT_PRIORITY, &tmp116_driver_api);

View file

@ -1,5 +1,7 @@
/* vl53l0x.c - Driver for ST VL53L0X time of flight sensor */
#define DT_DRV_COMPAT st_vl53l0x
/*
* Copyright (c) 2017 STMicroelectronics
*
@ -202,39 +204,39 @@ static int vl53l0x_init(struct device *dev)
LOG_DBG("enter in %s", __func__);
#ifdef DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_CONTROLLER
#if DT_INST_NODE_HAS_PROP(0, xshut_gpios)
struct device *gpio;
/* configure and set VL53L0X_XSHUT_Pin */
gpio = device_get_binding(DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_CONTROLLER);
gpio = device_get_binding(DT_INST_GPIO_LABEL(0, xshut_gpios));
if (gpio == NULL) {
LOG_ERR("Could not get pointer to %s device.",
DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_CONTROLLER);
DT_INST_GPIO_LABEL(0, xshut_gpios));
return -EINVAL;
}
if (gpio_pin_configure(gpio,
DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_PIN,
DT_INST_GPIO_PIN(0, xshut_gpios),
GPIO_OUTPUT | GPIO_PULL_UP) < 0) {
LOG_ERR("Could not configure GPIO %s %d).",
DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_CONTROLLER,
DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_PIN);
DT_INST_GPIO_LABEL(0, xshut_gpios),
DT_INST_GPIO_PIN(0, xshut_gpios));
return -EINVAL;
}
gpio_pin_set(gpio, DT_INST_0_ST_VL53L0X_XSHUT_GPIOS_PIN, 1);
gpio_pin_set(gpio, DT_INST_GPIO_PIN(0, xshut_gpios), 1);
k_sleep(K_MSEC(100));
#endif
drv_data->i2c = device_get_binding(DT_INST_0_ST_VL53L0X_BUS_NAME);
drv_data->i2c = device_get_binding(DT_INST_BUS_LABEL(0));
if (drv_data->i2c == NULL) {
LOG_ERR("Could not get pointer to %s device.",
DT_INST_0_ST_VL53L0X_BUS_NAME);
DT_INST_BUS_LABEL(0));
return -EINVAL;
}
drv_data->vl53l0x.i2c = drv_data->i2c;
drv_data->vl53l0x.I2cDevAddr = DT_INST_0_ST_VL53L0X_BASE_ADDRESS;
drv_data->vl53l0x.I2cDevAddr = DT_INST_REG_ADDR(0);
/* Get info from sensor */
(void)memset(&vl53l0x_dev_info, 0, sizeof(VL53L0X_DeviceInfo_t));
@ -280,6 +282,6 @@ static int vl53l0x_init(struct device *dev)
static struct vl53l0x_data vl53l0x_driver;
DEVICE_AND_API_INIT(vl53l0x, DT_INST_0_ST_VL53L0X_LABEL, vl53l0x_init, &vl53l0x_driver,
DEVICE_AND_API_INIT(vl53l0x, DT_INST_LABEL(0), vl53l0x_init, &vl53l0x_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&vl53l0x_api_funcs);