sensor: ccs811: Convert to new DT_<COMPAT>_<INSTANCE> defines

Convert ccs811 sensor driver to use new defines so we can remove the
dts_fixup.h code for it.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-01-29 13:51:50 -06:00 committed by Kumar Gala
commit cdc1b1f103
6 changed files with 17 additions and 29 deletions

View file

@ -1,7 +1,3 @@
#define CONFIG_GPIO_SX1509B_DEV_NAME DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_LABEL #define CONFIG_GPIO_SX1509B_DEV_NAME DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_LABEL
#define CONFIG_GPIO_SX1509B_I2C_ADDR DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_BASE_ADDRESS #define CONFIG_GPIO_SX1509B_I2C_ADDR DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_BASE_ADDRESS
#define CONFIG_GPIO_SX1509B_I2C_MASTER_DEV_NAME DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_BUS_NAME #define CONFIG_GPIO_SX1509B_I2C_MASTER_DEV_NAME DT_NORDIC_NRF_I2C_40003000_SEMTECH_SX1509B_3E_BUS_NAME
#define DT_CCS811_NAME DT_NORDIC_NRF_I2C_40003000_AMS_CCS811_5A_LABEL
#define DT_CCS811_I2C_MASTER_DEV_NAME DT_NORDIC_NRF_I2C_40003000_AMS_CCS811_5A_BUS_NAME
#define DT_CCS811_I2C_ADDR DT_NORDIC_NRF_I2C_40003000_AMS_CCS811_5A_BASE_ADDRESS

View file

