sensor: remove unnecessary return variables
Remove unnecessary return variables (ret/rc) to reduce memory footprint. Change-Id: Ifc22fd993b4f8f2d0cf992f620f53cc510add1fa Signed-off-by: Murtaza Alexandru <alexandru.murtaza@intel.com>
This commit is contained in:
parent
2d7ae8b249
commit
261a448f33
16 changed files with 164 additions and 246 deletions
|
@ -26,7 +26,6 @@ static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
struct bma280_data *drv_data = dev->driver_data;
|
||||
uint8_t buf[6];
|
||||
uint8_t lsb;
|
||||
int rc;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL);
|
||||
|
||||
|
@ -34,9 +33,8 @@ static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
* since all accel data register addresses are consecutive,
|
||||
* a burst read can be used to read all the samples
|
||||
*/
|
||||
rc = i2c_burst_read(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_ACCEL_X_LSB, buf, 6);
|
||||
if (rc < 0) {
|
||||
if (i2c_burst_read(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_ACCEL_X_LSB, buf, 6) < 0) {
|
||||
SYS_LOG_DBG("Could not read accel axis data");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -50,10 +48,9 @@ static int bma280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
lsb = (buf[4] & BMA280_ACCEL_LSB_MASK) >> BMA280_ACCEL_LSB_SHIFT;
|
||||
drv_data->z_sample = (((int8_t)buf[5]) << BMA280_ACCEL_LSB_BITS) | lsb;
|
||||
|
||||
rc = i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_TEMP,
|
||||
(uint8_t *)&drv_data->temp_sample);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_TEMP,
|
||||
(uint8_t *)&drv_data->temp_sample) < 0) {
|
||||
SYS_LOG_DBG("Could not read temperature data");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -127,7 +124,6 @@ int bma280_init(struct device *dev)
|
|||
{
|
||||
struct bma280_data *drv_data = dev->driver_data;
|
||||
uint8_t id = 0;
|
||||
int rc;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_BMA280_I2C_MASTER_DEV_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
|
@ -137,9 +133,8 @@ int bma280_init(struct device *dev)
|
|||
}
|
||||
|
||||
/* read device ID */
|
||||
rc = i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_CHIP_ID, &id);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_read_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_CHIP_ID, &id) < 0) {
|
||||
SYS_LOG_DBG("Could not read chip id");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -149,25 +144,21 @@ int bma280_init(struct device *dev)
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
/* set the data filter bandwidth */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_PMU_BW, BMA280_PMU_BW);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_PMU_BW, BMA280_PMU_BW) < 0) {
|
||||
SYS_LOG_DBG("Could not set data filter bandwidth");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* set g-range */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_PMU_RANGE, BMA280_PMU_RANGE);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_PMU_RANGE, BMA280_PMU_RANGE) < 0) {
|
||||
SYS_LOG_DBG("Could not set data g-range");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_BMA280_TRIGGER
|
||||
rc = bma280_init_interrupt(dev);
|
||||
if (rc < 0) {
|
||||
if (bma280_init_interrupt(dev) < 0) {
|
||||
SYS_LOG_DBG("Could not initialize interrupts");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -29,7 +29,6 @@ int bma280_attr_set(struct device *dev,
|
|||
{
|
||||
struct bma280_data *drv_data = dev->driver_data;
|
||||
uint64_t slope_th;
|
||||
int rc;
|
||||
|
||||
if (chan != SENSOR_CHAN_ACCEL_ANY) {
|
||||
return -ENOTSUP;
|
||||
|
@ -39,18 +38,18 @@ int bma280_attr_set(struct device *dev,
|
|||
/* slope_th = (val * 10^6 * 2^10) / BMA280_PMU_FULL_RAGE */
|
||||
slope_th = (uint64_t)val->val1 * 1000000 + (uint64_t)val->val2;
|
||||
slope_th = (slope_th * (1 << 10)) / BMA280_PMU_FULL_RANGE;
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_SLOPE_TH, (uint8_t)slope_th);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_SLOPE_TH, (uint8_t)slope_th)
|
||||
< 0) {
|
||||
SYS_LOG_DBG("Could not set slope threshold");
|
||||
return -EIO;
|
||||
}
|
||||
} else if (attr == SENSOR_ATTR_SLOPE_DUR) {
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_5,
|
||||
BMA280_SLOPE_DUR_MASK,
|
||||
val->val1 << BMA280_SLOPE_DUR_SHIFT);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_5,
|
||||
BMA280_SLOPE_DUR_MASK,
|
||||
val->val1 << BMA280_SLOPE_DUR_SHIFT)
|
||||
< 0) {
|
||||
SYS_LOG_DBG("Could not set slope duration");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -141,14 +140,12 @@ int bma280_trigger_set(struct device *dev,
|
|||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct bma280_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
if (trig->type == SENSOR_TRIG_DATA_READY) {
|
||||
/* disable data ready interrupt while changing trigger params */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN, 0);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN, 0) < 0) {
|
||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -160,20 +157,18 @@ int bma280_trigger_set(struct device *dev,
|
|||
drv_data->data_ready_trigger = *trig;
|
||||
|
||||
/* enable data ready interrupt */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN,
|
||||
BMA280_BIT_DATA_EN);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN,
|
||||
BMA280_BIT_DATA_EN) < 0) {
|
||||
SYS_LOG_DBG("Could not enable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
} else if (trig->type == SENSOR_TRIG_DELTA) {
|
||||
/* disable any-motion interrupt while changing trigger params */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ, 0);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -185,11 +180,10 @@ int bma280_trigger_set(struct device *dev,
|
|||
drv_data->any_motion_trigger = *trig;
|
||||
|
||||
/* enable any-motion interrupt */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ,
|
||||
BMA280_SLOPE_EN_XYZ);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ,
|
||||
BMA280_SLOPE_EN_XYZ) < 0) {
|
||||
SYS_LOG_DBG("Could not enable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -203,14 +197,12 @@ int bma280_trigger_set(struct device *dev,
|
|||
int bma280_init_interrupt(struct device *dev)
|
||||
{
|
||||
struct bma280_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
/* set latched interrupts */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_RST_LATCH,
|
||||
BMA280_BIT_INT_LATCH_RESET |
|
||||
BMA280_INT_MODE_LATCH);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_RST_LATCH,
|
||||
BMA280_BIT_INT_LATCH_RESET |
|
||||
BMA280_INT_MODE_LATCH) < 0) {
|
||||
SYS_LOG_DBG("Could not set latched interrupts");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -231,46 +223,40 @@ int bma280_init_interrupt(struct device *dev)
|
|||
bma280_gpio_callback,
|
||||
BIT(CONFIG_BMA280_GPIO_PIN_NUM));
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Could not set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* map data ready interrupt to INT1 */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_MAP_1,
|
||||
BMA280_INT_MAP_1_BIT_DATA,
|
||||
BMA280_INT_MAP_1_BIT_DATA);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_MAP_1,
|
||||
BMA280_INT_MAP_1_BIT_DATA,
|
||||
BMA280_INT_MAP_1_BIT_DATA) < 0) {
|
||||
SYS_LOG_DBG("Could not map data ready interrupt pin");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* map any-motion interrupt to INT1 */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_MAP_0,
|
||||
BMA280_INT_MAP_0_BIT_SLOPE,
|
||||
BMA280_INT_MAP_0_BIT_SLOPE);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_MAP_0,
|
||||
BMA280_INT_MAP_0_BIT_SLOPE,
|
||||
BMA280_INT_MAP_0_BIT_SLOPE) < 0) {
|
||||
SYS_LOG_DBG("Could not map any-motion interrupt pin");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* disable data ready interrupt */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN, 0);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_1,
|
||||
BMA280_BIT_DATA_EN, 0) < 0) {
|
||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* disable any-motion interrupt */
|
||||
rc = i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ, 0);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, BMA280_I2C_ADDRESS,
|
||||
BMA280_REG_INT_EN_0,
|
||||
BMA280_SLOPE_EN_XYZ, 0) < 0) {
|
||||
SYS_LOG_DBG("Could not disable data ready interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -76,14 +76,12 @@ static int bmp280_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
struct bmp280_data *data = dev->driver_data;
|
||||
uint8_t buf[6];
|
||||
int32_t adc_press, adc_temp;
|
||||
int ret;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL);
|
||||
|
||||
ret = i2c_burst_read(data->i2c_master, data->i2c_slave_addr,
|
||||
BMP280_REG_PRESS_MSB, buf, sizeof(buf));
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (i2c_burst_read(data->i2c_master, data->i2c_slave_addr,
|
||||
BMP280_REG_PRESS_MSB, buf, sizeof(buf)) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
adc_press = (buf[0] << 12) | (buf[1] << 4) | (buf[2] >> 4);
|
||||
|
@ -181,7 +179,6 @@ static int bmp280_chip_init(struct device *dev)
|
|||
int bmp280_init(struct device *dev)
|
||||
{
|
||||
struct bmp280_data *data = dev->driver_data;
|
||||
int ret;
|
||||
|
||||
data->i2c_master = device_get_binding(CONFIG_BMP280_I2C_MASTER_DEV_NAME);
|
||||
if (!data->i2c_master) {
|
||||
|
@ -192,9 +189,8 @@ int bmp280_init(struct device *dev)
|
|||
|
||||
data->i2c_slave_addr = CONFIG_BMP280_I2C_ADDR;
|
||||
|
||||
ret = bmp280_chip_init(dev);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (bmp280_chip_init(dev) < 0) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev->driver_api = &bmp280_api_funcs;
|
||||
|
|
|
@ -40,23 +40,20 @@ static int hdc1008_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
{
|
||||
struct hdc1008_data *drv_data = dev->driver_data;
|
||||
uint8_t buf[4];
|
||||
int rc;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL);
|
||||
|
||||
gpio_pin_enable_callback(drv_data->gpio, CONFIG_HDC1008_GPIO_PIN_NUM);
|
||||
|
||||
buf[0] = HDC1008_REG_TEMP;
|
||||
rc = i2c_write(drv_data->i2c, buf, 1, HDC1008_I2C_ADDRESS);
|
||||
if (rc < 0) {
|
||||
if (i2c_write(drv_data->i2c, buf, 1, HDC1008_I2C_ADDRESS) < 0) {
|
||||
SYS_LOG_DBG("Failed to write address pointer");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
nano_sem_take(&drv_data->data_sem, TICKS_UNLIMITED);
|
||||
|
||||
rc = i2c_read(drv_data->i2c, buf, 4, HDC1008_I2C_ADDRESS);
|
||||
if (rc < 0) {
|
||||
if (i2c_read(drv_data->i2c, buf, 4, HDC1008_I2C_ADDRESS) < 0) {
|
||||
SYS_LOG_DBG("Failed to read sample data");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -107,7 +104,6 @@ static struct sensor_driver_api hdc1008_driver_api = {
|
|||
int hdc1008_init(struct device *dev)
|
||||
{
|
||||
struct hdc1008_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_HDC1008_I2C_MASTER_DEV_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
|
@ -134,8 +130,7 @@ int hdc1008_init(struct device *dev)
|
|||
hdc1008_gpio_callback,
|
||||
BIT(CONFIG_HDC1008_GPIO_PIN_NUM));
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Failed to set GPIO callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -31,19 +31,16 @@ static int isl29035_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
{
|
||||
struct isl29035_driver_data *drv_data = dev->driver_data;
|
||||
uint8_t msb, lsb;
|
||||
int ret;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL);
|
||||
|
||||
ret = i2c_reg_read_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_DATA_MSB_REG, &msb);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_read_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_DATA_MSB_REG, &msb) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = i2c_reg_read_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_DATA_LSB_REG, &lsb);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_read_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_DATA_LSB_REG, &lsb) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
@ -87,7 +84,6 @@ static struct sensor_driver_api isl29035_api = {
|
|||
static int isl29035_init(struct device *dev)
|
||||
{
|
||||
struct isl29035_driver_data *drv_data = dev->driver_data;
|
||||
int ret;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_ISL29035_I2C_MASTER_DEV_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
|
@ -98,63 +94,56 @@ static int isl29035_init(struct device *dev)
|
|||
drv_data->data_sample = 0;
|
||||
|
||||
/* clear blownout status bit */
|
||||
ret = i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_ID_REG, ISL29035_BOUT_MASK, 0);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_ID_REG, ISL29035_BOUT_MASK, 0) < 0) {
|
||||
SYS_LOG_DBG("Failed to clear blownout status bit.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* set command registers to set default attributes */
|
||||
ret = i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_I_REG, 0);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_I_REG, 0) < 0) {
|
||||
SYS_LOG_DBG("Failed to clear COMMAND-I.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
ret = i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG, 0);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG, 0) < 0) {
|
||||
SYS_LOG_DBG("Failed to clear COMMAND-II.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* set operation mode */
|
||||
ret = i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_I_REG,
|
||||
ISL29035_OPMODE_MASK,
|
||||
ISL29035_ACTIVE_OPMODE_BITS);
|
||||
if (ret < 0) {
|
||||
ISL29035_ACTIVE_OPMODE_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to set opmode.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* set lux range */
|
||||
ret = i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG,
|
||||
ISL29035_LUX_RANGE_MASK,
|
||||
ISL29035_LUX_RANGE_BITS);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG,
|
||||
ISL29035_LUX_RANGE_MASK,
|
||||
ISL29035_LUX_RANGE_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to set lux range.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* set ADC resolution */
|
||||
ret = i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG,
|
||||
ISL29035_ADC_RES_MASK,
|
||||
ISL29035_ADC_RES_BITS);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_II_REG,
|
||||
ISL29035_ADC_RES_MASK,
|
||||
ISL29035_ADC_RES_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to set ADC resolution.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_ISL29035_TRIGGER
|
||||
ret = isl29035_init_interrupt(dev);
|
||||
if (ret < 0) {
|
||||
if (isl29035_init_interrupt(dev) < 0) {
|
||||
SYS_LOG_DBG("Failed to initialize interrupt.");
|
||||
return ret;
|
||||
return -EIO;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
|
|
@ -153,14 +153,12 @@ int isl29035_trigger_set(struct device *dev,
|
|||
int isl29035_init_interrupt(struct device *dev)
|
||||
{
|
||||
struct isl29035_driver_data *drv_data = dev->driver_data;
|
||||
int ret;
|
||||
|
||||
/* set interrupt persistence */
|
||||
ret = i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_I_REG,
|
||||
ISL29035_INT_PRST_MASK,
|
||||
ISL29035_INT_PRST_BITS);
|
||||
if (ret < 0) {
|
||||
if (i2c_reg_update_byte(drv_data->i2c, ISL29035_I2C_ADDRESS,
|
||||
ISL29035_COMMAND_I_REG,
|
||||
ISL29035_INT_PRST_MASK,
|
||||
ISL29035_INT_PRST_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to set interrupt persistence cycles.");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -180,8 +178,7 @@ int isl29035_init_interrupt(struct device *dev)
|
|||
isl29035_gpio_callback,
|
||||
BIT(CONFIG_ISL29035_GPIO_PIN_NUM));
|
||||
|
||||
ret = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (ret < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Failed to set gpio callback.");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -63,7 +63,6 @@ int lis3dh_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
{
|
||||
struct lis3dh_data *drv_data = dev->driver_data;
|
||||
uint8_t buf[6];
|
||||
int rc;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_ACCEL_ANY);
|
||||
|
||||
|
@ -71,9 +70,8 @@ int lis3dh_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
* since all accel data register addresses are consecutive,
|
||||
* a burst read can be used to read all the samples
|
||||
*/
|
||||
rc = i2c_burst_read(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_ACCEL_X_LSB, buf, 6);
|
||||
if (rc < 0) {
|
||||
if (i2c_burst_read(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_ACCEL_X_LSB, buf, 6) < 0) {
|
||||
SYS_LOG_DBG("Could not read accel axis data");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -96,7 +94,6 @@ static struct sensor_driver_api lis3dh_driver_api = {
|
|||
int lis3dh_init(struct device *dev)
|
||||
{
|
||||
struct lis3dh_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_LIS3DH_I2C_MASTER_DEV_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
|
@ -106,24 +103,21 @@ int lis3dh_init(struct device *dev)
|
|||
}
|
||||
|
||||
/* enable accel measurements and set power mode and data rate */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL1, LIS3DH_ACCEL_EN_BITS |
|
||||
LIS3DH_LP_EN_BIT | LIS3DH_ODR_BITS);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL1, LIS3DH_ACCEL_EN_BITS |
|
||||
LIS3DH_LP_EN_BIT | LIS3DH_ODR_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to configure chip.");
|
||||
}
|
||||
|
||||
/* set full scale range */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL4, LIS3DH_FS_BITS);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL4, LIS3DH_FS_BITS) < 0) {
|
||||
SYS_LOG_DBG("Failed to set full scale range.");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
#ifdef CONFIG_LIS3DH_TRIGGER
|
||||
rc = lis3dh_init_interrupt(dev);
|
||||
if (rc < 0) {
|
||||
if (lis3dh_init_interrupt(dev) < 0) {
|
||||
SYS_LOG_DBG("Failed to initialize interrupts.");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -103,7 +103,6 @@ static void lis3dh_work_cb(struct nano_work *work)
|
|||
int lis3dh_init_interrupt(struct device *dev)
|
||||
{
|
||||
struct lis3dh_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
/* setup data ready gpio interrupt */
|
||||
drv_data->gpio = device_get_binding(CONFIG_LIS3DH_GPIO_DEV_NAME);
|
||||
|
@ -121,23 +120,20 @@ int lis3dh_init_interrupt(struct device *dev)
|
|||
lis3dh_gpio_callback,
|
||||
BIT(CONFIG_LIS3DH_GPIO_PIN_NUM));
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Could not set gpio callback");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* clear data ready interrupt line by reading sample data */
|
||||
rc = lis3dh_sample_fetch(dev, SENSOR_CHAN_ALL);
|
||||
if (rc < 0) {
|
||||
if (lis3dh_sample_fetch(dev, SENSOR_CHAN_ALL) < 0) {
|
||||
SYS_LOG_DBG("Could not clear data ready interrupt line.");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* enable data ready interrupt on INT1 line */
|
||||
rc = i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL3, LIS3DH_EN_DRDY1_INT1);
|
||||
if (rc < 0) {
|
||||
if (i2c_reg_write_byte(drv_data->i2c, LIS3DH_I2C_ADDRESS,
|
||||
LIS3DH_REG_CTRL3, LIS3DH_EN_DRDY1_INT1) < 0) {
|
||||
SYS_LOG_DBG("Failed to enable data ready interrupt.");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -29,8 +29,6 @@
|
|||
|
||||
int mcp9808_reg_read(struct mcp9808_data *data, uint8_t reg, uint16_t *val)
|
||||
{
|
||||
int ret;
|
||||
|
||||
struct i2c_msg msgs[2] = {
|
||||
{
|
||||
.buf = ®,
|
||||
|
@ -44,9 +42,9 @@ int mcp9808_reg_read(struct mcp9808_data *data, uint8_t reg, uint16_t *val)
|
|||
},
|
||||
};
|
||||
|
||||
ret = i2c_transfer(data->i2c_master, msgs, 2, data->i2c_slave_addr);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (i2c_transfer(data->i2c_master, msgs, 2, data->i2c_slave_addr)
|
||||
< 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
*val = sys_be16_to_cpu(*val);
|
||||
|
|
|
@ -46,12 +46,10 @@ static int mcp9808_reg_write(struct mcp9808_data *data, uint8_t reg, uint16_t va
|
|||
static int mcp9808_reg_update(struct mcp9808_data *data, uint8_t reg,
|
||||
uint16_t mask, uint16_t val)
|
||||
{
|
||||
int ret;
|
||||
uint16_t old_val, new_val;
|
||||
|
||||
ret = mcp9808_reg_read(data, reg, &old_val);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (mcp9808_reg_read(data, reg, &old_val) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
new_val = old_val & ~mask;
|
||||
|
|
|
@ -75,7 +75,6 @@ static int sht3xd_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
struct sht3xd_data *drv_data = dev->driver_data;
|
||||
uint8_t rx_buf[6];
|
||||
uint16_t t_sample, rh_sample;
|
||||
int rc;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL);
|
||||
|
||||
|
@ -97,8 +96,7 @@ static int sht3xd_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
},
|
||||
};
|
||||
|
||||
rc = i2c_transfer(drv_data->i2c, msgs, 2, SHT3XD_I2C_ADDRESS);
|
||||
if (rc < 0) {
|
||||
if (i2c_transfer(drv_data->i2c, msgs, 2, SHT3XD_I2C_ADDRESS) < 0) {
|
||||
SYS_LOG_DBG("Failed to read data sample!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -163,7 +161,6 @@ static struct sensor_driver_api sht3xd_driver_api = {
|
|||
static int sht3xd_init(struct device *dev)
|
||||
{
|
||||
struct sht3xd_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
drv_data->i2c = device_get_binding(CONFIG_SHT3XD_I2C_MASTER_DEV_NAME);
|
||||
if (drv_data->i2c == NULL) {
|
||||
|
@ -173,8 +170,7 @@ static int sht3xd_init(struct device *dev)
|
|||
}
|
||||
|
||||
/* clear status register */
|
||||
rc = sht3xd_write_command(drv_data, SHT3XD_CMD_CLEAR_STATUS);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_command(drv_data, SHT3XD_CMD_CLEAR_STATUS) < 0) {
|
||||
SYS_LOG_DBG("Failed to clear status register!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -182,9 +178,9 @@ static int sht3xd_init(struct device *dev)
|
|||
sys_thread_busy_wait(SHT3XD_CLEAR_STATUS_WAIT_USEC);
|
||||
|
||||
/* set periodic measurement mode */
|
||||
rc = sht3xd_write_command(drv_data,
|
||||
sht3xd_measure_cmd[SHT3XD_MPS_IDX][SHT3XD_REPEATABILITY_IDX]);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_command(drv_data,
|
||||
sht3xd_measure_cmd[SHT3XD_MPS_IDX][SHT3XD_REPEATABILITY_IDX])
|
||||
< 0) {
|
||||
SYS_LOG_DBG("Failed to set measurement mode!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -192,8 +188,7 @@ static int sht3xd_init(struct device *dev)
|
|||
sys_thread_busy_wait(sht3xd_measure_wait[SHT3XD_REPEATABILITY_IDX]);
|
||||
|
||||
#ifdef CONFIG_SHT3XD_TRIGGER
|
||||
rc = sht3xd_init_interrupt(dev);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_init_interrupt(dev) < 0) {
|
||||
SYS_LOG_DBG("Failed to initialize interrupt");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -182,7 +182,6 @@ int sht3xd_trigger_set(struct device *dev,
|
|||
int sht3xd_init_interrupt(struct device *dev)
|
||||
{
|
||||
struct sht3xd_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
drv_data->t_low = 0;
|
||||
drv_data->rh_low = 0;
|
||||
|
@ -190,27 +189,24 @@ int sht3xd_init_interrupt(struct device *dev)
|
|||
drv_data->rh_high = 0xFFFF;
|
||||
|
||||
/* set alert thresholds to match reamsurement ranges */
|
||||
rc = sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_HIGH_SET, 0xFFFF);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_HIGH_SET, 0xFFFF)
|
||||
< 0) {
|
||||
SYS_LOG_DBG("Failed to write threshold high set value!");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_HIGH_CLEAR,
|
||||
0xFFFF);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_HIGH_CLEAR,
|
||||
0xFFFF) < 0) {
|
||||
SYS_LOG_DBG("Failed to write threshold high clear value!");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_LOW_SET, 0);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_LOW_SET, 0) < 0) {
|
||||
SYS_LOG_DBG("Failed to write threshold low set value!");
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
rc = sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_LOW_SET, 0);
|
||||
if (rc < 0) {
|
||||
if (sht3xd_write_reg(drv_data, SHT3XD_CMD_WRITE_TH_LOW_SET, 0) < 0) {
|
||||
SYS_LOG_DBG("Failed to write threshold low clear value!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -231,8 +227,7 @@ int sht3xd_init_interrupt(struct device *dev)
|
|||
sht3xd_gpio_callback,
|
||||
BIT(CONFIG_SHT3XD_GPIO_PIN_NUM));
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Failed to set gpio callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
|
@ -90,29 +90,26 @@ static struct sensor_driver_api sx9500_api_funcs = {
|
|||
static int sx9500_init_chip(struct device *dev)
|
||||
{
|
||||
struct sx9500_data *data = (struct sx9500_data *) dev->driver_data;
|
||||
int ret;
|
||||
uint8_t val;
|
||||
|
||||
ret = i2c_write(data->i2c_master, sx9500_reg_defaults,
|
||||
sizeof(sx9500_reg_defaults), data->i2c_slave_addr);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (i2c_write(data->i2c_master, sx9500_reg_defaults,
|
||||
sizeof(sx9500_reg_defaults), data->i2c_slave_addr)
|
||||
< 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* No interrupts active. We only activate them when an
|
||||
* application registers a trigger.
|
||||
*/
|
||||
ret = i2c_reg_write_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK, 0);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (i2c_reg_write_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK, 0) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
/* Read irq source reg to clear reset status. */
|
||||
ret = i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, &val);
|
||||
if (ret) {
|
||||
return ret;
|
||||
if (i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, &val) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
return i2c_reg_write_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
|
@ -123,7 +120,6 @@ static int sx9500_init_chip(struct device *dev)
|
|||
int sx9500_init(struct device *dev)
|
||||
{
|
||||
struct sx9500_data *data = dev->driver_data;
|
||||
int ret;
|
||||
|
||||
data->i2c_master = device_get_binding(CONFIG_SX9500_I2C_DEV_NAME);
|
||||
if (!data->i2c_master) {
|
||||
|
@ -134,16 +130,14 @@ int sx9500_init(struct device *dev)
|
|||
|
||||
data->i2c_slave_addr = CONFIG_SX9500_I2C_ADDR;
|
||||
|
||||
ret = sx9500_init_chip(dev);
|
||||
if (ret) {
|
||||
if (sx9500_init_chip(dev) < 0) {
|
||||
SYS_LOG_DBG("sx9500: failed to initialize chip err %d", ret);
|
||||
return ret;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
ret = sx9500_setup_interrupt(dev);
|
||||
if (ret) {
|
||||
if (sx9500_setup_interrupt(dev) < 0) {
|
||||
SYS_LOG_DBG("sx9500: failed to setup interrupt err %d", ret);
|
||||
return ret;
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
dev->driver_api = &sx9500_api_funcs;
|
||||
|
|
|
@ -32,29 +32,28 @@ int sx9500_trigger_set(struct device *dev,
|
|||
sensor_trigger_handler_t handler)
|
||||
{
|
||||
struct sx9500_data *data = dev->driver_data;
|
||||
int ret;
|
||||
|
||||
switch (trig->type) {
|
||||
case SENSOR_TRIG_DATA_READY:
|
||||
ret = i2c_reg_update_byte(data->i2c_master,
|
||||
data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK,
|
||||
SX9500_CONV_DONE_IRQ,
|
||||
SX9500_CONV_DONE_IRQ);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (i2c_reg_update_byte(data->i2c_master,
|
||||
data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK,
|
||||
SX9500_CONV_DONE_IRQ,
|
||||
SX9500_CONV_DONE_IRQ) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
data->handler_drdy = handler;
|
||||
data->trigger_drdy = *trig;
|
||||
break;
|
||||
|
||||
case SENSOR_TRIG_NEAR_FAR:
|
||||
ret = i2c_reg_update_byte(data->i2c_master,
|
||||
data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK,
|
||||
SX9500_NEAR_FAR_IRQ,
|
||||
SX9500_NEAR_FAR_IRQ);
|
||||
if (ret)
|
||||
return ret;
|
||||
if (i2c_reg_update_byte(data->i2c_master,
|
||||
data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_MSK,
|
||||
SX9500_NEAR_FAR_IRQ,
|
||||
SX9500_NEAR_FAR_IRQ) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
data->handler_near_far = handler;
|
||||
data->trigger_near_far = *trig;
|
||||
break;
|
||||
|
@ -84,16 +83,14 @@ static void sx9500_fiber_main(int arg1, int unused)
|
|||
struct device *dev = INT_TO_POINTER(arg1);
|
||||
struct sx9500_data *data = dev->driver_data;
|
||||
uint8_t reg_val;
|
||||
int ret;
|
||||
|
||||
ARG_UNUSED(unused);
|
||||
|
||||
while (1) {
|
||||
nano_fiber_sem_take(&data->sem, TICKS_UNLIMITED);
|
||||
|
||||
ret = i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, ®_val);
|
||||
if (ret) {
|
||||
if (i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, ®_val) < 0) {
|
||||
SYS_LOG_DBG("sx9500: error %d reading IRQ source register", ret);
|
||||
continue;
|
||||
}
|
||||
|
@ -126,11 +123,9 @@ static void sx9500_gpio_fiber_cb(void *arg)
|
|||
struct device *dev = arg;
|
||||
struct sx9500_data *data = dev->driver_data;
|
||||
uint8_t reg_val;
|
||||
int ret;
|
||||
|
||||
ret = i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, ®_val);
|
||||
if (ret) {
|
||||
if (i2c_reg_read_byte(data->i2c_master, data->i2c_slave_addr,
|
||||
SX9500_REG_IRQ_SRC, ®_val) < 0) {
|
||||
SYS_LOG_DBG("sx9500: error %d reading IRQ source register", ret);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -76,12 +76,14 @@ static int tmp007_sample_fetch(struct device *dev, enum sensor_channel chan)
|
|||
{
|
||||
struct tmp007_data *drv_data = dev->driver_data;
|
||||
uint16_t val;
|
||||
int rc;
|
||||
|
||||
__ASSERT(chan == SENSOR_CHAN_ALL || chan == SENSOR_CHAN_TEMP);
|
||||
|
||||
rc = tmp007_reg_read(drv_data, TMP007_REG_TOBJ, &val);
|
||||
if (rc < 0 || val & TMP007_DATA_INVALID_BIT) {
|
||||
if (tmp007_reg_read(drv_data, TMP007_REG_TOBJ, &val) < 0) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
if (val & TMP007_DATA_INVALID_BIT) {
|
||||
return -EIO;
|
||||
}
|
||||
|
||||
|
|
|
@ -143,11 +143,9 @@ int tmp007_trigger_set(struct device *dev,
|
|||
int tmp007_init_interrupt(struct device *dev)
|
||||
{
|
||||
struct tmp007_data *drv_data = dev->driver_data;
|
||||
int rc;
|
||||
|
||||
rc = tmp007_reg_update(drv_data, TMP007_REG_CONFIG,
|
||||
TMP007_ALERT_EN_BIT, TMP007_ALERT_EN_BIT);
|
||||
if (rc < 0) {
|
||||
if (tmp007_reg_update(drv_data, TMP007_REG_CONFIG,
|
||||
TMP007_ALERT_EN_BIT, TMP007_ALERT_EN_BIT) < 0) {
|
||||
SYS_LOG_DBG("Failed to enable interrupt pin!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -168,8 +166,7 @@ int tmp007_init_interrupt(struct device *dev)
|
|||
tmp007_gpio_callback,
|
||||
BIT(CONFIG_TMP007_GPIO_PIN_NUM));
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
SYS_LOG_DBG("Failed to set gpio callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue