Skip to content

Commit

Permalink
Updated to v4.4.8. Fixed an indexing bug while getting heater configu…
Browse files Browse the repository at this point in the history
…ration. Fixed typos and minor bugs.
  • Loading branch information
kegov committed May 17, 2023
1 parent 6dab330 commit 80ea120
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 91 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.

BSD-3-Clause

Expand Down
93 changes: 51 additions & 42 deletions bme68x.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x.c
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down Expand Up @@ -145,28 +145,27 @@ int8_t bme68x_init(struct bme68x_dev *dev)
{
int8_t rslt;

rslt = bme68x_soft_reset(dev);
(void) bme68x_soft_reset(dev);

rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);

if (rslt == BME68X_OK)
{
rslt = bme68x_get_regs(BME68X_REG_CHIP_ID, &dev->chip_id, 1, dev);
if (rslt == BME68X_OK)
if (dev->chip_id == BME68X_CHIP_ID)
{
if (dev->chip_id == BME68X_CHIP_ID)
{
/* Read Variant ID */
rslt = read_variant_id(dev);
/* Read Variant ID */
rslt = read_variant_id(dev);

if (rslt == BME68X_OK)
{
/* Get the Calibration data */
rslt = get_calib_data(dev);
}
}
else
if (rslt == BME68X_OK)
{
rslt = BME68X_E_DEV_NOT_FOUND;
/* Get the Calibration data */
rslt = get_calib_data(dev);
}
}
else
{
rslt = BME68X_E_DEV_NOT_FOUND;
}
}

return rslt;
Expand Down Expand Up @@ -289,10 +288,11 @@ int8_t bme68x_soft_reset(struct bme68x_dev *dev)
{
rslt = bme68x_set_regs(&reg_addr, &soft_rst_cmd, 1, dev);

/* Wait for 5ms */
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);
if (rslt == BME68X_OK)
{
/* Wait for 5ms */
dev->delay_us(BME68X_PERIOD_RESET, dev->intf_ptr);

/* After reset get the memory page */
if (dev->intf == BME68X_SPI_INTF)
{
Expand Down Expand Up @@ -681,39 +681,41 @@ int8_t bme68x_set_heatr_conf(uint8_t op_mode, const struct bme68x_heatr_conf *co
return rslt;
}

/*
/*!
* @brief This API is used to get the gas configuration of the sensor.
*/
int8_t bme68x_get_heatr_conf(const struct bme68x_heatr_conf *conf, struct bme68x_dev *dev)
{
int8_t rslt;
int8_t rslt = BME68X_OK;
uint8_t data_array[10] = { 0 };
uint8_t i;

/* FIXME: Add conversion to deg C and ms and add the other parameters */
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);
if (rslt == BME68X_OK)
if ((conf != NULL) && (conf->heatr_dur_prof != NULL) && (conf->heatr_temp_prof != NULL))
{
if (conf && conf->heatr_dur_prof && conf->heatr_temp_prof)
/* FIXME: Add conversion to deg C and ms and add the other parameters */
rslt = bme68x_get_regs(BME68X_REG_RES_HEAT0, data_array, 10, dev);

if (rslt == BME68X_OK)
{
for (i = 0; i < 10; i++)
for (i = 0; i < conf->profile_len; i++)
{
conf->heatr_temp_prof[i] = data_array[i];
}

rslt = bme68x_get_regs(BME68X_REG_GAS_WAIT0, data_array, 10, dev);

if (rslt == BME68X_OK)
{
for (i = 0; i < 10; i++)
for (i = 0; i < conf->profile_len; i++)
{
conf->heatr_dur_prof[i] = data_array[i];
}
}
}
else
{
rslt = BME68X_E_NULL_PTR;
}
}
else
{
rslt = BME68X_E_NULL_PTR;
}

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

/* Copy required parameters from reference bme68x_dev struct */
t_dev.amb_temp = 25;
t_dev.read = dev->read;
t_dev.write = dev->write;
t_dev.intf = dev->intf;
t_dev.delay_us = dev->delay_us;
t_dev.intf_ptr = dev->intf_ptr;
rslt = bme68x_init(&t_dev);
rslt = null_ptr_check(dev);

if (rslt == BME68X_OK)
{
/* Copy required parameters from reference bme68x_dev struct */
t_dev.amb_temp = 25;
t_dev.read = dev->read;
t_dev.write = dev->write;
t_dev.intf = dev->intf;
t_dev.delay_us = dev->delay_us;
t_dev.intf_ptr = dev->intf_ptr;

rslt = bme68x_init(&t_dev);
}

if (rslt == BME68X_OK)
{
/* Set the temperature, pressure and humidity & filter settings */
Expand Down Expand Up @@ -974,7 +983,7 @@ static uint32_t calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range
return calc_gas_res;
}

/* This internal API is used to calculate the heater resistance value using float */
/* This internal API is used to calculate the heater resistance value using integer */
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
{
uint8_t heatr_res;
Expand Down Expand Up @@ -1132,7 +1141,7 @@ static float calc_gas_resistance_high(uint16_t gas_res_adc, uint8_t gas_range)
return calc_gas_res;
}

/* This internal API is used to calculate the heater resistance value */
/* This internal API is used to calculate the heater resistance value using float */
static uint8_t calc_res_heat(uint16_t temp, const struct bme68x_dev *dev)
{
float var1;
Expand Down
6 changes: 3 additions & 3 deletions bme68x.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x.h
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down
6 changes: 3 additions & 3 deletions bme68x_defs.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (c) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (c) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* BSD-3-Clause
*
Expand Down Expand Up @@ -31,8 +31,8 @@
* POSSIBILITY OF SUCH DAMAGE.
*
* @file bme68x_defs.h
* @date 2021-11-09
* @version v4.4.7
* @date 2023-02-07
* @version v4.4.8
*
*/

Expand Down
69 changes: 36 additions & 33 deletions examples/common/common.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down Expand Up @@ -29,46 +29,55 @@ static uint8_t dev_addr;
*/
BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
uint8_t dev_addr = *(uint8_t*)intf_ptr;
uint8_t device_addr = *(uint8_t*)intf_ptr;

return coines_read_i2c(COINES_I2C_BUS_0, dev_addr, reg_addr, reg_data, (uint16_t)len);
(void)intf_ptr;

return coines_read_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len);
}

/*!
* I2C write function map to COINES platform
*/
BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
uint8_t dev_addr = *(uint8_t*)intf_ptr;
uint8_t device_addr = *(uint8_t*)intf_ptr;

(void)intf_ptr;

return coines_write_i2c(COINES_I2C_BUS_0, dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
return coines_write_i2c(COINES_I2C_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
}

/*!
* SPI read function map to COINES platform
*/
BME68X_INTF_RET_TYPE bme68x_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
uint8_t dev_addr = *(uint8_t*)intf_ptr;
uint8_t device_addr = *(uint8_t*)intf_ptr;

(void)intf_ptr;

return coines_read_spi(COINES_SPI_BUS_0, dev_addr, reg_addr, reg_data, (uint16_t)len);
return coines_read_spi(COINES_SPI_BUS_0, device_addr, reg_addr, reg_data, (uint16_t)len);
}

/*!
* SPI write function map to COINES platform
*/
BME68X_INTF_RET_TYPE bme68x_spi_write(uint8_t reg_addr, const uint8_t *reg_data, uint32_t len, void *intf_ptr)
{
uint8_t dev_addr = *(uint8_t*)intf_ptr;
uint8_t device_addr = *(uint8_t*)intf_ptr;

return coines_write_spi(COINES_SPI_BUS_0, dev_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
(void)intf_ptr;

return coines_write_spi(COINES_SPI_BUS_0, device_addr, reg_addr, (uint8_t *)reg_data, (uint16_t)len);
}

/*!
* Delay function map to COINES platform
*/
void bme68x_delay_us(uint32_t period, void *intf_ptr)
{
(void)intf_ptr;
coines_delay_usec(period);
}

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

if (result != COINES_SUCCESS)
if (result == COINES_SUCCESS)
{
printf("\n Unable to retrieve board information ! \n");
exit(COINES_E_FAILURE);
if ((board_info.shuttle_id != BME68X_SHUTTLE_ID))
{
printf(
"! Warning invalid sensor shuttle : 0x%x (Expected : 0x%x) \n ," "This application will not support this sensor \n",
board_info.shuttle_id,
BME68X_SHUTTLE_ID);
}
}

if ((board_info.shuttle_id != BME68X_SHUTTLE_ID))
{
printf("! Warning invalid sensor shuttle \n ," "This application will not support this sensor \n");
exit(COINES_E_FAILURE);
}

coines_set_shuttleboard_vdd_vddio_config(0, 0);
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
coines_delay_msec(100);

/* Bus configuration : I2C */
Expand All @@ -149,11 +157,11 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
bme->read = bme68x_i2c_read;
bme->write = bme68x_i2c_write;
bme->intf = BME68X_I2C_INTF;

/* SDO pin is made low */
coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);

result = coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE);
/* SDO pin is made low */
(void)coines_set_pin_config(COINES_SHUTTLE_PIN_SDO, COINES_PIN_DIRECTION_OUT, COINES_PIN_VALUE_LOW);