@ -28,7 +28,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
/* Check data ready flag for the measurement interval of 1 seconds */ /* Check data ready flag for the measurement interval of 1 seconds */
while (tries-- > 0) { while (tries-- > 0) {
if (i2c_reg_read_byte(drv_data->i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_read_byte(drv_data->i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_STATUS, &status) < 0) { CCS811_REG_STATUS, &status) < 0) {
LOG_ERR("Failed to read Status register"); LOG_ERR("Failed to read Status register");
return -EIO; return -EIO;
@ -46,7 +46,7 @@ static int ccs811_sample_fetch(struct device *dev, enum sensor_channel chan)
return -EIO; return -EIO;
} }
if (i2c_burst_read(drv_data->i2c, DT_CCS811_I2C_ADDR, if (i2c_burst_read(drv_data->i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_ALG_RESULT_DATA, (u8_t *)buf, 8) < 0) { CCS811_REG_ALG_RESULT_DATA, (u8_t *)buf, 8) < 0) {
LOG_ERR("Failed to read conversion data."); LOG_ERR("Failed to read conversion data.");
return -EIO; return -EIO;
@ -117,7 +117,7 @@ static int switch_to_app_mode(struct device *i2c)
LOG_DBG("Switching to Application mode..."); LOG_DBG("Switching to Application mode...");
if (i2c_reg_read_byte(i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_read_byte(i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_STATUS, &status) < 0) { CCS811_REG_STATUS, &status) < 0) {
LOG_ERR("Failed to read Status register"); LOG_ERR("Failed to read Status register");
return -EIO; return -EIO;
@ -131,12 +131,12 @@ static int switch_to_app_mode(struct device *i2c)
buf = CCS811_REG_APP_START; buf = CCS811_REG_APP_START;
/* Set the device to application mode */ /* Set the device to application mode */
if (i2c_write(i2c, &buf, 1, DT_CCS811_I2C_ADDR) < 0) { if (i2c_write(i2c, &buf, 1, DT_AMS_CCS811_0_BASE_ADDRESS) < 0) {
LOG_ERR("Failed to set Application mode"); LOG_ERR("Failed to set Application mode");
return -EIO; return -EIO;
} }
if (i2c_reg_read_byte(i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_read_byte(i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_STATUS, &status) < 0) { CCS811_REG_STATUS, &status) < 0) {
LOG_ERR("Failed to read Status register"); LOG_ERR("Failed to read Status register");
return -EIO; return -EIO;
@ -159,10 +159,10 @@ int ccs811_init(struct device *dev)
int ret; int ret;
u8_t hw_id, status; u8_t hw_id, status;
drv_data->i2c = device_get_binding(DT_CCS811_I2C_MASTER_DEV_NAME); drv_data->i2c = device_get_binding(DT_AMS_CCS811_0_BUS_NAME);
if (drv_data->i2c == NULL) { if (drv_data->i2c == NULL) {
LOG_ERR("Failed to get pointer to %s device!", LOG_ERR("Failed to get pointer to %s device!",
DT_CCS811_I2C_MASTER_DEV_NAME); DT_AMS_CCS811_0_BUS_NAME);
return -EINVAL; return -EINVAL;
} }
@ -202,7 +202,7 @@ int ccs811_init(struct device *dev)
} }
/* Check Hardware ID */ /* Check Hardware ID */
if (i2c_reg_read_byte(drv_data->i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_read_byte(drv_data->i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_HW_ID, &hw_id) < 0) { CCS811_REG_HW_ID, &hw_id) < 0) {
LOG_ERR("Failed to read Hardware ID register"); LOG_ERR("Failed to read Hardware ID register");
return -EIO; return -EIO;
@ -214,7 +214,7 @@ int ccs811_init(struct device *dev)
} }
/* Set Measurement mode for 1 second */ /* Set Measurement mode for 1 second */
if (i2c_reg_write_byte(drv_data->i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_write_byte(drv_data->i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_MEAS_MODE, CCS811_REG_MEAS_MODE,
CCS811_MODE_IAQ_1SEC) < 0) { CCS811_MODE_IAQ_1SEC) < 0) {
LOG_ERR("Failed to set Measurement mode"); LOG_ERR("Failed to set Measurement mode");
@ -222,7 +222,7 @@ int ccs811_init(struct device *dev)
} }
/* Check for error */ /* Check for error */
if (i2c_reg_read_byte(drv_data->i2c, DT_CCS811_I2C_ADDR, if (i2c_reg_read_byte(drv_data->i2c, DT_AMS_CCS811_0_BASE_ADDRESS,
CCS811_REG_STATUS, &status) < 0) { CCS811_REG_STATUS, &status) < 0) {
LOG_ERR("Failed to read Status register"); LOG_ERR("Failed to read Status register");
return -EIO; return -EIO;
@ -238,6 +238,6 @@ int ccs811_init(struct device *dev)
static struct ccs811_data ccs811_driver; static struct ccs811_data ccs811_driver;
DEVICE_AND_API_INIT(ccs811, DT_CCS811_NAME, ccs811_init, &ccs811_driver, DEVICE_AND_API_INIT(ccs811, DT_AMS_CCS811_0_LABEL, ccs811_init, &ccs811_driver,
NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY, NULL, POST_KERNEL, CONFIG_SENSOR_INIT_PRIORITY,
&ccs811_driver_api); &ccs811_driver_api);

View file

@ -1,9 +0,0 @@
#if defined(CONFIG_HAS_DTS_I2C)
#ifndef DT_CCS811_NAME
#define DT_CCS811_NAME ""
#define DT_CCS811_I2C_ADDR 0
#define DT_CCS811_I2C_MASTER_DEV_NAME ""
#endif
#endif /* CONFIG_HAS_DTS_I2C */

View file

@ -5,4 +5,5 @@ tests:
test: test:
harness: sensor harness: sensor
tags: sensors tags: sensors
platform_whitelist: nrf52_pca20020
depends_on: i2c depends_on: i2c

View file

@ -34,7 +34,7 @@ void main(void)
{ {
struct device *dev; struct device *dev;
dev = device_get_binding("CCS811"); dev = device_get_binding(DT_AMS_CCS811_0_LABEL);
if (!dev) { if (!dev) {
printk("Failed to get device binding"); printk("Failed to get device binding");
return; return;

View file

@ -37,10 +37,10 @@
#define DT_BOSCH_BME280_BUS_I2C 1 #define DT_BOSCH_BME280_BUS_I2C 1
#endif #endif
#ifndef DT_CCS811_NAME #ifndef DT_AMS_CCS811_0_LABEL
#define DT_CCS811_NAME "" #define DT_AMS_CCS811_0_LABEL ""
#define DT_CCS811_I2C_MASTER_DEV_NAME "" #define DT_AMS_CCS811_0_BUS_NAME ""
#define DT_CCS811_I2C_ADDR 0 #define DT_AMS_CCS811_0_BASE_ADDRESS 0
#endif #endif
#ifndef DT_NXP_FXAS21002_0_LABEL #ifndef DT_NXP_FXAS21002_0_LABEL