Skip to content

Commit 56686ac

Browse files
vamoiridjic23
authored andcommitted
iio: chemical: bme680: Add support for preheat current
Add functionality to inject a specified amount of current to the heating plate before the start of the gas measurement to allow the sensor to reach faster to the requested temperature. Signed-off-by: Vasileios Amoiridis <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 80b9f3a commit 56686ac

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

drivers/iio/chemical/bme680.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#define BME680_RHRANGE_MASK GENMASK(5, 4)
4343
#define BME680_REG_RES_HEAT_VAL 0x00
4444
#define BME680_RSERROR_MASK GENMASK(7, 4)
45+
#define BME680_REG_IDAC_HEAT_0 0x50
4546
#define BME680_REG_RES_HEAT_0 0x5A
4647
#define BME680_REG_GAS_WAIT_0 0x64
4748
#define BME680_ADC_GAS_RES GENMASK(15, 6)

drivers/iio/chemical/bme680_core.c

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ struct bme680_data {
118118
u8 oversampling_temp;
119119
u8 oversampling_press;
120120
u8 oversampling_humid;
121+
u8 preheat_curr_mA;
121122
u16 heater_dur;
122123
u16 heater_temp;
123124

@@ -214,6 +215,12 @@ static const struct iio_chan_spec bme680_channels[] = {
214215
},
215216
},
216217
IIO_CHAN_SOFT_TIMESTAMP(4),
218+
{
219+
.type = IIO_CURRENT,
220+
.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
221+
.output = 1,
222+
.scan_index = -1,
223+
},
217224
};
218225

219226
static int bme680_read_calib(struct bme680_data *data,
@@ -561,6 +568,12 @@ static u8 bme680_calc_heater_dur(u16 dur)
561568
return durval;
562569
}
563570

571+
/* Taken from datasheet, section 5.3.3 */
572+
static u8 bme680_calc_heater_preheat_current(u8 curr)
573+
{
574+
return 8 * curr - 1;
575+
}
576+
564577
static int bme680_set_mode(struct bme680_data *data, enum bme680_op_mode mode)
565578
{
566579
struct device *dev = regmap_get_device(data->regmap);
@@ -659,6 +672,20 @@ static int bme680_chip_config(struct bme680_data *data)
659672
return 0;
660673
}
661674

675+
static int bme680_preheat_curr_config(struct bme680_data *data, u8 val)
676+
{
677+
struct device *dev = regmap_get_device(data->regmap);
678+
u8 heatr_curr;
679+
int ret;
680+
681+
heatr_curr = bme680_calc_heater_preheat_current(val);
682+
ret = regmap_write(data->regmap, BME680_REG_IDAC_HEAT_0, heatr_curr);
683+
if (ret < 0)
684+
dev_err(dev, "failed to write idac_heat_0 register\n");
685+
686+
return ret;
687+
}
688+
662689
static int bme680_gas_config(struct bme680_data *data)
663690
{
664691
struct device *dev = regmap_get_device(data->regmap);
@@ -687,6 +714,10 @@ static int bme680_gas_config(struct bme680_data *data)
687714
return ret;
688715
}
689716

717+
ret = bme680_preheat_curr_config(data, data->preheat_curr_mA);
718+
if (ret)
719+
return ret;
720+
690721
/* Enable the gas sensor and select heater profile set-point 0 */
691722
ret = regmap_update_bits(data->regmap, BME680_REG_CTRL_GAS_1,
692723
BME680_RUN_GAS_MASK | BME680_NB_CONV_MASK,
@@ -939,6 +970,15 @@ static int bme680_write_raw(struct iio_dev *indio_dev,
939970

940971
return bme680_chip_config(data);
941972
}
973+
case IIO_CHAN_INFO_PROCESSED:
974+
{
975+
switch (chan->type) {
976+
case IIO_CURRENT:
977+
return bme680_preheat_curr_config(data, (u8)val);
978+
default:
979+
return -EINVAL;
980+
}
981+
}
942982
default:
943983
return -EINVAL;
944984
}
@@ -1072,6 +1112,7 @@ int bme680_core_probe(struct device *dev, struct regmap *regmap,
10721112
data->oversampling_temp = 8; /* 8X oversampling rate */
10731113
data->heater_temp = 320; /* degree Celsius */
10741114
data->heater_dur = 150; /* milliseconds */
1115+
data->preheat_curr_mA = 0;
10751116

10761117
ret = regmap_write(regmap, BME680_REG_SOFT_RESET, BME680_CMD_SOFTRESET);
10771118
if (ret < 0)

0 commit comments

Comments
 (0)