Committer:
mcm
Date:
Tue Sep 03 15:59:50 2019 +0000
Revision:
4:a1c46ef057a6
Parent:
3:ab857b70346e
The driver was completed and tested ( NUCLEO-L152RE ), it works as expected.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mcm 1:f01fab2521b1 1 /**
mcm 1:f01fab2521b1 2 * @brief BME280.h
mcm 1:f01fab2521b1 3 * @details Combined humidity and pressure sensor.
mcm 1:f01fab2521b1 4 * Header file.
mcm 1:f01fab2521b1 5 *
mcm 1:f01fab2521b1 6 *
mcm 1:f01fab2521b1 7 * @return N/A
mcm 1:f01fab2521b1 8 *
mcm 1:f01fab2521b1 9 * @author Manuel Caballero
mcm 1:f01fab2521b1 10 * @date 03/September/2019
mcm 1:f01fab2521b1 11 * @version 03/September/2019 The ORIGIN
mcm 1:f01fab2521b1 12 * @pre This is just a port from Bosh driver to mBed ( c++ )
mcm 1:f01fab2521b1 13 * @warning N/A
mcm 1:f01fab2521b1 14 * @pre This code belongs to AqueronteBlog ( http://unbarquero.blogspot.com ).
mcm 1:f01fab2521b1 15 */
mcm 1:f01fab2521b1 16 /**
mcm 1:f01fab2521b1 17 * Copyright (C) 2018 - 2019 Bosch Sensortec GmbH
mcm 1:f01fab2521b1 18 *
mcm 1:f01fab2521b1 19 * Redistribution and use in source and binary forms, with or without
mcm 1:f01fab2521b1 20 * modification, are permitted provided that the following conditions are met:
mcm 1:f01fab2521b1 21 *
mcm 1:f01fab2521b1 22 * Redistributions of source code must retain the above copyright
mcm 1:f01fab2521b1 23 * notice, this list of conditions and the following disclaimer.
mcm 1:f01fab2521b1 24 *
mcm 1:f01fab2521b1 25 * Redistributions in binary form must reproduce the above copyright
mcm 1:f01fab2521b1 26 * notice, this list of conditions and the following disclaimer in the
mcm 1:f01fab2521b1 27 * documentation and/or other materials provided with the distribution.
mcm 1:f01fab2521b1 28 *
mcm 1:f01fab2521b1 29 * Neither the name of the copyright holder nor the names of the
mcm 1:f01fab2521b1 30 * contributors may be used to endorse or promote products derived from
mcm 1:f01fab2521b1 31 * this software without specific prior written permission.
mcm 1:f01fab2521b1 32 *
mcm 1:f01fab2521b1 33 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
mcm 1:f01fab2521b1 34 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
mcm 1:f01fab2521b1 35 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
mcm 1:f01fab2521b1 36 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
mcm 1:f01fab2521b1 37 * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
mcm 1:f01fab2521b1 38 * OR CONTRIBUTORS BE LIABLE FOR ANY
mcm 1:f01fab2521b1 39 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
mcm 1:f01fab2521b1 40 * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
mcm 1:f01fab2521b1 41 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
mcm 1:f01fab2521b1 42 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
mcm 1:f01fab2521b1 43 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
mcm 1:f01fab2521b1 44 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
mcm 1:f01fab2521b1 45 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
mcm 1:f01fab2521b1 46 * ANY WAY OUT OF THE USE OF THIS
mcm 1:f01fab2521b1 47 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
mcm 1:f01fab2521b1 48 *
mcm 1:f01fab2521b1 49 * The information provided is believed to be accurate and reliable.
mcm 1:f01fab2521b1 50 * The copyright holder assumes no responsibility
mcm 1:f01fab2521b1 51 * for the consequences of use
mcm 1:f01fab2521b1 52 * of such information nor for any infringement of patents or
mcm 1:f01fab2521b1 53 * other rights of third parties which may result from its use.
mcm 1:f01fab2521b1 54 * No license is granted by implication or otherwise under any patent or
mcm 1:f01fab2521b1 55 * patent rights of the copyright holder.
mcm 1:f01fab2521b1 56 *
mcm 1:f01fab2521b1 57 * @file bme280.h
mcm 1:f01fab2521b1 58 * @date 08 Mar 2019
mcm 1:f01fab2521b1 59 * @version 3.3.6
mcm 1:f01fab2521b1 60 * @brief
mcm 1:f01fab2521b1 61 *
mcm 1:f01fab2521b1 62 */
mcm 1:f01fab2521b1 63
mcm 1:f01fab2521b1 64 /*! @file bme280.h
mcm 1:f01fab2521b1 65 * @brief Sensor driver for BME280 sensor
mcm 1:f01fab2521b1 66 */
mcm 1:f01fab2521b1 67
mcm 1:f01fab2521b1 68 /*!
mcm 1:f01fab2521b1 69 * @defgroup BME280 SENSOR API
mcm 1:f01fab2521b1 70 */
mcm 1:f01fab2521b1 71 #ifndef BME280_H_
mcm 1:f01fab2521b1 72 #define BME280_H_
mcm 1:f01fab2521b1 73
mcm 1:f01fab2521b1 74 #include "mbed.h"
mcm 1:f01fab2521b1 75 #include "bme280_defs.h"
mcm 1:f01fab2521b1 76
mcm 1:f01fab2521b1 77
mcm 1:f01fab2521b1 78 /**
mcm 1:f01fab2521b1 79 Example:
mcm 1:f01fab2521b1 80 @code
mcm 1:f01fab2521b1 81 #include "mbed.h"
mcm 1:f01fab2521b1 82 #include "BME280.h"
mcm 1:f01fab2521b1 83
mcm 4:a1c46ef057a6 84 BME280 myBME280 ( I2C_SDA, I2C_SCL, 400000 );
mcm 1:f01fab2521b1 85 Serial pc ( USBTX, USBRX );
mcm 1:f01fab2521b1 86
mcm 4:a1c46ef057a6 87 DigitalOut myled ( LED1 );
mcm 1:f01fab2521b1 88 Ticker newReading;
mcm 1:f01fab2521b1 89
mcm 1:f01fab2521b1 90 uint32_t myState = 0;
mcm 1:f01fab2521b1 91
mcm 1:f01fab2521b1 92
mcm 1:f01fab2521b1 93 //@brief FUNCTION PROTOTYPES
mcm 1:f01fab2521b1 94 void changeDATA ( void );
mcm 1:f01fab2521b1 95 void user_delay_ms ( uint32_t period );
mcm 1:f01fab2521b1 96 int8_t user_i2c_read ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len );
mcm 1:f01fab2521b1 97 int8_t user_i2c_write ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len );
mcm 1:f01fab2521b1 98
mcm 1:f01fab2521b1 99
mcm 1:f01fab2521b1 100 //@brief FUNCTION FOR APPLICATION MAIN ENTRY.
mcm 1:f01fab2521b1 101 int main()
mcm 1:f01fab2521b1 102 {
mcm 4:a1c46ef057a6 103 uint8_t settings_sel;
mcm 4:a1c46ef057a6 104 struct bme280_dev dev;
mcm 4:a1c46ef057a6 105 struct bme280_data comp_data;
mcm 4:a1c46ef057a6 106 int8_t rslt = BME280_OK;
mcm 4:a1c46ef057a6 107
mcm 1:f01fab2521b1 108 pc.baud ( 115200 );
mcm 1:f01fab2521b1 109
mcm 1:f01fab2521b1 110 myled = 1;
mcm 1:f01fab2521b1 111 wait(3);
mcm 1:f01fab2521b1 112 myled = 0;
mcm 1:f01fab2521b1 113
mcm 4:a1c46ef057a6 114 // Configure the device I2C interface
mcm 4:a1c46ef057a6 115 dev.dev_id = BME280_I2C_ADDR_PRIM;
mcm 4:a1c46ef057a6 116 dev.intf = BME280_I2C_INTF;
mcm 4:a1c46ef057a6 117 dev.read = user_i2c_read;
mcm 4:a1c46ef057a6 118 dev.write = user_i2c_write;
mcm 4:a1c46ef057a6 119 dev.delay_ms = user_delay_ms;
mcm 4:a1c46ef057a6 120
mcm 4:a1c46ef057a6 121 rslt = myBME280.bme280_init(&dev);
mcm 4:a1c46ef057a6 122
mcm 4:a1c46ef057a6 123 // Configure the device in Force mode
mcm 4:a1c46ef057a6 124 dev.settings.osr_h = BME280_OVERSAMPLING_1X;
mcm 4:a1c46ef057a6 125 dev.settings.osr_p = BME280_OVERSAMPLING_16X;
mcm 4:a1c46ef057a6 126 dev.settings.osr_t = BME280_OVERSAMPLING_2X;
mcm 4:a1c46ef057a6 127 dev.settings.filter = BME280_FILTER_COEFF_16;
mcm 4:a1c46ef057a6 128
mcm 4:a1c46ef057a6 129 settings_sel = BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL;
mcm 4:a1c46ef057a6 130
mcm 4:a1c46ef057a6 131 rslt = myBME280.bme280_set_sensor_settings(settings_sel, &dev);
mcm 4:a1c46ef057a6 132
mcm 1:f01fab2521b1 133
mcm 1:f01fab2521b1 134
mcm 1:f01fab2521b1 135 newReading.attach( &changeDATA, 1 ); // the address of the function to be attached ( changeDATA ) and the interval ( 1s )
mcm 1:f01fab2521b1 136
mcm 1:f01fab2521b1 137 // Let the callbacks take care of everything
mcm 1:f01fab2521b1 138 while(1) {
mcm 1:f01fab2521b1 139 sleep();
mcm 1:f01fab2521b1 140
mcm 1:f01fab2521b1 141 myled = 1;
mcm 1:f01fab2521b1 142
mcm 1:f01fab2521b1 143 if ( myState == 1 ) {
mcm 4:a1c46ef057a6 144 // Trigger a new sample
mcm 4:a1c46ef057a6 145 rslt = myBME280.bme280_set_sensor_mode(BME280_FORCED_MODE, &dev);
mcm 1:f01fab2521b1 146
mcm 4:a1c46ef057a6 147 // Wait for the measurement to complete and print data @25Hz
mcm 4:a1c46ef057a6 148 dev.delay_ms(40);
mcm 4:a1c46ef057a6 149
mcm 4:a1c46ef057a6 150 // Get the data
mcm 4:a1c46ef057a6 151 rslt = myBME280.bme280_get_sensor_data(BME280_ALL, &comp_data, &dev);
mcm 4:a1c46ef057a6 152
mcm 4:a1c46ef057a6 153 // Transmit result over the UART
mcm 4:a1c46ef057a6 154 pc.printf( "T: %ld C | P: %ld Pa | RH: %ld %%\r\n", ( comp_data.temperature / 100 ), comp_data.pressure, ( comp_data.humidity / 1024 ) );
mcm 4:a1c46ef057a6 155
mcm 4:a1c46ef057a6 156 myState = 0; // Reset the variable
mcm 1:f01fab2521b1 157 }
mcm 1:f01fab2521b1 158
mcm 1:f01fab2521b1 159 myled = 0;
mcm 1:f01fab2521b1 160 }
mcm 1:f01fab2521b1 161 }
mcm 1:f01fab2521b1 162
mcm 1:f01fab2521b1 163
mcm 4:a1c46ef057a6 164 // @brief changeDATA ( void )
mcm 4:a1c46ef057a6 165 //
mcm 4:a1c46ef057a6 166 // @details It changes myState variable
mcm 4:a1c46ef057a6 167 //
mcm 4:a1c46ef057a6 168 // @param[in] N/A
mcm 4:a1c46ef057a6 169 //
mcm 4:a1c46ef057a6 170 // @param[out] N/A.
mcm 4:a1c46ef057a6 171 //
mcm 4:a1c46ef057a6 172 //
mcm 4:a1c46ef057a6 173 // @return N/A..
mcm 4:a1c46ef057a6 174 //
mcm 4:a1c46ef057a6 175 //
mcm 4:a1c46ef057a6 176 // @author Manuel Caballero
mcm 4:a1c46ef057a6 177 // @date 03/September/2019
mcm 4:a1c46ef057a6 178 // @version 03/September/2019 The ORIGIN
mcm 4:a1c46ef057a6 179 // @pre N/A
mcm 4:a1c46ef057a6 180 // @warning N/A.
mcm 1:f01fab2521b1 181 void changeDATA ( void )
mcm 1:f01fab2521b1 182 {
mcm 1:f01fab2521b1 183 myState = 1;
mcm 1:f01fab2521b1 184 }
mcm 1:f01fab2521b1 185
mcm 1:f01fab2521b1 186
mcm 4:a1c46ef057a6 187 // @brief user_delay_ms ( uint32_t )
mcm 4:a1c46ef057a6 188 //
mcm 4:a1c46ef057a6 189 // @details Return control or wait, for a period amount of milliseconds
mcm 4:a1c46ef057a6 190 //
mcm 4:a1c46ef057a6 191 // @param[in] period: Delay in milliseconds.
mcm 4:a1c46ef057a6 192 //
mcm 4:a1c46ef057a6 193 // @param[out] N/A.
mcm 4:a1c46ef057a6 194 //
mcm 4:a1c46ef057a6 195 //
mcm 4:a1c46ef057a6 196 // @return N/A..
mcm 4:a1c46ef057a6 197 //
mcm 4:a1c46ef057a6 198 //
mcm 4:a1c46ef057a6 199 // @author Manuel Caballero
mcm 4:a1c46ef057a6 200 // @date 03/September/2019
mcm 4:a1c46ef057a6 201 // @version 03/September/2019 The ORIGIN
mcm 4:a1c46ef057a6 202 // @pre This is a Bosh pointer function adapted to our system.
mcm 4:a1c46ef057a6 203 // @warning N/A.
mcm 1:f01fab2521b1 204 void user_delay_ms ( uint32_t period )
mcm 1:f01fab2521b1 205 {
mcm 4:a1c46ef057a6 206 // Return control or wait,
mcm 4:a1c46ef057a6 207 // for a period amount of milliseconds
mcm 1:f01fab2521b1 208
mcm 1:f01fab2521b1 209 wait_ms ( period );
mcm 1:f01fab2521b1 210 }
mcm 1:f01fab2521b1 211
mcm 1:f01fab2521b1 212
mcm 4:a1c46ef057a6 213 // @brief user_i2c_read ( uint8_t , uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 4:a1c46ef057a6 214 //
mcm 4:a1c46ef057a6 215 // @details It adapts I2C reading functionality.
mcm 4:a1c46ef057a6 216 //
mcm 4:a1c46ef057a6 217 // @param[in] dev_id: I2C address.
mcm 4:a1c46ef057a6 218 // @param[in] reg_addr: Register to be read.
mcm 4:a1c46ef057a6 219 // @param[in] len: How many bytes to read.
mcm 4:a1c46ef057a6 220 //
mcm 4:a1c46ef057a6 221 // @param[out] reg_data: Result.
mcm 4:a1c46ef057a6 222 //
mcm 4:a1c46ef057a6 223 //
mcm 4:a1c46ef057a6 224 // @return Status of user_i2c_read.
mcm 4:a1c46ef057a6 225 //
mcm 4:a1c46ef057a6 226 //
mcm 4:a1c46ef057a6 227 // @author Manuel Caballero
mcm 4:a1c46ef057a6 228 // @date 03/September/2019
mcm 4:a1c46ef057a6 229 // @version 03/September/2019 The ORIGIN
mcm 4:a1c46ef057a6 230 // @pre This is a Bosh pointer function adapted to our system.
mcm 4:a1c46ef057a6 231 // @warning N/A.
mcm 1:f01fab2521b1 232 int8_t user_i2c_read ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 1:f01fab2521b1 233 {
mcm 1:f01fab2521b1 234 int8_t rslt = 0; // Return 0 for Success, non-zero for failure
mcm 1:f01fab2521b1 235
mcm 1:f01fab2521b1 236 // The parameter dev_id can be used as a variable to store the I2C address of the device
mcm 1:f01fab2521b1 237
mcm 1:f01fab2521b1 238
mcm 4:a1c46ef057a6 239 // Data on the bus should be like
mcm 4:a1c46ef057a6 240 // |------------+---------------------|
mcm 4:a1c46ef057a6 241 // | I2C action | Data |
mcm 4:a1c46ef057a6 242 // |------------+---------------------|
mcm 4:a1c46ef057a6 243 // | Start | - |
mcm 4:a1c46ef057a6 244 // | Write | (reg_addr) |
mcm 4:a1c46ef057a6 245 // | Stop | - |
mcm 4:a1c46ef057a6 246 // | Start | - |
mcm 4:a1c46ef057a6 247 // | Read | (reg_data[0]) |
mcm 4:a1c46ef057a6 248 // | Read | (....) |
mcm 4:a1c46ef057a6 249 // | Read | (reg_data[len - 1]) |
mcm 4:a1c46ef057a6 250 // | Stop | - |
mcm 4:a1c46ef057a6 251 // |------------+---------------------|
mcm 1:f01fab2521b1 252
mcm 4:a1c46ef057a6 253 // Read data
mcm 4:a1c46ef057a6 254 uint32_t aux = 0;
mcm 4:a1c46ef057a6 255 aux = myBME280._i2c.write ( dev_id, (char*)&reg_addr, 1, true );
mcm 4:a1c46ef057a6 256 aux = myBME280._i2c.read ( dev_id, (char*)&reg_data[0], len );
mcm 4:a1c46ef057a6 257
mcm 4:a1c46ef057a6 258
mcm 4:a1c46ef057a6 259 if ( aux == 0 ) {
mcm 4:a1c46ef057a6 260 rslt = 0;
mcm 4:a1c46ef057a6 261 } else {
mcm 4:a1c46ef057a6 262 rslt = 0xFF;
mcm 4:a1c46ef057a6 263 }
mcm 1:f01fab2521b1 264
mcm 1:f01fab2521b1 265
mcm 1:f01fab2521b1 266 return rslt;
mcm 1:f01fab2521b1 267 }
mcm 1:f01fab2521b1 268
mcm 1:f01fab2521b1 269
mcm 4:a1c46ef057a6 270 // @brief user_i2c_write ( uint8_t , uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 4:a1c46ef057a6 271 //
mcm 4:a1c46ef057a6 272 // @details It adapts I2C writing functionality.
mcm 4:a1c46ef057a6 273 //
mcm 4:a1c46ef057a6 274 // @param[in] dev_id: I2C address.
mcm 4:a1c46ef057a6 275 // @param[in] reg_addr: Register to be read.
mcm 4:a1c46ef057a6 276 // @param[out] reg_data: Data to be written.
mcm 4:a1c46ef057a6 277 // @param[in] len: How many bytes to read.
mcm 4:a1c46ef057a6 278 //
mcm 4:a1c46ef057a6 279 // @param[out] N/A.
mcm 4:a1c46ef057a6 280 //
mcm 4:a1c46ef057a6 281 //
mcm 4:a1c46ef057a6 282 // @return Status of user_i2c_write.
mcm 4:a1c46ef057a6 283 //
mcm 4:a1c46ef057a6 284 //
mcm 4:a1c46ef057a6 285 // @author Manuel Caballero
mcm 4:a1c46ef057a6 286 // @date 03/September/2019
mcm 4:a1c46ef057a6 287 // @version 03/September/2019 The ORIGIN
mcm 4:a1c46ef057a6 288 // @pre This is a Bosh pointer function adapted to our system.
mcm 4:a1c46ef057a6 289 // @warning N/A.
mcm 1:f01fab2521b1 290 int8_t user_i2c_write ( uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len )
mcm 1:f01fab2521b1 291 {
mcm 1:f01fab2521b1 292 int8_t rslt = 0; // Return 0 for Success, non-zero for failure
mcm 1:f01fab2521b1 293
mcm 1:f01fab2521b1 294 // The parameter dev_id can be used as a variable to store the I2C address of the device
mcm 1:f01fab2521b1 295
mcm 1:f01fab2521b1 296
mcm 1:f01fab2521b1 297 // Data on the bus should be like
mcm 1:f01fab2521b1 298 // |------------+---------------------|
mcm 1:f01fab2521b1 299 // | I2C action | Data |
mcm 1:f01fab2521b1 300 // |------------+---------------------|
mcm 1:f01fab2521b1 301 // | Start | - |
mcm 1:f01fab2521b1 302 // | Write | (reg_addr) |
mcm 1:f01fab2521b1 303 // | Write | (reg_data[0]) |
mcm 1:f01fab2521b1 304 // | Write | (....) |
mcm 1:f01fab2521b1 305 // | Write | (reg_data[len - 1]) |
mcm 1:f01fab2521b1 306 // | Stop | - |
mcm 1:f01fab2521b1 307 // |------------+---------------------|
mcm 1:f01fab2521b1 308
mcm 4:a1c46ef057a6 309 uint32_t aux = 0;
mcm 4:a1c46ef057a6 310 char cmd[64] = { 0 };
mcm 4:a1c46ef057a6 311 uint32_t i = 0;
mcm 1:f01fab2521b1 312
mcm 4:a1c46ef057a6 313 // Prepare the data to be sent
mcm 4:a1c46ef057a6 314 cmd[0] = reg_addr;
mcm 4:a1c46ef057a6 315 for ( i = 1; i <= len; i++ ) {
mcm 4:a1c46ef057a6 316 cmd[i] = reg_data[i - 1];
mcm 4:a1c46ef057a6 317 }
mcm 4:a1c46ef057a6 318
mcm 4:a1c46ef057a6 319 // Write data
mcm 4:a1c46ef057a6 320 aux = myBME280._i2c.write ( dev_id, &cmd[0], len + 1, false );
mcm 4:a1c46ef057a6 321
mcm 4:a1c46ef057a6 322
mcm 4:a1c46ef057a6 323 if ( aux == 0 ) {
mcm 4:a1c46ef057a6 324 rslt = 0;
mcm 4:a1c46ef057a6 325 } else {
mcm 4:a1c46ef057a6 326 rslt = 0xFF;
mcm 4:a1c46ef057a6 327 }
mcm 1:f01fab2521b1 328
mcm 1:f01fab2521b1 329 return rslt;
mcm 1:f01fab2521b1 330 }
mcm 1:f01fab2521b1 331 @endcode
mcm 1:f01fab2521b1 332 */
mcm 1:f01fab2521b1 333
mcm 1:f01fab2521b1 334
mcm 1:f01fab2521b1 335
mcm 1:f01fab2521b1 336 /*!
mcm 3:ab857b70346e 337 Library for BME280 Combined humidity and pressure sensor.
mcm 1:f01fab2521b1 338 */
mcm 3:ab857b70346e 339 class BME280
mcm 1:f01fab2521b1 340 {
mcm 1:f01fab2521b1 341 public:
mcm 1:f01fab2521b1 342 /** Create an BME680 object connected to the specified I2C pins.
mcm 1:f01fab2521b1 343 *
mcm 1:f01fab2521b1 344 * @param sda I2C data pin
mcm 1:f01fab2521b1 345 * @param scl I2C clock pin
mcm 1:f01fab2521b1 346 * @param freq I2C frequency
mcm 1:f01fab2521b1 347 */
mcm 1:f01fab2521b1 348 BME280 ( PinName sda, PinName scl, uint32_t freq );
mcm 1:f01fab2521b1 349
mcm 1:f01fab2521b1 350 /** Delete BME680 object.
mcm 1:f01fab2521b1 351 */
mcm 1:f01fab2521b1 352 ~BME280();
mcm 1:f01fab2521b1 353
mcm 1:f01fab2521b1 354 /*!
mcm 1:f01fab2521b1 355 * @brief This API is the entry point.
mcm 1:f01fab2521b1 356 * It reads the chip-id and calibration data from the sensor.
mcm 1:f01fab2521b1 357 *
mcm 1:f01fab2521b1 358 * @param[in,out] dev : Structure instance of bme280_dev
mcm 1:f01fab2521b1 359 *
mcm 1:f01fab2521b1 360 * @return Result of API execution status
mcm 1:f01fab2521b1 361 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 362 */
mcm 1:f01fab2521b1 363 int8_t bme280_init(struct bme280_dev *dev);
mcm 1:f01fab2521b1 364
mcm 1:f01fab2521b1 365 /*!
mcm 1:f01fab2521b1 366 * @brief This API writes the given data to the register address
mcm 1:f01fab2521b1 367 * of the sensor.
mcm 1:f01fab2521b1 368 *
mcm 1:f01fab2521b1 369 * @param[in] reg_addr : Register address from where the data to be written.
mcm 1:f01fab2521b1 370 * @param[in] reg_data : Pointer to data buffer which is to be written
mcm 1:f01fab2521b1 371 * in the sensor.
mcm 1:f01fab2521b1 372 * @param[in] len : No of bytes of data to write..
mcm 1:f01fab2521b1 373 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 374 *
mcm 1:f01fab2521b1 375 * @return Result of API execution status
mcm 1:f01fab2521b1 376 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 377 */
mcm 1:f01fab2521b1 378 int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, const struct bme280_dev *dev);
mcm 1:f01fab2521b1 379
mcm 1:f01fab2521b1 380 /*!
mcm 1:f01fab2521b1 381 * @brief This API reads the data from the given register address of the sensor.
mcm 1:f01fab2521b1 382 *
mcm 1:f01fab2521b1 383 * @param[in] reg_addr : Register address from where the data to be read
mcm 1:f01fab2521b1 384 * @param[out] reg_data : Pointer to data buffer to store the read data.
mcm 1:f01fab2521b1 385 * @param[in] len : No of bytes of data to be read.
mcm 1:f01fab2521b1 386 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 387 *
mcm 1:f01fab2521b1 388 * @return Result of API execution status
mcm 1:f01fab2521b1 389 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 390 */
mcm 1:f01fab2521b1 391 int8_t bme280_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, const struct bme280_dev *dev);
mcm 1:f01fab2521b1 392
mcm 1:f01fab2521b1 393 /*!
mcm 1:f01fab2521b1 394 * @brief This API sets the oversampling, filter and standby duration
mcm 1:f01fab2521b1 395 * (normal mode) settings in the sensor.
mcm 1:f01fab2521b1 396 *
mcm 1:f01fab2521b1 397 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 398 * @param[in] desired_settings : Variable used to select the settings which
mcm 1:f01fab2521b1 399 * are to be set in the sensor.
mcm 1:f01fab2521b1 400 *
mcm 1:f01fab2521b1 401 * @note : Below are the macros to be used by the user for selecting the
mcm 1:f01fab2521b1 402 * desired settings. User can do OR operation of these macros for configuring
mcm 1:f01fab2521b1 403 * multiple settings.
mcm 1:f01fab2521b1 404 *
mcm 1:f01fab2521b1 405 * Macros | Functionality
mcm 1:f01fab2521b1 406 * -----------------------|----------------------------------------------
mcm 1:f01fab2521b1 407 * BME280_OSR_PRESS_SEL | To set pressure oversampling.
mcm 1:f01fab2521b1 408 * BME280_OSR_TEMP_SEL | To set temperature oversampling.
mcm 1:f01fab2521b1 409 * BME280_OSR_HUM_SEL | To set humidity oversampling.
mcm 1:f01fab2521b1 410 * BME280_FILTER_SEL | To set filter setting.
mcm 1:f01fab2521b1 411 * BME280_STANDBY_SEL | To set standby duration setting.
mcm 1:f01fab2521b1 412 *
mcm 1:f01fab2521b1 413 * @return Result of API execution status
mcm 1:f01fab2521b1 414 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:f01fab2521b1 415 */
mcm 1:f01fab2521b1 416 int8_t bme280_set_sensor_settings(uint8_t desired_settings, const struct bme280_dev *dev);
mcm 1:f01fab2521b1 417
mcm 1:f01fab2521b1 418 /*!
mcm 1:f01fab2521b1 419 * @brief This API gets the oversampling, filter and standby duration
mcm 1:f01fab2521b1 420 * (normal mode) settings from the sensor.
mcm 1:f01fab2521b1 421 *
mcm 1:f01fab2521b1 422 * @param[in,out] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 423 *
mcm 1:f01fab2521b1 424 * @return Result of API execution status
mcm 1:f01fab2521b1 425 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:f01fab2521b1 426 */
mcm 1:f01fab2521b1 427 int8_t bme280_get_sensor_settings(struct bme280_dev *dev);
mcm 1:f01fab2521b1 428
mcm 1:f01fab2521b1 429 /*!
mcm 1:f01fab2521b1 430 * @brief This API sets the power mode of the sensor.
mcm 1:f01fab2521b1 431 *
mcm 1:f01fab2521b1 432 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 433 * @param[in] sensor_mode : Variable which contains the power mode to be set.
mcm 1:f01fab2521b1 434 *
mcm 1:f01fab2521b1 435 * sensor_mode | Macros
mcm 1:f01fab2521b1 436 * ---------------------|-------------------
mcm 1:f01fab2521b1 437 * 0 | BME280_SLEEP_MODE
mcm 1:f01fab2521b1 438 * 1 | BME280_FORCED_MODE
mcm 1:f01fab2521b1 439 * 3 | BME280_NORMAL_MODE
mcm 1:f01fab2521b1 440 *
mcm 1:f01fab2521b1 441 * @return Result of API execution status
mcm 1:f01fab2521b1 442 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 443 */
mcm 1:f01fab2521b1 444 int8_t bme280_set_sensor_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
mcm 1:f01fab2521b1 445
mcm 1:f01fab2521b1 446 /*!
mcm 1:f01fab2521b1 447 * @brief This API gets the power mode of the sensor.
mcm 1:f01fab2521b1 448 *
mcm 1:f01fab2521b1 449 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 450 * @param[out] sensor_mode : Pointer variable to store the power mode.
mcm 1:f01fab2521b1 451 *
mcm 1:f01fab2521b1 452 * sensor_mode | Macros
mcm 1:f01fab2521b1 453 * ---------------------|-------------------
mcm 1:f01fab2521b1 454 * 0 | BME280_SLEEP_MODE
mcm 1:f01fab2521b1 455 * 1 | BME280_FORCED_MODE
mcm 1:f01fab2521b1 456 * 3 | BME280_NORMAL_MODE
mcm 1:f01fab2521b1 457 *
mcm 1:f01fab2521b1 458 * @return Result of API execution status
mcm 1:f01fab2521b1 459 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 460 */
mcm 1:f01fab2521b1 461 int8_t bme280_get_sensor_mode(uint8_t *sensor_mode, const struct bme280_dev *dev);
mcm 1:f01fab2521b1 462
mcm 1:f01fab2521b1 463 /*!
mcm 1:f01fab2521b1 464 * @brief This API performs the soft reset of the sensor.
mcm 1:f01fab2521b1 465 *
mcm 1:f01fab2521b1 466 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 467 *
mcm 1:f01fab2521b1 468 * @return Result of API execution status
mcm 1:f01fab2521b1 469 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
mcm 1:f01fab2521b1 470 */
mcm 1:f01fab2521b1 471 int8_t bme280_soft_reset(const struct bme280_dev *dev);
mcm 1:f01fab2521b1 472
mcm 1:f01fab2521b1 473 /*!
mcm 1:f01fab2521b1 474 * @brief This API reads the pressure, temperature and humidity data from the
mcm 1:f01fab2521b1 475 * sensor, compensates the data and store it in the bme280_data structure
mcm 1:f01fab2521b1 476 * instance passed by the user.
mcm 1:f01fab2521b1 477 *
mcm 1:f01fab2521b1 478 * @param[in] sensor_comp : Variable which selects which data to be read from
mcm 1:f01fab2521b1 479 * the sensor.
mcm 1:f01fab2521b1 480 *
mcm 1:f01fab2521b1 481 * sensor_comp | Macros
mcm 1:f01fab2521b1 482 * ------------|-------------------
mcm 1:f01fab2521b1 483 * 1 | BME280_PRESS
mcm 1:f01fab2521b1 484 * 2 | BME280_TEMP
mcm 1:f01fab2521b1 485 * 4 | BME280_HUM
mcm 1:f01fab2521b1 486 * 7 | BME280_ALL
mcm 1:f01fab2521b1 487 *
mcm 1:f01fab2521b1 488 * @param[out] comp_data : Structure instance of bme280_data.
mcm 1:f01fab2521b1 489 * @param[in] dev : Structure instance of bme280_dev.
mcm 1:f01fab2521b1 490 *
mcm 1:f01fab2521b1 491 * @return Result of API execution status
mcm 1:f01fab2521b1 492 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 1:f01fab2521b1 493 */
mcm 1:f01fab2521b1 494 int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev);
mcm 1:f01fab2521b1 495
mcm 1:f01fab2521b1 496 I2C _i2c;
mcm 1:f01fab2521b1 497
mcm 1:f01fab2521b1 498 private:
mcm 1:f01fab2521b1 499 /*!
mcm 3:ab857b70346e 500 * @brief This internal API puts the device to sleep mode.
mcm 3:ab857b70346e 501 *
mcm 3:ab857b70346e 502 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 503 *
mcm 3:ab857b70346e 504 * @return Result of API execution status.
mcm 3:ab857b70346e 505 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 506 */
mcm 3:ab857b70346e 507 int8_t put_device_to_sleep(const struct bme280_dev *dev);
mcm 3:ab857b70346e 508
mcm 3:ab857b70346e 509 /*!
mcm 3:ab857b70346e 510 * @brief This internal API writes the power mode in the sensor.
mcm 3:ab857b70346e 511 *
mcm 3:ab857b70346e 512 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 513 * @param[in] sensor_mode : Variable which contains the power mode to be set.
mcm 3:ab857b70346e 514 *
mcm 3:ab857b70346e 515 * @return Result of API execution status.
mcm 3:ab857b70346e 516 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 517 */
mcm 3:ab857b70346e 518 int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
mcm 3:ab857b70346e 519
mcm 3:ab857b70346e 520 /*!
mcm 3:ab857b70346e 521 * @brief This internal API is used to validate the device pointer for
mcm 3:ab857b70346e 522 * null conditions.
mcm 3:ab857b70346e 523 *
mcm 3:ab857b70346e 524 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 525 *
mcm 3:ab857b70346e 526 * @return Result of API execution status
mcm 3:ab857b70346e 527 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 528 */
mcm 3:ab857b70346e 529 int8_t null_ptr_check(const struct bme280_dev *dev);
mcm 3:ab857b70346e 530
mcm 3:ab857b70346e 531 /*!
mcm 3:ab857b70346e 532 * @brief This internal API interleaves the register address between the
mcm 3:ab857b70346e 533 * register data buffer for burst write operation.
mcm 3:ab857b70346e 534 *
mcm 3:ab857b70346e 535 * @param[in] reg_addr : Contains the register address array.
mcm 3:ab857b70346e 536 * @param[out] temp_buff : Contains the temporary buffer to store the
mcm 3:ab857b70346e 537 * register data and register address.
mcm 3:ab857b70346e 538 * @param[in] reg_data : Contains the register data to be written in the
mcm 3:ab857b70346e 539 * temporary buffer.
mcm 3:ab857b70346e 540 * @param[in] len : No of bytes of data to be written for burst write.
mcm 3:ab857b70346e 541 */
mcm 3:ab857b70346e 542 void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint8_t len);
mcm 3:ab857b70346e 543
mcm 3:ab857b70346e 544 /*!
mcm 3:ab857b70346e 545 * @brief This internal API reads the calibration data from the sensor, parse
mcm 3:ab857b70346e 546 * it and store in the device structure.
mcm 3:ab857b70346e 547 *
mcm 3:ab857b70346e 548 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 549 *
mcm 3:ab857b70346e 550 * @return Result of API execution status
mcm 3:ab857b70346e 551 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 552 */
mcm 3:ab857b70346e 553 int8_t get_calib_data(struct bme280_dev *dev);
mcm 3:ab857b70346e 554
mcm 3:ab857b70346e 555 /*!
mcm 3:ab857b70346e 556 * @brief This internal API is used to parse the temperature and
mcm 3:ab857b70346e 557 * pressure calibration data and store it in the device structure.
mcm 3:ab857b70346e 558 *
mcm 3:ab857b70346e 559 * @param[out] dev : Structure instance of bme280_dev to store the calib data.
mcm 3:ab857b70346e 560 * @param[in] reg_data : Contains the calibration data to be parsed.
mcm 3:ab857b70346e 561 */
mcm 3:ab857b70346e 562 void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
mcm 3:ab857b70346e 563
mcm 3:ab857b70346e 564 /*!
mcm 3:ab857b70346e 565 * @brief This internal API is used to parse the humidity calibration data
mcm 3:ab857b70346e 566 * and store it in device structure.
mcm 3:ab857b70346e 567 *
mcm 3:ab857b70346e 568 * @param[out] dev : Structure instance of bme280_dev to store the calib data.
mcm 3:ab857b70346e 569 * @param[in] reg_data : Contains calibration data to be parsed.
mcm 3:ab857b70346e 570 */
mcm 3:ab857b70346e 571 void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
mcm 3:ab857b70346e 572
mcm 3:ab857b70346e 573 #ifdef BME280_FLOAT_ENABLE
mcm 3:ab857b70346e 574
mcm 3:ab857b70346e 575 /*!
mcm 3:ab857b70346e 576 * @brief This internal API is used to compensate the raw pressure data and
mcm 3:ab857b70346e 577 * return the compensated pressure data in double data type.
mcm 3:ab857b70346e 578 *
mcm 3:ab857b70346e 579 * @param[in] uncomp_data : Contains the uncompensated pressure data.
mcm 3:ab857b70346e 580 * @param[in] calib_data : Pointer to the calibration data structure.
mcm 3:ab857b70346e 581 *
mcm 3:ab857b70346e 582 * @return Compensated pressure data.
mcm 3:ab857b70346e 583 * @retval Compensated pressure data in double.
mcm 3:ab857b70346e 584 */
mcm 3:ab857b70346e 585 double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 586 const struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 587
mcm 3:ab857b70346e 588 /*!
mcm 3:ab857b70346e 589 * @brief This internal API is used to compensate the raw humidity data and
mcm 3:ab857b70346e 590 * return the compensated humidity data in double data type.
mcm 3:ab857b70346e 591 *
mcm 3:ab857b70346e 592 * @param[in] uncomp_data : Contains the uncompensated humidity data.
mcm 3:ab857b70346e 593 * @param[in] calib_data : Pointer to the calibration data structure.
mcm 3:ab857b70346e 594 *
mcm 3:ab857b70346e 595 * @return Compensated humidity data.
mcm 3:ab857b70346e 596 * @retval Compensated humidity data in double.
mcm 3:ab857b70346e 597 */
mcm 3:ab857b70346e 598 double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 599 const struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 600
mcm 3:ab857b70346e 601 /*!
mcm 3:ab857b70346e 602 * @brief This internal API is used to compensate the raw temperature data and
mcm 3:ab857b70346e 603 * return the compensated temperature data in double data type.
mcm 3:ab857b70346e 604 *
mcm 3:ab857b70346e 605 * @param[in] uncomp_data : Contains the uncompensated temperature data.
mcm 3:ab857b70346e 606 * @param[in] calib_data : Pointer to calibration data structure.
mcm 3:ab857b70346e 607 *
mcm 3:ab857b70346e 608 * @return Compensated temperature data.
mcm 3:ab857b70346e 609 * @retval Compensated temperature data in double.
mcm 3:ab857b70346e 610 */
mcm 3:ab857b70346e 611 double compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 612 struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 613
mcm 3:ab857b70346e 614 #else
mcm 3:ab857b70346e 615
mcm 3:ab857b70346e 616 /*!
mcm 3:ab857b70346e 617 * @brief This internal API is used to compensate the raw temperature data and
mcm 3:ab857b70346e 618 * return the compensated temperature data in integer data type.
mcm 3:ab857b70346e 619 *
mcm 3:ab857b70346e 620 * @param[in] uncomp_data : Contains the uncompensated temperature data.
mcm 3:ab857b70346e 621 * @param[in] calib_data : Pointer to calibration data structure.
mcm 3:ab857b70346e 622 *
mcm 3:ab857b70346e 623 * @return Compensated temperature data.
mcm 3:ab857b70346e 624 * @retval Compensated temperature data in integer.
mcm 3:ab857b70346e 625 */
mcm 3:ab857b70346e 626 int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 627 struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 628
mcm 3:ab857b70346e 629 /*!
mcm 3:ab857b70346e 630 * @brief This internal API is used to compensate the raw pressure data and
mcm 3:ab857b70346e 631 * return the compensated pressure data in integer data type.
mcm 3:ab857b70346e 632 *
mcm 3:ab857b70346e 633 * @param[in] uncomp_data : Contains the uncompensated pressure data.
mcm 3:ab857b70346e 634 * @param[in] calib_data : Pointer to the calibration data structure.
mcm 3:ab857b70346e 635 *
mcm 3:ab857b70346e 636 * @return Compensated pressure data.
mcm 3:ab857b70346e 637 * @retval Compensated pressure data in integer.
mcm 3:ab857b70346e 638 */
mcm 3:ab857b70346e 639 uint32_t compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 640 const struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 641
mcm 3:ab857b70346e 642 /*!
mcm 3:ab857b70346e 643 * @brief This internal API is used to compensate the raw humidity data and
mcm 3:ab857b70346e 644 * return the compensated humidity data in integer data type.
mcm 3:ab857b70346e 645 *
mcm 3:ab857b70346e 646 * @param[in] uncomp_data : Contains the uncompensated humidity data.
mcm 3:ab857b70346e 647 * @param[in] calib_data : Pointer to the calibration data structure.
mcm 3:ab857b70346e 648 *
mcm 3:ab857b70346e 649 * @return Compensated humidity data.
mcm 3:ab857b70346e 650 * @retval Compensated humidity data in integer.
mcm 3:ab857b70346e 651 */
mcm 3:ab857b70346e 652 uint32_t compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
mcm 4:a1c46ef057a6 653 const struct bme280_calib_data *calib_data);
mcm 3:ab857b70346e 654
mcm 3:ab857b70346e 655 #endif
mcm 3:ab857b70346e 656
mcm 3:ab857b70346e 657 /*!
mcm 3:ab857b70346e 658 * @brief This internal API is used to identify the settings which the user
mcm 3:ab857b70346e 659 * wants to modify in the sensor.
mcm 3:ab857b70346e 660 *
mcm 3:ab857b70346e 661 * @param[in] sub_settings : Contains the settings subset to identify particular
mcm 3:ab857b70346e 662 * group of settings which the user is interested to change.
mcm 3:ab857b70346e 663 * @param[in] desired_settings : Contains the user specified settings.
mcm 3:ab857b70346e 664 *
mcm 3:ab857b70346e 665 * @return Indicates whether user is interested to modify the settings which
mcm 3:ab857b70346e 666 * are related to sub_settings.
mcm 3:ab857b70346e 667 * @retval True -> User wants to modify this group of settings
mcm 3:ab857b70346e 668 * @retval False -> User does not want to modify this group of settings
mcm 3:ab857b70346e 669 */
mcm 3:ab857b70346e 670 uint8_t are_settings_changed(uint8_t sub_settings, uint8_t desired_settings);
mcm 3:ab857b70346e 671
mcm 3:ab857b70346e 672 /*!
mcm 3:ab857b70346e 673 * @brief This API sets the humidity oversampling settings of the sensor.
mcm 3:ab857b70346e 674 *
mcm 3:ab857b70346e 675 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 676 *
mcm 3:ab857b70346e 677 * @return Result of API execution status
mcm 3:ab857b70346e 678 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 679 */
mcm 3:ab857b70346e 680 int8_t set_osr_humidity_settings(const struct bme280_settings *settings, const struct bme280_dev *dev);
mcm 3:ab857b70346e 681
mcm 3:ab857b70346e 682 /*!
mcm 3:ab857b70346e 683 * @brief This internal API sets the oversampling settings for pressure,
mcm 3:ab857b70346e 684 * temperature and humidity in the sensor.
mcm 3:ab857b70346e 685 *
mcm 3:ab857b70346e 686 * @param[in] desired_settings : Variable used to select the settings which
mcm 3:ab857b70346e 687 * are to be set.
mcm 3:ab857b70346e 688 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 689 *
mcm 3:ab857b70346e 690 * @return Result of API execution status
mcm 3:ab857b70346e 691 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 692 */
mcm 3:ab857b70346e 693 int8_t set_osr_settings(uint8_t desired_settings,
mcm 4:a1c46ef057a6 694 const struct bme280_settings *settings,
mcm 4:a1c46ef057a6 695 const struct bme280_dev *dev);
mcm 3:ab857b70346e 696
mcm 3:ab857b70346e 697 /*!
mcm 3:ab857b70346e 698 * @brief This API sets the pressure and/or temperature oversampling settings
mcm 3:ab857b70346e 699 * in the sensor according to the settings selected by the user.
mcm 3:ab857b70346e 700 *
mcm 3:ab857b70346e 701 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 702 * @param[in] desired_settings: variable to select the pressure and/or
mcm 3:ab857b70346e 703 * temperature oversampling settings.
mcm 3:ab857b70346e 704 *
mcm 3:ab857b70346e 705 * @return Result of API execution status
mcm 3:ab857b70346e 706 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 707 */
mcm 3:ab857b70346e 708 int8_t set_osr_press_temp_settings(uint8_t desired_settings,
mcm 4:a1c46ef057a6 709 const struct bme280_settings *settings,
mcm 4:a1c46ef057a6 710 const struct bme280_dev *dev);
mcm 3:ab857b70346e 711
mcm 3:ab857b70346e 712 /*!
mcm 3:ab857b70346e 713 * @brief This internal API fills the pressure oversampling settings provided by
mcm 3:ab857b70346e 714 * the user in the data buffer so as to write in the sensor.
mcm 3:ab857b70346e 715 *
mcm 3:ab857b70346e 716 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 717 * @param[out] reg_data : Variable which is filled according to the pressure
mcm 3:ab857b70346e 718 * oversampling data provided by the user.
mcm 3:ab857b70346e 719 */
mcm 3:ab857b70346e 720 void fill_osr_press_settings(uint8_t *reg_data, const struct bme280_settings *settings);
mcm 3:ab857b70346e 721
mcm 3:ab857b70346e 722 /*!
mcm 3:ab857b70346e 723 * @brief This internal API fills the temperature oversampling settings provided
mcm 3:ab857b70346e 724 * by the user in the data buffer so as to write in the sensor.
mcm 3:ab857b70346e 725 *
mcm 3:ab857b70346e 726 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 727 * @param[out] reg_data : Variable which is filled according to the temperature
mcm 3:ab857b70346e 728 * oversampling data provided by the user.
mcm 3:ab857b70346e 729 */
mcm 3:ab857b70346e 730 void fill_osr_temp_settings(uint8_t *reg_data, const struct bme280_settings *settings);
mcm 3:ab857b70346e 731
mcm 3:ab857b70346e 732 /*!
mcm 3:ab857b70346e 733 * @brief This internal API sets the filter and/or standby duration settings
mcm 3:ab857b70346e 734 * in the sensor according to the settings selected by the user.
mcm 3:ab857b70346e 735 *
mcm 3:ab857b70346e 736 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 737 * @param[in] desired_settings : variable to select the filter and/or
mcm 3:ab857b70346e 738 * standby duration settings.
mcm 3:ab857b70346e 739 *
mcm 3:ab857b70346e 740 * @return Result of API execution status
mcm 3:ab857b70346e 741 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 742 */
mcm 3:ab857b70346e 743 int8_t set_filter_standby_settings(uint8_t desired_settings,
mcm 4:a1c46ef057a6 744 const struct bme280_settings *settings,
mcm 4:a1c46ef057a6 745 const struct bme280_dev *dev);
mcm 3:ab857b70346e 746
mcm 3:ab857b70346e 747 /*!
mcm 3:ab857b70346e 748 * @brief This internal API fills the filter settings provided by the user
mcm 3:ab857b70346e 749 * in the data buffer so as to write in the sensor.
mcm 3:ab857b70346e 750 *
mcm 3:ab857b70346e 751 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 752 * @param[out] reg_data : Variable which is filled according to the filter
mcm 3:ab857b70346e 753 * settings data provided by the user.
mcm 3:ab857b70346e 754 */
mcm 3:ab857b70346e 755 void fill_filter_settings(uint8_t *reg_data, const struct bme280_settings *settings);
mcm 3:ab857b70346e 756
mcm 3:ab857b70346e 757 /*!
mcm 3:ab857b70346e 758 * @brief This internal API fills the standby duration settings provided by the
mcm 3:ab857b70346e 759 * user in the data buffer so as to write in the sensor.
mcm 3:ab857b70346e 760 *
mcm 3:ab857b70346e 761 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 762 * @param[out] reg_data : Variable which is filled according to the standby
mcm 3:ab857b70346e 763 * settings data provided by the user.
mcm 3:ab857b70346e 764 */
mcm 3:ab857b70346e 765 void fill_standby_settings(uint8_t *reg_data, const struct bme280_settings *settings);
mcm 3:ab857b70346e 766
mcm 3:ab857b70346e 767 /*!
mcm 3:ab857b70346e 768 * @brief This internal API parse the oversampling(pressure, temperature
mcm 3:ab857b70346e 769 * and humidity), filter and standby duration settings and store in the
mcm 3:ab857b70346e 770 * device structure.
mcm 3:ab857b70346e 771 *
mcm 3:ab857b70346e 772 * @param[out] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 773 * @param[in] reg_data : Register data to be parsed.
mcm 3:ab857b70346e 774 */
mcm 3:ab857b70346e 775 void parse_device_settings(const uint8_t *reg_data, struct bme280_settings *settings);
mcm 3:ab857b70346e 776
mcm 3:ab857b70346e 777 /*!
mcm 3:ab857b70346e 778 * @brief This internal API reloads the already existing device settings in the
mcm 3:ab857b70346e 779 * sensor after soft reset.
mcm 3:ab857b70346e 780 *
mcm 3:ab857b70346e 781 * @param[in] dev : Structure instance of bme280_dev.
mcm 3:ab857b70346e 782 * @param[in] settings : Pointer variable which contains the settings to
mcm 3:ab857b70346e 783 * be set in the sensor.
mcm 3:ab857b70346e 784 *
mcm 3:ab857b70346e 785 * @return Result of API execution status
mcm 3:ab857b70346e 786 * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
mcm 3:ab857b70346e 787 */
mcm 3:ab857b70346e 788 int8_t reload_device_settings(const struct bme280_settings *settings, const struct bme280_dev *dev);
mcm 3:ab857b70346e 789
mcm 3:ab857b70346e 790 /*!
mcm 1:f01fab2521b1 791 * @brief This API is used to parse the pressure, temperature and
mcm 1:f01fab2521b1 792 * humidity data and store it in the bme280_uncomp_data structure instance.
mcm 1:f01fab2521b1 793 *
mcm 1:f01fab2521b1 794 * @param[in] reg_data : Contains register data which needs to be parsed
mcm 1:f01fab2521b1 795 * @param[out] uncomp_data : Contains the uncompensated pressure, temperature
mcm 1:f01fab2521b1 796 * and humidity data.
mcm 1:f01fab2521b1 797 */
mcm 1:f01fab2521b1 798 void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data);
mcm 1:f01fab2521b1 799
mcm 1:f01fab2521b1 800 /*!
mcm 1:f01fab2521b1 801 * @brief This API is used to compensate the pressure and/or
mcm 1:f01fab2521b1 802 * temperature and/or humidity data according to the component selected by the
mcm 1:f01fab2521b1 803 * user.
mcm 1:f01fab2521b1 804 *
mcm 1:f01fab2521b1 805 * @param[in] sensor_comp : Used to select pressure and/or temperature and/or
mcm 1:f01fab2521b1 806 * humidity.
mcm 1:f01fab2521b1 807 * @param[in] uncomp_data : Contains the uncompensated pressure, temperature and
mcm 1:f01fab2521b1 808 * humidity data.
mcm 1:f01fab2521b1 809 * @param[out] comp_data : Contains the compensated pressure and/or temperature
mcm 1:f01fab2521b1 810 * and/or humidity data.
mcm 1:f01fab2521b1 811 * @param[in] calib_data : Pointer to the calibration data structure.
mcm 1:f01fab2521b1 812 *
mcm 1:f01fab2521b1 813 * @return Result of API execution status.
mcm 1:f01fab2521b1 814 * @retval zero -> Success / -ve value -> Error
mcm 1:f01fab2521b1 815 */
mcm 1:f01fab2521b1 816 int8_t bme280_compensate_data(uint8_t sensor_comp,
mcm 1:f01fab2521b1 817 const struct bme280_uncomp_data *uncomp_data,
mcm 1:f01fab2521b1 818 struct bme280_data *comp_data,
mcm 1:f01fab2521b1 819 struct bme280_calib_data *calib_data);
mcm 1:f01fab2521b1 820
mcm 1:f01fab2521b1 821
mcm 1:f01fab2521b1 822 uint32_t _BME280_Addr;
mcm 1:f01fab2521b1 823 };
mcm 1:f01fab2521b1 824
mcm 1:f01fab2521b1 825 #endif /* BME280_H_ */
mcm 1:f01fab2521b1 826 /** @}*/