sensors: hts221: Get I2C address from device tree

Change driver to get I2C address of sensor from the device tree like
most other sensor drivers that utilize device tree.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-01-16 08:49:46 -06:00 committed by Kumar Gala
parent a5e8921de9
commit c77a322c6e
4 changed files with 7 additions and 6 deletions

View file

@ -62,7 +62,7 @@ static int hts221_sample_fetch(struct device *dev, enum sensor_channel chan)
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
if (i2c_burst_read(drv_data->i2c, DT_ST_HTS221_0_BASE_ADDRESS,
HTS221_REG_DATA_START | HTS221_AUTOINCREMENT_ADDR,
buf, 4) < 0) {
LOG_ERR("Failed to fetch data sample.");
@ -79,7 +79,7 @@ static int hts221_read_conversion_data(struct hts221_data *drv_data)
{
u8_t buf[16];
if (i2c_burst_read(drv_data->i2c, HTS221_I2C_ADDR,
if (i2c_burst_read(drv_data->i2c, DT_ST_HTS221_0_BASE_ADDRESS,
HTS221_REG_CONVERSION_START |
HTS221_AUTOINCREMENT_ADDR, buf, 16) < 0) {
LOG_ERR("Failed to read conversion data.");
@ -119,7 +119,7 @@ int hts221_init(struct device *dev)
}
/* check chip ID */
if (i2c_reg_read_byte(drv_data->i2c, HTS221_I2C_ADDR,
if (i2c_reg_read_byte(drv_data->i2c, DT_ST_HTS221_0_BASE_ADDRESS,
HTS221_REG_WHO_AM_I, &id) < 0) {
LOG_ERR("Failed to read chip ID.");
return -EIO;
@ -142,7 +142,8 @@ int hts221_init(struct device *dev)
return -EINVAL;
}
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR, HTS221_REG_CTRL1,
if (i2c_reg_write_byte(drv_data->i2c, DT_ST_HTS221_0_BASE_ADDRESS,
HTS221_REG_CTRL1,
(idx + 1) << HTS221_ODR_SHIFT | HTS221_BDU_BIT |
HTS221_PD_BIT) < 0) {
LOG_ERR("Failed to configure chip.");

View file

@ -12,7 +12,6 @@
#include <zephyr/types.h>
#include <gpio.h>
#define HTS221_I2C_ADDR 0x5F
#define HTS221_AUTOINCREMENT_ADDR BIT(7)
#define HTS221_REG_WHO_AM_I 0x0F

View file

@ -120,7 +120,7 @@ int hts221_init_interrupt(struct device *dev)
}
/* enable data-ready interrupt */
if (i2c_reg_write_byte(drv_data->i2c, HTS221_I2C_ADDR,
if (i2c_reg_write_byte(drv_data->i2c, DT_ST_HTS221_0_BASE_ADDRESS,
HTS221_REG_CTRL3, HTS221_DRDY_EN) < 0) {
LOG_ERR("Could not enable data-ready interrupt.");
return -EIO;

View file

@ -62,6 +62,7 @@
#ifndef DT_ST_HTS221_0_LABEL
#define DT_ST_HTS221_0_LABEL ""
#define DT_ST_HTS221_0_BUS_NAME ""
#define DT_ST_HTS221_0_BASE_ADDRESS 0
#endif
#ifndef CONFIG_LIS2MDL_GPIO_PIN_NUM