Skip to content

Commit 4865ee1

Browse files
vamoiridjic23
authored andcommitted
iio: chemical: bme680: refactorize set_mode() mode
Refactorize the set_mode() function to use an external enum that describes the possible modes of the BME680 device instead of using true/false variables for selecting SLEEPING/FORCED mode. Signed-off-by: Vasileios Amoiridis <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 01f567d commit 4865ee1

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

drivers/iio/chemical/bme680.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
#define BME680_OSRS_TEMP_MASK GENMASK(7, 5)
2828
#define BME680_OSRS_PRESS_MASK GENMASK(4, 2)
2929
#define BME680_MODE_MASK GENMASK(1, 0)
30-
#define BME680_MODE_FORCED 1
31-
#define BME680_MODE_SLEEP 0
3230

3331
#define BME680_REG_CONFIG 0x75
3432
#define BME680_FILTER_MASK GENMASK(4, 2)

drivers/iio/chemical/bme680_core.c

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,12 @@ struct bme680_calib {
9595
s8 range_sw_err;
9696
};
9797

98+
/* values of CTRL_MEAS register */
99+
enum bme680_op_mode {
100+
BME680_MODE_SLEEP = 0,
101+
BME680_MODE_FORCED = 1,
102+
};
103+
98104
struct bme680_data {
99105
struct regmap *regmap;
100106
struct bme680_calib bme680;
@@ -502,23 +508,16 @@ static u8 bme680_calc_heater_dur(u16 dur)
502508
return durval;
503509
}
504510

505-
static int bme680_set_mode(struct bme680_data *data, bool mode)
511+
static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode mode)
506512
{
507513
struct device *dev = regmap_get_device(data->regmap);
508514
int ret;
509515

510-
if (mode) {
511-
ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
512-
BME680_MODE_MASK, BME680_MODE_FORCED);
513-
if (ret < 0)
514-
dev_err(dev, "failed to set forced mode\n");
515-
516-
} else {
517-
ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
518-
BME680_MODE_MASK, BME680_MODE_SLEEP);
519-
if (ret < 0)
520-
dev_err(dev, "failed to set sleep mode\n");
521-
516+
ret = regmap_write_bits(data->regmap, BME680_REG_CTRL_MEAS,
517+
BME680_MODE_MASK, mode);
518+
if (ret < 0) {
519+
dev_err(dev, "failed to set ctrl_meas register\n");
520+
return ret;
522521
}
523522

524523
return ret;
@@ -613,8 +612,7 @@ static int bme680_gas_config(struct bme680_data *data)
613612
int ret;
614613
u8 heatr_res, heatr_dur;
615614

616-
/* Go to sleep */
617-
ret = bme680_set_mode(data, false);
615+
ret = bme680_set_mode(data, BME680_MODE_SLEEP);
618616
if (ret < 0)
619617
return ret;
620618

@@ -745,8 +743,7 @@ static int bme680_read_raw(struct iio_dev *indio_dev,
745743

746744
guard(mutex)(&data->lock);
747745

748-
/* set forced mode to trigger measurement */
749-
ret = bme680_set_mode(data, true);
746+
ret = bme680_set_mode(data, BME680_MODE_FORCED);
750747
if (ret < 0)
751748
return ret;
752749

0 commit comments

Comments
 (0)