uses BBC micro:bit to measure and display indoor air quality using Bosch BME680 and/or Sensirion SGP30

Dependencies:   microbit

uses Bosch BME680 and/or Sensirion SGP30 sensors to measure indor air quality

sensors should be connected to BBC micro:bit using i2c

commands are received and data is being sent using uBit / nordic radio protocol

display ---

last line always indicates: - first dot: bme680 detected - second dot: sgp30 detected - third dot: sgp 30 setting humidity/temperature - fourth dor: sgp30 measuring - fith dot: bme680 measuring

the detect dots should be in a stable state (not blinking) the measuring dots should be blinking (constant light means: measurement failed)

if only one bme680 is present: - first 3 lines indicate gas resistence (air quality / more dots == worse quality) - fourth line indicates humidity level

if only sgp30 is present: - first two lines indicate SGP30 VOC level - third and fourth line indicate sgp30 CO2 level

if both sensors are present: - first line indicates SGP30 VOC level - second line line indicates sgp30 CO2 level - third line indicates bme680 gas resistence (air quality) - fourth line indicates bme 680 humidity level

buttons - B display state, switches betweeen - full bright - low light - display off

AB reset sgp30 baseline in non volatile storage

data logging -- during measurements the minimum and mximum values for each measured value (temperature, air pressure, humidity,gas resistance, VOC, CO2) are being stored in non volatile storage those (and the last measurement results) are being shown when btn A has been pressed

