Skip to content

Commit 90b3eeb

Browse files
Leonard Pollakcarlescufi
authored andcommitted
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 <[email protected]>
1 parent e9d7d5c commit 90b3eeb

File tree

2 files changed

+17
-27
lines changed

2 files changed

+17
-27
lines changed

drivers/sensor/bme680/bme680.c

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
/*
88
* Copyright (c) 2018 Bosch Sensortec GmbH
9+
* Copyright (c) 2022, Leonard Pollak
910
*
1011
* SPDX-License-Identifier: Apache-2.0
1112
*/
@@ -342,11 +343,17 @@ static int bme680_read_compensation(const struct device *dev)
342343
return 0;
343344
}
344345

345-
static int bme680_chip_init(const struct device *dev)
346+
static int bme680_init(const struct device *dev)
346347
{
347348
struct bme680_data *data = dev->data;
349+
const struct bme680_config *config = dev->config;
348350
int err;
349351

352+
if (!device_is_ready(config->bus.bus)) {
353+
LOG_ERR("I2C master %s not ready", config->bus.bus->name);
354+
return -EINVAL;
355+
}
356+
350357
err = bme680_reg_read(dev, BME680_REG_CHIP_ID, &data->chip_id, 1);
351358
if (err < 0) {
352359
return err;
@@ -355,7 +362,7 @@ static int bme680_chip_init(const struct device *dev)
355362
if (data->chip_id == BME680_CHIP_ID) {
356363
LOG_DBG("BME680 chip detected");
357364
} else {
358-
LOG_ERR("Bad BME680 chip id 0x%x", data->chip_id);
365+
LOG_ERR("Bad BME680 chip id: 0x%x", data->chip_id);
359366
return -ENOTSUP;
360367
}
361368

@@ -394,27 +401,8 @@ static int bme680_chip_init(const struct device *dev)
394401

395402
err = bme680_reg_write(dev, BME680_REG_CTRL_MEAS,
396403
BME680_CTRL_MEAS_VAL);
397-
if (err < 0) {
398-
return err;
399-
}
400-
401-
return 0;
402-
}
403404

404-
static int bme680_init(const struct device *dev)
405-
{
406-
const struct bme680_config *config = dev->config;
407-
408-
if (!device_is_ready(config->bus.bus)) {
409-
LOG_ERR("I2C master %s not ready", config->bus.bus->name);
410-
return -EINVAL;
411-
}
412-
413-
if (bme680_chip_init(dev) < 0) {
414-
return -EINVAL;
415-
}
416-
417-
return 0;
405+
return err;
418406
}
419407

420408
static const struct sensor_driver_api bme680_api_funcs = {

drivers/sensor/bme680/bme680.h

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
/*
22
* Copyright (c) 2018 Bosch Sensortec GmbH
3+
* Copyright (c) 2022, Leonard Pollak
34
*
45
* SPDX-License-Identifier: Apache-2.0
56
*/
67

7-
#ifndef __SENSOR_BME680_H__
8-
#define __SENSOR_BME680_H__
8+
#ifndef __ZEPHYR_DRIVERS_SENSOR_BME680_H__
9+
#define __ZEPHYR_DRIVERS_SENSOR_BME680_H__
910

11+
#include <zephyr/types.h>
1012
#include <device.h>
1113
#include <drivers/i2c.h>
1214

@@ -32,9 +34,9 @@
3234
#define BME680_REG_MEM_PAGE 0x73
3335
#define BME680_REG_UNIQUE_ID 0x83
3436
#define BME680_REG_COEFF1 0x8a
35-
#define BME680_REG_CHIP_ID 0xd0
36-
#define BME680_REG_SOFT_RESET 0xe0
3737
#define BME680_REG_COEFF2 0xe1
38+
#define BME680_REG_CHIP_ID 0xd0
39+
#define BME680_REG_SOFT_RESET 0xe0
3840

3941
#define BME680_MSK_NEW_DATA 0x80
4042
#define BME680_MSK_GAS_RANGE 0x0f
@@ -167,4 +169,4 @@ struct bme680_config {
167169
struct i2c_dt_spec bus;
168170
};
169171

170-
#endif /* __SENSOR_BME680_H__ */
172+
#endif /* __ZEPHYR_DRIVERS_SENSOR_BME680_H__ */

0 commit comments

Comments
 (0)