drivers: sensor: bme680: prep work
Consolidate the initialization routines and change the include guard to conform with the coding guidelines as a preparation for the following commits which add support for the SPI interface. Signed-off-by: Leonard Pollak <leonardp@tr-host.de>
This commit is contained in:
parent
8e7907aa6f
commit
4e804bfa73
2 changed files with 17 additions and 27 deletions
|
@ -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 = {
|
||||
|
|
|
@ -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 <zephyr/types.h>
|
||||
#include <device.h>
|
||||
#include <drivers/i2c.h>
|
||||
|
||||
|
@ -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__ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue