Skip to content

Commit 80ea120

Browse files
committed
Updated to v4.4.8. Fixed an indexing bug while getting heater configuration. Fixed typos and minor bugs.
1 parent 6dab330 commit 80ea120

10 files changed

Lines changed: 103 additions & 91 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
1+
Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
22

33
BSD-3-Clause
44

bme68x.c

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x.c
34-
* @date 2021-11-09
35-
* @version v4.4.7
34+
* @date 2023-02-07
35+
* @version v4.4.8
3636
*
3737
*/
3838

@@ -145,28 +145,27 @@ int8_t bme68x_init(struct bme68x_dev *dev)
145145
{
146146
int8_t rslt;
147147

148-
rslt = bme68x_soft_reset(dev);
148+
(void) bme68x_soft_reset(dev);
149+
150+
rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);
151+
149152
if (rslt == BME68X_OK)
150153
{
151-
rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);
152-
if (rslt == BME68X_OK)
154+
if (dev->chip_id == BME68X_CHIP_ID)
153155
{
154-
if (dev->chip_id == BME68X_CHIP_ID)
155-
{
156-
/* Read Variant ID */
157-
rslt = read_variant_id(dev);
156+
/* Read Variant ID */
157+
rslt = read_variant_id(dev);
158158

159-
if (rslt == BME68X_OK)
160-
{
161-
/* Get the Calibration data */
162-
rslt = get_calib_data(dev);
163-
}
164-
}
165-
else
159+
if (rslt == BME68X_OK)
166160
{
167-
rslt = BME68X_E_DEV_NOT_FOUND;
161+
/* Get the Calibration data */
162+
rslt = get_calib_data(dev);
168163
}
169164
}
165+
else
166+
{
167+
rslt = BME68X_E_DEV_NOT_FOUND;
168+
}
170169
}
171170

172171
return rslt;
@@ -289,10 +288,11 @@ int8_t bme68x_soft_reset(struct bme68x_dev *dev)
289288
{
290289
rslt = bme68x_set_regs(&reg_addr, &soft_rst_cmd, 1, dev);
291290

292-
/* Wait for 5ms */
293-
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);
294291
if (rslt == BME68X_OK)
295292
{
293+
/* Wait for 5ms */
294+
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);
295+
296296
/* After reset get the memory page */
297297
if (dev->intf == BME68X_SPI_INTF)
298298
{
@@ -681,39 +681,41 @@ int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *co
681681
return rslt;
682682
}
683683

684-
/*
684+
/*!
685685
* @brief This API is used to get the gas configuration of the sensor.
686686
*/
687687
int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev)
688688
{
689-
int8_t rslt;
689+
int8_t rslt = BME68X_OK;
690690
uint8_t data_array[10] = { 0 };
691691
uint8_t i;
692692

693-
/* FIXME: Add conversion to deg C and ms and add the other parameters */
694-
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);
695-
if (rslt == BME68X_OK)
693+
if ((conf != NULL) && (conf->heatr_dur_prof != NULL) && (conf->heatr_temp_prof != NULL))
696694
{
697-
if (conf && conf->heatr_dur_prof && conf->heatr_temp_prof)
695+
/* FIXME: Add conversion to deg C and ms and add the other parameters */
696+
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);
697+
698+
if (rslt == BME68X_OK)
698699
{
699-
for (i = 0; i < 10; i++)
700+
for (i = 0; i < conf->profile_len; i++)
700701
{
701702
conf->heatr_temp_prof[i] = data_array[i];
702703
}
703704

704705
rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0, data_array, 10, dev);
706+
705707
if (rslt == BME68X_OK)
706708
{
707-
for (i = 0; i < 10; i++)
709+
for (i = 0; i < conf->profile_len; i++)
708710
{
709711
conf->heatr_dur_prof[i] = data_array[i];
710712
}
711713
}
712714
}
713-
else
714-
{
715-
rslt = BME68X_E_NULL_PTR;
716-
}
715+
}
716+
else
717+
{
718+
rslt = BME68X_E_NULL_PTR;
717719
}
718720