Committer:
jsa1969
Date:
Fri Jun 03 17:05:56 2022 +0000
Revision:
60:6b21ca38ee7c
Parent:
0:cef60cc92da0
cleanup

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jsa1969 0:cef60cc92da0 1 /**
jsa1969 0:cef60cc92da0 2 * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
jsa1969 0:cef60cc92da0 3 *
jsa1969 0:cef60cc92da0 4 * Redistribution and use in source and binary forms, with or without
jsa1969 0:cef60cc92da0 5 * modification, are permitted provided that the following conditions are met:
jsa1969 0:cef60cc92da0 6 *
jsa1969 0:cef60cc92da0 7 * Redistributions of source code must retain the above copyright
jsa1969 0:cef60cc92da0 8 * notice, this list of conditions and the following disclaimer.
jsa1969 0:cef60cc92da0 9 *
jsa1969 0:cef60cc92da0 10 * Redistributions in binary form must reproduce the above copyright
jsa1969 0:cef60cc92da0 11 * notice, this list of conditions and the following disclaimer in the
jsa1969 0:cef60cc92da0 12 * documentation and/or other materials provided with the distribution.
jsa1969 0:cef60cc92da0 13 *
jsa1969 0:cef60cc92da0 14 * Neither the name of the copyright holder nor the names of the
jsa1969 0:cef60cc92da0 15 * contributors may be used to endorse or promote products derived from
jsa1969 0:cef60cc92da0 16 * this software without specific prior written permission.
jsa1969 0:cef60cc92da0 17 *
jsa1969 0:cef60cc92da0 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
jsa1969 0:cef60cc92da0 19 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
jsa1969 0:cef60cc92da0 20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
jsa1969 0:cef60cc92da0 21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
jsa1969 0:cef60cc92da0 22 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
jsa1969 0:cef60cc92da0 23 * OR CONTRIBUTORS BE LIABLE FOR ANY
jsa1969 0:cef60cc92da0 24 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
jsa1969 0:cef60cc92da0 25 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
jsa1969 0:cef60cc92da0 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
jsa1969 0:cef60cc92da0 27 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
jsa1969 0:cef60cc92da0 28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
jsa1969 0:cef60cc92da0 29 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
jsa1969 0:cef60cc92da0 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
jsa1969 0:cef60cc92da0 31 * ANY WAY OUT OF THE USE OF THIS
jsa1969 0:cef60cc92da0 32 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
jsa1969 0:cef60cc92da0 33 *
jsa1969 0:cef60cc92da0 34 * The information provided is believed to be accurate and reliable.
jsa1969 0:cef60cc92da0 35 * The copyright holder assumes no responsibility
jsa1969 0:cef60cc92da0 36 * for the consequences of use
jsa1969 0:cef60cc92da0 37 * of such information nor for any infringement of patents or
jsa1969 0:cef60cc92da0 38 * other rights of third parties which may result from its use.
jsa1969 0:cef60cc92da0 39 * No license is granted by implication or otherwise under any patent or
jsa1969 0:cef60cc92da0 40 * patent rights of the copyright holder.
jsa1969 0:cef60cc92da0 41 *
jsa1969 0:cef60cc92da0 42 * @file bme680_defs.h
jsa1969 0:cef60cc92da0 43 * @date 22 Feb 2018
jsa1969 0:cef60cc92da0 44 * @version 3.5.8
jsa1969 0:cef60cc92da0 45 * @brief
jsa1969 0:cef60cc92da0 46 *
jsa1969 0:cef60cc92da0 47 */
jsa1969 0:cef60cc92da0 48
jsa1969 0:cef60cc92da0 49 /*! @file bme680_defs.h
jsa1969 0:cef60cc92da0 50 @brief Sensor driver for BME680 sensor */
jsa1969 0:cef60cc92da0 51 /*!
jsa1969 0:cef60cc92da0 52 * @defgroup BME680 SENSOR API
jsa1969 0:cef60cc92da0 53 * @brief
jsa1969 0:cef60cc92da0 54 * @{*/
jsa1969 0:cef60cc92da0 55 #ifndef BME680_DEFS_H_
jsa1969 0:cef60cc92da0 56 #define BME680_DEFS_H_
jsa1969 0:cef60cc92da0 57
jsa1969 0:cef60cc92da0 58 /********************************************************/
jsa1969 0:cef60cc92da0 59 /* header includes */
jsa1969 0:cef60cc92da0 60 #ifdef __KERNEL__
jsa1969 0:cef60cc92da0 61 #include <linux/types.h>
jsa1969 0:cef60cc92da0 62 #include <linux/kernel.h>
jsa1969 0:cef60cc92da0 63 #else
jsa1969 0:cef60cc92da0 64 #include <stdint.h>
jsa1969 0:cef60cc92da0 65 #include <stddef.h>
jsa1969 0:cef60cc92da0 66 #endif
jsa1969 0:cef60cc92da0 67
jsa1969 0:cef60cc92da0 68 /******************************************************************************/
jsa1969 0:cef60cc92da0 69 /*! @name Common macros */
jsa1969 0:cef60cc92da0 70 /******************************************************************************/
jsa1969 0:cef60cc92da0 71
jsa1969 0:cef60cc92da0 72 #if !defined(UINT8_C) && !defined(INT8_C)
jsa1969 0:cef60cc92da0 73 #define INT8_C(x) int8_t(x)
jsa1969 0:cef60cc92da0 74 #define UINT8_C(x) uint8_t(x)
jsa1969 0:cef60cc92da0 75 #endif
jsa1969 0:cef60cc92da0 76
jsa1969 0:cef60cc92da0 77 #if !defined(UINT16_C) && !defined(INT16_C)
jsa1969 0:cef60cc92da0 78 #define INT16_C(x) int16_t(x)
jsa1969 0:cef60cc92da0 79 #define UINT16_C(x) uint16_t(x)
jsa1969 0:cef60cc92da0 80 #endif
jsa1969 0:cef60cc92da0 81
jsa1969 0:cef60cc92da0 82 #if !defined(INT32_C) && !defined(UINT32_C)
jsa1969 0:cef60cc92da0 83 #define INT32_C(x) int32_t(x)
jsa1969 0:cef60cc92da0 84 #define UINT32_C(x) uint32_t(x)
jsa1969 0:cef60cc92da0 85 #endif
jsa1969 0:cef60cc92da0 86
jsa1969 0:cef60cc92da0 87 #if !defined(INT64_C) && !defined(UINT64_C)
jsa1969 0:cef60cc92da0 88 #define INT64_C(x) S64_C(x)
jsa1969 0:cef60cc92da0 89 #define UINT64_C(x) U64_C(x)
jsa1969 0:cef60cc92da0 90 #endif
jsa1969 0:cef60cc92da0 91
jsa1969 0:cef60cc92da0 92 /**@}*/
jsa1969 0:cef60cc92da0 93
jsa1969 0:cef60cc92da0 94 /**\name C standard macros */
jsa1969 0:cef60cc92da0 95 #ifndef NULL
jsa1969 0:cef60cc92da0 96 #ifdef __cplusplus
jsa1969 0:cef60cc92da0 97 #define NULL 0
jsa1969 0:cef60cc92da0 98 #else
jsa1969 0:cef60cc92da0 99 #define NULL ((void *) 0)
jsa1969 0:cef60cc92da0 100 #endif
jsa1969 0:cef60cc92da0 101 #endif
jsa1969 0:cef60cc92da0 102
jsa1969 0:cef60cc92da0 103 /** BME680 configuration macros */
jsa1969 0:cef60cc92da0 104 /** Enable or un-comment the macro to provide floating point data output */
jsa1969 0:cef60cc92da0 105 #ifndef BME680_FLOAT_POINT_COMPENSATION
jsa1969 0:cef60cc92da0 106 /* #define BME680_FLOAT_POINT_COMPENSATION */
jsa1969 0:cef60cc92da0 107 #endif
jsa1969 0:cef60cc92da0 108
jsa1969 0:cef60cc92da0 109 /** BME680 General config */
jsa1969 0:cef60cc92da0 110 #define BME680_POLL_PERIOD_MS UINT8_C(10)
jsa1969 0:cef60cc92da0 111
jsa1969 0:cef60cc92da0 112 /** BME680 I2C addresses */
jsa1969 0:cef60cc92da0 113 #define BME680_I2C_ADDR_PRIMARY UINT8_C(0x76)
jsa1969 0:cef60cc92da0 114 #define BME680_I2C_ADDR_SECONDARY UINT8_C(0x77)
jsa1969 0:cef60cc92da0 115
jsa1969 0:cef60cc92da0 116 /** BME680 unique chip identifier */
jsa1969 0:cef60cc92da0 117 #define BME680_CHIP_ID UINT8_C(0x61)
jsa1969 0:cef60cc92da0 118
jsa1969 0:cef60cc92da0 119 /** BME680 coefficients related defines */
jsa1969 0:cef60cc92da0 120 #define BME680_COEFF_SIZE UINT8_C(41)
jsa1969 0:cef60cc92da0 121 #define BME680_COEFF_ADDR1_LEN UINT8_C(25)
jsa1969 0:cef60cc92da0 122 #define BME680_COEFF_ADDR2_LEN UINT8_C(16)
jsa1969 0:cef60cc92da0 123
jsa1969 0:cef60cc92da0 124 /** BME680 field_x related defines */
jsa1969 0:cef60cc92da0 125 #define BME680_FIELD_LENGTH UINT8_C(15)
jsa1969 0:cef60cc92da0 126 #define BME680_FIELD_ADDR_OFFSET UINT8_C(17)
jsa1969 0:cef60cc92da0 127
jsa1969 0:cef60cc92da0 128 /** Soft reset command */
jsa1969 0:cef60cc92da0 129 #define BME680_SOFT_RESET_CMD UINT8_C(0xb6)
jsa1969 0:cef60cc92da0 130
jsa1969 0:cef60cc92da0 131 /** Error code definitions */
jsa1969 0:cef60cc92da0 132 #define BME680_OK INT8_C(0)
jsa1969 0:cef60cc92da0 133 /* Errors */
jsa1969 0:cef60cc92da0 134 #define BME680_E_NULL_PTR INT8_C(-1)
jsa1969 0:cef60cc92da0 135 #define BME680_E_COM_FAIL INT8_C(-2)
jsa1969 0:cef60cc92da0 136 #define BME680_E_DEV_NOT_FOUND INT8_C(-3)
jsa1969 0:cef60cc92da0 137 #define BME680_E_INVALID_LENGTH INT8_C(-4)
jsa1969 0:cef60cc92da0 138 #define BME680_W_SELF_TEST_FAILED INT8_C(-5)
jsa1969 0:cef60cc92da0 139
jsa1969 0:cef60cc92da0 140 /* Warnings */
jsa1969 0:cef60cc92da0 141 #define BME680_W_DEFINE_PWR_MODE INT8_C(1)
jsa1969 0:cef60cc92da0 142 #define BME680_W_NO_NEW_DATA INT8_C(2)
jsa1969 0:cef60cc92da0 143
jsa1969 0:cef60cc92da0 144 /* Info's */
jsa1969 0:cef60cc92da0 145 #define BME680_I_MIN_CORRECTION UINT8_C(1)
jsa1969 0:cef60cc92da0 146 #define BME680_I_MAX_CORRECTION UINT8_C(2)
jsa1969 0:cef60cc92da0 147
jsa1969 0:cef60cc92da0 148 /** Register map */
jsa1969 0:cef60cc92da0 149 /** Other coefficient's address */
jsa1969 0:cef60cc92da0 150 #define BME680_ADDR_RES_HEAT_VAL_ADDR UINT8_C(0x00)
jsa1969 0:cef60cc92da0 151 #define BME680_ADDR_RES_HEAT_RANGE_ADDR UINT8_C(0x02)
jsa1969 0:cef60cc92da0 152 #define BME680_ADDR_RANGE_SW_ERR_ADDR UINT8_C(0x04)
jsa1969 0:cef60cc92da0 153 #define BME680_ADDR_SENS_CONF_START UINT8_C(0x5A)
jsa1969 0:cef60cc92da0 154 #define BME680_ADDR_GAS_CONF_START UINT8_C(0x64)
jsa1969 0:cef60cc92da0 155
jsa1969 0:cef60cc92da0 156 /** Field settings */
jsa1969 0:cef60cc92da0 157 #define BME680_FIELD0_ADDR UINT8_C(0x1d)
jsa1969 0:cef60cc92da0 158
jsa1969 0:cef60cc92da0 159 /** Heater settings */
jsa1969 0:cef60cc92da0 160 #define BME680_RES_HEAT0_ADDR UINT8_C(0x5a)
jsa1969 0:cef60cc92da0 161 #define BME680_GAS_WAIT0_ADDR UINT8_C(0x64)
jsa1969 0:cef60cc92da0 162
jsa1969 0:cef60cc92da0 163 /** Sensor configuration registers */
jsa1969 0:cef60cc92da0 164 #define BME680_CONF_HEAT_CTRL_ADDR UINT8_C(0x70)
jsa1969 0:cef60cc92da0 165 #define BME680_CONF_ODR_RUN_GAS_NBC_ADDR UINT8_C(0x71)
jsa1969 0:cef60cc92da0 166 #define BME680_CONF_OS_H_ADDR UINT8_C(0x72)
jsa1969 0:cef60cc92da0 167 #define BME680_MEM_PAGE_ADDR UINT8_C(0xf3)
jsa1969 0:cef60cc92da0 168 #define BME680_CONF_T_P_MODE_ADDR UINT8_C(0x74)
jsa1969 0:cef60cc92da0 169 #define BME680_CONF_ODR_FILT_ADDR UINT8_C(0x75)
jsa1969 0:cef60cc92da0 170
jsa1969 0:cef60cc92da0 171 /** Coefficient's address */
jsa1969 0:cef60cc92da0 172 #define BME680_COEFF_ADDR1 UINT8_C(0x89)
jsa1969 0:cef60cc92da0 173 #define BME680_COEFF_ADDR2 UINT8_C(0xe1)
jsa1969 0:cef60cc92da0 174
jsa1969 0:cef60cc92da0 175 /** Chip identifier */
jsa1969 0:cef60cc92da0 176 #define BME680_CHIP_ID_ADDR UINT8_C(0xd0)
jsa1969 0:cef60cc92da0 177
jsa1969 0:cef60cc92da0 178 /** Soft reset register */
jsa1969 0:cef60cc92da0 179 #define BME680_SOFT_RESET_ADDR UINT8_C(0xe0)
jsa1969 0:cef60cc92da0 180
jsa1969 0:cef60cc92da0 181 /** Heater control settings */
jsa1969 0:cef60cc92da0 182 #define BME680_ENABLE_HEATER UINT8_C(0x00)
jsa1969 0:cef60cc92da0 183 #define BME680_DISABLE_HEATER UINT8_C(0x08)
jsa1969 0:cef60cc92da0 184
jsa1969 0:cef60cc92da0 185 /** Gas measurement settings */
jsa1969 0:cef60cc92da0 186 #define BME680_DISABLE_GAS_MEAS UINT8_C(0x00)
jsa1969 0:cef60cc92da0 187 #define BME680_ENABLE_GAS_MEAS UINT8_C(0x01)
jsa1969 0:cef60cc92da0 188
jsa1969 0:cef60cc92da0 189 /** Over-sampling settings */
jsa1969 0:cef60cc92da0 190 #define BME680_OS_NONE UINT8_C(0)
jsa1969 0:cef60cc92da0 191 #define BME680_OS_1X UINT8_C(1)
jsa1969 0:cef60cc92da0 192 #define BME680_OS_2X UINT8_C(2)
jsa1969 0:cef60cc92da0 193 #define BME680_OS_4X UINT8_C(3)
jsa1969 0:cef60cc92da0 194 #define BME680_OS_8X UINT8_C(4)
jsa1969 0:cef60cc92da0 195 #define BME680_OS_16X UINT8_C(5)
jsa1969 0:cef60cc92da0 196
jsa1969 0:cef60cc92da0 197 /** IIR filter settings */
jsa1969 0:cef60cc92da0 198 #define BME680_FILTER_SIZE_0 UINT8_C(0)
jsa1969 0:cef60cc92da0 199 #define BME680_FILTER_SIZE_1 UINT8_C(1)
jsa1969 0:cef60cc92da0 200 #define BME680_FILTER_SIZE_3 UINT8_C(2)
jsa1969 0:cef60cc92da0 201 #define BME680_FILTER_SIZE_7 UINT8_C(3)
jsa1969 0:cef60cc92da0 202 #define BME680_FILTER_SIZE_15 UINT8_C(4)
jsa1969 0:cef60cc92da0 203 #define BME680_FILTER_SIZE_31 UINT8_C(5)
jsa1969 0:cef60cc92da0 204 #define BME680_FILTER_SIZE_63 UINT8_C(6)
jsa1969 0:cef60cc92da0 205 #define BME680_FILTER_SIZE_127 UINT8_C(7)
jsa1969 0:cef60cc92da0 206
jsa1969 0:cef60cc92da0 207 /** Power mode settings */
jsa1969 0:cef60cc92da0 208 #define BME680_SLEEP_MODE UINT8_C(0)
jsa1969 0:cef60cc92da0 209 #define BME680_FORCED_MODE UINT8_C(1)
jsa1969 0:cef60cc92da0 210
jsa1969 0:cef60cc92da0 211 /** Delay related macro declaration */
jsa1969 0:cef60cc92da0 212 #define BME680_RESET_PERIOD UINT32_C(10)
jsa1969 0:cef60cc92da0 213
jsa1969 0:cef60cc92da0 214 /** SPI memory page settings */
jsa1969 0:cef60cc92da0 215 #define BME680_MEM_PAGE0 UINT8_C(0x10)
jsa1969 0:cef60cc92da0 216 #define BME680_MEM_PAGE1 UINT8_C(0x00)
jsa1969 0:cef60cc92da0 217
jsa1969 0:cef60cc92da0 218 /** Ambient humidity shift value for compensation */
jsa1969 0:cef60cc92da0 219 #define BME680_HUM_REG_SHIFT_VAL UINT8_C(4)
jsa1969 0:cef60cc92da0 220
jsa1969 0:cef60cc92da0 221 /** Run gas enable and disable settings */
jsa1969 0:cef60cc92da0 222 #define BME680_RUN_GAS_DISABLE UINT8_C(0)
jsa1969 0:cef60cc92da0 223 #define BME680_RUN_GAS_ENABLE UINT8_C(1)
jsa1969 0:cef60cc92da0 224
jsa1969 0:cef60cc92da0 225 /** Buffer length macro declaration */
jsa1969 0:cef60cc92da0 226 #define BME680_TMP_BUFFER_LENGTH UINT8_C(40)
jsa1969 0:cef60cc92da0 227 #define BME680_REG_BUFFER_LENGTH UINT8_C(6)
jsa1969 0:cef60cc92da0 228 #define BME680_FIELD_DATA_LENGTH UINT8_C(3)
jsa1969 0:cef60cc92da0 229 #define BME680_GAS_REG_BUF_LENGTH UINT8_C(20)
jsa1969 0:cef60cc92da0 230
jsa1969 0:cef60cc92da0 231 /** Settings selector */
jsa1969 0:cef60cc92da0 232 #define BME680_OST_SEL UINT16_C(1)
jsa1969 0:cef60cc92da0 233 #define BME680_OSP_SEL UINT16_C(2)
jsa1969 0:cef60cc92da0 234 #define BME680_OSH_SEL UINT16_C(4)
jsa1969 0:cef60cc92da0 235 #define BME680_GAS_MEAS_SEL UINT16_C(8)
jsa1969 0:cef60cc92da0 236 #define BME680_FILTER_SEL UINT16_C(16)
jsa1969 0:cef60cc92da0 237 #define BME680_HCNTRL_SEL UINT16_C(32)
jsa1969 0:cef60cc92da0 238 #define BME680_RUN_GAS_SEL UINT16_C(64)
jsa1969 0:cef60cc92da0 239 #define BME680_NBCONV_SEL UINT16_C(128)
jsa1969 0:cef60cc92da0 240 #define BME680_GAS_SENSOR_SEL (BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)
jsa1969 0:cef60cc92da0 241
jsa1969 0:cef60cc92da0 242 /** Number of conversion settings*/
jsa1969 0:cef60cc92da0 243 #define BME680_NBCONV_MIN UINT8_C(0)
jsa1969 0:cef60cc92da0 244 #define BME680_NBCONV_MAX UINT8_C(10)
jsa1969 0:cef60cc92da0 245
jsa1969 0:cef60cc92da0 246 /** Mask definitions */
jsa1969 0:cef60cc92da0 247 #define BME680_GAS_MEAS_MSK UINT8_C(0x30)
jsa1969 0:cef60cc92da0 248 #define BME680_NBCONV_MSK UINT8_C(0X0F)
jsa1969 0:cef60cc92da0 249 #define BME680_FILTER_MSK UINT8_C(0X1C)
jsa1969 0:cef60cc92da0 250 #define BME680_OST_MSK UINT8_C(0XE0)
jsa1969 0:cef60cc92da0 251 #define BME680_OSP_MSK UINT8_C(0X1C)
jsa1969 0:cef60cc92da0 252 #define BME680_OSH_MSK UINT8_C(0X07)
jsa1969 0:cef60cc92da0 253 #define BME680_HCTRL_MSK UINT8_C(0x08)
jsa1969 0:cef60cc92da0 254 #define BME680_RUN_GAS_MSK UINT8_C(0x10)
jsa1969 0:cef60cc92da0 255 #define BME680_MODE_MSK UINT8_C(0x03)
jsa1969 0:cef60cc92da0 256 #define BME680_RHRANGE_MSK UINT8_C(0x30)
jsa1969 0:cef60cc92da0 257 #define BME680_RSERROR_MSK UINT8_C(0xf0)
jsa1969 0:cef60cc92da0 258 #define BME680_NEW_DATA_MSK UINT8_C(0x80)
jsa1969 0:cef60cc92da0 259 #define BME680_GAS_INDEX_MSK UINT8_C(0x0f)
jsa1969 0:cef60cc92da0 260 #define BME680_GAS_RANGE_MSK UINT8_C(0x0f)
jsa1969 0:cef60cc92da0 261 #define BME680_GASM_VALID_MSK UINT8_C(0x20)
jsa1969 0:cef60cc92da0 262 #define BME680_HEAT_STAB_MSK UINT8_C(0x10)
jsa1969 0:cef60cc92da0 263 #define BME680_MEM_PAGE_MSK UINT8_C(0x10)
jsa1969 0:cef60cc92da0 264 #define BME680_SPI_RD_MSK UINT8_C(0x80)
jsa1969 0:cef60cc92da0 265 #define BME680_SPI_WR_MSK UINT8_C(0x7f)
jsa1969 0:cef60cc92da0 266 #define BME680_BIT_H1_DATA_MSK UINT8_C(0x0F)
jsa1969 0:cef60cc92da0 267
jsa1969 0:cef60cc92da0 268 /** Bit position definitions for sensor settings */
jsa1969 0:cef60cc92da0 269 #define BME680_GAS_MEAS_POS UINT8_C(4)
jsa1969 0:cef60cc92da0 270 #define BME680_FILTER_POS UINT8_C(2)
jsa1969 0:cef60cc92da0 271 #define BME680_OST_POS UINT8_C(5)
jsa1969 0:cef60cc92da0 272 #define BME680_OSP_POS UINT8_C(2)
jsa1969 0:cef60cc92da0 273 #define BME680_RUN_GAS_POS UINT8_C(4)
jsa1969 0:cef60cc92da0 274
jsa1969 0:cef60cc92da0 275 /** Array Index to Field data mapping for Calibration Data*/
jsa1969 0:cef60cc92da0 276 #define BME680_T2_LSB_REG (1)
jsa1969 0:cef60cc92da0 277 #define BME680_T2_MSB_REG (2)
jsa1969 0:cef60cc92da0 278 #define BME680_T3_REG (3)
jsa1969 0:cef60cc92da0 279 #define BME680_P1_LSB_REG (5)
jsa1969 0:cef60cc92da0 280 #define BME680_P1_MSB_REG (6)
jsa1969 0:cef60cc92da0 281 #define BME680_P2_LSB_REG (7)
jsa1969 0:cef60cc92da0 282 #define BME680_P2_MSB_REG (8)
jsa1969 0:cef60cc92da0 283 #define BME680_P3_REG (9)
jsa1969 0:cef60cc92da0 284 #define BME680_P4_LSB_REG (11)
jsa1969 0:cef60cc92da0 285 #define BME680_P4_MSB_REG (12)
jsa1969 0:cef60cc92da0 286 #define BME680_P5_LSB_REG (13)
jsa1969 0:cef60cc92da0 287 #define BME680_P5_MSB_REG (14)
jsa1969 0:cef60cc92da0 288 #define BME680_P7_REG (15)
jsa1969 0:cef60cc92da0 289 #define BME680_P6_REG (16)
jsa1969 0:cef60cc92da0 290 #define BME680_P8_LSB_REG (19)
jsa1969 0:cef60cc92da0 291 #define BME680_P8_MSB_REG (20)
jsa1969 0:cef60cc92da0 292 #define BME680_P9_LSB_REG (21)
jsa1969 0:cef60cc92da0 293 #define BME680_P9_MSB_REG (22)
jsa1969 0:cef60cc92da0 294 #define BME680_P10_REG (23)
jsa1969 0:cef60cc92da0 295 #define BME680_H2_MSB_REG (25)
jsa1969 0:cef60cc92da0 296 #define BME680_H2_LSB_REG (26)
jsa1969 0:cef60cc92da0 297 #define BME680_H1_LSB_REG (26)
jsa1969 0:cef60cc92da0 298 #define BME680_H1_MSB_REG (27)
jsa1969 0:cef60cc92da0 299 #define BME680_H3_REG (28)
jsa1969 0:cef60cc92da0 300 #define BME680_H4_REG (29)
jsa1969 0:cef60cc92da0 301 #define BME680_H5_REG (30)
jsa1969 0:cef60cc92da0 302 #define BME680_H6_REG (31)
jsa1969 0:cef60cc92da0 303 #define BME680_H7_REG (32)
jsa1969 0:cef60cc92da0 304 #define BME680_T1_LSB_REG (33)
jsa1969 0:cef60cc92da0 305 #define BME680_T1_MSB_REG (34)
jsa1969 0:cef60cc92da0 306 #define BME680_GH2_LSB_REG (35)
jsa1969 0:cef60cc92da0 307 #define BME680_GH2_MSB_REG (36)
jsa1969 0:cef60cc92da0 308 #define BME680_GH1_REG (37)
jsa1969 0:cef60cc92da0 309 #define BME680_GH3_REG (38)
jsa1969 0:cef60cc92da0 310
jsa1969 0:cef60cc92da0 311 /** BME680 register buffer index settings*/
jsa1969 0:cef60cc92da0 312 #define BME680_REG_FILTER_INDEX UINT8_C(5)
jsa1969 0:cef60cc92da0 313 #define BME680_REG_TEMP_INDEX UINT8_C(4)
jsa1969 0:cef60cc92da0 314 #define BME680_REG_PRES_INDEX UINT8_C(4)
jsa1969 0:cef60cc92da0 315 #define BME680_REG_HUM_INDEX UINT8_C(2)
jsa1969 0:cef60cc92da0 316 #define BME680_REG_NBCONV_INDEX UINT8_C(1)
jsa1969 0:cef60cc92da0 317 #define BME680_REG_RUN_GAS_INDEX UINT8_C(1)
jsa1969 0:cef60cc92da0 318 #define BME680_REG_HCTRL_INDEX UINT8_C(0)
jsa1969 0:cef60cc92da0 319
jsa1969 0:cef60cc92da0 320 /** BME680 pressure calculation macros */
jsa1969 0:cef60cc92da0 321 /*! This max value is used to provide precedence to multiplication or division
jsa1969 0:cef60cc92da0 322 * in pressure compensation equation to achieve least loss of precision and
jsa1969 0:cef60cc92da0 323 * avoiding overflows.
jsa1969 0:cef60cc92da0 324 * i.e Comparing value, BME680_MAX_OVERFLOW_VAL = INT32_C(1 << 30)
jsa1969 0:cef60cc92da0 325 */
jsa1969 0:cef60cc92da0 326 #define BME680_MAX_OVERFLOW_VAL INT32_C(0x40000000)
jsa1969 0:cef60cc92da0 327
jsa1969 0:cef60cc92da0 328 /** Macro to combine two 8 bit data's to form a 16 bit data */
jsa1969 0:cef60cc92da0 329 #define BME680_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
jsa1969 0:cef60cc92da0 330
jsa1969 0:cef60cc92da0 331 /** Macro to SET and GET BITS of a register */
jsa1969 0:cef60cc92da0 332 #define BME680_SET_BITS(reg_data, bitname, data) \
jsa1969 0:cef60cc92da0 333 ((reg_data & ~(bitname##_MSK)) | \
jsa1969 0:cef60cc92da0 334 ((data << bitname##_POS) & bitname##_MSK))
jsa1969 0:cef60cc92da0 335 #define BME680_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
jsa1969 0:cef60cc92da0 336 (bitname##_POS))
jsa1969 0:cef60cc92da0 337
jsa1969 0:cef60cc92da0 338 /** Macro variant to handle the bitname position if it is zero */
jsa1969 0:cef60cc92da0 339 #define BME680_SET_BITS_POS_0(reg_data, bitname, data) \
jsa1969 0:cef60cc92da0 340 ((reg_data & ~(bitname##_MSK)) | \
jsa1969 0:cef60cc92da0 341 (data & bitname##_MSK))
jsa1969 0:cef60cc92da0 342 #define BME680_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
jsa1969 0:cef60cc92da0 343
jsa1969 0:cef60cc92da0 344 /** Type definitions */
jsa1969 0:cef60cc92da0 345 /*!
jsa1969 0:cef60cc92da0 346 * Generic communication function pointer
jsa1969 0:cef60cc92da0 347 * @param[in] dev_id: Place holder to store the id of the device structure
jsa1969 0:cef60cc92da0 348 * Can be used to store the index of the Chip select or
jsa1969 0:cef60cc92da0 349 * I2C address of the device.
jsa1969 0:cef60cc92da0 350 * @param[in] reg_addr: Used to select the register the where data needs to
jsa1969 0:cef60cc92da0 351 * be read from or written to.
jsa1969 0:cef60cc92da0 352 * @param[in/out] reg_data: Data array to read/write
jsa1969 0:cef60cc92da0 353 * @param[in] len: Length of the data array
jsa1969 0:cef60cc92da0 354 */
jsa1969 0:cef60cc92da0 355 typedef int8_t (*bme680_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
jsa1969 0:cef60cc92da0 356
jsa1969 0:cef60cc92da0 357 /*!
jsa1969 0:cef60cc92da0 358 * Delay function pointer
jsa1969 0:cef60cc92da0 359 * @param[in] period: Time period in milliseconds
jsa1969 0:cef60cc92da0 360 */
jsa1969 0:cef60cc92da0 361 typedef void (*bme680_delay_fptr_t)(uint32_t period);
jsa1969 0:cef60cc92da0 362
jsa1969 0:cef60cc92da0 363 /*!
jsa1969 0:cef60cc92da0 364 * @brief Interface selection Enumerations
jsa1969 0:cef60cc92da0 365 */
jsa1969 0:cef60cc92da0 366 enum bme680_intf {
jsa1969 0:cef60cc92da0 367 /*! SPI interface */
jsa1969 0:cef60cc92da0 368 BME680_SPI_INTF,
jsa1969 0:cef60cc92da0 369 /*! I2C interface */
jsa1969 0:cef60cc92da0 370 BME680_I2C_INTF
jsa1969 0:cef60cc92da0 371 };
jsa1969 0:cef60cc92da0 372
jsa1969 0:cef60cc92da0 373 /* structure definitions */
jsa1969 0:cef60cc92da0 374 /*!
jsa1969 0:cef60cc92da0 375 * @brief Sensor field data structure
jsa1969 0:cef60cc92da0 376 */
jsa1969 0:cef60cc92da0 377 struct bme680_field_data {
jsa1969 0:cef60cc92da0 378 /*! Contains new_data, gasm_valid & heat_stab */
jsa1969 0:cef60cc92da0 379 uint8_t status;
jsa1969 0:cef60cc92da0 380 /*! The index of the heater profile used */
jsa1969 0:cef60cc92da0 381 uint8_t gas_index;
jsa1969 0:cef60cc92da0 382 /*! Measurement index to track order */
jsa1969 0:cef60cc92da0 383 uint8_t meas_index;
jsa1969 0:cef60cc92da0 384
jsa1969 0:cef60cc92da0 385 #ifndef BME680_FLOAT_POINT_COMPENSATION
jsa1969 0:cef60cc92da0 386 /*! Temperature in degree celsius x100 */
jsa1969 0:cef60cc92da0 387 int16_t temperature;
jsa1969 0:cef60cc92da0 388 /*! Pressure in Pascal */
jsa1969 0:cef60cc92da0 389 uint32_t pressure;
jsa1969 0:cef60cc92da0 390 /*! Humidity in % relative humidity x1000 */
jsa1969 0:cef60cc92da0 391 uint32_t humidity;
jsa1969 0:cef60cc92da0 392 /*! Gas resistance in Ohms */
jsa1969 0:cef60cc92da0 393 uint32_t gas_resistance;
jsa1969 0:cef60cc92da0 394 #else
jsa1969 0:cef60cc92da0 395 /*! Temperature in degree celsius */
jsa1969 0:cef60cc92da0 396 float temperature;
jsa1969 0:cef60cc92da0 397 /*! Pressure in Pascal */
jsa1969 0:cef60cc92da0 398 float pressure;
jsa1969 0:cef60cc92da0 399 /*! Humidity in % relative humidity x1000 */
jsa1969 0:cef60cc92da0 400 float humidity;
jsa1969 0:cef60cc92da0 401 /*! Gas resistance in Ohms */
jsa1969 0:cef60cc92da0 402 float gas_resistance;
jsa1969 0:cef60cc92da0 403
jsa1969 0:cef60cc92da0 404 #endif
jsa1969 0:cef60cc92da0 405
jsa1969 0:cef60cc92da0 406 };
jsa1969 0:cef60cc92da0 407
jsa1969 0:cef60cc92da0 408 /*!
jsa1969 0:cef60cc92da0 409 * @brief Structure to hold the Calibration data
jsa1969 0:cef60cc92da0 410 */
jsa1969 0:cef60cc92da0 411 struct bme680_calib_data {
jsa1969 0:cef60cc92da0 412 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 413 uint16_t par_h1;
jsa1969 0:cef60cc92da0 414 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 415 uint16_t par_h2;
jsa1969 0:cef60cc92da0 416 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 417 int8_t par_h3;
jsa1969 0:cef60cc92da0 418 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 419 int8_t par_h4;
jsa1969 0:cef60cc92da0 420 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 421 int8_t par_h5;
jsa1969 0:cef60cc92da0 422 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 423 uint8_t par_h6;
jsa1969 0:cef60cc92da0 424 /*! Variable to store calibrated humidity data */
jsa1969 0:cef60cc92da0 425 int8_t par_h7;
jsa1969 0:cef60cc92da0 426 /*! Variable to store calibrated gas data */
jsa1969 0:cef60cc92da0 427 int8_t par_gh1;
jsa1969 0:cef60cc92da0 428 /*! Variable to store calibrated gas data */
jsa1969 0:cef60cc92da0 429 int16_t par_gh2;
jsa1969 0:cef60cc92da0 430 /*! Variable to store calibrated gas data */
jsa1969 0:cef60cc92da0 431 int8_t par_gh3;
jsa1969 0:cef60cc92da0 432 /*! Variable to store calibrated temperature data */
jsa1969 0:cef60cc92da0 433 uint16_t par_t1;
jsa1969 0:cef60cc92da0 434 /*! Variable to store calibrated temperature data */
jsa1969 0:cef60cc92da0 435 int16_t par_t2;
jsa1969 0:cef60cc92da0 436 /*! Variable to store calibrated temperature data */
jsa1969 0:cef60cc92da0 437 int8_t par_t3;
jsa1969 0:cef60cc92da0 438 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 439 uint16_t par_p1;
jsa1969 0:cef60cc92da0 440 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 441 int16_t par_p2;
jsa1969 0:cef60cc92da0 442 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 443 int8_t par_p3;
jsa1969 0:cef60cc92da0 444 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 445 int16_t par_p4;
jsa1969 0:cef60cc92da0 446 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 447 int16_t par_p5;
jsa1969 0:cef60cc92da0 448 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 449 int8_t par_p6;
jsa1969 0:cef60cc92da0 450 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 451 int8_t par_p7;
jsa1969 0:cef60cc92da0 452 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 453 int16_t par_p8;
jsa1969 0:cef60cc92da0 454 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 455 int16_t par_p9;
jsa1969 0:cef60cc92da0 456 /*! Variable to store calibrated pressure data */
jsa1969 0:cef60cc92da0 457 uint8_t par_p10;
jsa1969 0:cef60cc92da0 458
jsa1969 0:cef60cc92da0 459 #ifndef BME680_FLOAT_POINT_COMPENSATION
jsa1969 0:cef60cc92da0 460 /*! Variable to store t_fine size */
jsa1969 0:cef60cc92da0 461 int32_t t_fine;
jsa1969 0:cef60cc92da0 462 #else
jsa1969 0:cef60cc92da0 463 /*! Variable to store t_fine size */
jsa1969 0:cef60cc92da0 464 float t_fine;
jsa1969 0:cef60cc92da0 465 #endif
jsa1969 0:cef60cc92da0 466 /*! Variable to store heater resistance range */
jsa1969 0:cef60cc92da0 467 uint8_t res_heat_range;
jsa1969 0:cef60cc92da0 468 /*! Variable to store heater resistance value */
jsa1969 0:cef60cc92da0 469 int8_t res_heat_val;
jsa1969 0:cef60cc92da0 470 /*! Variable to store error range */
jsa1969 0:cef60cc92da0 471 int8_t range_sw_err;
jsa1969 0:cef60cc92da0 472 };
jsa1969 0:cef60cc92da0 473
jsa1969 0:cef60cc92da0 474 /*!
jsa1969 0:cef60cc92da0 475 * @brief BME680 sensor settings structure which comprises of ODR,
jsa1969 0:cef60cc92da0 476 * over-sampling and filter settings.
jsa1969 0:cef60cc92da0 477 */
jsa1969 0:cef60cc92da0 478 struct bme680_tph_sett {
jsa1969 0:cef60cc92da0 479 /*! Humidity oversampling */
jsa1969 0:cef60cc92da0 480 uint8_t os_hum;
jsa1969 0:cef60cc92da0 481 /*! Temperature oversampling */
jsa1969 0:cef60cc92da0 482 uint8_t os_temp;
jsa1969 0:cef60cc92da0 483 /*! Pressure oversampling */
jsa1969 0:cef60cc92da0 484 uint8_t os_pres;
jsa1969 0:cef60cc92da0 485 /*! Filter coefficient */
jsa1969 0:cef60cc92da0 486 uint8_t filter;
jsa1969 0:cef60cc92da0 487 };
jsa1969 0:cef60cc92da0 488
jsa1969 0:cef60cc92da0 489 /*!
jsa1969 0:cef60cc92da0 490 * @brief BME680 gas sensor which comprises of gas settings
jsa1969 0:cef60cc92da0 491 * and status parameters
jsa1969 0:cef60cc92da0 492 */
jsa1969 0:cef60cc92da0 493 struct bme680_gas_sett {
jsa1969 0:cef60cc92da0 494 /*! Variable to store nb conversion */
jsa1969 0:cef60cc92da0 495 uint8_t nb_conv;
jsa1969 0:cef60cc92da0 496 /*! Variable to store heater control */
jsa1969 0:cef60cc92da0 497 uint8_t heatr_ctrl;
jsa1969 0:cef60cc92da0 498 /*! Run gas enable value */
jsa1969 0:cef60cc92da0 499 uint8_t run_gas;
jsa1969 0:cef60cc92da0 500 /*! Heater temperature value */
jsa1969 0:cef60cc92da0 501 uint16_t heatr_temp;
jsa1969 0:cef60cc92da0 502 /*! Duration profile value */
jsa1969 0:cef60cc92da0 503 uint16_t heatr_dur;
jsa1969 0:cef60cc92da0 504 };
jsa1969 0:cef60cc92da0 505
jsa1969 0:cef60cc92da0 506 /*!
jsa1969 0:cef60cc92da0 507 * @brief BME680 device structure
jsa1969 0:cef60cc92da0 508 */
jsa1969 0:cef60cc92da0 509 struct bme680_dev {
jsa1969 0:cef60cc92da0 510 /*! Chip Id */
jsa1969 0:cef60cc92da0 511 uint8_t chip_id;
jsa1969 0:cef60cc92da0 512 /*! Device Id */
jsa1969 0:cef60cc92da0 513 uint8_t dev_id;
jsa1969 0:cef60cc92da0 514 /*! SPI/I2C interface */
jsa1969 0:cef60cc92da0 515 enum bme680_intf intf;
jsa1969 0:cef60cc92da0 516 /*! Memory page used */
jsa1969 0:cef60cc92da0 517 uint8_t mem_page;
jsa1969 0:cef60cc92da0 518 /*! Ambient temperature in Degree C */
jsa1969 0:cef60cc92da0 519 int8_t amb_temp;
jsa1969 0:cef60cc92da0 520 /*! Sensor calibration data */
jsa1969 0:cef60cc92da0 521 struct bme680_calib_data calib;
jsa1969 0:cef60cc92da0 522 /*! Sensor settings */
jsa1969 0:cef60cc92da0 523 struct bme680_tph_sett tph_sett;
jsa1969 0:cef60cc92da0 524 /*! Gas Sensor settings */
jsa1969 0:cef60cc92da0 525 struct bme680_gas_sett gas_sett;
jsa1969 0:cef60cc92da0 526 /*! Sensor power modes */
jsa1969 0:cef60cc92da0 527 uint8_t power_mode;
jsa1969 0:cef60cc92da0 528 /*! New sensor fields */
jsa1969 0:cef60cc92da0 529 uint8_t new_fields;
jsa1969 0:cef60cc92da0 530 /*! Store the info messages */
jsa1969 0:cef60cc92da0 531 uint8_t info_msg;
jsa1969 0:cef60cc92da0 532 /*! Bus read function pointer */
jsa1969 0:cef60cc92da0 533 //bme680_com_fptr_t read;
jsa1969 0:cef60cc92da0 534 /*! Bus write function pointer */
jsa1969 0:cef60cc92da0 535 //bme680_com_fptr_t write;
jsa1969 0:cef60cc92da0 536 /*! delay function pointer */
jsa1969 0:cef60cc92da0 537 // delay_ms;
jsa1969 0:cef60cc92da0 538 /*! Communication function result */
jsa1969 0:cef60cc92da0 539 int com_rslt;
jsa1969 0:cef60cc92da0 540 };
jsa1969 0:cef60cc92da0 541
jsa1969 0:cef60cc92da0 542
jsa1969 0:cef60cc92da0 543
jsa1969 0:cef60cc92da0 544 #endif /* BME680_DEFS_H_ */
jsa1969 0:cef60cc92da0 545 /** @}*/
jsa1969 0:cef60cc92da0 546 /** @}*/