Low power gas, pressure, temperature and humidity sensor

Dependents:   MERGE Sensor_iAQ_sgp30_bme_si7051 POCBreath_V2_smd_commercial

Committer:
mcm
Date:
Mon Jul 23 11:41:39 2018 +0000
Revision:
3:8aefe9304f85
Parent:
1:4d60db802cfb
An example that shows how to use this driver was added into the header file.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 0:0180d9905fe5 1 /**
mcm 1:4d60db802cfb 2 * @brief BME680.h
mcm 1:4d60db802cfb 3 * @details Low power gas, pressure, temperature & humidity sensor.
mcm 1:4d60db802cfb 4 * Header file.
mcm 0:0180d9905fe5 5 *
mcm 0:0180d9905fe5 6 *
mcm 1:4d60db802cfb 7 * @return N/A
mcm 0:0180d9905fe5 8 *
mcm 1:4d60db802cfb 9 * @author Manuel Caballero
mcm 1:4d60db802cfb 10 * @date 21/July/2018
mcm 1:4d60db802cfb 11 * @version 21/July/2018 The ORIGIN
mcm 1:4d60db802cfb 12 * @pre This is just a port from Bosh driver to mBed ( c++ )
mcm 1:4d60db802cfb 13 * @warning N/A
mcm 1:4d60db802cfb 14 * @pre This code belongs to Nimbus Centre ( http://www.nimbus.cit.ie ).
mcm 0:0180d9905fe5 15 */
mcm 1:4d60db802cfb 16 /**
mcm 1:4d60db802cfb 17 * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
mcm 1:4d60db802cfb 18 *
mcm 1:4d60db802cfb 19 * Redistribution and use in source and binary forms, with or without
mcm 1:4d60db802cfb 20 * modification, are permitted provided that the following conditions are met:
mcm 1:4d60db802cfb 21 *
mcm 1:4d60db802cfb 22 * Redistributions of source code must retain the above copyright
mcm 1:4d60db802cfb 23 * notice, this list of conditions and the following disclaimer.
mcm 1:4d60db802cfb 24 *
mcm 1:4d60db802cfb 25 * Redistributions in binary form must reproduce the above copyright
mcm 1:4d60db802cfb 26 * notice, this list of conditions and the following disclaimer in the
mcm 1:4d60db802cfb 27 * documentation and/or other materials provided with the distribution.
mcm 1:4d60db802cfb 28 *
mcm 1:4d60db802cfb 29 * Neither the name of the copyright holder nor the names of the
mcm 1:4d60db802cfb 30 * contributors may be used to endorse or promote products derived from
mcm 1:4d60db802cfb 31 * this software without specific prior written permission.
mcm 1:4d60db802cfb 32 *
mcm 1:4d60db802cfb 33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
mcm 1:4d60db802cfb 34 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
mcm 1:4d60db802cfb 35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mcm 1:4d60db802cfb 36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mcm 1:4d60db802cfb 37 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
mcm 1:4d60db802cfb 38 * OR CONTRIBUTORS BE LIABLE FOR ANY
mcm 1:4d60db802cfb 39 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
mcm 1:4d60db802cfb 40 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
mcm 1:4d60db802cfb 41 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mcm 1:4d60db802cfb 42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mcm 1:4d60db802cfb 43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
mcm 1:4d60db802cfb 44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mcm 1:4d60db802cfb 45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mcm 1:4d60db802cfb 46 * ANY WAY OUT OF THE USE OF THIS
mcm 1:4d60db802cfb 47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
mcm 1:4d60db802cfb 48 *
mcm 1:4d60db802cfb 49 * The information provided is believed to be accurate and reliable.
mcm 1:4d60db802cfb 50 * The copyright holder assumes no responsibility
mcm 1:4d60db802cfb 51 * for the consequences of use
mcm 1:4d60db802cfb 52 * of such information nor for any infringement of patents or
mcm 1:4d60db802cfb 53 * other rights of third parties which may result from its use.
mcm 1:4d60db802cfb 54 * No license is granted by implication or otherwise under any patent or
mcm 1:4d60db802cfb 55 * patent rights of the copyright holder.
mcm 1:4d60db802cfb 56 *
mcm 1:4d60db802cfb 57 * @file bme680.h
mcm 1:4d60db802cfb 58 * @date 19 Jun 2018
mcm 1:4d60db802cfb 59 * @version 3.5.9
mcm 1:4d60db802cfb 60 * @brief
mcm 1:4d60db802cfb 61 *
mcm 1:4d60db802cfb 62 */
mcm 0:0180d9905fe5 63 /*! @file bme680.h
mcm 0:0180d9905fe5 64 @brief Sensor driver for BME680 sensor */
mcm 0:0180d9905fe5 65 /*!
mcm 0:0180d9905fe5 66 * @defgroup BME680 SENSOR API
mcm 0:0180d9905fe5 67 * @{*/
mcm 0:0180d9905fe5 68 #ifndef BME680_H_
mcm 0:0180d9905fe5 69 #define BME680_H_
mcm 0:0180d9905fe5 70
mcm 1:4d60db802cfb 71 #include "mbed.h"
mcm 0:0180d9905fe5 72 #include "bme680_defs.h"
mcm 0:0180d9905fe5 73
mcm 0:0180d9905fe5 74
mcm 1:4d60db802cfb 75 /**
mcm 1:4d60db802cfb 76 Example:
mcm 1:4d60db802cfb 77 @code
mcm 3:8aefe9304f85 78 #include "mbed.h"
mcm 3:8aefe9304f85 79 #include "BME680.h"
mcm 3:8aefe9304f85 80
mcm 3:8aefe9304f85 81 BME680 myBME680 ( I2C_SDA, I2C_SCL, 400000 );
mcm 3:8aefe9304f85 82 Serial pc ( USBTX, USBRX );
mcm 3:8aefe9304f85 83
mcm 3:8aefe9304f85 84 DigitalOut myled ( LED1 );
mcm 3:8aefe9304f85 85 Ticker newReading;
mcm 3:8aefe9304f85 86
mcm 3:8aefe9304f85 87 uint32_t myState = 0;
mcm 3:8aefe9304f85 88
mcm 3:8aefe9304f85 89
mcm 3:8aefe9304f85 90 //@brief FUNCTION PROTOTYPES
mcm 3:8aefe9304f85 91 void changeDATA ( void );
mcm 3:8aefe9304f85 92 void user_delay_ms ( uint32_t period );
mcm 3:8aefe9304f85 93 int8_t user_i2c_read ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len );
mcm 3:8aefe9304f85 94 int8_t user_i2c_write ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len );
mcm 3:8aefe9304f85 95
mcm 3:8aefe9304f85 96
mcm 3:8aefe9304f85 97 //@brief FUNCTION FOR APPLICATION MAIN ENTRY.
mcm 3:8aefe9304f85 98 int main()
mcm 3:8aefe9304f85 99 {
mcm 3:8aefe9304f85 100 pc.baud ( 115200 );
mcm 3:8aefe9304f85 101
mcm 3:8aefe9304f85 102 myled = 1;
mcm 3:8aefe9304f85 103 wait(3);
mcm 3:8aefe9304f85 104 myled = 0;
mcm 3:8aefe9304f85 105
mcm 3:8aefe9304f85 106
mcm 3:8aefe9304f85 107 struct bme680_dev gas_sensor;
mcm 3:8aefe9304f85 108
mcm 3:8aefe9304f85 109 gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
mcm 3:8aefe9304f85 110 gas_sensor.intf = BME680_I2C_INTF;
mcm 3:8aefe9304f85 111 gas_sensor.read = user_i2c_read;
mcm 3:8aefe9304f85 112 gas_sensor.write = user_i2c_write;
mcm 3:8aefe9304f85 113 gas_sensor.delay_ms = user_delay_ms;
mcm 3:8aefe9304f85 114 // amb_temp can be set to 25 prior to configuring the gas sensor
mcm 3:8aefe9304f85 115 // or by performing a few temperature readings without operating the gas sensor.
mcm 3:8aefe9304f85 116 gas_sensor.amb_temp = 25;
mcm 3:8aefe9304f85 117
mcm 3:8aefe9304f85 118
mcm 3:8aefe9304f85 119 int8_t rslt = BME680_OK;
mcm 3:8aefe9304f85 120 rslt = myBME680.bme680_init ( &gas_sensor );
mcm 3:8aefe9304f85 121
mcm 3:8aefe9304f85 122
mcm 3:8aefe9304f85 123 uint8_t set_required_settings;
mcm 3:8aefe9304f85 124
mcm 3:8aefe9304f85 125 // Set the temperature, pressure and humidity settings
mcm 3:8aefe9304f85 126 gas_sensor.tph_sett.os_hum = BME680_OS_2X;
mcm 3:8aefe9304f85 127 gas_sensor.tph_sett.os_pres = BME680_OS_4X;
mcm 3:8aefe9304f85 128 gas_sensor.tph_sett.os_temp = BME680_OS_8X;
mcm 3:8aefe9304f85 129 gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
mcm 3:8aefe9304f85 130
mcm 3:8aefe9304f85 131 // Set the remaining gas sensor settings and link the heating profile
mcm 3:8aefe9304f85 132 gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
mcm 3:8aefe9304f85 133 // Create a ramp heat waveform in 3 steps
mcm 3:8aefe9304f85 134 gas_sensor.gas_sett.heatr_temp = 320; // degree Celsius
mcm 3:8aefe9304f85 135 gas_sensor.gas_sett.heatr_dur = 150; // milliseconds
mcm 3:8aefe9304f85 136
mcm 3:8aefe9304f85 137 // Select the power mode
mcm 3:8aefe9304f85 138 // Must be set before writing the sensor configuration
mcm 3:8aefe9304f85 139 gas_sensor.power_mode = BME680_FORCED_MODE;
mcm 3:8aefe9304f85 140
mcm 3:8aefe9304f85 141 // Set the required sensor settings needed
mcm 3:8aefe9304f85 142 set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL | BME680_GAS_SENSOR_SEL;
mcm 3:8aefe9304f85 143
mcm 3:8aefe9304f85 144 // Set the desired sensor configuration
mcm 3:8aefe9304f85 145 rslt = myBME680.bme680_set_sensor_settings ( set_required_settings, &gas_sensor );
mcm 3:8aefe9304f85 146
mcm 3:8aefe9304f85 147 // Set the power mode
mcm 3:8aefe9304f85 148 rslt = myBME680.bme680_set_sensor_mode ( &gas_sensor );
mcm 3:8aefe9304f85 149
mcm 3:8aefe9304f85 150
mcm 3:8aefe9304f85 151 // Get the total measurement duration so as to sleep or wait till the measurement is complete
mcm 3:8aefe9304f85 152 uint16_t meas_period;
mcm 3:8aefe9304f85 153 myBME680.bme680_get_profile_dur ( &meas_period, &gas_sensor );
mcm 3:8aefe9304f85 154
mcm 3:8aefe9304f85 155 struct bme680_field_data data;
mcm 3:8aefe9304f85 156
mcm 3:8aefe9304f85 157
mcm 3:8aefe9304f85 158 newReading.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
mcm 3:8aefe9304f85 159
mcm 3:8aefe9304f85 160 // Let the callbacks take care of everything
mcm 3:8aefe9304f85 161 while(1) {
mcm 3:8aefe9304f85 162 sleep();
mcm 3:8aefe9304f85 163
mcm 3:8aefe9304f85 164 myled = 1;
mcm 3:8aefe9304f85 165
mcm 3:8aefe9304f85 166 if ( myState == 1 ) {
mcm 3:8aefe9304f85 167 // Delay till the measurement is ready
mcm 3:8aefe9304f85 168 user_delay_ms ( meas_period );
mcm 3:8aefe9304f85 169
mcm 3:8aefe9304f85 170 rslt = myBME680.bme680_get_sensor_data ( &data, &gas_sensor );
mcm 3:8aefe9304f85 171
mcm 3:8aefe9304f85 172 // Prepare the data to be sent through the UART. NOTE: sprintf does NOT allow float numbers, that is why we round the number and plot them as integer
mcm 3:8aefe9304f85 173 // Avoid using measurements from an unstable heating setup
mcm 3:8aefe9304f85 174 if ( data.status & BME680_GASM_VALID_MSK ) {
mcm 3:8aefe9304f85 175 pc.printf( "T: %.2f degC, P: %.2f hPa, H %.2f %%rH, G: %d ohms\r\n", ( data.temperature/100.0f ), ( data.pressure / 100.0f ), ( data.humidity / 1000.0f ), data.gas_resistance );
mcm 3:8aefe9304f85 176 } else {
mcm 3:8aefe9304f85 177 pc.printf( "T: %.2f degC, P: %.2f hPa, H %.2f %%rH\r\n", ( data.temperature/100.0f ), ( data.pressure / 100.0f ), ( data.humidity / 1000.0f ) );
mcm 3:8aefe9304f85 178 }
mcm 3:8aefe9304f85 179
mcm 3:8aefe9304f85 180
mcm 3:8aefe9304f85 181 // Trigger the next measurement if you would like to read data out continuously
mcm 3:8aefe9304f85 182 if ( gas_sensor.power_mode == BME680_FORCED_MODE ) {
mcm 3:8aefe9304f85 183 rslt = myBME680.bme680_set_sensor_mode ( &gas_sensor );
mcm 3:8aefe9304f85 184 }
mcm 3:8aefe9304f85 185
mcm 3:8aefe9304f85 186 myState = 0; // Reset the variable
mcm 3:8aefe9304f85 187 }
mcm 3:8aefe9304f85 188
mcm 3:8aefe9304f85 189 myled = 0;
mcm 3:8aefe9304f85 190 }
mcm 3:8aefe9304f85 191 }
mcm 3:8aefe9304f85 192
mcm 3:8aefe9304f85 193
mcm 3:8aefe9304f85 194
mcm 3:8aefe9304f85 195
mcm 3:8aefe9304f85 196 // @brief changeDATA ( void )
mcm 3:8aefe9304f85 197 //
mcm 3:8aefe9304f85 198 // @details It changes myState variable
mcm 3:8aefe9304f85 199 //
mcm 3:8aefe9304f85 200 // @param[in] N/A
mcm 3:8aefe9304f85 201 //
mcm 3:8aefe9304f85 202 // @param[out] N/A.
mcm 3:8aefe9304f85 203 //
mcm 3:8aefe9304f85 204 //
mcm 3:8aefe9304f85 205 // @return N/A..
mcm 3:8aefe9304f85 206 //
mcm 3:8aefe9304f85 207 //
mcm 3:8aefe9304f85 208 // @author Manuel Caballero
mcm 3:8aefe9304f85 209 // @date 21/July/2018
mcm 3:8aefe9304f85 210 // @version 21/July/2018 The ORIGIN
mcm 3:8aefe9304f85 211 // @pre N/A
mcm 3:8aefe9304f85 212 // @warning N/A.
mcm 3:8aefe9304f85 213 void changeDATA ( void )
mcm 3:8aefe9304f85 214 {
mcm 3:8aefe9304f85 215 myState = 1;
mcm 3:8aefe9304f85 216 }
mcm 3:8aefe9304f85 217
mcm 3:8aefe9304f85 218
mcm 3:8aefe9304f85 219
mcm 3:8aefe9304f85 220 // @brief user_delay_ms ( uint32_t )
mcm 3:8aefe9304f85 221 //
mcm 3:8aefe9304f85 222 // @details Return control or wait, for a period amount of milliseconds
mcm 3:8aefe9304f85 223 //
mcm 3:8aefe9304f85 224 // @param[in] period: Delay in milliseconds.
mcm 3:8aefe9304f85 225 //
mcm 3:8aefe9304f85 226 // @param[out] N/A.
mcm 3:8aefe9304f85 227 //
mcm 3:8aefe9304f85 228 //
mcm 3:8aefe9304f85 229 // @return N/A..
mcm 3:8aefe9304f85 230 //
mcm 3:8aefe9304f85 231 //
mcm 3:8aefe9304f85 232 // @author Manuel Caballero
mcm 3:8aefe9304f85 233 // @date 21/July/2018
mcm 3:8aefe9304f85 234 // @version 21/July/2018 The ORIGIN
mcm 3:8aefe9304f85 235 // @pre This is a Bosh pointer function adapted to our system.
mcm 3:8aefe9304f85 236 // @warning N/A.
mcm 3:8aefe9304f85 237 void user_delay_ms ( uint32_t period )
mcm 3:8aefe9304f85 238 {
mcm 3:8aefe9304f85 239 // Return control or wait,
mcm 3:8aefe9304f85 240 // for a period amount of milliseconds
mcm 3:8aefe9304f85 241
mcm 3:8aefe9304f85 242 wait_ms ( period );
mcm 3:8aefe9304f85 243 }
mcm 3:8aefe9304f85 244
mcm 3:8aefe9304f85 245
mcm 3:8aefe9304f85 246
mcm 3:8aefe9304f85 247 // @brief user_i2c_read ( uint8_t , uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 3:8aefe9304f85 248 //
mcm 3:8aefe9304f85 249 // @details It adapts I2C reading functionality.
mcm 3:8aefe9304f85 250 //
mcm 3:8aefe9304f85 251 // @param[in] dev_id: I2C address.
mcm 3:8aefe9304f85 252 // @param[in] reg_addr: Register to be read.
mcm 3:8aefe9304f85 253 // @param[in] len: How many bytes to read.
mcm 3:8aefe9304f85 254 //
mcm 3:8aefe9304f85 255 // @param[out] reg_data: Result.
mcm 3:8aefe9304f85 256 //
mcm 3:8aefe9304f85 257 //
mcm 3:8aefe9304f85 258 // @return Status of user_i2c_read.
mcm 3:8aefe9304f85 259 //
mcm 3:8aefe9304f85 260 //
mcm 3:8aefe9304f85 261 // @author Manuel Caballero
mcm 3:8aefe9304f85 262 // @date 21/July/2018
mcm 3:8aefe9304f85 263 // @version 21/July/2018 The ORIGIN
mcm 3:8aefe9304f85 264 // @pre This is a Bosh pointer function adapted to our system.
mcm 3:8aefe9304f85 265 // @warning N/A.
mcm 3:8aefe9304f85 266 int8_t user_i2c_read ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 3:8aefe9304f85 267 {
mcm 3:8aefe9304f85 268 int8_t rslt = 0; // Return 0 for Success, non-zero for failure
mcm 3:8aefe9304f85 269
mcm 3:8aefe9304f85 270 // The parameter dev_id can be used as a variable to store the I2C address of the device
mcm 3:8aefe9304f85 271
mcm 3:8aefe9304f85 272
mcm 3:8aefe9304f85 273 // Data on the bus should be like
mcm 3:8aefe9304f85 274 // |------------+---------------------|
mcm 3:8aefe9304f85 275 // | I2C action | Data |
mcm 3:8aefe9304f85 276 // |------------+---------------------|
mcm 3:8aefe9304f85 277 // | Start | - |
mcm 3:8aefe9304f85 278 // | Write | (reg_addr) |
mcm 3:8aefe9304f85 279 // | Stop | - |
mcm 3:8aefe9304f85 280 // | Start | - |
mcm 3:8aefe9304f85 281 // | Read | (reg_data[0]) |
mcm 3:8aefe9304f85 282 // | Read | (....) |
mcm 3:8aefe9304f85 283 // | Read | (reg_data[len - 1]) |
mcm 3:8aefe9304f85 284 // | Stop | - |
mcm 3:8aefe9304f85 285 // |------------+---------------------|
mcm 3:8aefe9304f85 286
mcm 3:8aefe9304f85 287 // Read data
mcm 3:8aefe9304f85 288 uint32_t aux = 0;
mcm 3:8aefe9304f85 289 aux = myBME680._i2c.write ( dev_id, (char*)&reg_addr, 1, true );
mcm 3:8aefe9304f85 290 aux = myBME680._i2c.read ( dev_id, (char*)&reg_data[0], len );
mcm 3:8aefe9304f85 291
mcm 3:8aefe9304f85 292
mcm 3:8aefe9304f85 293
mcm 3:8aefe9304f85 294 if ( aux == 0 ) {
mcm 3:8aefe9304f85 295 rslt = 0;
mcm 3:8aefe9304f85 296 } else {
mcm 3:8aefe9304f85 297 rslt = 0xFF;
mcm 3:8aefe9304f85 298 }
mcm 3:8aefe9304f85 299
mcm 3:8aefe9304f85 300
mcm 3:8aefe9304f85 301 return rslt;
mcm 3:8aefe9304f85 302 }
mcm 3:8aefe9304f85 303
mcm 3:8aefe9304f85 304
mcm 3:8aefe9304f85 305
mcm 3:8aefe9304f85 306
mcm 3:8aefe9304f85 307 // @brief user_i2c_write ( uint8_t , uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 3:8aefe9304f85 308 //
mcm 3:8aefe9304f85 309 // @details It adapts I2C writing functionality.
mcm 3:8aefe9304f85 310 //
mcm 3:8aefe9304f85 311 // @param[in] dev_id: I2C address.
mcm 3:8aefe9304f85 312 // @param[in] reg_addr: Register to be read.
mcm 3:8aefe9304f85 313 // @param[out] reg_data: Data to be written.
mcm 3:8aefe9304f85 314 // @param[in] len: How many bytes to read.
mcm 3:8aefe9304f85 315 //
mcm 3:8aefe9304f85 316 // @param[out] N/A.
mcm 3:8aefe9304f85 317 //
mcm 3:8aefe9304f85 318 //
mcm 3:8aefe9304f85 319 // @return Status of user_i2c_write.
mcm 3:8aefe9304f85 320 //
mcm 3:8aefe9304f85 321 //
mcm 3:8aefe9304f85 322 // @author Manuel Caballero
mcm 3:8aefe9304f85 323 // @date 21/July/2018
mcm 3:8aefe9304f85 324 // @version 21/July/2018 The ORIGIN
mcm 3:8aefe9304f85 325 // @pre This is a Bosh pointer function adapted to our system.
mcm 3:8aefe9304f85 326 // @warning N/A.
mcm 3:8aefe9304f85 327 int8_t user_i2c_write ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 3:8aefe9304f85 328 {
mcm 3:8aefe9304f85 329 int8_t rslt = 0; // Return 0 for Success, non-zero for failure
mcm 3:8aefe9304f85 330
mcm 3:8aefe9304f85 331 // The parameter dev_id can be used as a variable to store the I2C address of the device
mcm 3:8aefe9304f85 332
mcm 3:8aefe9304f85 333
mcm 3:8aefe9304f85 334 // Data on the bus should be like
mcm 3:8aefe9304f85 335 // |------------+---------------------|
mcm 3:8aefe9304f85 336 // | I2C action | Data |
mcm 3:8aefe9304f85 337 // |------------+---------------------|
mcm 3:8aefe9304f85 338 // | Start | - |
mcm 3:8aefe9304f85 339 // | Write | (reg_addr) |
mcm 3:8aefe9304f85 340 // | Write | (reg_data[0]) |
mcm 3:8aefe9304f85 341 // | Write | (....) |
mcm 3:8aefe9304f85 342 // | Write | (reg_data[len - 1]) |
mcm 3:8aefe9304f85 343 // | Stop | - |
mcm 3:8aefe9304f85 344 // |------------+---------------------|
mcm 3:8aefe9304f85 345
mcm 3:8aefe9304f85 346 uint32_t aux = 0;
mcm 3:8aefe9304f85 347 char cmd[16] = { 0 };
mcm 3:8aefe9304f85 348 uint32_t i = 0;
mcm 3:8aefe9304f85 349
mcm 3:8aefe9304f85 350 // Prepare the data to be sent
mcm 3:8aefe9304f85 351 cmd[0] = reg_addr;
mcm 3:8aefe9304f85 352 for ( i = 1; i <= len; i++ ) {
mcm 3:8aefe9304f85 353 cmd[i] = reg_data[i - 1];
mcm 3:8aefe9304f85 354 }
mcm 3:8aefe9304f85 355
mcm 3:8aefe9304f85 356 // Write data
mcm 3:8aefe9304f85 357 aux = myBME680._i2c.write ( dev_id, &cmd[0], len + 1, false );
mcm 3:8aefe9304f85 358
mcm 3:8aefe9304f85 359
mcm 3:8aefe9304f85 360
mcm 3:8aefe9304f85 361 if ( aux == 0 ) {
mcm 3:8aefe9304f85 362 rslt = 0;
mcm 3:8aefe9304f85 363 } else {
mcm 3:8aefe9304f85 364 rslt = 0xFF;
mcm 3:8aefe9304f85 365 }
mcm 3:8aefe9304f85 366
mcm 3:8aefe9304f85 367
mcm 3:8aefe9304f85 368 return rslt;
mcm 3:8aefe9304f85 369 }
mcm 1:4d60db802cfb 370 @endcode
mcm 1:4d60db802cfb 371 */
mcm 0:0180d9905fe5 372
mcm 0:0180d9905fe5 373
mcm 0:0180d9905fe5 374 /*!
mcm 1:4d60db802cfb 375 Library for BME680 Low power gas, pressure, temperature & humidity sensor.
mcm 1:4d60db802cfb 376 */
mcm 1:4d60db802cfb 377 class BME680
mcm 1:4d60db802cfb 378 {
mcm 1:4d60db802cfb 379 public:
mcm 1:4d60db802cfb 380
mcm 1:4d60db802cfb 381 /** Create an BME680 object connected to the specified I2C pins.
mcm 1:4d60db802cfb 382 *
mcm 1:4d60db802cfb 383 * @param sda I2C data pin
mcm 1:4d60db802cfb 384 * @param scl I2C clock pin
mcm 1:4d60db802cfb 385 * @param freq I2C frequency
mcm 1:4d60db802cfb 386 */
mcm 1:4d60db802cfb 387 BME680 ( PinName sda, PinName scl, uint32_t freq );
mcm 1:4d60db802cfb 388
mcm 1:4d60db802cfb 389 /** Delete BME680 object.
mcm 1:4d60db802cfb 390 */
mcm 1:4d60db802cfb 391 ~BME680();
mcm 1:4d60db802cfb 392
mcm 1:4d60db802cfb 393 /* function prototype declarations */
mcm 1:4d60db802cfb 394 /*!
mcm 1:4d60db802cfb 395 * @brief This API is the entry point.
mcm 1:4d60db802cfb 396 * It reads the chip-id and calibration data from the sensor.
mcm 1:4d60db802cfb 397 *
mcm 1:4d60db802cfb 398 * @param[in,out] dev : Structure instance of bme680_dev
mcm 1:4d60db802cfb 399 *
mcm 1:4d60db802cfb 400 * @return Result of API execution status
mcm 1:4d60db802cfb 401 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 402 */
mcm 1:4d60db802cfb 403 int8_t bme680_init(struct bme680_dev *dev);
mcm 1:4d60db802cfb 404
mcm 1:4d60db802cfb 405 /*!
mcm 1:4d60db802cfb 406 * @brief This API writes the given data to the register address
mcm 1:4d60db802cfb 407 * of the sensor.
mcm 1:4d60db802cfb 408 *
mcm 1:4d60db802cfb 409 * @param[in] reg_addr : Register address from where the data to be written.
mcm 1:4d60db802cfb 410 * @param[in] reg_data : Pointer to data buffer which is to be written
mcm 1:4d60db802cfb 411 * in the sensor.
mcm 1:4d60db802cfb 412 * @param[in] len : No of bytes of data to write..
mcm 1:4d60db802cfb 413 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 414 *
mcm 1:4d60db802cfb 415 * @return Result of API execution status
mcm 1:4d60db802cfb 416 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 417 */
mcm 1:4d60db802cfb 418 int8_t bme680_set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, struct bme680_dev *dev);
mcm 1:4d60db802cfb 419
mcm 1:4d60db802cfb 420 /*!
mcm 1:4d60db802cfb 421 * @brief This API reads the data from the given register address of the sensor.
mcm 1:4d60db802cfb 422 *
mcm 1:4d60db802cfb 423 * @param[in] reg_addr : Register address from where the data to be read
mcm 1:4d60db802cfb 424 * @param[out] reg_data : Pointer to data buffer to store the read data.
mcm 1:4d60db802cfb 425 * @param[in] len : No of bytes of data to be read.
mcm 1:4d60db802cfb 426 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 427 *
mcm 1:4d60db802cfb 428 * @return Result of API execution status
mcm 1:4d60db802cfb 429 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 430 */
mcm 1:4d60db802cfb 431 int8_t bme680_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bme680_dev *dev);
mcm 1:4d60db802cfb 432
mcm 1:4d60db802cfb 433 /*!
mcm 1:4d60db802cfb 434 * @brief This API performs the soft reset of the sensor.
mcm 1:4d60db802cfb 435 *
mcm 1:4d60db802cfb 436 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 437 *
mcm 1:4d60db802cfb 438 * @return Result of API execution status
mcm 1:4d60db802cfb 439 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:4d60db802cfb 440 */
mcm 1:4d60db802cfb 441 int8_t bme680_soft_reset(struct bme680_dev *dev);
mcm 1:4d60db802cfb 442
mcm 1:4d60db802cfb 443 /*!
mcm 1:4d60db802cfb 444 * @brief This API is used to set the power mode of the sensor.
mcm 1:4d60db802cfb 445 *
mcm 1:4d60db802cfb 446 * @param[in] dev : Structure instance of bme680_dev
mcm 1:4d60db802cfb 447 * @note : Pass the value to bme680_dev.power_mode structure variable.
mcm 1:4d60db802cfb 448 *
mcm 1:4d60db802cfb 449 * value | mode
mcm 1:4d60db802cfb 450 * -------------|------------------
mcm 1:4d60db802cfb 451 * 0x00 | BME680_SLEEP_MODE
mcm 1:4d60db802cfb 452 * 0x01 | BME680_FORCED_MODE
mcm 1:4d60db802cfb 453 *
mcm 1:4d60db802cfb 454 * * @return Result of API execution status
mcm 1:4d60db802cfb 455 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 456 */
mcm 1:4d60db802cfb 457 int8_t bme680_set_sensor_mode(struct bme680_dev *dev);
mcm 1:4d60db802cfb 458
mcm 1:4d60db802cfb 459 /*!
mcm 1:4d60db802cfb 460 * @brief This API is used to get the power mode of the sensor.
mcm 1:4d60db802cfb 461 *
mcm 1:4d60db802cfb 462 * @param[in] dev : Structure instance of bme680_dev
mcm 1:4d60db802cfb 463 * @note : bme680_dev.power_mode structure variable hold the power mode.
mcm 1:4d60db802cfb 464 *
mcm 1:4d60db802cfb 465 * value | mode
mcm 1:4d60db802cfb 466 * ---------|------------------
mcm 1:4d60db802cfb 467 * 0x00 | BME680_SLEEP_MODE
mcm 1:4d60db802cfb 468 * 0x01 | BME680_FORCED_MODE
mcm 1:4d60db802cfb 469 *
mcm 1:4d60db802cfb 470 * @return Result of API execution status
mcm 1:4d60db802cfb 471 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 472 */
mcm 1:4d60db802cfb 473 int8_t bme680_get_sensor_mode(struct bme680_dev *dev);
mcm 0:0180d9905fe5 474
mcm 1:4d60db802cfb 475 /*!
mcm 1:4d60db802cfb 476 * @brief This API is used to set the profile duration of the sensor.
mcm 1:4d60db802cfb 477 *
mcm 1:4d60db802cfb 478 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 479 * @param[in] duration : Duration of the measurement in ms.
mcm 1:4d60db802cfb 480 *
mcm 1:4d60db802cfb 481 * @return Nothing
mcm 1:4d60db802cfb 482 */
mcm 1:4d60db802cfb 483 void bme680_set_profile_dur(uint16_t duration, struct bme680_dev *dev);
mcm 1:4d60db802cfb 484
mcm 1:4d60db802cfb 485 /*!
mcm 1:4d60db802cfb 486 * @brief This API is used to get the profile duration of the sensor.
mcm 1:4d60db802cfb 487 *
mcm 1:4d60db802cfb 488 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 489 * @param[in] duration : Duration of the measurement in ms.
mcm 1:4d60db802cfb 490 *
mcm 1:4d60db802cfb 491 * @return Nothing
mcm 1:4d60db802cfb 492 */
mcm 1:4d60db802cfb 493 void bme680_get_profile_dur(uint16_t *duration, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 494
mcm 1:4d60db802cfb 495 /*!
mcm 1:4d60db802cfb 496 * @brief This API reads the pressure, temperature and humidity and gas data
mcm 1:4d60db802cfb 497 * from the sensor, compensates the data and store it in the bme680_data
mcm 1:4d60db802cfb 498 * structure instance passed by the user.
mcm 1:4d60db802cfb 499 *
mcm 1:4d60db802cfb 500 * @param[out] data: Structure instance to hold the data.
mcm 1:4d60db802cfb 501 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 502 *
mcm 1:4d60db802cfb 503 * @return Result of API execution status
mcm 1:4d60db802cfb 504 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 505 */
mcm 1:4d60db802cfb 506 int8_t bme680_get_sensor_data(struct bme680_field_data *data, struct bme680_dev *dev);
mcm 0:0180d9905fe5 507
mcm 1:4d60db802cfb 508 /*!
mcm 1:4d60db802cfb 509 * @brief This API is used to set the oversampling, filter and T,P,H, gas selection
mcm 1:4d60db802cfb 510 * settings in the sensor.
mcm 1:4d60db802cfb 511 *
mcm 1:4d60db802cfb 512 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 513 * @param[in] desired_settings : Variable used to select the settings which
mcm 1:4d60db802cfb 514 * are to be set in the sensor.
mcm 1:4d60db802cfb 515 *
mcm 1:4d60db802cfb 516 * Macros | Functionality
mcm 1:4d60db802cfb 517 *---------------------------------|----------------------------------------------
mcm 1:4d60db802cfb 518 * BME680_OST_SEL | To set temperature oversampling.
mcm 1:4d60db802cfb 519 * BME680_OSP_SEL | To set pressure oversampling.
mcm 1:4d60db802cfb 520 * BME680_OSH_SEL | To set humidity oversampling.
mcm 1:4d60db802cfb 521 * BME680_GAS_MEAS_SEL | To set gas measurement setting.
mcm 1:4d60db802cfb 522 * BME680_FILTER_SEL | To set filter setting.
mcm 1:4d60db802cfb 523 * BME680_HCNTRL_SEL | To set humidity control setting.
mcm 1:4d60db802cfb 524 * BME680_RUN_GAS_SEL | To set run gas setting.
mcm 1:4d60db802cfb 525 * BME680_NBCONV_SEL | To set NB conversion setting.
mcm 1:4d60db802cfb 526 * BME680_GAS_SENSOR_SEL | To set all gas sensor related settings
mcm 1:4d60db802cfb 527 *
mcm 1:4d60db802cfb 528 * @note : Below are the macros to be used by the user for selecting the
mcm 1:4d60db802cfb 529 * desired settings. User can do OR operation of these macros for configuring
mcm 1:4d60db802cfb 530 * multiple settings.
mcm 1:4d60db802cfb 531 *
mcm 1:4d60db802cfb 532 * @return Result of API execution status
mcm 1:4d60db802cfb 533 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:4d60db802cfb 534 */
mcm 1:4d60db802cfb 535 int8_t bme680_set_sensor_settings(uint16_t desired_settings, struct bme680_dev *dev);
mcm 1:4d60db802cfb 536
mcm 1:4d60db802cfb 537 /*!
mcm 1:4d60db802cfb 538 * @brief This API is used to get the oversampling, filter and T,P,H, gas selection
mcm 1:4d60db802cfb 539 * settings in the sensor.
mcm 1:4d60db802cfb 540 *
mcm 1:4d60db802cfb 541 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 542 * @param[in] desired_settings : Variable used to select the settings which
mcm 1:4d60db802cfb 543 * are to be get from the sensor.
mcm 1:4d60db802cfb 544 *
mcm 1:4d60db802cfb 545 * @return Result of API execution status
mcm 1:4d60db802cfb 546 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:4d60db802cfb 547 */
mcm 1:4d60db802cfb 548 int8_t bme680_get_sensor_settings(uint16_t desired_settings, struct bme680_dev *dev);
mcm 1:4d60db802cfb 549
mcm 3:8aefe9304f85 550
mcm 3:8aefe9304f85 551 I2C _i2c;
mcm 3:8aefe9304f85 552
mcm 1:4d60db802cfb 553 private:
mcm 1:4d60db802cfb 554 /*!
mcm 1:4d60db802cfb 555 * @brief This internal API is used to read the calibrated data from the sensor.
mcm 1:4d60db802cfb 556 *
mcm 1:4d60db802cfb 557 * This function is used to retrieve the calibration
mcm 1:4d60db802cfb 558 * data from the image registers of the sensor.
mcm 1:4d60db802cfb 559 *
mcm 1:4d60db802cfb 560 * @note Registers 89h to A1h for calibration data 1 to 24
mcm 1:4d60db802cfb 561 * from bit 0 to 7
mcm 1:4d60db802cfb 562 * @note Registers E1h to F0h for calibration data 25 to 40
mcm 1:4d60db802cfb 563 * from bit 0 to 7
mcm 1:4d60db802cfb 564 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 565 *
mcm 1:4d60db802cfb 566 * @return Result of API execution status.
mcm 1:4d60db802cfb 567 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 568 */
mcm 1:4d60db802cfb 569 int8_t get_calib_data(struct bme680_dev *dev);
mcm 1:4d60db802cfb 570
mcm 1:4d60db802cfb 571 /*!
mcm 1:4d60db802cfb 572 * @brief This internal API is used to set the gas configuration of the sensor.
mcm 1:4d60db802cfb 573 *
mcm 1:4d60db802cfb 574 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 575 *
mcm 1:4d60db802cfb 576 * @return Result of API execution status.
mcm 1:4d60db802cfb 577 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 578 */
mcm 1:4d60db802cfb 579 int8_t set_gas_config(struct bme680_dev *dev);
mcm 0:0180d9905fe5 580
mcm 1:4d60db802cfb 581 /*!
mcm 1:4d60db802cfb 582 * @brief This internal API is used to get the gas configuration of the sensor.
mcm 1:4d60db802cfb 583 * @note heatr_temp and heatr_dur values are currently register data
mcm 1:4d60db802cfb 584 * and not the actual values set
mcm 1:4d60db802cfb 585 *
mcm 1:4d60db802cfb 586 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 587 *
mcm 1:4d60db802cfb 588 * @return Result of API execution status.
mcm 1:4d60db802cfb 589 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 590 */
mcm 1:4d60db802cfb 591 int8_t get_gas_config(struct bme680_dev *dev);
mcm 1:4d60db802cfb 592
mcm 1:4d60db802cfb 593 /*!
mcm 1:4d60db802cfb 594 * @brief This internal API is used to calculate the Heat duration value.
mcm 1:4d60db802cfb 595 *
mcm 1:4d60db802cfb 596 * @param[in] dur :Value of the duration to be shared.
mcm 1:4d60db802cfb 597 *
mcm 1:4d60db802cfb 598 * @return uint8_t threshold duration after calculation.
mcm 1:4d60db802cfb 599 */
mcm 1:4d60db802cfb 600 uint8_t calc_heater_dur(uint16_t dur);
mcm 1:4d60db802cfb 601
mcm 1:4d60db802cfb 602 #ifndef BME680_FLOAT_POINT_COMPENSATION
mcm 1:4d60db802cfb 603
mcm 1:4d60db802cfb 604 /*!
mcm 1:4d60db802cfb 605 * @brief This internal API is used to calculate the temperature value.
mcm 1:4d60db802cfb 606 *
mcm 1:4d60db802cfb 607 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 608 * @param[in] temp_adc :Contains the temperature ADC value .
mcm 1:4d60db802cfb 609 *
mcm 1:4d60db802cfb 610 * @return uint32_t calculated temperature.
mcm 1:4d60db802cfb 611 */
mcm 1:4d60db802cfb 612 int16_t calc_temperature(uint32_t temp_adc, struct bme680_dev *dev);
mcm 1:4d60db802cfb 613
mcm 1:4d60db802cfb 614 /*!
mcm 1:4d60db802cfb 615 * @brief This internal API is used to calculate the pressure value.
mcm 1:4d60db802cfb 616 *
mcm 1:4d60db802cfb 617 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 618 * @param[in] pres_adc :Contains the pressure ADC value .
mcm 1:4d60db802cfb 619 *
mcm 1:4d60db802cfb 620 * @return uint32_t calculated pressure.
mcm 1:4d60db802cfb 621 */
mcm 1:4d60db802cfb 622 uint32_t calc_pressure(uint32_t pres_adc, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 623
mcm 1:4d60db802cfb 624 /*!
mcm 1:4d60db802cfb 625 * @brief This internal API is used to calculate the humidity value.
mcm 1:4d60db802cfb 626 *
mcm 1:4d60db802cfb 627 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 628 * @param[in] hum_adc :Contains the humidity ADC value.
mcm 1:4d60db802cfb 629 *
mcm 1:4d60db802cfb 630 * @return uint32_t calculated humidity.
mcm 1:4d60db802cfb 631 */
mcm 1:4d60db802cfb 632 uint32_t calc_humidity(uint16_t hum_adc, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 633
mcm 1:4d60db802cfb 634 /*!
mcm 1:4d60db802cfb 635 * @brief This internal API is used to calculate the Gas Resistance value.
mcm 1:4d60db802cfb 636 *
mcm 1:4d60db802cfb 637 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 638 * @param[in] gas_res_adc :Contains the Gas Resistance ADC value.
mcm 1:4d60db802cfb 639 * @param[in] gas_range :Contains the range of gas values.
mcm 1:4d60db802cfb 640 *
mcm 1:4d60db802cfb 641 * @return uint32_t calculated gas resistance.
mcm 1:4d60db802cfb 642 */
mcm 1:4d60db802cfb 643 uint32_t calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 644
mcm 1:4d60db802cfb 645 /*!
mcm 1:4d60db802cfb 646 * @brief This internal API is used to calculate the Heat Resistance value.
mcm 1:4d60db802cfb 647 *
mcm 1:4d60db802cfb 648 * @param[in] dev : Structure instance of bme680_dev
mcm 1:4d60db802cfb 649 * @param[in] temp : Contains the target temperature value.
mcm 1:4d60db802cfb 650 *
mcm 1:4d60db802cfb 651 * @return uint8_t calculated heater resistance.
mcm 1:4d60db802cfb 652 */
mcm 1:4d60db802cfb 653 uint8_t calc_heater_res(uint16_t temp, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 654
mcm 1:4d60db802cfb 655 #else
mcm 1:4d60db802cfb 656 /*!
mcm 1:4d60db802cfb 657 * @brief This internal API is used to calculate the
mcm 1:4d60db802cfb 658 * temperature value value in float format
mcm 1:4d60db802cfb 659 *
mcm 1:4d60db802cfb 660 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 661 * @param[in] temp_adc :Contains the temperature ADC value .
mcm 1:4d60db802cfb 662 *
mcm 1:4d60db802cfb 663 * @return Calculated temperature in float
mcm 1:4d60db802cfb 664 */
mcm 1:4d60db802cfb 665 float calc_temperature(uint32_t temp_adc, struct bme680_dev *dev);
mcm 1:4d60db802cfb 666
mcm 1:4d60db802cfb 667 /*!
mcm 1:4d60db802cfb 668 * @brief This internal API is used to calculate the
mcm 1:4d60db802cfb 669 * pressure value value in float format
mcm 1:4d60db802cfb 670 *
mcm 1:4d60db802cfb 671 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 672 * @param[in] pres_adc :Contains the pressure ADC value .
mcm 1:4d60db802cfb 673 *
mcm 1:4d60db802cfb 674 * @return Calculated pressure in float.
mcm 1:4d60db802cfb 675 */
mcm 1:4d60db802cfb 676 float calc_pressure(uint32_t pres_adc, const struct bme680_dev *dev);
mcm 0:0180d9905fe5 677
mcm 1:4d60db802cfb 678 /*!
mcm 1:4d60db802cfb 679 * @brief This internal API is used to calculate the
mcm 1:4d60db802cfb 680 * humidity value value in float format
mcm 1:4d60db802cfb 681 *
mcm 1:4d60db802cfb 682 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 683 * @param[in] hum_adc :Contains the humidity ADC value.
mcm 1:4d60db802cfb 684 *
mcm 1:4d60db802cfb 685 * @return Calculated humidity in float.
mcm 1:4d60db802cfb 686 */
mcm 1:4d60db802cfb 687 float calc_humidity(uint16_t hum_adc, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 688
mcm 1:4d60db802cfb 689 /*!
mcm 1:4d60db802cfb 690 * @brief This internal API is used to calculate the
mcm 1:4d60db802cfb 691 * gas resistance value value in float format
mcm 1:4d60db802cfb 692 *
mcm 1:4d60db802cfb 693 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 694 * @param[in] gas_res_adc :Contains the Gas Resistance ADC value.
mcm 1:4d60db802cfb 695 * @param[in] gas_range :Contains the range of gas values.
mcm 1:4d60db802cfb 696 *
mcm 1:4d60db802cfb 697 * @return Calculated gas resistance in float.
mcm 1:4d60db802cfb 698 */
mcm 1:4d60db802cfb 699 float calc_gas_resistance(uint16_t gas_res_adc, uint8_t gas_range, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 700
mcm 1:4d60db802cfb 701 /*!
mcm 1:4d60db802cfb 702 * @brief This internal API is used to calculate the
mcm 1:4d60db802cfb 703 * heater resistance value in float format
mcm 1:4d60db802cfb 704 *
mcm 1:4d60db802cfb 705 * @param[in] temp : Contains the target temperature value.
mcm 1:4d60db802cfb 706 * @param[in] dev : Structure instance of bme680_dev.
mcm 1:4d60db802cfb 707 *
mcm 1:4d60db802cfb 708 * @return Calculated heater resistance in float.
mcm 1:4d60db802cfb 709 */
mcm 1:4d60db802cfb 710 float calc_heater_res(uint16_t temp, const struct bme680_dev *dev);
mcm 1:4d60db802cfb 711
mcm 1:4d60db802cfb 712 #endif
mcm 1:4d60db802cfb 713
mcm 1:4d60db802cfb 714 /*!
mcm 1:4d60db802cfb 715 * @brief This internal API is used to calculate the field data of sensor.
mcm 1:4d60db802cfb 716 *
mcm 1:4d60db802cfb 717 * @param[out] data :Structure instance to hold the data
mcm 1:4d60db802cfb 718 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 719 *
mcm 1:4d60db802cfb 720 * @return int8_t result of the field data from sensor.
mcm 1:4d60db802cfb 721 */
mcm 1:4d60db802cfb 722 int8_t read_field_data(struct bme680_field_data *data, struct bme680_dev *dev);
mcm 0:0180d9905fe5 723
mcm 1:4d60db802cfb 724 /*!
mcm 1:4d60db802cfb 725 * @brief This internal API is used to set the memory page
mcm 1:4d60db802cfb 726 * based on register address.
mcm 1:4d60db802cfb 727 *
mcm 1:4d60db802cfb 728 * The value of memory page
mcm 1:4d60db802cfb 729 * value | Description
mcm 1:4d60db802cfb 730 * --------|--------------
mcm 1:4d60db802cfb 731 * 0 | BME680_PAGE0_SPI
mcm 1:4d60db802cfb 732 * 1 | BME680_PAGE1_SPI
mcm 1:4d60db802cfb 733 *
mcm 1:4d60db802cfb 734 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 735 * @param[in] reg_addr :Contains the register address array.
mcm 1:4d60db802cfb 736 *
mcm 1:4d60db802cfb 737 * @return Result of API execution status
mcm 1:4d60db802cfb 738 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 739 */
mcm 1:4d60db802cfb 740 int8_t set_mem_page(uint8_t reg_addr, struct bme680_dev *dev);
mcm 1:4d60db802cfb 741
mcm 1:4d60db802cfb 742 /*!
mcm 1:4d60db802cfb 743 * @brief This internal API is used to get the memory page based
mcm 1:4d60db802cfb 744 * on register address.
mcm 1:4d60db802cfb 745 *
mcm 1:4d60db802cfb 746 * The value of memory page
mcm 1:4d60db802cfb 747 * value | Description
mcm 1:4d60db802cfb 748 * --------|--------------
mcm 1:4d60db802cfb 749 * 0 | BME680_PAGE0_SPI
mcm 1:4d60db802cfb 750 * 1 | BME680_PAGE1_SPI
mcm 1:4d60db802cfb 751 *
mcm 1:4d60db802cfb 752 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 753 *
mcm 1:4d60db802cfb 754 * @return Result of API execution status
mcm 1:4d60db802cfb 755 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 756 */
mcm 1:4d60db802cfb 757 int8_t get_mem_page(struct bme680_dev *dev);
mcm 1:4d60db802cfb 758
mcm 1:4d60db802cfb 759 /*!
mcm 1:4d60db802cfb 760 * @brief This internal API is used to validate the device pointer for
mcm 1:4d60db802cfb 761 * null conditions.
mcm 1:4d60db802cfb 762 *
mcm 1:4d60db802cfb 763 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 764 *
mcm 1:4d60db802cfb 765 * @return Result of API execution status
mcm 1:4d60db802cfb 766 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 767 */
mcm 1:4d60db802cfb 768 int8_t null_ptr_check(const struct bme680_dev *dev);
mcm 1:4d60db802cfb 769
mcm 1:4d60db802cfb 770 /*!
mcm 1:4d60db802cfb 771 * @brief This internal API is used to check the boundary
mcm 1:4d60db802cfb 772 * conditions.
mcm 1:4d60db802cfb 773 *
mcm 1:4d60db802cfb 774 * @param[in] value :pointer to the value.
mcm 1:4d60db802cfb 775 * @param[in] min :minimum value.
mcm 1:4d60db802cfb 776 * @param[in] max :maximum value.
mcm 1:4d60db802cfb 777 * @param[in] dev :Structure instance of bme680_dev.
mcm 1:4d60db802cfb 778 *
mcm 1:4d60db802cfb 779 * @return Result of API execution status
mcm 1:4d60db802cfb 780 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:4d60db802cfb 781 */
mcm 1:4d60db802cfb 782 int8_t boundary_check(uint8_t *value, uint8_t min, uint8_t max, struct bme680_dev *dev);
mcm 1:4d60db802cfb 783
mcm 1:4d60db802cfb 784
mcm 1:4d60db802cfb 785
mcm 1:4d60db802cfb 786 uint32_t _BME680_Addr;
mcm 1:4d60db802cfb 787 };
mcm 1:4d60db802cfb 788
mcm 1:4d60db802cfb 789 #endif
mcm 0:0180d9905fe5 790 /** @}*/