diff --git a/drivers/sensor/bme680/bme680.c b/drivers/sensor/bme680/bme680.c index f700aae87ed..a3373d97d93 100644 --- a/drivers/sensor/bme680/bme680.c +++ b/drivers/sensor/bme680/bme680.c @@ -6,6 +6,7 @@ /* * Copyright (c) 2018 Bosch Sensortec GmbH + * Copyright (c) 2022, Leonard Pollak * * SPDX-License-Identifier: Apache-2.0 */ @@ -342,11 +343,17 @@ static int bme680_read_compensation(const struct device *dev) return 0; } -static int bme680_chip_init(const struct device *dev) +static int bme680_init(const struct device *dev) { struct bme680_data *data = dev->data; + const struct bme680_config *config = dev->config; int err; + if (!device_is_ready(config->bus.bus)) { + LOG_ERR("I2C master %s not ready", config->bus.bus->name); + return -EINVAL; + } + err = bme680_reg_read(dev, BME680_REG_CHIP_ID, &data->chip_id, 1); if (err < 0) { return err; @@ -355,7 +362,7 @@ static int bme680_chip_init(const struct device *dev) if (data->chip_id == BME680_CHIP_ID) { LOG_DBG("BME680 chip detected"); } else { - LOG_ERR("Bad BME680 chip id 0x%x", data->chip_id); + LOG_ERR("Bad BME680 chip id: 0x%x", data->chip_id); return -ENOTSUP; } @@ -394,27 +401,8 @@ static int bme680_chip_init(const struct device *dev) err = bme680_reg_write(dev, BME680_REG_CTRL_MEAS, BME680_CTRL_MEAS_VAL); - if (err < 0) { - return err; - } - return 0; -} - -static int bme680_init(const struct device *dev) -{ - const struct bme680_config *config = dev->config; - - if (!device_is_ready(config->bus.bus)) { - LOG_ERR("I2C master %s not ready", config->bus.bus->name); - return -EINVAL; - } - - if (bme680_chip_init(dev) < 0) { - return -EINVAL; - } - - return 0; + return err; } static const struct sensor_driver_api bme680_api_funcs = { diff --git a/drivers/sensor/bme680/bme680.h b/drivers/sensor/bme680/bme680.h index 27f7ac27cea..5653a0e0b27 100644 --- a/drivers/sensor/bme680/bme680.h +++ b/drivers/sensor/bme680/bme680.h @@ -1,12 +1,14 @@ /* * Copyright (c) 2018 Bosch Sensortec GmbH + * Copyright (c) 2022, Leonard Pollak * * SPDX-License-Identifier: Apache-2.0 */ -#ifndef __SENSOR_BME680_H__ -#define __SENSOR_BME680_H__ +#ifndef __ZEPHYR_DRIVERS_SENSOR_BME680_H__ +#define __ZEPHYR_DRIVERS_SENSOR_BME680_H__ +#include #include #include @@ -32,9 +34,9 @@ #define BME680_REG_MEM_PAGE 0x73 #define BME680_REG_UNIQUE_ID 0x83 #define BME680_REG_COEFF1 0x8a -#define BME680_REG_CHIP_ID 0xd0 -#define BME680_REG_SOFT_RESET 0xe0 #define BME680_REG_COEFF2 0xe1 +#define BME680_REG_CHIP_ID 0xd0 +#define BME680_REG_SOFT_RESET 0xe0 #define BME680_MSK_NEW_DATA 0x80 #define BME680_MSK_GAS_RANGE 0x0f @@ -167,4 +169,4 @@ struct bme680_config { struct i2c_dt_spec bus; }; -#endif /* __SENSOR_BME680_H__ */ +#endif /* __ZEPHYR_DRIVERS_SENSOR_BME680_H__ */