/** \mainpage * **************************************************************************** * Copyright (C) 2013 - 2015 Bosch Sensortec GmbH * * File : bme280.h * * Date : 2015/03/27 * * Revision : 2.0.4(Pressure and Temperature compensation code revision is 1.1 * and Humidity compensation code revision is 1.0) * * Usage: Sensor Driver for BME280 sensor * **************************************************************************** * * \section License * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * * Neither the name of the copyright holder nor the names of the * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER * OR CONTRIBUTORS BE LIABLE FOR ANY * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, * OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO, * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN * ANY WAY OUT OF THE USE OF THIS * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE * * The information provided is believed to be accurate and reliable. * The copyright holder assumes no responsibility * for the consequences of use * of such information nor for any infringement of patents or * other rights of third parties which may result from its use. * No license is granted by implication or otherwise under any patent or * patent rights of the copyright holder. **************************************************************************/ /*! \file bme280.h \brief BME280 Sensor Driver Support Header File */ #ifndef __BME280_H__ #define __BME280_H__ /*! * @brief The following definition uses for define the data types * * @note While porting the API please consider the following * @note Please check the version of C standard * @note Are you using Linux platform */ /*! * @brief For the Linux platform support * Please use the types.h for your data types definitions */ #ifdef __KERNEL__ #include #include #define BME280_64BITSUPPORT_PRESENT /* singed integer type*/ typedef int8_t s8;/**< used for signed 8bit */ typedef int16_t s16;/**< used for signed 16bit */ typedef int32_t s32;/**< used for signed 32bit */ typedef int64_t s64;/**< used for signed 64bit */ typedef u_int8_t u8;/**< used for unsigned 8bit */ typedef u_int16_t u16;/**< used for unsigned 16bit */ typedef u_int32_t u32;/**< used for unsigned 32bit */ typedef u_int64_t u64;/**< used for unsigned 64bit */ #else /* ! __KERNEL__ */ /********************************************************** * These definition uses for define the C * standard version data types ***********************************************************/ # if !defined(__STDC_VERSION__) /************************************************ * compiler is C11 C standard ************************************************/ #if (__STDC_VERSION__ == 201112L) /************************************************/ #include /************************************************/ /*unsigned integer types*/ typedef uint8_t u8;/**< used for unsigned 8bit */ typedef uint16_t u16;/**< used for unsigned 16bit */ typedef uint32_t u32;/**< used for unsigned 32bit */ typedef uint64_t u64;/**< used for unsigned 64bit */ /*signed integer types*/ typedef int8_t s8;/**< used for signed 8bit */ typedef int16_t s16;/**< used for signed 16bit */ typedef int32_t s32;/**< used for signed 32bit */ typedef int64_t s64;/**< used for signed 64bit */ #define BME280_64BITSUPPORT_PRESENT /************************************************ * compiler is C99 C standard ************************************************/ #elif (__STDC_VERSION__ == 199901L) /* stdint.h is a C99 supported c library. which is used to fixed the integer size*/ /************************************************/ #include /************************************************/ /*unsigned integer types*/ typedef uint8_t u8;/**< used for unsigned 8bit */ typedef uint16_t u16;/**< used for unsigned 16bit */ typedef uint32_t u32;/**< used for unsigned 32bit */ typedef uint64_t u64;/**< used for unsigned 64bit */ /*signed integer types*/ typedef int8_t s8;/**< used for signed 8bit */ typedef int16_t s16;/**< used for signed 16bit */ typedef int32_t s32;/**< used for signed 32bit */ typedef int64_t s64;/**< used for signed 64bit */ #define BME280_64BITSUPPORT_PRESENT /************************************************ * compiler is C89 or other C standard ************************************************/ #else /* !defined(__STDC_VERSION__) */ /*! * @brief By default it is defined as 32 bit machine configuration * define your data types based on your * machine/compiler/controller configuration */ #define MACHINE_32_BIT /*! @brief * If your machine support 16 bit * define the MACHINE_16_BIT */ #ifdef MACHINE_16_BIT #include /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed long int s32;/**< used for signed 32bit */ #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL typedef long int s64;/**< used for signed 64bit */ typedef unsigned long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) typedef long long int s64;/**< used for signed 64bit */ typedef unsigned long long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #else #warning Either the correct data type for signed 64 bit integer \ could not be found, or 64 bit integers are not supported in your environment. #warning The API will only offer 32 bit pressure calculation.This will \ slightly impede accuracy(noise of ~1 pascal RMS will be added to output). #warning If 64 bit integers are supported on your platform, \ please set s64 manually and "#define(BMPE80_64BITSUPPORT_PRESENT)" manually. #endif /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned long int u32;/**< used for unsigned 32bit */ /* If your machine support 32 bit define the MACHINE_32_BIT*/ #elif defined MACHINE_32_BIT /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed int s32;/**< used for signed 32bit */ typedef signed long long int s64;/**< used for signed 64bit */ /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned int u32;/**< used for unsigned 32bit */ typedef unsigned long long int u64;/**< used for unsigned 64bit */ /*! @brief * If your machine support 64 bit * define the MACHINE_64_BIT */ #define BME280_64BITSUPPORT_PRESENT /* If your machine support 64 bit define the MACHINE_64_BIT*/ #elif defined MACHINE_64_BIT /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed int s32;/**< used for signed 32bit */ typedef signed long int s64;/**< used for signed 64bit */ /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned int u32;/**< used for unsigned 32bit */ typedef unsigned long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #else #warning The data types defined above which not supported \ define the data types manually #endif #endif /*** This else will execute for the compilers * which are not supported the C standards * Like C89/C99/C11***/ #else /*! * @brief By default it is defined as 32 bit machine configuration * define your data types based on your * machine/compiler/controller configuration */ #define MACHINE_32_BIT /* If your machine support 16 bit define the MACHINE_16_BIT*/ #ifdef MACHINE_16_BIT #include /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed long int s32;/**< used for signed 32bit */ #if defined(LONG_MAX) && LONG_MAX == 0x7fffffffffffffffL typedef long int s64;/**< used for signed 64bit */ typedef unsigned long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #elif defined(LLONG_MAX) && (LLONG_MAX == 0x7fffffffffffffffLL) typedef long long int s64;/**< used for signed 64bit */ typedef unsigned long long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #else #warning Either the correct data type for signed 64 bit integer \ could not be found, or 64 bit integers are not supported in your environment. #warning The API will only offer 32 bit pressure calculation.This will \ slightly impede accuracy(noise of ~1 pascal RMS will be added to output). #warning If 64 bit integers are supported on your platform, \ please set s64 manually and "#define(BME280_64BITSUPPORT_PRESENT)" manually. #endif /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned long int u32;/**< used for unsigned 32bit */ /*! @brief If your machine support 32 bit define the MACHINE_32_BIT*/ #elif defined MACHINE_32_BIT /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed int s32;/**< used for signed 32bit */ typedef signed long long int s64;/**< used for signed 64bit */ /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned int u32;/**< used for unsigned 32bit */ typedef unsigned long long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT /* If your machine support 64 bit define the MACHINE_64_BIT*/ #elif defined MACHINE_64_BIT /*signed integer types*/ typedef signed char s8;/**< used for signed 8bit */ typedef signed short int s16;/**< used for signed 16bit */ typedef signed int s32;/**< used for signed 32bit */ typedef signed long int s64;/**< used for signed 64bit */ /*unsigned integer types*/ typedef unsigned char u8;/**< used for unsigned 8bit */ typedef unsigned short int u16;/**< used for unsigned 16bit */ typedef unsigned int u32;/**< used for unsigned 32bit */ typedef unsigned long int u64;/**< used for unsigned 64bit */ #define BME280_64BITSUPPORT_PRESENT #else #warning The data types defined above which not supported \ define the data types manually #endif #endif #endif /********************************************/ /**\name ENABLE FLATING OUTPUT */ /**************************************/ /*! * @brief If the user wants to support floating point calculations, please set the following define. If floating point calculation is not wanted or allowed (e.g. in Linux kernel), please do not set the define. */ #define BME280_ENABLE_FLOAT /*! * @brief If the user wants to support 64 bit integer calculation (needed for optimal pressure accuracy) please set the following define. If int64 calculation is not wanted (e.g. because it would include large libraries), please do not set the define. */ #define BME280_ENABLE_INT64 /***************************************************************/ /**\name BUS READ AND WRITE FUNCTION POINTERS */ /***************************************************************/ /*! @brief Define the calling convention of YOUR bus communication routine. @note This includes types of parameters. This example shows the configuration for an SPI bus link. If your communication function looks like this: write_my_bus_xy(u8 device_addr, u8 register_addr, u8 * data, u8 length); The BME280_WR_FUNC_PTR would equal: BME280_WR_FUNC_PTR s8 (* bus_write)(u8, u8, u8 *, u8) Parameters can be mixed as needed refer to the refer BME280_BUS_WRITE_FUNC macro. */ /** defines the return parameter type of the BME280_WR_FUNCTION */ #define BME280_BUS_WR_RETURN_TYPE s8 /* links the order of parameters defined in BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ #define BME280_BUS_WR_PARAM_TYPES u8, u8,\ u8 *, u8 /* links the order of parameters defined in BME280_BUS_WR_PARAM_TYPE to function calls used inside the API*/ #define BME280_BUS_WR_PARAM_ORDER(device_addr, register_addr,\ register_data, wr_len) /* never change this line */ #define BME280_BUS_WRITE_FUNC(device_addr, register_addr,\ register_data, wr_len) bus_write(device_addr, register_addr,\ register_data, wr_len) /*! @brief link macro between API function calls and bus read function @note The bus write function can change since this is a system dependant issue. If the bus_read parameter calling order is like: reg_addr, reg_data, wr_len it would be as it is here. If the parameters are differently ordered or your communication function like I2C need to know the device address, you can change this macro accordingly. BME280_BUS_READ_FUNC(dev_addr, reg_addr, reg_data, wr_len)\ bus_read(dev_addr, reg_addr, reg_data, wr_len) This macro lets all API functions call YOUR communication routine in a way that equals your definition in the refer BME280_WR_FUNC_PTR definition. @note: this macro also includes the "MSB='1' for reading BME280 addresses. */ /*defines the return parameter type of the BME280_RD_FUNCTION */ #define BME280_BUS_RD_RETURN_TYPE s8 /**\brief defines the calling parameter types of the BME280_RD_FUNCTION */ #define BME280_BUS_RD_PARAM_TYPES (u8, u8,\ u8 *, u8) /* links the order of parameters defined in \ BME280_BUS_RD_PARAM_TYPE to function calls used inside the API */ #define BME280_BUS_RD_PARAM_ORDER (device_addr, register_addr,\ register_data) /* never change this line */ #define BME280_BUS_READ_FUNC(device_addr, register_addr,\ register_data, rd_len)bus_read(device_addr, register_addr,\ register_data, rd_len) /****************************************/ /**\name DELAY */ /****************************************/ /* defines the return parameter type of the BME280_DELAY_FUNCTION */ #define BME280_DELAY_RETURN_TYPE void /* defines the calling parameter types of the BME280_DELAY_FUNCTION */ #define BME280_DELAY_PARAM_TYPES u16 /***************************************************************/ /**\name GET AND SET BITSLICE FUNCTIONS */ /***************************************************************/ /* never change this line */ #define BME280_DELAY_FUNC(delay_in_msec)\ delay_func(delay_in_msec) #define BME280_GET_BITSLICE(regvar, bitname)\ ((regvar & bitname##__MSK) >> bitname##__POS) #define BME280_SET_BITSLICE(regvar, bitname, val)\ ((regvar & ~bitname##__MSK) | ((val< Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_init(struct bme280_t *bme280); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED TEMPERATURE */ /**************************************************************/ /*! * @brief This API is used to read uncompensated temperature * in the registers 0xFA, 0xFB and 0xFC * @note 0xFA -> MSB -> bit from 0 to 7 * @note 0xFB -> LSB -> bit from 0 to 7 * @note 0xFC -> LSB -> bit from 4 to 7 * * @param v_uncomp_temperature_s32 : The value of uncompensated temperature * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_temperature( s32 *v_uncomp_temperature_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION TRUE TEMPERATURE */ /**************************************************************/ /*! * @brief Reads actual temperature from uncompensated temperature * @note Returns the value in 0.01 degree Centigrade * Output value of "5123" equals 51.23 DegC. * * * * @param v_uncomp_temperature_s32 : value of uncompensated temperature * * * @return Returns the actual temperature * */ s32 bme280_compensate_temperature_int32(s32 v_uncomp_temperature_s32); /*! * @brief Reads actual temperature from uncompensated temperature * @note Returns the value with 500LSB/DegC centred around 24 DegC * output value of "5123" equals(5123/500)+24 = 34.246DegC * * * @param v_uncomp_temperature_s32: value of uncompensated temperature * * * * @return Return the actual temperature as s16 output * */ s16 bme280_compensate_temperature_int32_sixteen_bit_output( s32 v_uncomp_temperature_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE */ /**************************************************************/ /*! * @brief This API is used to read uncompensated pressure. * in the registers 0xF7, 0xF8 and 0xF9 * @note 0xF7 -> MSB -> bit from 0 to 7 * @note 0xF8 -> LSB -> bit from 0 to 7 * @note 0xF9 -> LSB -> bit from 4 to 7 * * * * @param v_uncomp_pressure_s32 : The value of uncompensated pressure * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure( s32 *v_uncomp_pressure_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION TRUE PRESSURE */ /**************************************************************/ /*! * @brief Reads actual pressure from uncompensated pressure * @note Returns the value in Pascal(Pa) * Output value of "96386" equals 96386 Pa = * 963.86 hPa = 963.86 millibar * * * * @param v_uncomp_pressure_s32 : value of uncompensated pressure * * * * @return Return the actual pressure output as u32 * */ u32 bme280_compensate_pressure_int32(s32 v_uncomp_pressure_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED HUMIDITY */ /**************************************************************/ /*! * @brief This API is used to read uncompensated humidity. * in the registers 0xF7, 0xF8 and 0xF9 * @note 0xFD -> MSB -> bit from 0 to 7 * @note 0xFE -> LSB -> bit from 0 to 7 * * * * @param v_uncomp_humidity_s32 : The value of uncompensated humidity * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_humidity( s32 *v_uncomp_humidity_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION RELATIVE HUMIDITY */ /**************************************************************/ /*! * @brief Reads actual humidity from uncompensated humidity * @note Returns the value in %rH as unsigned 32bit integer * in Q22.10 format(22 integer 10 fractional bits). * @note An output value of 42313 * represents 42313 / 1024 = 41.321 %rH * * * * @param v_uncomp_humidity_s32: value of uncompensated humidity * * @return Return the actual relative humidity output as u32 * */ u32 bme280_compensate_humidity_int32(s32 v_uncomp_humidity_s32); /*! * @brief Reads actual humidity from uncompensated humidity * @note Returns the value in %rH as unsigned 16bit integer * @note An output value of 42313 * represents 42313/512 = 82.643 %rH * * * * @param v_uncomp_humidity_s32: value of uncompensated humidity * * * @return Return the actual relative humidity output as u16 * */ u16 bme280_compensate_humidity_int32_sixteen_bit_output( s32 v_uncomp_humidity_s32); /**************************************************************/ /**\name FUNCTION FOR INTIALIZATION UNCOMPENSATED PRESSURE, TEMPERATURE AND HUMIDITY */ /**************************************************************/ /*! * @brief This API used to read uncompensated * pressure,temperature and humidity * * * * * @param v_uncomp_pressure_s32: The value of uncompensated pressure. * @param v_uncomp_temperature_s32: The value of uncompensated temperature * @param v_uncomp_humidity_s32: The value of uncompensated humidity. * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_uncomp_pressure_temperature_humidity( s32 *v_uncomp_pressure_s32, s32 *v_uncomp_temperature_s32, s32 *v_uncomp_humidity_s32); /**************************************************************/ /**\name FUNCTION FOR TRUE UNCOMPENSATED PRESSURE, TEMPERATURE AND HUMIDITY */ /**************************************************************/ /*! * @brief This API used to read true pressure, temperature and humidity * * * * * @param v_pressure_u32 : The value of compensated pressure. * @param v_temperature_s32 : The value of compensated temperature. * @param v_humidity_u32 : The value of compensated humidity. * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_pressure_temperature_humidity( u32 *v_pressure_u32, s32 *v_temperature_s32, u32 *v_humidity_u32); /**************************************************************/ /**\name FUNCTION FOR CALIBRATION */ /**************************************************************/ /*! * @brief This API is used to * calibration parameters used for calculation in the registers * * parameter | Register address | bit *------------|------------------|---------------- * dig_T1 | 0x88 and 0x89 | from 0 : 7 to 8: 15 * dig_T2 | 0x8A and 0x8B | from 0 : 7 to 8: 15 * dig_T3 | 0x8C and 0x8D | from 0 : 7 to 8: 15 * dig_P1 | 0x8E and 0x8F | from 0 : 7 to 8: 15 * dig_P2 | 0x90 and 0x91 | from 0 : 7 to 8: 15 * dig_P3 | 0x92 and 0x93 | from 0 : 7 to 8: 15 * dig_P4 | 0x94 and 0x95 | from 0 : 7 to 8: 15 * dig_P5 | 0x96 and 0x97 | from 0 : 7 to 8: 15 * dig_P6 | 0x98 and 0x99 | from 0 : 7 to 8: 15 * dig_P7 | 0x9A and 0x9B | from 0 : 7 to 8: 15 * dig_P8 | 0x9C and 0x9D | from 0 : 7 to 8: 15 * dig_P9 | 0x9E and 0x9F | from 0 : 7 to 8: 15 * dig_H1 | 0xA1 | from 0 to 7 * dig_H2 | 0xE1 and 0xE2 | from 0 : 7 to 8: 15 * dig_H3 | 0xE3 | from 0 to 7 * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_calib_param(void); /**************************************************************/ /**\name FUNCTION FOR TEMPERATURE OVER SAMPLING */ /**************************************************************/ /*! * @brief This API is used to get * the temperature oversampling setting in the register 0xF4 * bits from 5 to 7 * * value | Temperature oversampling * ---------------------|--------------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of temperature over sampling * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_temperature( u8 *v_value_u8); /*! * @brief This API is used to set * the temperature oversampling setting in the register 0xF4 * bits from 5 to 7 * * value | Temperature oversampling * ---------------------|--------------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of temperature over sampling * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_temperature( u8 v_value_u8); /**************************************************************/ /**\name FUNCTION FOR PRESSURE OVER SAMPLING */ /**************************************************************/ /*! * @brief This API is used to get * the pressure oversampling setting in the register 0xF4 * bits from 2 to 4 * * value | Pressure oversampling * --------------------|-------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of pressure oversampling * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_pressure( u8 *v_value_u8); /*! * @brief This API is used to set * the pressure oversampling setting in the register 0xF4 * bits from 2 to 4 * * value | Pressure oversampling * --------------------|-------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of pressure oversampling * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_pressure( u8 v_value_u8); /**************************************************************/ /**\name FUNCTION FOR HUMIDITY OVER SAMPLING */ /**************************************************************/ /*! * @brief This API is used to get * the humidity oversampling setting in the register 0xF2 * bits from 0 to 2 * * value | Humidity oversampling * ---------------------|------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of humidity over sampling * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_oversamp_humidity(u8 *v_value_u8); /*! * @brief This API is used to set * the humidity oversampling setting in the register 0xF2 * bits from 0 to 2 * * value | Humidity oversampling * ---------------------|------------------------- * 0x00 | Skipped * 0x01 | BME280_OVERSAMP_1X * 0x02 | BME280_OVERSAMP_2X * 0x03 | BME280_OVERSAMP_4X * 0x04 | BME280_OVERSAMP_8X * 0x05,0x06 and 0x07 | BME280_OVERSAMP_16X * * * @param v_value_u8 : The value of humidity over sampling * * * * @note The "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" * register sets the humidity * data acquisition options of the device. * @note changes to this registers only become * effective after a write operation to * "BME280_CTRL_MEAS_REG" register. * @note In the code automated reading and writing of * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" * @note register first set the * "BME280_CTRL_HUMIDITY_REG_OVERSAMP_HUMIDITY" * and then read and write * the "BME280_CTRL_MEAS_REG" register in the function. * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_oversamp_humidity( u8 v_value_u8); /**************************************************************/ /**\name FUNCTION FOR POWER MODE*/ /**************************************************************/ /*! * @brief This API used to get the * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 * * * * @param v_power_mode_u8 : The value of power mode * value | mode * -----------------|------------------ * 0x00 | BME280_SLEEP_MODE * 0x01 and 0x02 | BME280_FORCED_MODE * 0x03 | BME280_NORMAL_MODE * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_power_mode(u8 *v_power_mode_u8); /*! * @brief This API used to set the * Operational Mode from the sensor in the register 0xF4 bit 0 and 1 * * * * @param v_power_mode_u8 : The value of power mode * value | mode * -----------------|------------------ * 0x00 | BME280_SLEEP_MODE * 0x01 and 0x02 | BME280_FORCED_MODE * 0x03 | BME280_NORMAL_MODE * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_power_mode(u8 v_power_mode_u8); /**************************************************************/ /**\name FUNCTION FOR SOFT RESET*/ /**************************************************************/ /*! * @brief Used to reset the sensor * The value 0xB6 is written to the 0xE0 * register the device is reset using the * complete power-on-reset procedure. * @note Soft reset can be easily set using bme280_set_softreset(). * @note Usage Hint : bme280_set_softreset() * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_soft_rst(void); /**************************************************************/ /**\name FUNCTION FOR SPI ENABLE*/ /**************************************************************/ /*! * @brief This API used to get the sensor * SPI mode(communication type) in the register 0xF5 bit 0 * * * * @param v_enable_disable_u8 : The value of SPI enable * value | Description * --------|-------------- * 0 | Disable * 1 | Enable * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_spi3(u8 *v_enable_disable_u8); /*! * @brief This API used to set the sensor * SPI mode(communication type) in the register 0xF5 bit 0 * * * * @param v_enable_disable_u8 : The value of SPI enable * value | Description * --------|-------------- * 0 | Disable * 1 | Enable * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_spi3(u8 v_enable_disable_u8); /**************************************************************/ /**\name FUNCTION FOR IIR FILTER*/ /**************************************************************/ /*! * @brief This API is used to reads filter setting * in the register 0xF5 bit 3 and 4 * * * * @param v_value_u8 : The value of IIR filter coefficient * * value | Filter coefficient * -------------|------------------------- * 0x00 | BME280_FILTER_COEFF_OFF * 0x01 | BME280_FILTER_COEFF_2 * 0x02 | BME280_FILTER_COEFF_4 * 0x03 | BME280_FILTER_COEFF_8 * 0x04 | BME280_FILTER_COEFF_16 * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_filter(u8 *v_value_u8); /*! * @brief This API is used to write filter setting * in the register 0xF5 bit 3 and 4 * * * * @param v_value_u8 : The value of IIR filter coefficient * * value | Filter coefficient * -------------|------------------------- * 0x00 | BME280_FILTER_COEFF_OFF * 0x01 | BME280_FILTER_COEFF_2 * 0x02 | BME280_FILTER_COEFF_4 * 0x03 | BME280_FILTER_COEFF_8 * 0x04 | BME280_FILTER_COEFF_16 * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_filter(u8 v_value_u8); /**************************************************************/ /**\name FUNCTION FOR STANDBY DURATION*/ /**************************************************************/ /*! * @brief This API used to Read the * standby duration time from the sensor in the register 0xF5 bit 5 to 7 * * @param v_standby_durn_u8 : The value of standby duration time value. * value | standby duration * -------------|----------------------- * 0x00 | BME280_STANDBY_TIME_1_MS * 0x01 | BME280_STANDBY_TIME_63_MS * 0x02 | BME280_STANDBY_TIME_125_MS * 0x03 | BME280_STANDBY_TIME_250_MS * 0x04 | BME280_STANDBY_TIME_500_MS * 0x05 | BME280_STANDBY_TIME_1000_MS * 0x06 | BME280_STANDBY_TIME_2000_MS * 0x07 | BME280_STANDBY_TIME_4000_MS * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_standby_durn(u8 *v_standby_durn_u8); /*! * @brief This API used to write the * standby duration time from the sensor in the register 0xF5 bit 5 to 7 * * @param v_standby_durn_u8 : The value of standby duration time value. * value | standby duration * -------------|----------------------- * 0x00 | BME280_STANDBY_TIME_1_MS * 0x01 | BME280_STANDBY_TIME_63_MS * 0x02 | BME280_STANDBY_TIME_125_MS * 0x03 | BME280_STANDBY_TIME_250_MS * 0x04 | BME280_STANDBY_TIME_500_MS * 0x05 | BME280_STANDBY_TIME_1000_MS * 0x06 | BME280_STANDBY_TIME_2000_MS * 0x07 | BME280_STANDBY_TIME_4000_MS * * @note Normal mode comprises an automated perpetual * cycling between an (active) * Measurement period and an (inactive) standby period. * @note The standby time is determined by * the contents of the register t_sb. * Standby time can be set using BME280_STANDBY_TIME_125_MS. * * @note Usage Hint : bme280_set_standby_durn(BME280_STANDBY_TIME_125_MS) * * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_set_standby_durn(u8 v_standby_durn_u8); /**************************************************************/ /**\name FUNCTION FOR WORK MODE*/ /**************************************************************/ /* * @brief Writes the working mode to the sensor * * * * * @param v_work_mode_u8 : Mode to be set * value | Working mode * ----------|-------------------- * 0 | BME280_ULTRALOWPOWER_MODE * 1 | BME280_LOWPOWER_MODE * 2 | BME280_STANDARDRESOLUTION_MODE * 3 | BME280_HIGHRESOLUTION_MODE * 4 | BME280_ULTRAHIGHRESOLUTION_MODE * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ /*BME280_RETURN_FUNCTION_TYPE bme280_set_work_mode(u8 v_work_mode_u8);*/ /**************************************************************/ /**\name FUNCTION FOR FORCE MODE DATA READ*/ /**************************************************************/ /*! * @brief This API used to read uncompensated * temperature,pressure and humidity in forced mode * * * @param v_uncom_pressure_s32: The value of uncompensated pressure * @param v_uncom_temperature_s32: The value of uncompensated temperature * @param v_uncom_humidity_s32: The value of uncompensated humidity * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_get_forced_uncomp_pressure_temperature_humidity( s32 *v_uncom_pressure_s32, s32 *v_uncom_temperature_s32, s32 *v_uncom_humidity_s32); /**************************************************************/ /**\name FUNCTION FOR COMMON READ AND WRITE */ /**************************************************************/ /*! * @brief * This API write the data to * the given register * * * @param v_addr_u8 -> Address of the register * @param v_data_u8 -> The data from the register * @param v_len_u8 -> no of bytes to read * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_write_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8); /*! * @brief * This API reads the data from * the given register * * * @param v_addr_u8 -> Address of the register * @param v_data_u8 -> The data from the register * @param v_len_u8 -> no of bytes to read * * * @return results of bus communication function * @retval 0 -> Success * @retval -1 -> Error * * */ BME280_RETURN_FUNCTION_TYPE bme280_read_register(u8 v_addr_u8, u8 *v_data_u8, u8 v_len_u8); /**************************************************************/ /**\name FUNCTION FOR FLOAT OUTPUT TEMPERATURE*/ /**************************************************************/ #ifdef BME280_ENABLE_FLOAT /*! * @brief Reads actual temperature from uncompensated temperature * @note returns the value in Degree centigrade * @note Output value of "51.23" equals 51.23 DegC. * * * * @param v_uncom_temperature_s32 : value of uncompensated temperature * * * * @return Return the actual temperature in floating point * */ double bme280_compensate_temperature_double( s32 v_uncom_temperature_s32); /**************************************************************/ /**\name FUNCTION FOR FLOAT OUTPUT PRESSURE*/ /**************************************************************/ /*! * @brief Reads actual pressure from uncompensated pressure * @note Returns pressure in Pa as double. * @note Output value of "96386.2" * equals 96386.2 Pa = 963.862 hPa. * * * @param v_uncom_pressure_s32 : value of uncompensated pressure * * * @return Return the actual pressure in floating point * */ double bme280_compensate_pressure_double(s32 v_uncom_pressure_s32); /**************************************************************/ /**\name FUNCTION FOR FLOAT OUTPUT HUMIDITY*/ /**************************************************************/ /*! * @brief Reads actual humidity from uncompensated humidity * @note returns the value in relative humidity (%rH) * @note Output value of "42.12" equals 42.12 %rH * * @param v_uncom_humidity_s32 : value of uncompensated humidity * * * * @return Return the actual humidity in floating point * */ double bme280_compensate_humidity_double(s32 v_uncom_humidity_s32); #endif /**************************************************************/ /**\name FUNCTION FOR 64BIT OUTPUT PRESSURE*/ /**************************************************************/ #if defined(BME280_ENABLE_INT64) && defined(BME280_64BITSUPPORT_PRESENT) /*! * @brief Reads actual pressure from uncompensated pressure * @note Returns the value in Pa as unsigned 32 bit * integer in Q24.8 format (24 integer bits and * 8 fractional bits). * @note Output value of "24674867" * represents 24674867 / 256 = 96386.2 Pa = 963.862 hPa * * * * @param v_uncom_pressure_s32 : value of uncompensated temperature * * * @return Return the actual pressure in u32 * */ u32 bme280_compensate_pressure_int64(s32 v_uncom_pressure_s32); /**************************************************************/ /**\name FUNCTION FOR 24BIT OUTPUT PRESSURE*/ /**************************************************************/ /*! * @brief Reads actual pressure from uncompensated pressure * @note Returns the value in Pa. * @note Output value of "12337434" * @note represents 12337434 / 128 = 96386.2 Pa = 963.862 hPa * * * * @param v_uncom_pressure_s32 : value of uncompensated pressure * * * @return the actual pressure in u32 * */ u32 bme280_compensate_pressure_int64_twentyfour_bit_output( s32 v_uncom_pressure_s32); #endif /**************************************************************/ /**\name FUNCTION FOR WAIT PERIOD*/ /**************************************************************/ /*! * @brief Computing waiting time for sensor data read * * * * * @param v_delaytime_u8 : The value of delay time for force mode * * * @retval 0 -> Success * * */ BME280_RETURN_FUNCTION_TYPE bme280_compute_wait_time(u8 *v_delaytime_u8r); #endif