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