(void)coines_config_i2c_bus(COINES_I2C_BUS_0, COINES_I2C_STANDARD_MODE);
}
/* Bus configuration : SPI */
else if (intf == BME68X_SPI_INTF)
Expand All @@ -163,17 +171,12 @@ int8_t bme68x_interface_init(struct bme68x_dev *bme, uint8_t intf)
bme->read = bme68x_spi_read;
bme->write = bme68x_spi_write;
bme->intf = BME68X_SPI_INTF;
result = coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0);
}

if(COINES_SUCCESS != result)
{
rslt = COINES_E_COMM_INIT_FAILED;
(void)coines_config_spi_bus(COINES_SPI_BUS_0, COINES_SPI_SPEED_7_5_MHZ, COINES_SPI_MODE0);
}

coines_delay_msec(100);

coines_set_shuttleboard_vdd_vddio_config(3300, 3300);
(void)coines_set_shuttleboard_vdd_vddio_config(3300, 3300);

coines_delay_msec(100);

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

void bme68x_coines_deinit(void)
{
fflush(stdout);
(void)fflush(stdout);

coines_set_shuttleboard_vdd_vddio_config(0, 0);
(void)coines_set_shuttleboard_vdd_vddio_config(0, 0);
coines_delay_msec(1000);

/* Coines interface reset */
coines_soft_reset();
coines_delay_msec(1000);
coines_close_comm_intf(COINES_COMM_INTF_USB, NULL);
(void)coines_close_comm_intf(COINES_COMM_INTF_USB, NULL);
}
2 changes: 1 addition & 1 deletion examples/common/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH. All rights reserved.
* Copyright (C) 2023 Bosch Sensortec GmbH. All rights reserved.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
Expand Down
2 changes: 1 addition & 1 deletion examples/forced_mode/forced_mode.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright (C) 2021 Bosch Sensortec GmbH
* Copyright (C) 2023 Bosch Sensortec GmbH
*
* SPDX-License-Identifier: BSD-3-Clause
*
Expand Down
Loading

0 comments on commit 80ea120

Please sign in to comment.