719721
return rslt;
@@ -732,14 +734,21 @@ int8_t bme68x_selftest_check(const struct bme68x_dev *dev)
732734
struct bme68x_conf conf;
733735
struct bme68x_heatr_conf heatr_conf;
734736

735-
/* Copy required parameters from reference bme68x_dev struct */
736-
t_dev.amb_temp = 25;
737-
t_dev.read = dev->read;
738-
t_dev.write = dev->write;
739-
t_dev.intf = dev->intf;
740-
t_dev.delay_us = dev->delay_us;
741-
t_dev.intf_ptr = dev->intf_ptr;
742-
rslt = bme68x_init(&t_dev);
737+
rslt = null_ptr_check(dev);
738+
739+
if (rslt == BME68X_OK)
740+
{
741+
/* Copy required parameters from reference bme68x_dev struct */
742+
t_dev.amb_temp = 25;
743+
t_dev.read = dev->read;
744+
t_dev.write = dev->write;
745+
t_dev.intf = dev->intf;
746+
t_dev.delay_us = dev->delay_us;
747+
t_dev.intf_ptr = dev->intf_ptr;
748+
749+
rslt = bme68x_init(&t_dev);
750+
}
751+
743752
if (rslt == BME68X_OK)
744753
{
745754
/* Set the temperature, pressure and humidity & filter settings */
@@ -974,7 +983,7 @@ static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range
974983
return calc_gas_res;
975984
}
976985

977-
/* This internal API is used to calculate the heater resistance value using float */
986+
/* This internal API is used to calculate the heater resistance value using integer */
978987
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
979988
{
980989
uint8_t heatr_res;
@@ -1132,7 +1141,7 @@ static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range)
11321141
return calc_gas_res;
11331142
}
11341143

1135-
/* This internal API is used to calculate the heater resistance value */
1144+
/* This internal API is used to calculate the heater resistance value using float */
11361145
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
11371146
{
11381147
float var1;

bme68x.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x.h
34-
* @date 2021-11-09
35-
* @version v4.4.7
34+
* @date 2023-02-07
35+
* @version v4.4.8
3636
*
3737
*/
3838

bme68x_defs.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* BSD-3-Clause
55
*
@@ -31,8 +31,8 @@
3131
* POSSIBILITY OF SUCH DAMAGE.
3232
*
3333
* @file bme68x_defs.h
34-
* @date 2021-11-09
35-
* @version v4.4.7
34+
* @date 2023-02-07
35+
* @version v4.4.8
3636
*
3737
*/
3838

examples/common/common.c

Lines changed: 36 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/
@@ -29,46 +29,55 @@ static uint8_t dev_addr;
2929
*/
3030
BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
3131
{
32-
uint8_t dev_addr = *(uint8_t*)intf_ptr;
32+
uint8_t device_addr = *(uint8_t*)intf_ptr;
3333

34-
return coines_read_i2c(COINES_I2C_BUS_0, dev_addr, reg_addr, reg_data, (uint16_t)len);
34+
(void)intf_ptr;
35+
36+
return coines_read_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len);
3537
}
3638

