diff --git a/LICENSE b/LICENSE index 39d6442..3fe3a6b 100644 --- a/LICENSE +++ b/LICENSE @@ -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 diff --git a/bme68x.c b/bme68x.c index 7c3c935..cd6965b 100644 --- a/bme68x.c +++ b/bme68x.c @@ -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 * @@ -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 * */ @@ -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; @@ -289,10 +288,11 @@ int8_t bme68x_soft_reset(struct bme68x_dev *dev) { rslt = bme68x_set_regs(®_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) { @@ -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; @@ -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 */ @@ -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; @@ -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; diff --git a/bme68x.h b/bme68x.h index e6d4828..89b58ed 100644 --- a/bme68x.h +++ b/bme68x.h @@ -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 * @@ -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 * */ diff --git a/bme68x_defs.h b/bme68x_defs.h index 861b2f7..1ad1584 100644 --- a/bme68x_defs.h +++ b/bme68x_defs.h @@ -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 * @@ -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 * */ diff --git a/examples/common/common.c b/examples/common/common.c index 8f58787..91ca0da 100644 --- a/examples/common/common.c +++ b/examples/common/common.c @@ -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 */ @@ -29,9 +29,11 @@ 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); } /*! @@ -39,9 +41,11 @@ BME68X_INTF_RET_TYPE bme68x_i2c_read(uint8_t reg_addr, uint8_t *reg_data, uint32 */ 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); } /*! @@ -49,9 +53,11 @@ BME68X_INTF_RET_TYPE bme68x_i2c_write(uint8_t reg_addr, const uint8_t *reg_data, */ 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); } /*! @@ -59,9 +65,11 @@ BME68X_INTF_RET_TYPE bme68x_spi_read(uint8_t reg_addr, uint8_t *reg_data, uint32 */ 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); } /*! @@ -69,6 +77,7 @@ BME68X_INTF_RET_TYPE bme68x_spi_write(uint8_t reg_addr, const uint8_t *reg_data, */ void bme68x_delay_us(uint32_t period, void *intf_ptr) { + (void)intf_ptr; coines_delay_usec(period); } @@ -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 */ @@ -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) @@ -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); @@ -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); } diff --git a/examples/common/common.h b/examples/common/common.h index 5560f37..37fabb2 100644 --- a/examples/common/common.h +++ b/examples/common/common.h @@ -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 */ diff --git a/examples/forced_mode/forced_mode.c b/examples/forced_mode/forced_mode.c index 94e8360..eea6d3d 100644 --- a/examples/forced_mode/forced_mode.c +++ b/examples/forced_mode/forced_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Bosch Sensortec GmbH + * Copyright (C) 2023 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * diff --git a/examples/parallel_mode/parallel_mode.c b/examples/parallel_mode/parallel_mode.c index ec4011d..8c39d8b 100644 --- a/examples/parallel_mode/parallel_mode.c +++ b/examples/parallel_mode/parallel_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Bosch Sensortec GmbH + * Copyright (C) 2023 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * @@ -50,7 +50,7 @@ int main(void) * For I2C : BME68X_I2C_INTF * For SPI : BME68X_SPI_INTF */ - rslt = bme68x_interface_init(&bme, BME68X_I2C_INTF); + rslt = bme68x_interface_init(&bme, BME68X_SPI_INTF); bme68x_check_rslt("bme68x_interface_init", rslt); rslt = bme68x_init(&bme); @@ -75,7 +75,7 @@ int main(void) heatr_conf.heatr_dur_prof = mul_prof; /* Shared heating duration in milliseconds */ - heatr_conf.shared_heatr_dur = 140 - (bme68x_get_meas_dur(BME68X_PARALLEL_MODE, &conf, &bme) / 1000); + heatr_conf.shared_heatr_dur = (uint16_t)(140 - (bme68x_get_meas_dur(BME68X_PARALLEL_MODE, &conf, &bme) / 1000)); heatr_conf.profile_len = 10; rslt = bme68x_set_heatr_conf(BME68X_PARALLEL_MODE, &heatr_conf, &bme); diff --git a/examples/self_test/self_test.c b/examples/self_test/self_test.c index a6096a0..a176fd8 100644 --- a/examples/self_test/self_test.c +++ b/examples/self_test/self_test.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Bosch Sensortec GmbH + * Copyright (C) 2023 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * @@ -24,7 +24,7 @@ int main(void) * For I2C : BME68X_I2C_INTF * For SPI : BME68X_SPI_INTF */ - rslt = bme68x_interface_init(&bme, BME68X_I2C_INTF); + rslt = bme68x_interface_init(&bme, BME68X_SPI_INTF); bme68x_check_rslt("bme68x_interface_init", rslt); rslt = bme68x_init(&bme); diff --git a/examples/sequential_mode/sequential_mode.c b/examples/sequential_mode/sequential_mode.c index 0717cf9..aa854ab 100644 --- a/examples/sequential_mode/sequential_mode.c +++ b/examples/sequential_mode/sequential_mode.c @@ -1,5 +1,5 @@ /** - * Copyright (C) 2021 Bosch Sensortec GmbH + * Copyright (C) 2023 Bosch Sensortec GmbH * * SPDX-License-Identifier: BSD-3-Clause * @@ -44,7 +44,7 @@ int main(void) * For I2C : BME68X_I2C_INTF * For SPI : BME68X_SPI_INTF */ - rslt = bme68x_interface_init(&bme, BME68X_I2C_INTF); + rslt = bme68x_interface_init(&bme, BME68X_SPI_INTF); bme68x_check_rslt("bme68x_interface_init", rslt); rslt = bme68x_init(&bme);