diff --git a/LICENSE b/LICENSE index 237464c..df241f2 100644 --- a/LICENSE +++ b/LICENSE @@ -1,39 +1,30 @@ -Copyright (C) 2016 - 2017 Bosch Sensortec GmbH +Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. + +BSD-3-Clause Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: -Redistributions of source code must retain the above copyright -notice, this list of conditions and the following disclaimer. - -Redistributions in binary form must reproduce the above copyright -notice, this list of conditions and the following disclaimer in the -documentation and/or other materials provided with the distribution. +1. Redistributions of source code must retain the above copyright + notice, this list of conditions and the following disclaimer. -Neither the name of the copyright holder nor the names of the -contributors may be used to endorse or promote products derived from -this software without specific prior written permission. +2. Redistributions in binary form must reproduce the above copyright + notice, this list of conditions and the following disclaimer in the + documentation and/or other materials provided with the distribution. -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND -CONTRIBUTORS "AS IS" AND ANY EXPRESS OR -IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED -WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE -DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER -OR CONTRIBUTORS BE LIABLE FOR ANY -DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, -OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, -PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; -LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, -WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN -ANY WAY OUT OF THE USE OF THIS -SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE +3. Neither the name of the copyright holder nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. -The information provided is believed to be accurate and reliable. -The copyright holder assumes no responsibility -for the consequences of use -of such information nor for any infringement of patents or -other rights of third parties which may result from its use. -No license is granted by implication or otherwise under any patent or -patent rights of the copyright holder. \ No newline at end of file +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +POSSIBILITY OF SUCH DAMAGE. \ No newline at end of file diff --git a/README.md b/README.md index 0a01d2b..f76f7c9 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,9 @@ The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files. ## Version File | Version | Date --------------|---------|------------ -bme280.c | 3.3.7 | 26 Aug 2019 -bme280.h | 3.3.7 | 26 Aug 2019 -bme280_defs.h | 3.3.7 | 26 Aug 2019 +bme280.c | 3.4.1 | 10 Jan 2020 +bme280.h | 3.4.1 | 10 Jan 2020 +bme280_defs.h | 3.4.1 | 10 Jan 2020 ## Integration details * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project. @@ -103,6 +103,7 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev) { int8_t rslt; uint8_t settings_sel; + uint32_t req_delay; struct bme280_data comp_data; /* Recommended mode of operation: Indoor navigation */ @@ -114,13 +115,17 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev) settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; rslt = bme280_set_sensor_settings(settings_sel, dev); + + /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled + * and the oversampling configuration. */ + req_delay = bme280_cal_meas_delay(&dev->settings); printf("Temperature, Pressure, Humidity\r\n"); /* Continuously stream sensor data */ while (1) { rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev); /* Wait for the measurement to complete and print data @25Hz */ - dev->delay_ms(40); + dev->delay_ms(req_delay); rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev); print_sensor_data(&comp_data); } diff --git a/bme280.c b/bme280.c index 565afce..6085115 100644 --- a/bme280.c +++ b/bme280.c @@ -1,49 +1,40 @@ -/**\mainpage - * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the copyright holder nor the names of the - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - * - * The information provided is believed to be accurate and reliable. - * The copyright holder assumes no responsibility - * for the consequences of use - * of such information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of the copyright holder. - * - * File bme280.c - * Date 26 Aug 2019 - * Version 3.3.7 - * - */ +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme280.c +* @date 10/01/2020 +* @version 3.4.1 +* +*/ /*! @file bme280.c * @brief Sensor driver for BME280 sensor @@ -731,9 +722,9 @@ void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data data_xlsb = (uint32_t)reg_data[5] >> 4; uncomp_data->temperature = data_msb | data_lsb | data_xlsb; - /* Store the parsed register values for temperature data */ - data_lsb = (uint32_t)reg_data[6] << 8; - data_msb = (uint32_t)reg_data[7]; + /* Store the parsed register values for humidity data */ + data_msb = (uint32_t)reg_data[6] << 8; + data_lsb = (uint32_t)reg_data[7]; uncomp_data->humidity = data_msb | data_lsb; } @@ -781,6 +772,56 @@ int8_t bme280_compensate_data(uint8_t sensor_comp, return rslt; } +/*! + * @brief This API is used to calculate the maximum delay in milliseconds required for the + * temperature/pressure/humidity(which ever at enabled) measurement to complete. + */ +uint32_t bme280_cal_meas_delay(const struct bme280_settings *settings) +{ + uint32_t max_delay; + uint8_t temp_osr; + uint8_t pres_osr; + uint8_t hum_osr; + + /*Array to map OSR config register value to actual OSR */ + uint8_t osr_sett_to_act_osr[] = { 0, 1, 2, 4, 8, 16 }; + + /* Mapping osr settings to the actual osr values e.g. 0b101 -> osr X16 */ + if (settings->osr_t <= 5) + { + temp_osr = osr_sett_to_act_osr[settings->osr_t]; + } + else + { + temp_osr = 16; + } + + if (settings->osr_p <= 5) + { + pres_osr = osr_sett_to_act_osr[settings->osr_p]; + } + else + { + pres_osr = 16; + } + + if (settings->osr_h <= 5) + { + hum_osr = osr_sett_to_act_osr[settings->osr_h]; + } + else + { + hum_osr = 16; + } + + max_delay = + (uint32_t)((BME280_MEAS_OFFSET + (BME280_MEAS_DUR * temp_osr) + + ((BME280_MEAS_DUR * pres_osr) + BME280_PRES_HUM_MEAS_OFFSET) + + ((BME280_MEAS_DUR * hum_osr) + BME280_PRES_HUM_MEAS_OFFSET)) / BME280_MEAS_SCALING_FACTOR); + + return max_delay; +} + /*! * @brief This internal API sets the oversampling settings for pressure, * temperature and humidity in the sensor. @@ -1143,10 +1184,10 @@ static int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_da int32_t temperature_min = -4000; int32_t temperature_max = 8500; - var1 = (int32_t)((uncomp_data->temperature / 8) - ((int32_t)calib_data->dig_T1 * 2)); - var1 = (var1 * ((int32_t)calib_data->dig_T2)) / 2048; - var2 = (int32_t)((uncomp_data->temperature / 16) - ((int32_t)calib_data->dig_T1)); - var2 = (((var2 * var2) / 4096) * ((int32_t)calib_data->dig_T3)) / 16384; + var1 = (int32_t)((uncomp_data->temperature / 8) - ((int32_t)calib_data->dig_t1 * 2)); + var1 = (var1 * ((int32_t)calib_data->dig_t2)) / 2048; + var2 = (int32_t)((uncomp_data->temperature / 16) - ((int32_t)calib_data->dig_t1)); + var2 = (((var2 * var2) / 4096) * ((int32_t)calib_data->dig_t3)) / 16384; calib_data->t_fine = var1 + var2; temperature = (calib_data->t_fine * 5 + 128) / 256; if (temperature < temperature_min) @@ -1179,21 +1220,21 @@ static uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data uint32_t pressure_max = 11000000; var1 = ((int64_t)calib_data->t_fine) - 128000; - var2 = var1 * var1 * (int64_t)calib_data->dig_P6; - var2 = var2 + ((var1 * (int64_t)calib_data->dig_P5) * 131072); - var2 = var2 + (((int64_t)calib_data->dig_P4) * 34359738368); - var1 = ((var1 * var1 * (int64_t)calib_data->dig_P3) / 256) + ((var1 * ((int64_t)calib_data->dig_P2) * 4096)); + var2 = var1 * var1 * (int64_t)calib_data->dig_p6; + var2 = var2 + ((var1 * (int64_t)calib_data->dig_p5) * 131072); + var2 = var2 + (((int64_t)calib_data->dig_p4) * 34359738368); + var1 = ((var1 * var1 * (int64_t)calib_data->dig_p3) / 256) + ((var1 * ((int64_t)calib_data->dig_p2) * 4096)); var3 = ((int64_t)1) * 140737488355328; - var1 = (var3 + var1) * ((int64_t)calib_data->dig_P1) / 8589934592; + var1 = (var3 + var1) * ((int64_t)calib_data->dig_p1) / 8589934592; /* To avoid divide by zero exception */ if (var1 != 0) { var4 = 1048576 - uncomp_data->pressure; var4 = (((var4 * INT64_C(2147483648)) - var2) * 3125) / var1; - var1 = (((int64_t)calib_data->dig_P9) * (var4 / 8192) * (var4 / 8192)) / 33554432; - var2 = (((int64_t)calib_data->dig_P8) * var4) / 524288; - var4 = ((var4 + var1 + var2) / 256) + (((int64_t)calib_data->dig_P7) * 16); + var1 = (((int64_t)calib_data->dig_p9) * (var4 / 8192) * (var4 / 8192)) / 33554432; + var2 = (((int64_t)calib_data->dig_p8) * var4) / 524288; + var4 = ((var4 + var1 + var2) / 256) + (((int64_t)calib_data->dig_p7) * 16); pressure = (uint32_t)(((var4 / 2) * 100) / 128); if (pressure < pressure_min) { @@ -1289,16 +1330,16 @@ static uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data var1 = calib_data->t_fine - ((int32_t)76800); var2 = (int32_t)(uncomp_data->humidity * 16384); - var3 = (int32_t)(((int32_t)calib_data->dig_H4) * 1048576); - var4 = ((int32_t)calib_data->dig_H5) * var1; + var3 = (int32_t)(((int32_t)calib_data->dig_h4) * 1048576); + var4 = ((int32_t)calib_data->dig_h5) * var1; var5 = (((var2 - var3) - var4) + (int32_t)16384) / 32768; - var2 = (var1 * ((int32_t)calib_data->dig_H6)) / 1024; - var3 = (var1 * ((int32_t)calib_data->dig_H3)) / 2048; + var2 = (var1 * ((int32_t)calib_data->dig_h6)) / 1024; + var3 = (var1 * ((int32_t)calib_data->dig_h3)) / 2048; var4 = ((var2 * (var3 + (int32_t)32768)) / 1024) + (int32_t)2097152; - var2 = ((var4 * ((int32_t)calib_data->dig_H2)) + 8192) / 16384; + var2 = ((var4 * ((int32_t)calib_data->dig_h2)) + 8192) / 16384; var3 = var5 * var2; var4 = ((var3 / 32768) * (var3 / 32768)) / 128; - var5 = var3 - ((var4 * ((int32_t)calib_data->dig_H1)) / 16); + var5 = var3 - ((var4 * ((int32_t)calib_data->dig_h1)) / 16); var5 = (var5 < 0 ? 0 : var5); var5 = (var5 > 419430400 ? 419430400 : var5); humidity = (uint32_t)(var5 / 4096); @@ -1370,19 +1411,19 @@ static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_d { struct bme280_calib_data *calib_data = &dev->calib_data; - calib_data->dig_T1 = BME280_CONCAT_BYTES(reg_data[1], reg_data[0]); - calib_data->dig_T2 = (int16_t)BME280_CONCAT_BYTES(reg_data[3], reg_data[2]); - calib_data->dig_T3 = (int16_t)BME280_CONCAT_BYTES(reg_data[5], reg_data[4]); - calib_data->dig_P1 = BME280_CONCAT_BYTES(reg_data[7], reg_data[6]); - calib_data->dig_P2 = (int16_t)BME280_CONCAT_BYTES(reg_data[9], reg_data[8]); - calib_data->dig_P3 = (int16_t)BME280_CONCAT_BYTES(reg_data[11], reg_data[10]); - calib_data->dig_P4 = (int16_t)BME280_CONCAT_BYTES(reg_data[13], reg_data[12]); - calib_data->dig_P5 = (int16_t)BME280_CONCAT_BYTES(reg_data[15], reg_data[14]); - calib_data->dig_P6 = (int16_t)BME280_CONCAT_BYTES(reg_data[17], reg_data[16]); - calib_data->dig_P7 = (int16_t)BME280_CONCAT_BYTES(reg_data[19], reg_data[18]); - calib_data->dig_P8 = (int16_t)BME280_CONCAT_BYTES(reg_data[21], reg_data[20]); - calib_data->dig_P9 = (int16_t)BME280_CONCAT_BYTES(reg_data[23], reg_data[22]); - calib_data->dig_H1 = reg_data[25]; + calib_data->dig_t1 = BME280_CONCAT_BYTES(reg_data[1], reg_data[0]); + calib_data->dig_t2 = (int16_t)BME280_CONCAT_BYTES(reg_data[3], reg_data[2]); + calib_data->dig_t3 = (int16_t)BME280_CONCAT_BYTES(reg_data[5], reg_data[4]); + calib_data->dig_p1 = BME280_CONCAT_BYTES(reg_data[7], reg_data[6]); + calib_data->dig_p2 = (int16_t)BME280_CONCAT_BYTES(reg_data[9], reg_data[8]); + calib_data->dig_p3 = (int16_t)BME280_CONCAT_BYTES(reg_data[11], reg_data[10]); + calib_data->dig_p4 = (int16_t)BME280_CONCAT_BYTES(reg_data[13], reg_data[12]); + calib_data->dig_p5 = (int16_t)BME280_CONCAT_BYTES(reg_data[15], reg_data[14]); + calib_data->dig_p6 = (int16_t)BME280_CONCAT_BYTES(reg_data[17], reg_data[16]); + calib_data->dig_p7 = (int16_t)BME280_CONCAT_BYTES(reg_data[19], reg_data[18]); + calib_data->dig_p8 = (int16_t)BME280_CONCAT_BYTES(reg_data[21], reg_data[20]); + calib_data->dig_p9 = (int16_t)BME280_CONCAT_BYTES(reg_data[23], reg_data[22]); + calib_data->dig_h1 = reg_data[25]; } /*! @@ -1392,20 +1433,20 @@ static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_d static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev) { struct bme280_calib_data *calib_data = &dev->calib_data; - int16_t dig_H4_lsb; - int16_t dig_H4_msb; - int16_t dig_H5_lsb; - int16_t dig_H5_msb; - - calib_data->dig_H2 = (int16_t)BME280_CONCAT_BYTES(reg_data[1], reg_data[0]); - calib_data->dig_H3 = reg_data[2]; - dig_H4_msb = (int16_t)(int8_t)reg_data[3] * 16; - dig_H4_lsb = (int16_t)(reg_data[4] & 0x0F); - calib_data->dig_H4 = dig_H4_msb | dig_H4_lsb; - dig_H5_msb = (int16_t)(int8_t)reg_data[5] * 16; - dig_H5_lsb = (int16_t)(reg_data[4] >> 4); - calib_data->dig_H5 = dig_H5_msb | dig_H5_lsb; - calib_data->dig_H6 = (int8_t)reg_data[6]; + int16_t dig_h4_lsb; + int16_t dig_h4_msb; + int16_t dig_h5_lsb; + int16_t dig_h5_msb; + + calib_data->dig_h2 = (int16_t)BME280_CONCAT_BYTES(reg_data[1], reg_data[0]); + calib_data->dig_h3 = reg_data[2]; + dig_h4_msb = (int16_t)(int8_t)reg_data[3] * 16; + dig_h4_lsb = (int16_t)(reg_data[4] & 0x0F); + calib_data->dig_h4 = dig_h4_msb | dig_h4_lsb; + dig_h5_msb = (int16_t)(int8_t)reg_data[5] * 16; + dig_h5_lsb = (int16_t)(reg_data[4] >> 4); + calib_data->dig_h5 = dig_h5_msb | dig_h5_lsb; + calib_data->dig_h6 = (int8_t)reg_data[6]; } /*! diff --git a/bme280.h b/bme280.h index 414b3bd..958f0fa 100644 --- a/bme280.h +++ b/bme280.h @@ -1,50 +1,40 @@ /** - * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the copyright holder nor the names of the - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - * - * The information provided is believed to be accurate and reliable. - * The copyright holder assumes no responsibility - * for the consequences of use - * of such information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of the copyright holder. - * - * @file bme280.h - * @date 26 Aug 2019 - * @version 3.3.7 - * @brief - * - */ +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme280.h +* @date 10/01/2020 +* @version 3.4.1 +* +*/ /*! @file bme280.h * @brief Sensor driver for BME280 sensor @@ -237,6 +227,18 @@ int8_t bme280_compensate_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_calib_data *calib_data); +/*! + * @brief This API is used to calculate the maximum delay in milliseconds required for the + * temperature/pressure/humidity(which ever are enabled) measurement to complete. + * The delay depends upon the number of sensors enabled and their oversampling configuration. + * + * @param[in] settings : contains the oversampling configurations. + * + * @return delay required in milliseconds. + */ + +uint32_t bme280_cal_meas_delay(const struct bme280_settings *settings); + #ifdef __cplusplus } #endif /* End of CPP guard */ diff --git a/bme280_defs.h b/bme280_defs.h index 6c96540..40decc5 100644 --- a/bme280_defs.h +++ b/bme280_defs.h @@ -1,50 +1,40 @@ /** - * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the copyright holder nor the names of the - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - * - * The information provided is believed to be accurate and reliable. - * The copyright holder assumes no responsibility - * for the consequences of use - * of such information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of the copyright holder. - * - * @file bme280_defs.h - * @date 26 Aug 2019 - * @version 3.3.7 - * @brief - * - */ +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme280_defs.h +* @date 10/01/2020 +* @version 3.4.1 +* +*/ /*! @file bme280_defs.h * @brief Sensor driver for BME280 sensor @@ -221,6 +211,12 @@ #define BME280_OVERSAMPLING_8X UINT8_C(0x04) #define BME280_OVERSAMPLING_16X UINT8_C(0x05) +/**\name Measurement delay calculation macros */ +#define BME280_MEAS_OFFSET UINT16_C(1250) +#define BME280_MEAS_DUR UINT16_C(2300) +#define BME280_PRES_HUM_MEAS_OFFSET UINT16_C(575) +#define BME280_MEAS_SCALING_FACTOR UINT16_C(1000) + /**\name Standby duration selection macros */ #define BME280_STANDBY_TIME_0_5_MS (0x00) #define BME280_STANDBY_TIME_62_5_MS (0x01) @@ -269,24 +265,24 @@ struct bme280_calib_data */ /**@{*/ - uint16_t dig_T1; - int16_t dig_T2; - int16_t dig_T3; - uint16_t dig_P1; - int16_t dig_P2; - int16_t dig_P3; - int16_t dig_P4; - int16_t dig_P5; - int16_t dig_P6; - int16_t dig_P7; - int16_t dig_P8; - int16_t dig_P9; - uint8_t dig_H1; - int16_t dig_H2; - uint8_t dig_H3; - int16_t dig_H4; - int16_t dig_H5; - int8_t dig_H6; + uint16_t dig_t1; + int16_t dig_t2; + int16_t dig_t3; + uint16_t dig_p1; + int16_t dig_p2; + int16_t dig_p3; + int16_t dig_p4; + int16_t dig_p5; + int16_t dig_p6; + int16_t dig_p7; + int16_t dig_p8; + int16_t dig_p9; + uint8_t dig_h1; + int16_t dig_h2; + uint8_t dig_h3; + int16_t dig_h4; + int16_t dig_h5; + int8_t dig_h6; int32_t t_fine; /**@}*/ diff --git a/examples/linux_userspace.c b/examples/linux_userspace.c index 6ce3661..c360eb0 100644 --- a/examples/linux_userspace.c +++ b/examples/linux_userspace.c @@ -1,29 +1,208 @@ -/* - * Linux userspace test code, simple and mose code directy from the doco. +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file linux_userspace.c +* @date 10/01/2020 +* @version +* +*/ + +/*! + * @ingroup bme280GroupExample + * @defgroup bme280GroupExample linux_userspace + * @brief Linux userspace test code, simple and mose code directly from the doco. * compile like this: gcc linux_userspace.c ../bme280.c -I ../ -o bme280 * tested: Raspberry Pi. * Use like: ./bme280 /dev/i2c-0 + * \include linux_userspace.c */ -#include "bme280.h" -#include -#include -#include -#include + #ifdef __KERNEL__ #include #include #endif + +/******************************************************************************/ +/*! System header files */ +#include +#include +#include +#include #include #include +/******************************************************************************/ +/*! Own header files */ +#include "bme280.h" + +/*****************************************************************************/ +/*! Global variables */ int fd; -int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len); +/****************************************************************************/ +/*! Functions */ + +/*! + * @brief Function that creates a mandatory delay required in some of the APIs. + * + * @param[in] period : The required wait time in microseconds. + * @return void. + * + */ void user_delay_ms(uint32_t period); -int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len); + +/*! + * @brief Function for print the temperature, humidity and pressure data. + * + * @param[out] comp_data : Structure instance of bme280_data + * + * @note Sensor data whose can be read + * + * sens_list + * -------------- + * Pressure + * Temperature + * Humidity + * + */ void print_sensor_data(struct bme280_data *comp_data); + +/*! + * @brief Function for reading the sensor's registers through I2C bus. + * + * @param[in] id : Sensor I2C address. + * @param[in] reg_addr : Register address. + * @param[out] data : Pointer to the data buffer to store the read data. + * @param[in] len : No of bytes to read. + * + * @return Status of execution + * + * @retval 0 -> Success + * @retval > 0 -> Failure Info + * + */ +int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len); + +/*! + * @brief Function for writing the sensor's registers through I2C bus. + * + * @param[in] id : Sensor I2C address. + * @param[in] reg_addr : Register address. + * @param[in] data : Pointer to the data buffer whose value is to be written. + * @param[in] len : No of bytes to write. + * + * @return Status of execution + * + * @retval BME280_OK -> Success + * @retval BME280_E_COMM_FAIL -> Communication failure. + * + */ +int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len); + +/*! + * @brief Function reads temperature, humidity and pressure data in forced mode. + * + * @param[in] dev : Structure instance of bme280_dev. + * + * @return Result of API execution status + * + * @retval BME280_OK - Success. + * @retval BME280_E_NULL_PTR - Error: Null pointer error + * @retval BME280_E_COMM_FAIL - Error: Communication fail error + * @retval BME280_E_NVM_COPY_FAILED - Error: NVM copy failed + * + */ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev); +/*! + * @brief This function starts execution of the program. + */ +int main(int argc, char* argv[]) +{ + struct bme280_dev dev; + + /* Variable to define the result */ + int8_t rslt = BME280_OK; + + if (argc < 2) + { + fprintf(stderr, "Missing argument for i2c bus.\n"); + exit(1); + } + + /* Make sure to select BME280_I2C_ADDR_PRIM or BME280_I2C_ADDR_SEC as needed */ + dev.dev_id = BME280_I2C_ADDR_PRIM; + + /* dev.dev_id = BME280_I2C_ADDR_SEC; */ + dev.intf = BME280_I2C_INTF; + dev.read = user_i2c_read; + dev.write = user_i2c_write; + dev.delay_ms = user_delay_ms; + + if ((fd = open(argv[1], O_RDWR)) < 0) + { + fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]); + exit(1); + } + +#ifdef __KERNEL__ + if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0) + { + fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n"); + exit(1); + } +#endif + + /* Initialize the bme280 */ + rslt = bme280_init(&dev); + if (rslt != BME280_OK) + { + fprintf(stderr, "Failed to initialize the device (code %+d).\n", rslt); + exit(1); + } + + rslt = stream_sensor_data_forced_mode(&dev); + if (rslt != BME280_OK) + { + fprintf(stderr, "Failed to stream sensor data (code %+d).\n", rslt); + exit(1); + } + + return 0; +} + +/*! + * @brief This function reading the sensor's registers through I2C bus. + */ int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) { write(fd, ®_addr, 1); @@ -32,11 +211,19 @@ int8_t user_i2c_read(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) return 0; } +/*! + * @brief This function provides the delay for required time (Microseconds) as per the input provided in some of the + * APIs + */ void user_delay_ms(uint32_t period) { + /* Milliseconds convert to microseconds */ usleep(period * 1000); } +/*! + * @brief This function for writing the sensor's registers through I2C bus. + */ int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) { int8_t *buf; @@ -45,14 +232,22 @@ int8_t user_i2c_write(uint8_t id, uint8_t reg_addr, uint8_t *data, uint16_t len) buf[0] = reg_addr; memcpy(buf + 1, data, len); if (write(fd, buf, len + 1) < len) + { return BME280_E_COMM_FAIL; + } + free(buf); - return BME280_OK; + + return BME280_OK; } +/*! + * @brief This API used to print the sensor temperature, pressure and humidity data. + */ void print_sensor_data(struct bme280_data *comp_data) { float temp, press, hum; + #ifdef BME280_FLOAT_ENABLE temp = comp_data->temperature; press = 0.01 * comp_data->pressure; @@ -71,10 +266,21 @@ void print_sensor_data(struct bme280_data *comp_data) printf("%0.2lf deg C, %0.2lf hPa, %0.2lf%%\n", temp, press, hum); } +/*! + * @brief This API reads the sensor temperature, pressure and humidity data in forced mode. + */ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev) { - int8_t rslt; - uint8_t settings_sel; + /* Variable to define the result */ + int8_t rslt = BME280_OK; + + /* Variable to define the selecting sensors */ + uint8_t settings_sel = 0; + + /* Variable to store minimum wait time between consecutive measurement in force mode */ + uint32_t req_delay; + + /* Structure to get the pressure, temperature and humidity values */ struct bme280_data comp_data; /* Recommended mode of operation: Indoor navigation */ @@ -85,87 +291,43 @@ int8_t stream_sensor_data_forced_mode(struct bme280_dev *dev) settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL; + /* Set the sensor settings */ rslt = bme280_set_sensor_settings(settings_sel, dev); - if (rslt != BME280_OK) - { - fprintf(stderr, "Failed to set sensor settings (code %+d).", rslt); - return rslt; - } + if (rslt != BME280_OK) + { + fprintf(stderr, "Failed to set sensor settings (code %+d).", rslt); + + return rslt; + } printf("Temperature, Pressure, Humidity\n"); + + /*Calculate the minimum delay required between consecutive measurement based upon the sensor enabled + * and the oversampling configuration. */ + req_delay = bme280_cal_meas_delay(&dev->settings); + /* Continuously stream sensor data */ while (1) { + /* Set the sensor to forced mode */ rslt = bme280_set_sensor_mode(BME280_FORCED_MODE, dev); if (rslt != BME280_OK) { fprintf(stderr, "Failed to set sensor mode (code %+d).", rslt); break; } - /* Wait for the measurement to complete and print data @25Hz */ - dev->delay_ms(40); + + /* Wait for the measurement to complete and print data */ + dev->delay_ms(req_delay); rslt = bme280_get_sensor_data(BME280_ALL, &comp_data, dev); if (rslt != BME280_OK) { fprintf(stderr, "Failed to get sensor data (code %+d).", rslt); break; } + print_sensor_data(&comp_data); } return rslt; } - -int main(int argc, char* argv[]) -{ - struct bme280_dev dev; - int8_t rslt = BME280_OK; - - if (argc < 2) - { - fprintf(stderr, "Missing argument for i2c bus.\n"); - exit(1); - } - - // make sure to select BME280_I2C_ADDR_PRIM - // or BME280_I2C_ADDR_SEC as needed - dev.dev_id = -#if 1 - BME280_I2C_ADDR_PRIM -#else - BME280_I2C_ADDR_SEC -#endif -; - - dev.intf = BME280_I2C_INTF; - dev.read = user_i2c_read; - dev.write = user_i2c_write; - dev.delay_ms = user_delay_ms; - - if ((fd = open(argv[1], O_RDWR)) < 0) - { - fprintf(stderr, "Failed to open the i2c bus %s\n", argv[1]); - exit(1); - } -#ifdef __KERNEL__ - if (ioctl(fd, I2C_SLAVE, dev.dev_id) < 0) - { - fprintf(stderr, "Failed to acquire bus access and/or talk to slave.\n"); - exit(1); - } -#endif - - rslt = bme280_init(&dev); - if (rslt != BME280_OK) - { - fprintf(stderr, "Failed to initialize the device (code %+d).\n", rslt); - exit(1); -} - rslt = stream_sensor_data_forced_mode(&dev); - if (rslt != BME280_OK) - { - fprintf(stderr, "Failed to stream sensor data (code %+d).\n", rslt); - exit(1); - } - return 0; -} diff --git a/selftest/bme280_selftest.c b/selftest/bme280_selftest.c index 5cbe031..28f7fdd 100644 --- a/selftest/bme280_selftest.c +++ b/selftest/bme280_selftest.c @@ -1,49 +1,40 @@ -/**\mainpage - * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the copyright holder nor the names of the - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - * - * The information provided is believed to be accurate and reliable. - * The copyright holder assumes no responsibility - * for the consequences of use - * of such information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of the copyright holder. - * - * File bme280_selftest.c - * Date 26 Aug 2019 - * Version 3.3.7 - * - */ +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme280_selftest.c +* @date 10/01/2020 +* @version 3.4.1 +* +*/ #include "bme280_selftest.h" @@ -73,7 +64,7 @@ static uint8_t crc_calculate(uint8_t *mem_values, uint8_t mem_length); * @return Result of API execution status * @retval zero -> self test success / +ve value -> warning(self test fail) */ -int8_t bme280_crc_selftest(const struct bme280_dev *dev) +int8_t bme280_selftest_crc(const struct bme280_dev *dev) { int8_t rslt; uint8_t reg_addr; @@ -128,14 +119,14 @@ static uint8_t crc_calculate(uint8_t *mem_values, uint8_t mem_length) { uint32_t crc_reg = 0xFF; uint8_t polynomial = 0x1D; - uint8_t bitNo, index; + uint8_t bitno, index; uint8_t din = 0; for (index = 0; index < mem_length; index++) { - for (bitNo = 0; bitNo < 8; bitNo++) + for (bitno = 0; bitno < 8; bitno++) { - if (((crc_reg & 0x80) > 0) != ((mem_values[index] & 0x80) > 0)) + if ((crc_reg & 0x80) != (mem_values[index] & 0x80)) { din = 1; } diff --git a/selftest/bme280_selftest.h b/selftest/bme280_selftest.h index 2cb9509..2a9fe90 100644 --- a/selftest/bme280_selftest.h +++ b/selftest/bme280_selftest.h @@ -1,49 +1,40 @@ -/**\mainpage - * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * - * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * Neither the name of the copyright holder nor the names of the - * contributors may be used to endorse or promote products derived from - * this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER - * OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, - * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, - * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN - * ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE - * - * The information provided is believed to be accurate and reliable. - * The copyright holder assumes no responsibility - * for the consequences of use - * of such information nor for any infringement of patents or - * other rights of third parties which may result from its use. - * No license is granted by implication or otherwise under any patent or - * patent rights of the copyright holder. - * - * File bme280_selftest.h - * Date 26 Aug 2019 - * Version 3.3.7 - * - */ +/** +* Copyright (c) 2020 Bosch Sensortec GmbH. All rights reserved. +* +* BSD-3-Clause +* +* Redistribution and use in source and binary forms, with or without +* modification, are permitted provided that the following conditions are met: +* +* 1. Redistributions of source code must retain the above copyright +* notice, this list of conditions and the following disclaimer. +* +* 2. Redistributions in binary form must reproduce the above copyright +* notice, this list of conditions and the following disclaimer in the +* documentation and/or other materials provided with the distribution. +* +* 3. Neither the name of the copyright holder nor the names of its +* contributors may be used to endorse or promote products derived from +* this software without specific prior written permission. +* +* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS +* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT +* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS +* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE +* COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, +* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING +* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +* POSSIBILITY OF SUCH DAMAGE. +* +* @file bme280_selftest.h +* @date 10/01/2020 +* @version 3.4.1 +* +*/ /*! * @addtogroup bme280_selftest @@ -71,7 +62,7 @@ extern "C" { * @return Result of API execution status * @retval zero -> Success / +ve value -> Warning / -ve value -> Error */ -int8_t bme280_crc_selftest(const struct bme280_dev *dev); +int8_t bme280_selftest_crc(const struct bme280_dev *dev); /*! CPP guard */ #ifdef __cplusplus