3739
/*!
3840
* I2C write function map to COINES platform
3941
*/
4042
BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
4143
{
42-
uint8_t dev_addr = *(uint8_t*)intf_ptr;
44+
uint8_t device_addr = *(uint8_t*)intf_ptr;
45+
46+
(void)intf_ptr;
4347

44-
return coines_write_i2c(COINES_I2C_BUS_0, dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
48+
return coines_write_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
4549
}
4650

4751
/*!
4852
* SPI read function map to COINES platform
4953
*/
5054
BME68X_INTF_RET_TYPE bme68x_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
5155
{
52-
uint8_t dev_addr = *(uint8_t*)intf_ptr;
56+
uint8_t device_addr = *(uint8_t*)intf_ptr;
57+
58+
(void)intf_ptr;
5359

54-
return coines_read_spi(COINES_SPI_BUS_0, dev_addr, reg_addr, reg_data, (uint16_t)len);
60+
return coines_read_spi(COINES_SPI_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len);
5561
}
5662

5763
/*!
5864
* SPI write function map to COINES platform
5965
*/
6066
BME68X_INTF_RET_TYPE bme68x_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
6167
{
62-
uint8_t dev_addr = *(uint8_t*)intf_ptr;
68+
uint8_t device_addr = *(uint8_t*)intf_ptr;
6369

64-
return coines_write_spi(COINES_SPI_BUS_0, dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
70+
(void)intf_ptr;
71+
72+
return coines_write_spi(COINES_SPI_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
6573
}
6674

6775
/*!
6876
* Delay function map to COINES platform
6977
*/
7078
void bme68x_delay_us(uint32_t period, void *intf_ptr)
7179
{
80+
(void)intf_ptr;
7281
coines_delay_usec(period);
7382
}
7483

@@ -126,19 +135,18 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
126135
setbuf(stdout, NULL);
127136
#endif
128137

129-
if (result != COINES_SUCCESS)
138+
if (result == COINES_SUCCESS)
130139
{
131-
printf("\n Unable to retrieve board information ! \n");
132-
exit(COINES_E_FAILURE);
140+
if ((board_info.shuttle_id != BME68X_SHUTTLE_ID))
141+
{
142+
printf(
143+
"! Warning invalid sensor shuttle : 0x%x (Expected : 0x%x) \n ," "This application will not support this sensor \n",
144+
board_info.shuttle_id,
145+
BME68X_SHUTTLE_ID);
146+
}
133147
}
134148

135-
if ((board_info.shuttle_id != BME68X_SHUTTLE_ID))
136-
{
137-
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
138-
exit(COINES_E_FAILURE);
139-
}
140-
141-
coines_set_shuttleboard_vdd_vddio_config(0, 0);
149+
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
142150
coines_delay_msec(100);
143151

144152
/* Bus configuration : I2C */
@@ -149,11 +157,11 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
149157
bme->read = bme68x_i2c_read;
150158
bme->write = bme68x_i2c_write;
151159
bme->intf = BME68X_I2C_INTF;
152-
153-
/* SDO pin is made low */
154-
coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);
155160

156-
result = coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE);
161+
/* SDO pin is made low */
162+
(void)coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);
163+
164+
(void)coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE);
157165
}
158166
/* Bus configuration : SPI */
159167
else if (intf == BME68X_SPI_INTF)
@@ -163,17 +171,12 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
163171
bme->read = bme68x_spi_read;
164172
bme->write = bme68x_spi_write;
165173
bme->intf = BME68X_SPI_INTF;
166-
result = coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0);
167-
}
168-
169-
if(COINES_SUCCESS != result)
170-
{
171-
rslt = COINES_E_COMM_INIT_FAILED;
174+
(void)coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0);
172175
}
173176

174177
coines_delay_msec(100);
175178

176-
coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
179+
(void)coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
177180

178181
coines_delay_msec(100);
179182

@@ -191,13 +194,13 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
191194

192195
void bme68x_coines_deinit(void)
193196
{
194-
fflush(stdout);
197+
(void)fflush(stdout);
195198

196-
coines_set_shuttleboard_vdd_vddio_config(0, 0);
199+
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
197200
coines_delay_msec(1000);
198201

199202
/* Coines interface reset */
200203
coines_soft_reset();
201204
coines_delay_msec(1000);
202-
coines_close_comm_intf(COINES_COMM_INTF_USB, NULL);
205+
(void)coines_close_comm_intf(COINES_COMM_INTF_USB, NULL);
203206
}

examples/common/common.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
2+
* Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved.
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*/

examples/forced_mode/forced_mode.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright (C) 2021 Bosch Sensortec GmbH
2+
* Copyright (C) 2023 Bosch Sensortec GmbH
33
*
44
* SPDX-License-Identifier: BSD-3-Clause
55
*

0 commit comments

Comments
 (0)