Upgraded bme680 API to v3.5.1

Added Self test APIs
This commit is contained in:
Bosch Sensortec 2017-07-17 17:22:43 +02:00
parent d1c68f0c0b
commit 2a51b9c0c1
12 changed files with 2277 additions and 4847 deletions

Binary file not shown.

351
README.md
View File

@ -1,148 +1,239 @@
## Table of Contents # BME680 sensor API
- [Introduction](#intro) ## Introduction
- [Version](#ver) This package contains the Bosch Sensortec's BME680 gas sensor API
- [Integration details](#integration)
- [Driver files information](#fileinfo)
- [Supported sensor interface](#interface)
- [Simple Integration Example](#sample)
### Introduction<a name=intro></a> The sensor driver package includes bme680.h, bme680.c and bme680_defs.h files
- This package contains the Bosch Sensortec MEMS BME680 sensor driver (sensor API)
- The sensor driver package includes below files
* bme680.c
* bme680.h
* bme680_calculations.c
* bme680_calculations.h
* bme680_internal.h
* sensor_api_common_types.h
### Version<a name=ver></a> ## Version
File | Version | Date File | Version | Date
-----|---------|----- -----|---------|-----
bme680.c | 2.2.0 | 5 May 2017 bme680.c | 3.5.1 | 5 Jul 2017
bme680.h | 2.2.0 | 5 May 2017 bme680.h | 3.5.1 | 5 Jul 2017
bme680_calculations.c | 2.2.0 | 5 May 2017 bme680_defs.h | 3.5.1 | 5 Jul 2017
bme680_calculations.h | 2.2.0 | 5 May 2017
bme680_internal.h | 2.2.0 | 5 May 2017
sensor_api_common_types.h | 2.2.0 | 5 May 2017
### Integration details<a name=integration></a> ## Integration details
- Integrate files bme680.c, bme680.h, bme680_calculations.c, bme680_calculations.h, bme680_internal.h and sensor_api_common_types.h into your project. * Integrate bme680.h, bme680_defs.h and bme680.c file in to your project.
- Include the bme680.h file in your code like below. * Include the bme680.h file in your code like below.
``` c ``` c
#include "bme680.h" #include "bme680.h"
``` ```
- The BME680_SensorAPI_Example_Guide.pdf contains examples for API use cases.
### Driver files information<a name=fileinfo></a> ## File information
- bme680.h * bme680_defs.h : This header file has the constants, macros and datatype declarations.
* This header file has the constant definitions, user data types and supported sensor driver calls declarations which is required by the user. * bme680.h : This header file contains the declarations of the sensor driver APIs.
- bme680.c * bme680.c : This source file contains the definitions of the sensor driver APIs.
* This file contains the implementation for the sensor driver APIs.
- bme680_calculations.h
* This header file has the internal function declaration for the sensor calculation.
- bme680_calculations.c
* This file contains the implementation of the sensor calculations for sensor driver APIs.
- bme680_internal.h
* This header file has the register address definition, internal constant definitions.
- sensor_api_common_types.h
* This header file has the data type definition for different compiler platform.
### Supported sensor interface<a name=interface></a> ## Supported sensor interfaces
- This BME680 sensor driver supports SPI and I2C interfaces * SPI 4-wire
* I2C
### Simple Integration Example<a name=sample></a> ## Usage guide
- A simple example for BME680 is given below. ### Initializing the sensor
- Example meant for Single BME680 sensor in Force Mode with Temperature, Pressure, Humidity and Gas Enabled To initialize the sensor, you will first need to create a device structure. You
- Please refer bme680.h to refer the API calls for the integration. can do this by creating an instance of the structure bme680_dev. Then go on to
fill in the various parameters as shown below
#### Example for SPI 4-Wire
``` c ``` c
/* include bme680 main header */ struct bme680_dev gas_sensor;
#include "bme680.h"
/*!
* BME680_MAX_NO_OF_SENSOR = 2; defined in bme680.h file
* In order to interface only one sensor over SPI, user must change the value of
* BME680_MAX_NO_OF_SENSOR = 1
* Test setup: It has been assumed that <20>BME680 sensor_0<5F> interfaced over SPI with
* Native chip select line
*/
/* BME680 sensor structure instance */
struct bme680_t bme680_sensor_no[BME680_MAX_NO_OF_SENSOR];
/* BME680 sensor's compensated data structure instance */
struct bme680_comp_field_data compensate_data_sensor[BME680_MAX_NO_OF_SENSOR][3];
/* BME680 sensor's uncompensated data structure instance */
struct bme680_uncomp_field_data uncompensated_data_of_sensor[BME680_MAX_NO_OF_SENSOR][3];
/* BME680 sensor's configuration structure instance */
struct bme680_sens_conf set_conf_sensor[BME680_MAX_NO_OF_SENSOR];
/* BME680 sensor's heater configuration structure instance */
struct bme680_heater_conf set_heatr_conf_sensor[BME680_MAX_NO_OF_SENSOR];
void main(void) /* You may assign a chip select identifier to be handled later */
gas_sensor.dev_id = 0;
gas_sensor.intf = BME680_SPI_INTF;
gas_sensor.read = user_spi_read;
gas_sensor.write = user_spi_write;
gas_sensor.delay_ms = user_delay_ms;
int8_t rslt = BME680_OK;
rslt = bme680_init(&gas_sensor);
```
#### Example for I2C
``` c
struct bme680_dev gas_sensor;
gas_sensor.dev_id = BME680_I2C_ADDR_PRIMARY;
gas_sensor.intf = BME680_I2C_INTF;
gas_sensor.read = user_i2c_read;
gas_sensor.write = user_i2c_write;
gas_sensor.delay_ms = user_delay_ms;
int8_t rslt = BME680_OK;
rslt = bme680_init(&gas_sensor);
```
### Configuring the sensor
#### Example for configuring the sensor in forced mode
``` c
uint8_t set_required_settings;
/* Set the temperature, pressure and humidity settings */
gas_sensor.tph_sett.os_hum = BME680_OS_2X;
gas_sensor.tph_sett.os_pres = BME680_OS_4X;
gas_sensor.tph_sett.os_temp = BME680_OS_8X;
gas_sensor.tph_sett.filter = BME680_FILTER_SIZE_3;
/* Set the remaining gas sensor settings and link the heating profile */
gas_sensor.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
/* Create a ramp heat waveform in 3 steps */
gas_sensor.gas_sett.heatr_temp = 320; /* degree Celsius */
gas_sensor.gas_sett.heatr_dur = 150; /* milliseconds */
/* Select the power mode */
/* Must be set before writing the sensor configuration */
gas_sensor.power_mode = BME680_FORCED_MODE;
/* Set the required sensor settings needed */
set_required_settings = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_FILTER_SEL
| BME680_GAS_SENSOR_SEL;
/* Set the desired sensor configuration */
rslt = bme680_set_sensor_settings(set_required_settings,&gas_sensor);
/* Set the power mode */
rslt = bme680_set_sensor_mode(&gas_sensor);
/* Get the total measurement duration so as to sleep or wait till the
* measurement is complete */
uint16_t meas_period;
bme680_get_profile_dur(&meas_period, &gas_sensor);
user_delay_ms(meas_period); /* Delay till the measurement is ready */
```
### Reading sensor data
#### Example for reading all sensor data
``` c
struct bme680_field_data data;
while(1)
{ {
unsigned int i = 0; rslt = bme680_get_sensor_data(&data, &gas_sensor);
enum bme680_return_type com_rslt = BME680_COMM_RES_ERROR;
/* Do BME680 sensor structure instance initialization*/ printf("T: %.2f degC, P: %.2f hPa, H %.2f %%rH ", data.temperature / 100.0f,
/* Sensor_0 interface over SPI with native chip select line */ data.pressure / 100.0f, data.humidity / 1000.0f );
/* USER defined SPI bus read function */ /* Avoid using measurements from an unstable heating setup */
bme680_sensor_no[0].bme680_bus_read = BME680_SPI_bus_read_user; if(data.status & BME680_HEAT_STAB_MSK)
/* USER defined SPI bus write function */ printf(", G: %d ohms", data.gas_resistance);
bme680_sensor_no[0].bme680_bus_write = BME680_SPI_bus_write_user;
/* USER defined SPI burst read function */
bme680_sensor_no[0].bme680_burst_read = BME680_SPI_bus_read_user;
/* USER defined delay function */
bme680_sensor_no[0].delay_msec = BME680_delay_msec_user;
/* Mention communication interface */
bme680_sensor_no[0].interface = BME680_SPI_INTERFACE;
/* get chip id and calibration parameter */ printf("\r\n");
com_rslt = bme680_init(&bme680_sensor_no[0]);
/* Do Sensor initialization */
for (i=0;i<BME680_MAX_NO_OF_SENSOR;i++) {
/* Check Device-ID before next steps of sensor operations */
if (BME680_CHIP_ID == bme680_sensor_no[i].chip_id) {
/* Select sensor configuration parameters */
set_conf_sensor[i].heatr_ctrl = BME680_HEATR_CTRL_ENABLE;
set_conf_sensor[i].run_gas = BME680_RUN_GAS_ENABLE;
set_conf_sensor[i].nb_conv = 0x00;
set_conf_sensor[i].osrs_hum = BME680_OSRS_1X;
set_conf_sensor[i].osrs_pres = BME680_OSRS_1X;
set_conf_sensor[i].osrs_temp = BME680_OSRS_1X;
/* activate sensor configuration */
com_rslt += bme680_set_sensor_config(&set_conf_sensor[i],
&bme680_sensor_no[i]);
/* Select Heater configuration parameters */
set_heatr_conf_sensor[i].heater_temp[0] = 300;
set_heatr_conf_sensor[i].heatr_idacv[0] = 1;
set_heatr_conf_sensor[i].heatr_dur[0] = 137;
set_heatr_conf_sensor[i].profile_cnt = 1;
/* activate heater configuration */
com_rslt += bme680_set_gas_heater_config(&set_heatr_conf_sensor[i],
&bme680_sensor_no[i]);
/* Set power mode as forced mode */
com_rslt += bme680_set_power_mode(BME680_FORCED_MODE,&bme680_sensor_no[i]);
if (BME680_COMM_RES_OK == com_rslt) {
/*Get the uncompensated T+P+G+H data*/
bme680_get_uncomp_data(uncompensated_data_of_sensor[i], 1, BME680_ALL,
&bme680_sensor_no[i]);
/*Get the compensated T+P+G+H data*/
bme680_compensate_data(uncompensated_data_of_sensor[i],
compensate_data_sensor[i], 1,
BME680_ALL, &bme680_sensor_no[i]);
/* put sensor into sleep mode explicitly */
bme680_set_power_mode(BME680_SLEEP_MODE, &bme680_sensor_no[i]);
/* call user define delay function(duration millisecond) */
User_define_delay(100);
}
}
}
} }
``` ```
### Templates for function pointers
``` c
void user_delay_ms(uint32_t period)
{
/*
* Return control or wait,
* for a period amount of milliseconds
*/
}
int8_t user_spi_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
/*
* The parameter dev_id can be used as a variable to select which Chip Select pin has
* to be set low to activate the relevant device on the SPI bus
*/
/*
* Data on the bus should be like
* |----------------+---------------------+-------------|
* | MOSI | MISO | Chip Select |
* |----------------+---------------------|-------------|
* | (don't care) | (don't care) | HIGH |
* | (reg_addr) | (don't care) | LOW |
* | (don't care) | (reg_data[0]) | LOW |
* | (....) | (....) | LOW |
* | (don't care) | (reg_data[len - 1]) | LOW |
* | (don't care) | (don't care) | HIGH |
* |----------------+---------------------|-------------|
*/
return rslt;
}
int8_t user_spi_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
/*
* The parameter dev_id can be used as a variable to select which Chip Select pin has
* to be set low to activate the relevant device on the SPI bus
*/
/*
* Data on the bus should be like
* |---------------------+--------------+-------------|
* | MOSI | MISO | Chip Select |
* |---------------------+--------------|-------------|
* | (don't care) | (don't care) | HIGH |
* | (reg_addr) | (don't care) | LOW |
* | (reg_data[0]) | (don't care) | LOW |
* | (....) | (....) | LOW |
* | (reg_data[len - 1]) | (don't care) | LOW |
* | (don't care) | (don't care) | HIGH |
* |---------------------+--------------|-------------|
*/
return rslt;
}
int8_t user_i2c_read(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
/*
* The parameter dev_id can be used as a variable to store the I2C address of the device
*/
/*
* Data on the bus should be like
* |------------+---------------------|
* | I2C action | Data |
* |------------+---------------------|
* | Start | - |
* | Write | (reg_addr) |
* | Stop | - |
* | Start | - |
* | Read | (reg_data[0]) |
* | Read | (....) |
* | Read | (reg_data[len - 1]) |
* | Stop | - |
* |------------+---------------------|
*/
return rslt;
}
int8_t user_i2c_write(uint8_t dev_id, uint8_t reg_addr, uint8_t *reg_data, uint16_t len)
{
int8_t rslt = 0; /* Return 0 for Success, non-zero for failure */
/*
* The parameter dev_id can be used as a variable to store the I2C address of the device
*/
/*
* Data on the bus should be like
* |------------+---------------------|
* | I2C action | Data |
* |------------+---------------------|
* | Start | - |
* | Write | (reg_addr) |
* | Write | (reg_data[0]) |
* | Write | (....) |
* | Write | (reg_data[len - 1]) |
* | Stop | - |
* |------------+---------------------|
*/
return rslt;
}
```
## Copyright (C) 2017 - 2018 Bosch Sensortec GmbH

189
Self test/bme680_selftest.c Normal file
View File

@ -0,0 +1,189 @@
/**\mainpage
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* 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 bme680_selftest.c
* @date 5 Jul 2017
* @version 3.5.1
*
*/
/*!
* @addtogroup bme680_selftest
* @brief
* @{*/
#include "bme680_selftest.h"
#define MIN_TEMPERATURE INT16_C(0) /* 0 degree Celsius */
#define MAX_TEMPERATURE INT16_C(4000) /* 40 degree Celsius */
#define MIN_PRESSURE UINT32_C(90000) /* 900 hecto Pascals */
#define MAX_PRESSURE UINT32_C(110000) /* 1100 hecto Pascals */
#define MIN_HUMIDITY UINT32_C(20000) /* 20% relative humidity */
#define MAX_HUMIDITY UINT32_C(80000) /* 80% relative humidity*/
#define HEATR_DUR 2000
#define N_MEAS 6
#define LOW_TEMP 200
#define HIGH_TEMP 350
/*!
* @brief Function to analyze the sensor data
*
* @param[in] data Array of measurement data
* @param[in] n_meas Number of measurements
*
* @return Error code
* @retval 0 Success
* @retval > 0 Warning
*/
static int8_t analyze_sensor_data(struct bme680_field_data *data, uint8_t n_meas);
/*!
* @brief Self-test API for the BME680
*/
int8_t bme680_self_test(struct bme680_dev *dev)
{
int8_t rslt = BME680_OK;
struct bme680_field_data data[N_MEAS];
struct bme680_dev t_dev;
/* Copy required parameters from reference bme680_dev struct */
t_dev.dev_id = dev->dev_id;
t_dev.amb_temp = 25;
t_dev.read = dev->read;
t_dev.write = dev->write;
t_dev.intf = dev->intf;
t_dev.delay_ms = dev->delay_ms;
rslt = bme680_init(&t_dev);
if (rslt == BME680_OK) {
/* Select the power mode */
/* Must be set before writing the sensor configuration */
t_dev.power_mode = BME680_FORCED_MODE;
uint16_t settings_sel;
/* Set the temperature, pressure and humidity & filter settings */
t_dev.tph_sett.os_hum = BME680_OS_1X;
t_dev.tph_sett.os_pres = BME680_OS_16X;
t_dev.tph_sett.os_temp = BME680_OS_2X;
/* Set the remaining gas sensor settings and link the heating profile */
t_dev.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
t_dev.gas_sett.heatr_dur = HEATR_DUR;
settings_sel = BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_GAS_SENSOR_SEL;
uint16_t profile_dur = 0;
bme680_get_profile_dur(&profile_dur, &t_dev);
uint8_t i = 0;
while ((rslt == BME680_OK) && (i < N_MEAS)) {
if (rslt == BME680_OK) {
if (i % 2 == 0)
t_dev.gas_sett.heatr_temp = LOW_TEMP; /* Lower temperature */
else
t_dev.gas_sett.heatr_temp = HIGH_TEMP; /* Higher temperature */
rslt = bme680_set_sensor_settings(settings_sel, &t_dev);
if (rslt == BME680_OK) {
rslt = bme680_set_sensor_mode(&t_dev); /* Trigger a measurement */
t_dev.delay_ms(profile_dur); /* Wait for the measurement to complete */
rslt = bme680_get_sensor_data(&data[i], &t_dev);
}
}
i++;
}
if (rslt == BME680_OK)
rslt = analyze_sensor_data(data, N_MEAS);
}
return rslt;
}
/*!
* @brief Function to analyze the sensor data
*/
static int8_t analyze_sensor_data(struct bme680_field_data *data, uint8_t n_meas)
{
int8_t rslt = BME680_OK;
uint8_t self_test_failed = 0, i;
uint32_t cent_res = 0;
if ((data[0].temperature < MIN_TEMPERATURE) || (data[0].temperature > MAX_TEMPERATURE))
self_test_failed++;
if ((data[0].pressure < MIN_PRESSURE) || (data[0].pressure > MAX_PRESSURE))
self_test_failed++;
if ((data[0].humidity < MIN_HUMIDITY) || (data[0].humidity > MAX_HUMIDITY))
self_test_failed++;
for (i = 0; i < n_meas; i++) /* Every gas measurement should be valid */
if (!(data[i].status & (BME680_GASM_VALID_MSK | BME680_HEAT_STAB_MSK)))
self_test_failed++;
for (i = 2; i < n_meas; i += 2) {
/* Invert formula to get integer values for centroid resistance, i.e. > 1 */
cent_res = (data[i - 2].gas_resistance + data[i].gas_resistance) / (2 * data[i - 1].gas_resistance);
}
if ((cent_res < 3) || (cent_res > 20)) /* 0.05 > cent_res^-1 < 0.03 */
self_test_failed++;
if (self_test_failed)
rslt = BME680_W_SELF_TEST_FAILED;
return rslt;
}
/** @}*/

View File

@ -0,0 +1,88 @@
/**
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* 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 bme680_selftest.h
* @date 5 Jul 2017
* @version 3.5.1
* @brief
*
*/
/*!
* @addtogroup bme680_selftest
* @brief
* @{*/
#ifndef BME680_SELFTEST_H_
#define BME680_SELFTEST_H_
#include "bme680.h"
/*! CPP guard */
#ifdef __cplusplus
extern "C"
{
#endif
#define BME680_W_SELF_TEST_FAILED 3
/*!
* @brief Self-test API for the BME680
*
* @param[in] Device structure containing relevant information on how
* to communicate with the sensor
*
* @return Error code
* @retval 0 Success
* @retval < 0 Error
* @retval > 0 Warning
*/
int8_t bme680_self_test(struct bme680_dev *dev);
/*! CPP guard */
#ifdef __cplusplus
}
#endif
#endif /* BME680_SELFTEST_H_ */
/** @}*/

3399
bme680.c

File diff suppressed because it is too large Load Diff

832
bme680.h
View File

@ -1,667 +1,225 @@
/** /**
*
****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH * Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
* *
* File : bme680.h * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* *
* Date: 5 May 2017 * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* *
* Revision : 2.2.0 $ * 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.
* *
* Usage: Sensor Driver for BME680 sensor * 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
* *
* \section Disclaimer * The information provided is believed to be accurate and reliable.
* * The copyright holder assumes no responsibility
* Common: * for the consequences of use
* Bosch Sensortec products are developed for the consumer goods industry. * of such information nor for any infringement of patents or
* They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser.
*
* The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims.
*
* The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents.
*
* Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering
* samples.
*
* Special:
* This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following
* terms and conditions:
*
* The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the
* proper experience or training.
*
* This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose.
*
* Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment
* of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law.
*
* The Information provided is believed to be accurate and reliable.
* Bosch Sensortec 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. * other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or * No license is granted by implication or otherwise under any patent or
* patent rights of Bosch. Specifications mentioned in the Information are * patent rights of the copyright holder.
* subject to change without notice. *
**************************************************************************/ * @file bme680.h
/*! \file bme680.h * @date 5 Jul 2017
\brief BME680 Sensor Driver Support Header File */ * @version 3.5.1
* @brief
#ifndef __BME680_H__ *
#define __BME680_H__ */
/*! @file bme680.h
@brief Sensor driver for BME680 sensor */
/*!
* @defgroup BME680 SENSOR API
* @{*/
#ifndef BME680_H_
#define BME680_H_
/*! CPP guard */
#ifdef __cplusplus #ifdef __cplusplus
extern "C" extern "C"
{ {
#endif #endif
/* BME680 Release version 2.0.0 /* Header includes */
BME680 Release Version format major_version.minor_version.point_version #include "bme680_defs.h"
Example: 2.0.0 */
#define BME680_API_REL_MAJOR_VERSION (2)
#define BME680_API_REL_MINOR_VERSION (0)
#define BME680_API_REL_POINT_VERSION (1)
/***************************************************************************
Header files
****************************************************************************/
#include "sensor_api_common_types.h"
/* sensor_api_common_types.h */
/************************************************************************
Macros, Enums, Constants
*************************************************************************/
#define BME680_PRESSURE (0U)
#define BME680_TEMPERATURE (1U)
#define BME680_HUMIDITY (2U)
#define BME680_GAS (3U)
#define BME680_ALL (4U)
#define BME680_STATUS_DATA_LEN (2U)
#define BME680_TEMPERATURE_DATA_LEN (3U)
#define BME680_PRESSURE_DATA_LEN (3U)
#define BME680_GAS_DATA_LEN (2U)
#define BME680_HUMIDITY_DATA_LEN (2U)
#define BME680_PRESENT_DATA_FIELD (1U)
#define BME680_PRESENT_AND_PREVIOUS_DATA_FIELD (2U)
#define BME680_ALL_DATA_FIELD (3U)
#define BME680_MAX_FIELD_INDEX (3U)
#define BME680_FIELD_INDEX0 (0U)
#define BME680_FIELD_INDEX1 (1U)
#define BME680_FIELD_INDEX2 (2U)
/***************************************************************/
/**\name BUS READ AND WRITE FUNCTION POINTERS */
/***************************************************************/
/**< function pointer to the SPI or I2C burst read function */
typedef s8 (*sensor_burst_read)(u8 slave_addr, u8 reg_addr, u8 *data_u8,
u32 length_u32);
typedef s8 (*sensor_write)(u8 dev_addr, u8 reg_addr, u8 *reg_data_ptr,
u8 data_len);
/**< function pointer for Write operation in either I2C or SPI*/
typedef s8 (*sensor_read)(u8 dev_addr, u8 reg_addr, u8 *reg_data_ptr,
u8 data_len);
/**< function pointer for Read operation in either I2C or SPI*/
#define BME680_MAX_NO_OF_SENSOR (2)
/**< This macro used for maximum number of sensor*/
#define BME680_MDELAY_DATA_TYPE u32
/**< This macro used for delay*/
#define BME680_CHIP_ID (0x61)
/**< BME680 chip identifier */
#define BME680_SPECIFIC_FIELD_DATA_READ_ENABLED
/**< This macro is used to prevent the compilation
of single function calls when not used */
/*
* Use below macro for fixed Point Calculation
* else Floating Point calculation will be used
*/
/* #define FIXED_POINT_COMPENSATION */
/* temperature to Resistance formulae #defines */
/*
* Use any of the below constants according to
* the heater version of the sensor used
*/
#define HEATER_C1_ENABLE
/* Sensor Specific constants */
#define BME680_SLEEP_MODE (0x00)
#define BME680_FORCED_MODE (0x01)
#define BME680_PARALLEL_MODE (0x02)
#define BME680_SEQUENTIAL_MODE (0x03)
#define BME680_GAS_PROFILE_TEMPERATURE_MIN (200)
#define BME680_GAS_PROFILE_TEMPERATURE_MAX (400)
#define BME680_GAS_RANGE_RL_LENGTH (16)
#define BME680_SIGN_BIT_MASK (0x08)
#ifdef FIXED_POINT_COMPENSATION
/**< Multiply by 1000, In order to convert
float value into fixed point */
#define BME680_MAX_HUMIDITY_VALUE (102400)
#define BME680_MIN_HUMIDITY_VALUE (0)
#else
#define BME680_MAX_HUMIDITY_VALUE (double)(100.0)
#define BME680_MIN_HUMIDITY_VALUE (double)(0.0)
#endif
/* BME680 I2C addresses */
#define BME680_I2C_ADDR_PRIMARY (0x76)
#define BME680_I2C_ADDR_SECONDARY (0x77)
/* Maximum no of gas profiles to be used */
#define BME680_MAX_PROFILES (10)
/**************************************************************/
/**\name Interface selection macro */
/*************************************************************/
#define BME680_SPI_INTERFACE (1)
#define BME680_I2C_INTERFACE (2)
/* bme680_internal.h */
/***************************************************************/
/**\name COMMON USED CONSTANTS */
/***************************************************************/
/* Constants */
#define BME680_NULL_PTR ((void *)0)
#define BME680_RETURN_FUNCTION_TYPE s8
/* Section 3.5: Function macros */
#define BME680_SET_REG(reg, data, mask, shift)\
((reg & mask) | ((data << shift) & ~mask))
#define BME680_GET_REG(reg, mask, shift)\
((reg & ~mask) >> shift)
#define DIFF(a, b) ((a > b)?(a - b):(b - a))
/*************************************************************
Module globals, typedefs
**************************************************************/
/* function prototype declarations */
/*! /*!
* @brief This structure holds all * @brief This API is the entry point.
* calibration parameters * It reads the chip-id and calibration data from the sensor.
*/
struct bme680_calibration_param_t {
s8 par_T3;/**<calibration T3 data*/
s8 par_P3;/**<calibration P3 data*/
s8 par_P6;/**<calibration P6 data*/
s8 par_P7;/**<calibration P7 data*/
u8 par_P10;/**<calibration P10 data*/
s8 par_H3;/**<calibration H3 data*/
s8 par_H4;/**<calibration H4 data*/
s8 par_H5;/**<calibration H5 data*/
u8 par_H6;/**<calibration H6 data*/
s8 par_H7;/**<calibration H7 data*/
s8 par_GH1;/**<calibration GH1 data*/
u8 res_heat_range;/**<resistance calculation*/
s8 res_heat_val; /**<correction factor*/
s8 range_switching_error;/**<range switching error*/
s16 par_GH2;/**<calibration GH2 data*/
u16 par_T1;/**<calibration T1 data*/
s16 par_T2;/**<calibration T2 data*/
u16 par_P1;/**<calibration P1 data*/
s16 par_P2;/**<calibration P2 data*/
s16 par_P4;/**<calibration P4 data*/
s16 par_P5;/**<calibration P5 data*/
s16 par_P8;/**<calibration P8 data*/
s16 par_P9;/**<calibration P9 data*/
u16 par_H1;/**<calibration H1 data*/
u16 par_H2;/**<calibration H2 data*/
s32 t_fine;/**<calibration T_FINE data*/
s8 par_GH3;/**<calibration GH3 data*/
};
/*!
* @brief bme680 structure
* This structure holds all relevant
* information about bme680
*/
struct bme680_t {
struct bme680_calibration_param_t cal_param;
/**<This structure holds all the calibration parameters */
u8 latest_field_index;
/**<stores the field index of latest data */
u8 recent_field_index;
/**<stores the field index of recent data */
u8 old_field_index;
/**<stores the field index of old data */
/**< The structure stores the calibration values*/
u8 chip_id;
/**< used to save the bme680's chip id*/
u8 dev_addr;
/**< used to store the I2C address*/
u8 last_set_mode;
/**< used to store the last set power mode*/
u8 interface;
/**< used to store the communication protocol*/
sensor_write bme680_bus_write;
/**< function pointer to the SPI or I2C write function */
sensor_read bme680_bus_read;
/**< function pointer to the SPI or I2C read function */
sensor_burst_read bme680_burst_read;
/**< function pointer to the SPI or I2C burst read function */
void (*delay_msec)(BME680_MDELAY_DATA_TYPE);
/**< function pointer to a delay in milliseconds function */
};
/*!
* @brief This structure holds heater configuration
* parameters
*/
struct bme680_heater_conf {
u16 heatr_dur_shared;
/**< variable to store heater duration for parallel mode */
u16 heater_temp[BME680_MAX_PROFILES];
/**< variable to store heater resistance */
u16 heatr_dur[BME680_MAX_PROFILES];
/**< variable to store heater duration for force and sequential mode*/
u8 profile_cnt;
/**< variable to store profile count for user reference */
};
/*!
* @brief Enumeration for function return codes
* *
*/ * @param[in,out] dev : Structure instance of bme680_dev
enum bme680_return_type {
BME680_COMM_RES_OK,
BME680_COMM_RES_ERROR = -1,
BME680_ERROR_NULL_PTR = -2,
BME680_CHIP_ID_ERROR = -4,
BME680_PROFILE_CNT_ERROR = -5
};
/*!
* @brief This enum holds different ODR values
* for Gas data
*/
enum bme680_odr {
BME680_ODR_0_59MS,
BME680_ODR_62_5MS,
BME680_ODR_125MS,
BME680_ODR_250MS,
BME680_ODR_500MS,
BME680_ODR_1000MS,
BME680_ODR_10MS,
BME680_ODR_20MS,
BME680_ODR_NONE
};
/*!
* @brief This enum holds gas control
* parameters
*/
enum bme680_run_gas {
BME680_RUN_GAS_DISABLE,
BME680_RUN_GAS_ENABLE
};
/*!
* @brief This enum holds heater control
* parameters
*/
enum bme680_heatr_ctrl {
BME680_HEATR_CTRL_ENABLE,
BME680_HEATR_CTRL_DISABLE
};
/*!
* @brief This enum holds osrs setting
* of TPH data
*/
enum bme680_osrs_x {
BME680_OSRS_NONE,
BME680_OSRS_1X,
BME680_OSRS_2X,
BME680_OSRS_4X,
BME680_OSRS_8X,
BME680_OSRS_16X
};
/*!
* @brief This enum holds filter
* coefficient settings
*/
enum bme680_filter {
BME680_FILTER_COEFF_0,
BME680_FILTER_COEFF_1,
BME680_FILTER_COEFF_3,
BME680_FILTER_COEFF_7,
BME680_FILTER_COEFF_15,
BME680_FILTER_COEFF_31,
BME680_FILTER_COEFF_63,
BME680_FILTER_COEFF_127
};
/*!
* @brief This enum holds spi 3wire
* interrupt control setting parameters
*/
enum bme680_spi_3w_intr {
BME680_SPI_3W_INTR_DISABLE,
BME680_SPI_3W_INTR_ENABLE
};
/*!
* @brief This enum holds spi_3w_interface
* enabling parameters
*/
enum bme680_spi_3w {
BME680_SPI_3W_DISABLE,
BME680_SPI_3W_ENABLE
};
/*!
* @brief This enum holds nb conversion
* parameters
*/
enum bme680_nb_conv {
BME680_NB_CONV_SKIPPED,
BME680_NB_CONV_1,
BME680_NB_CONV_2,
BME680_NB_CONV_3,
BME680_NB_CONV_4,
BME680_NB_CONV_5,
BME680_NB_CONV_6,
BME680_NB_CONV_7,
BME680_NB_CONV_8,
BME680_NB_CONV_9
};
/*!
* @brief This structure holds sensor configuration
* parameters
*/
struct bme680_sens_conf {
s8 nb_conv;
/**< variable to store nb conversion */
enum bme680_heatr_ctrl heatr_ctrl;
/**< instance of heater control */
enum bme680_odr odr;
/**< instance of ODR */
enum bme680_run_gas run_gas;
/**< instance of gas enable */
enum bme680_osrs_x osrs_hum;
/**< instance of osrs for humidity */
enum bme680_osrs_x osrs_temp;
/**< instance of osrs for temperature */
enum bme680_osrs_x osrs_pres;
/**< instance of osrs for pressure */
enum bme680_filter filter;
/**< instance of filter */
enum bme680_spi_3w_intr intr;
/**< instance of 3_wire_spi for interrupt mode */
enum bme680_spi_3w spi_3w;
/**< instance of 3 wire spi interface */
};
/*!
* @brief This structure holds sensor status
* parameters
*/
struct bme680_status {
u8 new_data;
/**<New data flag */
u8 gas_meas_stat;
/**<Gas measuring status */
u8 tphg_meas_stat;
/**<TPHG status */
u8 gas_meas_index;
/**<Gas measuring index */
u8 meas_index;
/**<Measurement index */
u8 gas_valid;
/**<gas data valid check */
u8 heatr_stab;
/**<stability check */
};
/*!
* @brief This structure holds the compensated data
* for either fixed or floating point compensation
*/
struct bme680_comp_field_data {
#ifdef FIXED_POINT_COMPENSATION
s32 comp_pressure;
/**< the value of field2 compensated pressure*/
s32 comp_temperature1;
/**< the value of field2 compensated temperature1*/
s32 comp_humidity;
/**< the value of field2 compensated humidity*/
s32 comp_gas;
/**< the value of field2 compensated gas*/
#else
double comp_pressure;
/**< the value of field2 compensated pressure*/
double comp_temperature1;
/**< the value of field2 compensated temperature1*/
double comp_humidity;
/**< the value of field2 compensated humidity*/
double comp_gas;
/**< the value of field2 compensated gas*/
#endif
};
/*!
* @brief This structure holds the uncompensated data
* for either fixed or floating point compensation
*/
struct bme680_uncomp_field_data {
/**< data field status*/
struct bme680_status status;
u8 gas_range;
/**<Range index of the back-end of the ADC */
#ifdef FIXED_POINT_COMPENSATION
u32 pres_adcv;
/**< the value of field2 uncompensated pressure*/
u32 temp_adcv;
/**< the value of field2 uncompensated temperature1*/
u16 hum_adcv;
/**< the value of field2 uncompensated humidity*/
u16 gas_res_adcv;
/**< the value of field2 uncompensated gas*/
#else
double pres_adcv;
/**< the value of pressure*/
double temp_adcv;
/**< adc value of temperature*/
double hum_adcv;
/**< adc value of humidity*/
double gas_res_adcv;
/**< adc value of gas resistance*/
#endif
};
/*********************************************************
Function declarations
**********************************************************/
/*********************************************************/
/**\name FUNCTION FOR BME680 INITIALIZE */
/*********************************************************/
/*!
* @brief This function is used to read the
* the chip id and calibration data of the BME680 sensor
* chip id is read in the register 0xD0/0x50(I2C/SPI) from bit 0 to 7
*/
enum bme680_return_type bme680_init(struct bme680_t *bme680);
/**************************************************/
/**\name FUNCTION FOR COMMON WRITE AND READ */
/*************************************************/
/*!
* @brief This function is used to write the data to
* the given register
*/
enum bme680_return_type bme680_write_reg(u8 addr_u8, u8 *data_u8, u8 len_u8,
struct bme680_t *bme680);
/*!
* @brief This function is used to reads the data from
* the given register
*/
enum bme680_return_type bme680_read_reg(u8 addr_u8, u8 *data_u8, u8 len_u8,
struct bme680_t *bme680);
/**************************************************/
/**\name FUNCTION FOR NEW DATA STATUS
OF FIELD0, FIELD1 AND FIELD2*/
/**************************************************/
/*!
* @brief This function is used to read the new data0
* @note Field-0(new_data_0),Field-1(new_data_1) and Field-2(new_data_2)
*/
enum bme680_return_type bme680_get_new_data(u8 *new_data_u8,
u8 field_u8, struct bme680_t *bme680);
/*!
* @brief This function is used to read the uncompensated
* sensor data from Field-0, Field-1, Field-2 and page-1
*/
enum bme680_return_type bme680_get_uncomp_data(
struct bme680_uncomp_field_data *uncomp_data, u8 field_count,
u8 sensor_type, struct bme680_t *bme680);
/*!
* @brief This function is used to get the
* Operational Mode from the sensor in the
* register 0x74 bit 0 and 1
*/
enum bme680_return_type bme680_get_power_mode(u8 *power_mode_u8,
struct bme680_t *bme680);
/*!
* @brief This function is used to set the
* Operational Mode of the sensor in the
* register 0x74 bit 0 and 1
*/
enum bme680_return_type bme680_set_power_mode(u8 power_mode_u8,
struct bme680_t *bme680);
/*!
* @brief This function is used to set the sensor configuration
*/
enum bme680_return_type bme680_set_sensor_config(
struct bme680_sens_conf *sens_conf, struct bme680_t *bme680);
/*!
* @brief This function is used for setting gas heater configuration
* of the sensor from register 5A to 6E address
*/
enum bme680_return_type bme680_set_gas_heater_config(
struct bme680_heater_conf *heatr_conf, struct bme680_t *bme680);
/*!
* @brief This function is used to get the sensor configuration
*/
enum bme680_return_type bme680_get_sensor_config(
struct bme680_sens_conf *sens_conf, struct bme680_t *bme680);
/*!
* @brief This function is used to read the sensor heater
* configuration from register 5A to 6E address
*/
enum bme680_return_type bme680_get_gas_heater_config(
struct bme680_heater_conf *heatr_conf, struct bme680_t *bme680);
/*!
* @brief This function is used to compensate the TPHG raw
* values of the sensor in order to convert to meaningful values
* *
* @note: if "BME680_SPECIFIC_FIELD_DATA_READ_ENABLED" is not defined in * @return Result of API execution status
* bme680.h then for any sensor_type function will perform * @retval zero -> Success / +ve value -> Warning / -ve value -> Error
* read operation for BME680_ALL.
* @note : pressure and humidity depends on temperature.
*/ */
enum bme680_return_type bme680_compensate_data( int8_t bme680_init(struct bme680_dev *dev);
struct bme680_uncomp_field_data uncomp_data[],
struct bme680_comp_field_data comp_data[], u8 field_count,
u8 sensor_type, struct bme680_t *bme680);
/*! /*!
* @brief This function is used to Align uncompensated data * @brief This API writes the given data to the register address
* from function bme680_get_uncomp_data() * of the sensor.
*
* @param[in] reg_addr : Register address from where the data to be written.
* @param[in] reg_data : Pointer to data buffer which is to be written
* in the sensor.
* @param[in] len : No of bytes of data to write..
* @param[in] dev : Structure instance of bme680_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/ */
void bme680_align_uncomp_data(u8 *a_data_u8, u8 field_count, u8 sensor_type, int8_t bme680_set_regs(const uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, struct bme680_dev *dev);
struct bme680_uncomp_field_data *uncomp_data,
struct bme680_t *bme680);
/*! /*!
* @brief This function is used to read the status according to filed index. * @brief This API reads the data from the given register address of the sensor.
*
* @param[in] reg_addr : Register address from where the data to be read
* @param[out] reg_data : Pointer to data buffer to store the read data.
* @param[in] len : No of bytes of data to be read.
* @param[in] dev : Structure instance of bme680_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/ */
enum bme680_return_type bme680_read_status_fields( int8_t bme680_get_regs(uint8_t reg_addr, uint8_t *reg_data, uint16_t len, struct bme680_dev *dev);
struct bme680_uncomp_field_data *uncomp_data,
u8 *a_data_u8, u8 *new_data,
struct bme680_t *bme680);
/* bme680_calculations.h */
/*!
* @brief This API performs the soft reset of the sensor.
*
* @param[in] dev : Structure instance of bme680_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
*/
int8_t bme680_soft_reset(struct bme680_dev *dev);
/*!
* @brief This API is used to set the power mode of the sensor.
*
* @param[in] dev : Structure instance of bme680_dev
* @note : Pass the value to bme680_dev.power_mode structure variable.
*
* value | mode
* -------------|------------------
* 0x00 | BME680_SLEEP_MODE
* 0x01 | BME680_FORCED_MODE
*
* * @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
int8_t bme680_set_sensor_mode(struct bme680_dev *dev);
/*!
* @brief This API is used to get the power mode of the sensor.
*
* @param[in] dev : Structure instance of bme680_dev
* @note : bme680_dev.power_mode structure variable hold the power mode.
*
* value | mode
* ---------|------------------
* 0x00 | BME680_SLEEP_MODE
* 0x01 | BME680_FORCED_MODE
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
int8_t bme680_get_sensor_mode(struct bme680_dev *dev);
/*!
* @brief This API is used to set the profile duration of the sensor.
*
* @param[in] dev : Structure instance of bme680_dev.
* @param[in] duration : Duration of the measurement in ms.
*
* @return Nothing
*/
void bme680_set_profile_dur(uint16_t duration, struct bme680_dev *dev);
/*!
* @brief This API is used to get the profile duration of the sensor.
*
* @param[in] dev : Structure instance of bme680_dev.
* @param[in] duration : Duration of the measurement in ms.
*
* @return Nothing
*/
void bme680_get_profile_dur(uint16_t *duration, struct bme680_dev *dev);
/*!
* @brief This API reads the pressure, temperature and humidity and gas data
* from the sensor, compensates the data and store it in the bme680_data
* structure instance passed by the user.
*
* @param[out] data: Structure instance to hold the data.
* @param[in] dev : Structure instance of bme680_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
int8_t bme680_get_sensor_data(struct bme680_field_data *data, struct bme680_dev *dev);
/*!
* @brief This API is used to set the oversampling, filter and T,P,H, gas selection
* settings in the sensor.
*
* @param[in] dev : Structure instance of bme680_dev.
* @param[in] desired_settings : Variable used to select the settings which
* are to be set in the sensor.
*
* Macros | Functionality
*-------------------------|----------------------------------------------
* BME680_OST_SEL | To set temperature oversampling.
* BME680_OSP_SEL | To set pressure oversampling.
* BME680_OSH_SEL | To set humidity oversampling.
* BME680_GAS_MEAS_SEL | To set gas measurement setting.
* BME680_FILTER_SEL | To set filter setting.
* BME680_HCNTRL_SEL | To set humidity control setting.
* BME680_RUN_GAS_SEL | To set run gas setting.
* BME680_NBCONV_SEL | To set NB conversion setting.
* BME680_GAS_SENSOR_SEL | To set all gas sensor related settings
*
* @note : Below are the macros to be used by the user for selecting the
* desired settings. User can do OR operation of these macros for configuring
* multiple settings.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
*/
int8_t bme680_set_sensor_settings(uint16_t desired_settings, struct bme680_dev *dev);
/*!
* @brief This API is used to get the oversampling, filter and T,P,H, gas selection
* settings in the sensor.
*
* @param[in] dev : Structure instance of bme680_dev.
* @param[in] desired_settings : Variable used to select the settings which
* are to be get from the sensor.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error.
*/
int8_t bme680_get_sensor_settings(uint16_t desired_settings, struct bme680_dev *dev);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif /* End of CPP guard */
#endif /* BME680_H_ */
#endif /** @}*/

View File

@ -1,684 +0,0 @@
/**
*
****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* File : bme680_calculations.c
*
* Date: 5 May 2017
*
* Revision : 2.2.0 $
*
* Usage: Sensor Driver for BME680 sensor
*
****************************************************************************
*
* \section Disclaimer
*
* Common:
* Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser.
*
* The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims.
*
* The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents.
*
* Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering
* samples.
*
* Special:
* This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following
* terms and conditions:
*
* The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the
* proper experience or training.
*
* This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose.
*
* Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment
* of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law.
*
* The Information provided is believed to be accurate and reliable.
* Bosch Sensortec 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 Bosch. Specifications mentioned in the Information are
* subject to change without notice.
**************************************************************************/
/*! \file bme680_calculations.c
\brief BME680 Sensor Driver calculation source File */
/***************************************************************************
Header files
****************************************************************************/
#include "bme680_calculations.h"
/***************************************************************************
Macros, Enums, Constants
****************************************************************************/
/***************************************************************************
File globals, typedefs
****************************************************************************/
/***************************************************************************
Function definitions
****************************************************************************/
/* bme680.c */
#ifdef FIXED_POINT_COMPENSATION
/*!
* @brief This function is used to convert uncompensated gas data to
* compensated gas data using compensation formula(integer version)
*
* @param gas_adc_u16: The value of gas resistance calculated
* using temperature
* @param gas_range_u8: The value of gas range form register value
* @param bme680: structure pointer.
*
* @return calculated compensated gas from compensation formula
* @retval compensated gas data
*
*
*/
s32 bme680_calculate_gas_int32(u16 gas_adc_u16, u8 gas_range_u8,
struct bme680_t *bme680)
{
s8 range_switching_error_val = 0;
s64 var1 = 0;
s64 var2 = 0;
s32 gas_res = 0;
const u64 lookup_k1_range[BME680_GAS_RANGE_RL_LENGTH] = {
2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL, 2147483647UL,
2126008810UL, 2147483647UL, 2130303777UL, 2147483647UL, 2147483647UL,
2143188679UL, 2136746228UL, 2147483647UL, 2126008810UL, 2147483647UL,
2147483647UL};
const u64 lookup_k2_range[BME680_GAS_RANGE_RL_LENGTH] = {
4096000000UL, 2048000000UL, 1024000000UL, 512000000UL,
255744255UL, 127110228UL, 64000000UL, 32258064UL, 16016016UL,
8000000UL, 4000000UL, 2000000UL, 1000000UL, 500000UL, 250000UL,
125000UL};
range_switching_error_val =
bme680->cal_param.range_switching_error;
var1 = (s64)((1340 + (5 * (s64)range_switching_error_val)) *
((s64)lookup_k1_range[gas_range_u8])) >> 16;
var2 = (s64)((s64)gas_adc_u16 << 15) - (s64)(1 << 24) + var1;
#ifndef __KERNEL__
gas_res = (s32)(((((s64)lookup_k2_range[gas_range_u8] *
(s64)var1) >> 9) + (var2 >> 1)) / var2);
#else
gas_res = (s32)(div64_s64(((((s64)lookup_k2_range[gas_range_u8] *
(s64)var1) >> 9) + (var2 >> 1)), var2));
#endif
return gas_res;
}
/*!
* @brief This function is used to convert the uncompensated
* temperature data to compensated temperature data using
* compensation formula(integer version)
* @note Returns the value in 0.01 degree Centigrade
* Output value of "5123" equals 51.23 DegC.
*
*
*
* @param v_uncomp_temperature_u32 : value of uncompensated temperature
* @param bme680: structure pointer.
*
* @return Returns the compensated temperature data
*
*/
s32 bme680_compensate_temperature_int32(u32 v_uncomp_temperature_u32,
struct bme680_t *bme680)
{
s32 var1 = 0;
s32 var2 = 0;
s32 var3 = 0;
s32 temp_comp = 0;
var1 = ((s32)v_uncomp_temperature_u32 >> 3) -
((s32)bme680->cal_param.par_T1 << 1);
var2 = (var1 * (s32)bme680->cal_param.par_T2) >> 11;
var3 = ((((var1 >> 1) * (var1 >> 1)) >> 12) *
((s32)bme680->cal_param.par_T3 << 4)) >> 14;
bme680->cal_param.t_fine = var2 + var3;
temp_comp = ((bme680->cal_param.t_fine * 5) + 128) >> 8;
return temp_comp;
}
/*!
* @brief This function is used to convert the uncompensated
* humidity data to compensated humidity data using
* compensation formula(integer version)
*
* @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_u32: value of uncompensated humidity
* @param bme680: structure pointer.
*
* @return Return the compensated humidity data
*
*/
s32 bme680_compensate_humidity_int32(u32 v_uncomp_humidity_u32,
struct bme680_t *bme680)
{
s32 temp_scaled = 0;
s32 var1 = 0;
s32 var2 = 0;
s32 var3 = 0;
s32 var4 = 0;
s32 var5 = 0;
s32 var6 = 0;
s32 humidity_comp = 0;
temp_scaled = (((s32)bme680->cal_param.t_fine * 5) + 128) >> 8;
var1 = (s32)v_uncomp_humidity_u32 -
((s32)((s32)bme680->cal_param.par_H1 << 4)) -
(((temp_scaled * (s32)bme680->cal_param.par_H3) /
((s32)100)) >> 1);
var2 = ((s32)bme680->cal_param.par_H2 *
(((temp_scaled * (s32)bme680->cal_param.par_H4) /
((s32)100)) + (((temp_scaled *
((temp_scaled * (s32)bme680->cal_param.par_H5) /
((s32)100))) >> 6) / ((s32)100)) + (s32)(1 << 14))) >> 10;
var3 = var1 * var2;
var4 = ((((s32)bme680->cal_param.par_H6) << 7) +
((temp_scaled * (s32)bme680->cal_param.par_H7) /
((s32)100))) >> 4;
var5 = ((var3 >> 14) * (var3 >> 14)) >> 10;
var6 = (var4 * var5) >> 1;
humidity_comp = (var3 + var6) >> 12;
if (humidity_comp > BME680_MAX_HUMIDITY_VALUE)
humidity_comp = BME680_MAX_HUMIDITY_VALUE;
else if (humidity_comp < BME680_MIN_HUMIDITY_VALUE)
humidity_comp = BME680_MIN_HUMIDITY_VALUE;
return humidity_comp;
}
/*!
* @brief This function is used to convert the uncompensated
* pressure data to compensated pressure data data using
* compensation formula(integer version)
*
* @note Returns the value in Pascal(Pa)
* Output value of "96386" equals 96386 Pa =
* 963.86 hPa = 963.86 millibar
*
*
*
* @param v_uncomp_pressure_u32 : value of uncompensated pressure
* @param bme680: structure pointer.
*
* @return Return the compensated pressure data
*
*/
s32 bme680_compensate_pressure_int32(u32 v_uncomp_pressure_u32,
struct bme680_t *bme680)
{
s32 var1 = 0;
s32 var2 = 0;
s32 var3 = 0;
s32 var4 = 0;
s32 pressure_comp = 0;
var1 = (((s32)bme680->cal_param.t_fine) >> 1) - 64000;
var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) *
(s32)bme680->cal_param.par_P6) >> 2;
var2 = var2 + ((var1 * (s32)bme680->cal_param.par_P5) << 1);
var2 = (var2 >> 2) + ((s32)bme680->cal_param.par_P4 << 16);
var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) *
((s32)bme680->cal_param.par_P3 << 5)) >> 3) +
(((s32)bme680->cal_param.par_P2 * var1) >> 1);
var1 = var1 >> 18;
var1 = ((32768 + var1) * (s32)bme680->cal_param.par_P1) >> 15;
pressure_comp = 1048576 - v_uncomp_pressure_u32;
pressure_comp = (s32)((pressure_comp - (var2 >> 12)) * ((u32)3125));
var4 = (1 << 31);
if (pressure_comp >= var4)
pressure_comp = ((pressure_comp / (u32)var1) << 1);
else
pressure_comp = ((pressure_comp << 1) / (u32)var1);
var1 = ((s32)bme680->cal_param.par_P9 * (s32)(((pressure_comp >> 3) *
(pressure_comp >> 3)) >> 13)) >> 12;
var2 = ((s32)(pressure_comp >> 2) *
(s32)bme680->cal_param.par_P8) >> 13;
var3 = ((s32)(pressure_comp >> 8) * (s32)(pressure_comp >> 8) *
(s32)(pressure_comp >> 8) *
(s32)bme680->cal_param.par_P10) >> 17;
pressure_comp = (s32)(pressure_comp) + ((var1 + var2 + var3 +
((s32)bme680->cal_param.par_P7 << 7)) >> 4);
return pressure_comp;
}
/*!
* @brief This function is used to convert temperature to resistance
* using the integer compensation formula
*
* @param heater_temp_u16: The value of heater temperature
* @param ambient_temp_s16: The value of ambient temperature
* @param bme680: structure pointer.
*
* @return calculated resistance from temperature
*
*
*
*/
u8 bme680_convert_temperature_to_resistance_int32(u16 heater_temp_u16,
s16 ambient_temp_s16, struct bme680_t *bme680)
{
s32 var1 = 0;
s32 var2 = 0;
s32 var3 = 0;
s32 var4 = 0;
s32 var5 = 0;
s32 res_heat_x100 = 0;
u8 res_heat = 0;
if ((heater_temp_u16 >= BME680_GAS_PROFILE_TEMPERATURE_MIN)
&& (heater_temp_u16 <= BME680_GAS_PROFILE_TEMPERATURE_MAX)) {
var1 = (((s32)ambient_temp_s16 *
bme680->cal_param.par_GH3) / 10) << 8;
var2 = (bme680->cal_param.par_GH1 + 784) *
(((((bme680->cal_param.par_GH2 + 154009) *
heater_temp_u16 * 5) / 100) + 3276800) / 10);
var3 = var1 + (var2 >> 1);
var4 = (var3 / (bme680->cal_param.res_heat_range + 4));
var5 = (131 * bme680->cal_param.res_heat_val) + 65536;
res_heat_x100 = (s32)(((var4 / var5) - 250) * 34);
res_heat = (u8) ((res_heat_x100 + 50) / 100);
}
return res_heat;
}
/*!
* @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_u32: value of uncompensated humidity
* @param bme680: structure pointer.
*
* @return Return the actual relative humidity output as u16
*
*/
u16 bme680_compensate_H_int32_sixteen_bit_output(u32 v_uncomp_humidity_u32,
struct bme680_t *bme680)
{
u32 v_x1_u32 = 0;
u16 v_x2_u32 = 0;
v_x1_u32 = (u32) bme680_compensate_humidity_int32(
v_uncomp_humidity_u32, bme680);
v_x2_u32 = (u16)(v_x1_u32 >> 1);
return v_x2_u32;
}
/*!
* @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_u32: value of uncompensated temperature
* @param bme680: structure pointer.
*
*
* @return Return the actual temperature as s16 output
*
*/
s16 bme680_compensate_T_int32_sixteen_bit_output(u32 v_uncomp_temperature_u32,
struct bme680_t *bme680)
{
s16 temperature = 0;
bme680_compensate_temperature_int32(v_uncomp_temperature_u32, bme680);
temperature = (s16)((((
bme680->cal_param.t_fine - 122880) * 25) + 128) >> 8);
return temperature;
}
/*!
* @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_uncomp_pressure_u32 : value of uncompensated pressure
* @param bme680: structure pointer.
*
* @return the actual pressure in u32
*
*/
u32 bme680_compensate_P_int32_twentyfour_bit_output(u32 v_uncomp_pressure_u32,
struct bme680_t *bme680)
{
u32 pressure = 0;
pressure = (u32)bme680_compensate_pressure_int32(
v_uncomp_pressure_u32, bme680);
pressure = (u32)(pressure >> 1);
return pressure;
}
#else
/*!
* @brief This function is used to convert uncompensated gas data to
* compensated gas data using compensation formula
*
* @param gas_adc_u16: The value of gas resistance calculated
* using temperature
* @param gas_range_u8: The value of gas range form register value
* @param bme680: structure pointer.
*
* @return calculated compensated gas from compensation formula
* @retval compensated gas
*
*
*/
double bme680_compensate_gas_double(u16 gas_adc_u16, u8 gas_range_u8,
struct bme680_t *bme680)
{
double gas_res_d = 0;
#ifdef HEATER_C1_ENABLE
const double lookup_k1_range[BME680_GAS_RANGE_RL_LENGTH] = {
0.0, 0.0, 0.0, 0.0, 0.0, -1.0, 0.0, -0.8,
0.0, 0.0, -0.2, -0.5, 0.0, -1.0, 0.0, 0.0};
const double lookup_k2_range[BME680_GAS_RANGE_RL_LENGTH] = {
0.0, 0.0, 0.0, 0.0, 0.1, 0.7, 0.0, -0.8,
-0.1, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0};
s8 range_switching_error_val = 0;
double var1 = 0;
double var2 = 0;
double var3 = 0;
range_switching_error_val =
bme680->cal_param.range_switching_error;
var1 = (1340.0 + (5.0 * range_switching_error_val));
var2 = (var1) * (1.0 + lookup_k1_range[gas_range_u8]/100.0);
var3 = 1.0 + (lookup_k2_range[gas_range_u8]/100.0);
gas_res_d = 1.0 / (double)(var3 * (0.000000125) *
(double)(1 << gas_range_u8)
* (((((double)gas_adc_u16) - 512.00)/var2) + 1.0));
#else
gas_res_d = 1.0 / ((0.000000125) * (double)(1 << gas_range_u8) *
((((double)(gas_adc_u16) - 512.00) / 1365.3333) + 1.0));
#endif
return gas_res_d;
}
/*!
* @brief This function is used to convert the uncompensated
* humidity data to compensated humidity data data using
* compensation formula
* @note returns the value in relative humidity (%rH)
* @note Output value of "42.12" equals 42.12 %rH
*
* @param uncom_humidity_u16 : value of uncompensated humidity
* @param comp_temperature : value of compensated temperature
* @param bme680: structure pointer.
*
*
* @return Return the compensated humidity data in floating point
*
*/
double bme680_compensate_humidity_double(u16 uncom_humidity_u16,
double comp_temperature, struct bme680_t *bme680)
{
double humidity_comp = 0;
double var1 = 0;
double var2 = 0;
double var3 = 0;
double var4 = 0;
var1 = (double)((double)uncom_humidity_u16) - (((double)
bme680->cal_param.par_H1 * 16.0) +
(((double)bme680->cal_param.par_H3 / 2.0)
* comp_temperature));
var2 = var1 * ((double)(
((double) bme680->cal_param.par_H2 / 262144.0)
*(1.0 + (((double)bme680->cal_param.par_H4 / 16384.0)
* comp_temperature) + (((double)bme680->cal_param.par_H5
/ 1048576.0) * comp_temperature
* comp_temperature))));
var3 = (double) bme680->cal_param.par_H6 / 16384.0;
var4 = (double) bme680->cal_param.par_H7 / 2097152.0;
humidity_comp = var2 +
((var3 + (var4 * comp_temperature)) * var2 * var2);
if (humidity_comp > BME680_MAX_HUMIDITY_VALUE)
humidity_comp = BME680_MAX_HUMIDITY_VALUE;
else if (humidity_comp < BME680_MIN_HUMIDITY_VALUE)
humidity_comp = BME680_MIN_HUMIDITY_VALUE;
return humidity_comp;
}
/*!
* @brief This function is used to convert the uncompensated
* pressure data to compensated data using compensation formula
* @note Returns pressure in Pa as double.
* @note Output value of "96386.2"
* equals 96386.2 Pa = 963.862 hPa.
*
*
* @param uncom_pressure_u32 : value of uncompensated pressure
* @param bme680: structure pointer.
*
* @return Return the compensated pressure data in floating point
*
*/
double bme680_compensate_pressure_double(u32 uncom_pressure_u32,
struct bme680_t *bme680)
{
double data1_d = 0;
double data2_d = 0;
double data3_d = 0;
double pressure_comp = 0;
data1_d = (((double)bme680->cal_param.t_fine / 2.0) - 64000.0);
data2_d = data1_d * data1_d * (((double)bme680->cal_param.par_P6) /
(131072.0));
data2_d = data2_d + (data1_d * ((double)bme680->cal_param.par_P5) *
2.0);
data2_d = (data2_d / 4.0) + (((double)bme680->cal_param.par_P4) *
65536.0);
data1_d = (((((double)bme680->cal_param.par_P3 * data1_d
* data1_d) / 16384.0) + ((double)bme680->cal_param.par_P2
* data1_d)) / 524288.0);
data1_d = ((1.0 + (data1_d / 32768.0)) *
((double)bme680->cal_param.par_P1));
pressure_comp = (1048576.0 - ((double)uncom_pressure_u32));
/* Avoid exception caused by division by zero */
if ((int)data1_d != 0) {
pressure_comp = (((pressure_comp - (data2_d
/ 4096.0)) * 6250.0) / data1_d);
data1_d = (((double)bme680->cal_param.par_P9) *
pressure_comp * pressure_comp) / 2147483648.0;
data2_d = pressure_comp * (((double)bme680->cal_param.par_P8)
/ 32768.0);
data3_d = ((pressure_comp / 256.0) * (pressure_comp / 256.0) *
(pressure_comp / 256.0) *
(bme680->cal_param.par_P10 / 131072.0));
pressure_comp = (pressure_comp + (data1_d + data2_d + data3_d +
((double)bme680->cal_param.par_P7 * 128.0)) / 16.0);
return pressure_comp;
} else {
return 0;
}
}
/*!
* @brief This function used to convert temperature data
* to uncompensated temperature data using compensation formula
* @note returns the value in Degree centigrade
* @note Output value of "51.23" equals 51.23 DegC.
*
* @param uncom_temperature_u32 : value of uncompensated temperature
* @param bme680: structure pointer.
*
* @return Return the actual temperature in floating point
*
*/
double bme680_compensate_temperature_double(u32 uncom_temperature_u32,
struct bme680_t *bme680)
{
double data1_d = 0;
double data2_d = 0;
double temperature = 0;
/* calculate x1 data */
data1_d = ((((double)uncom_temperature_u32 / 16384.0)
- ((double)bme680->cal_param.par_T1 / 1024.0))
* ((double)bme680->cal_param.par_T2));
/* calculate x2 data */
data2_d = (((((double)uncom_temperature_u32 / 131072.0) -
((double)bme680->cal_param.par_T1 / 8192.0)) *
(((double)uncom_temperature_u32 / 131072.0) -
((double)bme680->cal_param.par_T1 / 8192.0))) *
((double)bme680->cal_param.par_T3 * 16.0));
/* t fine value*/
bme680->cal_param.t_fine = (s32)(data1_d + data2_d);
/* compensated temperature data*/
temperature = ((data1_d + data2_d) /
5120.0);
return temperature;
}
/*!
* @brief This function is used to convert temperature to resistance
* using the compensation formula
*
* @param heater_temp_u16: The value of heater temperature
* @param ambient_temp_s16: The value of ambient temperature
* @param bme680: structure pointer.
*
* @return calculated resistance from temperature
*
*
*
*/
double bme680_convert_temperature_to_resistance_double(u16 heater_temp_u16,
s16 ambient_temp_s16, struct bme680_t *bme680)
{
double var1 = 0;
double var2 = 0;
double var3 = 0;
double var4 = 0;
double var5 = 0;
double res_heat = 0;
if ((heater_temp_u16 >= BME680_GAS_PROFILE_TEMPERATURE_MIN)
&& (heater_temp_u16 <= BME680_GAS_PROFILE_TEMPERATURE_MAX)) {
#ifdef HEATER_C1_ENABLE
var1 = (((double)bme680->cal_param.par_GH1 / (16.0)) + 49.0);
var2 = ((((double)bme680->cal_param.par_GH2
/(32768.0)) * (0.0005)) + 0.00235);
#endif
var3 = ((double)bme680->cal_param.par_GH3 / (1024.0));
var4 = (var1 * (1.0 + (var2 * (double)heater_temp_u16)));
var5 = (var4 + (var3 * (double)ambient_temp_s16));
#ifdef HEATER_C1_ENABLE
res_heat = (u8)(3.4 * ((var5 *
(4 / (4 + (double)bme680->cal_param.res_heat_range)) *
(1/(1 + ((double)bme680->cal_param.res_heat_val
* 0.002)))) - 25));
#else
res_heat = (((var5 * (4.0 /
(4.0 + (double)bme680->cal_param.res_heat_range)))
- 25.0) * 3.4);
#endif
}
return (u8)res_heat;
}
#endif
/* bme680.c */

View File

@ -1,277 +0,0 @@
/**
*
****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* File : bme680_calculations.h
*
* Date: 5 May 2017
*
* Revision : 2.2.0 $
*
* Usage: Sensor Driver for BME680 sensor
*
****************************************************************************
*
* \section Disclaimer
*
* Common:
* Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser.
*
* The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims.
*
* The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents.
*
* Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering
* samples.
*
* Special:
* This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following
* terms and conditions:
*
* The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the
* proper experience or training.
*
* This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose.
*
* Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment
* of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law.
*
* The Information provided is believed to be accurate and reliable.
* Bosch Sensortec 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 Bosch. Specifications mentioned in the Information are
* subject to change without notice.
**************************************************************************/
/*! \file bme680_calculations.h
\brief BME680 Sensor Driver calculation Header File */
/*************************************************************************/
#ifndef __BME680_CALCULATIONS_H__
#define __BME680_CALCULATIONS_H__
#ifdef __cplusplus
extern "C"
{
#endif
/***************************************************************************
Header files
****************************************************************************/
#include "bme680.h"
/***************************************************************************
Macros, Enums, Constants
****************************************************************************/
/***************************************************************************
Module globals, typedefs
****************************************************************************/
/***************************************************************************
Function definitions
****************************************************************************/
/* bme680_calculations.h */
#ifdef FIXED_POINT_COMPENSATION
/**************************************************************/
/**\name FUNCTION FOR INTEGER OUTPUT GAS*/
/**************************************************************/
/*!
* @brief This function is used to convert uncompensated gas data to
* compensated gas data using compensation formula(integer version)
*/
s32 bme680_calculate_gas_int32(u16 gas_adc_u16, u8 gas_range_u8,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR INTEGER OUTPUT TEMPERATURE*/
/**************************************************************/
/*!
* @brief This function is used to convert the uncompensated
* temperature data to compensated temperature data using
* compensation formula(integer version)
*
* @note Returns the value in 0.01 degree Centigrade
* Output value of "5123" equals 51.23 DegC.
*/
s32 bme680_compensate_temperature_int32(u32 v_uncomp_temperature_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR INTEGER OUTPUT HUMIDITY*/
/**************************************************************/
/*!
* @brief This function is used to convert the uncompensated
* humidity data to compensated humidity data using
* compensation formula(integer version)
*
* @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
*/
s32 bme680_compensate_humidity_int32(u32 v_uncomp_humidity_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR INTEGER OUTPUT PRESSURE*/
/**************************************************************/
/*!
* @brief This function is used to convert the uncompensated
* pressure data to compensated pressure data data using
* compensation formula(integer version)
*
* @note Returns the value in Pascal(Pa)
* Output value of "96386" equals 96386 Pa = 963.86 hPa = 963.86 millibar
*/
s32 bme680_compensate_pressure_int32(u32 v_uncomp_pressure_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR INTEGER TEMPERATURE-RESISTANCE*/
/**************************************************************/
/*!
* @brief This function is used to convert temperature to resistance
* using the integer compensation formula
*/
u8 bme680_convert_temperature_to_resistance_int32(u16 heater_temp_u16,
s16 ambient_temp_s16, struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION TO CONVERT INT32_H to U16_H BIT OPUTPUT*/
/**************************************************************/
/*!
* @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
*/
u16 bme680_compensate_H_int32_sixteen_bit_output(u32 v_uncomp_humidity_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION TO CONVERT INT32_T to S16_T BIT OPUTPUT*/
/**************************************************************/
/*!
* @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
*/
s16 bme680_compensate_T_int32_sixteen_bit_output(u32 v_uncomp_temperature_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION TO CONVERT INT32_P to U24_P BIT OPUTPUT*/
/**************************************************************/
/*!
* @brief Reads actual pressure from uncompensated pressure in Pa.
*
* @note Output value of "12337434" represents
* 12337434 / 128 = 96386.2 Pa = 963.862 hPa
*/
u32 bme680_compensate_P_int32_twentyfour_bit_output(u32 v_uncomp_pressure_u32,
struct bme680_t *bme680);
#else
/**************************************************************/
/**\name FUNCTION FOR FLOAT OUTPUT GAS */
/**************************************************************/
/*!
* @brief This function is used to convert uncompensated gas data to
* compensated gas data using compensation formula
*/
double bme680_compensate_gas_double(u16 gas_adc_u16, u8 gas_range_u8,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR FLOAT OUTPUT HUMIDITY */
/**************************************************************/
/*!
* @brief This function is used to convert the uncompensated
* humidity data to compensated humidity data data using
* compensation formula
*
* @note returns the value in relative humidity (%rH)
* @note Output value of "42.12" equals 42.12 %rH
*/
double bme680_compensate_humidity_double(u16 uncom_humidity_u16,
double comp_temperature, struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR FLOAT OUTPUT PRESSURE*/
/**************************************************************/
/*!
* @brief This function is used to convert the uncompensated
* pressure data to compensated data using compensation formula
*
* @note Returns pressure in Pa as double.
* @note Output value of "96386.2" equals 96386.2 Pa = 963.862 hPa.
*/
double bme680_compensate_pressure_double(u32 uncom_pressure_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR FLOAT OUTPUT TEMPERATURE*/
/**************************************************************/
/*!
* @brief This function used to convert temperature data
* to uncompensated temperature data using compensation formula
*
* @note returns the value in Degree centigrade
* @note Output value of "51.23" equals 51.23 DegC.
*/
double bme680_compensate_temperature_double(u32 uncom_temperature_u32,
struct bme680_t *bme680);
/**************************************************************/
/**\name FUNCTION FOR TEMPERATURE TO RESISTANCE */
/**************************************************************/
/*!
* @brief This function is used to convert temperature to resistance
* using the compensation formula
*/
double bme680_convert_temperature_to_resistance_double(u16 heater_temp_u16,
s16 ambient_temp_s16, struct bme680_t *bme680);
#endif
/* bme680_calculations.h */
#ifdef __cplusplus
}
#endif
#endif

529
bme680_defs.h Normal file
View File

@ -0,0 +1,529 @@
/**
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* 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 bme680_defs.h
* @date 5 Jul 2017
* @version 3.5.1
* @brief
*
*/
/*! @file bme680_defs.h
@brief Sensor driver for BME680 sensor */
/*!
* @defgroup BME680 SENSOR API
* @brief
* @{*/
#ifndef BME680_DEFS_H_
#define BME680_DEFS_H_
/********************************************************/
/* header includes */
#ifdef __KERNEL__
#include <linux/types.h>
#else
#include <stdint.h>
#endif
#ifdef __KERNEL__
#if (LONG_MAX) > 0x7fffffff
#define __have_long64 1
#elif (LONG_MAX) == 0x7fffffff
#define __have_long32 1
#endif
#if !defined(UINT8_C)
#define INT8_C(x) x
#if (INT_MAX) > 0x7f
#define UINT8_C(x) x
#else
#define UINT8_C(x) x##U
#endif
#endif
#if !defined(UINT16_C)
#define INT16_C(x) x
#if (INT_MAX) > 0x7fff
#define UINT16_C(x) x
#else
#define UINT16_C(x) x##U
#endif
#endif
#if !defined(INT32_C) && !defined(UINT32_C)
#if __have_long32
#define INT32_C(x) x##L
#define UINT32_C(x) x##UL
#else
#define INT32_C(x) x
#define UINT32_C(x) x##U
#endif
#endif
#if !defined(INT64_C) && !defined(UINT64_C)
#if __have_long64
#define INT64_C(x) x##L
#define UINT64_C(x) x##UL
#else
#define INT64_C(x) x##LL
#define UINT64_C(x) x##ULL
#endif
#endif
#endif
/**@}*/
/**\name C standard macros */
#ifndef NULL
#ifdef __cplusplus
#define NULL 0
#else
#define NULL ((void *) 0)
#endif
#endif
/** BME680 General config */
#define BME680_POLL_PERIOD_MS UINT8_C(10)
/** BME680 I2C addresses */
#define BME680_I2C_ADDR_PRIMARY UINT8_C(0x76)
#define BME680_I2C_ADDR_SECONDARY UINT8_C(0x77)
/** BME680 unique chip identifier */
#define BME680_CHIP_ID UINT8_C(0x61)
/** BME680 coefficients related defines */
#define BME680_COEFF_SIZE UINT8_C(0x41)
#define BME680_COEFF_ADDR1_LEN UINT8_C(25)
#define BME680_COEFF_ADDR2_LEN UINT8_C(16)
/** BME680 field_x related defines */
#define BME680_FIELD_LENGTH UINT8_C(15)
#define BME680_FIELD_ADDR_OFFSET UINT8_C(17)
/** Soft reset command */
#define BME680_SOFT_RESET_CMD UINT8_C(0xb6)
/** Error code definitions */
#define BME680_OK INT8_C(0)
/* Errors */
#define BME680_E_NULL_PTR INT8_C(-1)
#define BME680_E_COM_FAIL INT8_C(-2)
#define BME680_E_DEV_NOT_FOUND INT8_C(-3)
#define BME680_E_INVALID_LENGTH INT8_C(-4)
/* Warnings */
#define BME680_W_DEFINE_PWR_MODE INT8_C(1)
#define BME680_W_NO_NEW_DATA INT8_C(2)
/* Info's */
#define BME680_I_MIN_CORRECTION UINT8_C(1)
#define BME680_I_MAX_CORRECTION UINT8_C(2)
/** Register map */
/** Other coefficient's address */
#define BME680_ADDR_RES_HEAT_VAL_ADDR UINT8_C(0x00)
#define BME680_ADDR_RES_HEAT_RANGE_ADDR UINT8_C(0x02)
#define BME680_ADDR_RANGE_SW_ERR_ADDR UINT8_C(0x04)
#define BME680_ADDR_SENS_CONF_START UINT8_C(0x5A)
#define BME680_ADDR_GAS_CONF_START UINT8_C(0x64)
/** Field settings */
#define BME680_FIELD0_ADDR UINT8_C(0x1d)
/** Heater settings */
#define BME680_RES_HEAT0_ADDR UINT8_C(0x5a)
#define BME680_GAS_WAIT0_ADDR UINT8_C(0x64)
/** Sensor configuration registers */
#define BME680_CONF_HEAT_CTRL_ADDR UINT8_C(0x70)
#define BME680_CONF_ODR_RUN_GAS_NBC_ADDR UINT8_C(0x71)
#define BME680_CONF_OS_H_ADDR UINT8_C(0x72)
#define BME680_MEM_PAGE_ADDR UINT8_C(0xf3)
#define BME680_CONF_T_P_MODE_ADDR UINT8_C(0x74)
#define BME680_CONF_ODR_FILT_ADDR UINT8_C(0x75)
/** Coefficient's address */
#define BME680_COEFF_ADDR1 UINT8_C(0x89)
#define BME680_COEFF_ADDR2 UINT8_C(0xe1)
/** Chip identifier */
#define BME680_CHIP_ID_ADDR UINT8_C(0xd0)
/** Soft reset register */
#define BME680_SOFT_RESET_ADDR UINT8_C(0xe0)
/** Heater control settings */
#define BME680_ENABLE_HEATER UINT8_C(0x00)
#define BME680_DISABLE_HEATER UINT8_C(0x08)
/** Gas measurement settings */
#define BME680_DISABLE_GAS_MEAS UINT8_C(0x00)
#define BME680_ENABLE_GAS_MEAS UINT8_C(0x01)
/** Over-sampling settings */
#define BME680_OS_NONE UINT8_C(0)
#define BME680_OS_1X UINT8_C(1)
#define BME680_OS_2X UINT8_C(2)
#define BME680_OS_4X UINT8_C(3)
#define BME680_OS_8X UINT8_C(4)
#define BME680_OS_16X UINT8_C(5)
/** IIR filter settings */
#define BME680_FILTER_SIZE_0 UINT8_C(0)
#define BME680_FILTER_SIZE_1 UINT8_C(1)
#define BME680_FILTER_SIZE_3 UINT8_C(2)
#define BME680_FILTER_SIZE_7 UINT8_C(3)
#define BME680_FILTER_SIZE_15 UINT8_C(4)
#define BME680_FILTER_SIZE_31 UINT8_C(5)
#define BME680_FILTER_SIZE_63 UINT8_C(6)
#define BME680_FILTER_SIZE_127 UINT8_C(7)
/** Power mode settings */
#define BME680_SLEEP_MODE UINT8_C(0)
#define BME680_FORCED_MODE UINT8_C(1)
/** Delay related macro declaration */
#define BME680_RESET_PERIOD UINT32_C(10)
/** SPI memory page settings */
#define BME680_MEM_PAGE0 UINT8_C(0x10)
#define BME680_MEM_PAGE1 UINT8_C(0x00)
/** Ambient humidity shift value for compensation */
#define BME680_HUM_REG_SHIFT_VAL UINT8_C(4)
/** Run gas enable and disable settings */
#define BME680_RUN_GAS_DISABLE UINT8_C(0)
#define BME680_RUN_GAS_ENABLE UINT8_C(1)
/** Buffer length macro declaration */
#define BME680_TMP_BUFFER_LENGTH UINT8_C(40)
#define BME680_REG_BUFFER_LENGTH UINT8_C(6)
#define BME680_FIELD_DATA_LENGTH UINT8_C(3)
#define BME680_GAS_REG_BUF_LENGTH UINT8_C(20)
#define BME680_GAS_HEATER_PROF_LEN_MAX UINT8_C(10)
/** Settings selector */
#define BME680_OST_SEL UINT16_C(1)
#define BME680_OSP_SEL UINT16_C(2)
#define BME680_OSH_SEL UINT16_C(4)
#define BME680_GAS_MEAS_SEL UINT16_C(8)
#define BME680_FILTER_SEL UINT16_C(16)
#define BME680_HCNTRL_SEL UINT16_C(32)
#define BME680_RUN_GAS_SEL UINT16_C(64)
#define BME680_NBCONV_SEL UINT16_C(128)
#define BME680_GAS_SENSOR_SEL UINT16_C(BME680_GAS_MEAS_SEL | BME680_RUN_GAS_SEL | BME680_NBCONV_SEL)
/** Number of conversion settings*/
#define BME680_NBCONV_MIN UINT8_C(0)
#define BME680_NBCONV_MAX UINT8_C(10)
/** Mask definitions */
#define BME680_GAS_MEAS_MSK UINT8_C(0x30)
#define BME680_NBCONV_MSK UINT8_C(0X0F)
#define BME680_FILTER_MSK UINT8_C(0X1C)
#define BME680_OST_MSK UINT8_C(0XE0)
#define BME680_OSP_MSK UINT8_C(0X1C)
#define BME680_OSH_MSK UINT8_C(0X07)
#define BME680_HCTRL_MSK UINT8_C(0x08)
#define BME680_RUN_GAS_MSK UINT8_C(0x10)
#define BME680_MODE_MSK UINT8_C(0x03)
#define BME680_RHRANGE_MSK UINT8_C(0x30)
#define BME680_RSERROR_MSK UINT8_C(0xf0)
#define BME680_NEW_DATA_MSK UINT8_C(0x80)
#define BME680_GAS_INDEX_MSK UINT8_C(0x0f)
#define BME680_GAS_RANGE_MSK UINT8_C(0x0f)
#define BME680_GASM_VALID_MSK UINT8_C(0x20)
#define BME680_HEAT_STAB_MSK UINT8_C(0x10)
#define BME680_MEM_PAGE_MSK UINT8_C(0x10)
#define BME680_SPI_RD_MSK UINT8_C(0x80)
#define BME680_SPI_WR_MSK UINT8_C(0x7f)
#define BME680_BIT_H1_DATA_MSK UINT8_C(0x0F)
/** Bit position definitions for sensor settings */
#define BME680_GAS_MEAS_POS UINT8_C(4)
#define BME680_FILTER_POS UINT8_C(2)
#define BME680_OST_POS UINT8_C(5)
#define BME680_OSP_POS UINT8_C(2)
#define BME680_RUN_GAS_POS UINT8_C(4)
/** Array Index to Field data mapping for Calibration Data*/
#define BME680_T2_LSB_REG (1)
#define BME680_T2_MSB_REG (2)
#define BME680_T3_REG (3)
#define BME680_P1_LSB_REG (5)
#define BME680_P1_MSB_REG (6)
#define BME680_P2_LSB_REG (7)
#define BME680_P2_MSB_REG (8)
#define BME680_P3_REG (9)
#define BME680_P4_LSB_REG (11)
#define BME680_P4_MSB_REG (12)
#define BME680_P5_LSB_REG (13)
#define BME680_P5_MSB_REG (14)
#define BME680_P7_REG (15)
#define BME680_P6_REG (16)
#define BME680_P8_LSB_REG (19)
#define BME680_P8_MSB_REG (20)
#define BME680_P9_LSB_REG (21)
#define BME680_P9_MSB_REG (22)
#define BME680_P10_REG (23)
#define BME680_H2_MSB_REG (25)
#define BME680_H2_LSB_REG (26)
#define BME680_H1_LSB_REG (26)
#define BME680_H1_MSB_REG (27)
#define BME680_H3_REG (28)
#define BME680_H4_REG (29)
#define BME680_H5_REG (30)
#define BME680_H6_REG (31)
#define BME680_H7_REG (32)
#define BME680_T1_LSB_REG (33)
#define BME680_T1_MSB_REG (34)
#define BME680_GH2_LSB_REG (35)
#define BME680_GH2_MSB_REG (36)
#define BME680_GH1_REG (37)
#define BME680_GH3_REG (38)
/** BME680 register buffer index settings*/
#define BME680_REG_FILTER_INDEX UINT8_C(5)
#define BME680_REG_TEMP_INDEX UINT8_C(4)
#define BME680_REG_PRES_INDEX UINT8_C(4)
#define BME680_REG_HUM_INDEX UINT8_C(2)
#define BME680_REG_NBCONV_INDEX UINT8_C(1)
#define BME680_REG_RUN_GAS_INDEX UINT8_C(1)
#define BME680_REG_HCTRL_INDEX UINT8_C(0)
/** Macro to combine two 8 bit data's to form a 16 bit data */
#define BME680_CONCAT_BYTES(msb, lsb) (((uint16_t)msb << 8) | (uint16_t)lsb)
/** Macro to SET and GET BITS of a register */
#define BME680_SET_BITS(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
((data << bitname##_POS) & bitname##_MSK))
#define BME680_GET_BITS(reg_data, bitname) ((reg_data & (bitname##_MSK)) >> \
(bitname##_POS))
/** Macro variant to handle the bitname position if it is zero */
#define BME680_SET_BITS_POS_0(reg_data, bitname, data) \
((reg_data & ~(bitname##_MSK)) | \
(data & bitname##_MSK))
#define BME680_GET_BITS_POS_0(reg_data, bitname) (reg_data & (bitname##_MSK))
/** Type definitions */
/*
* Generic communication function pointer
* @param[in] dev_id: Place holder to store the id of the device structure
* Can be used to store the index of the Chip select or
* I2C address of the device.
* @param[in] reg_addr: Used to select the register the where data needs to
* be read from or written to.
* @param[in/out] reg_data: Data array to read/write
* @param[in] len: Length of the data array
*/
typedef int8_t (*bme680_com_fptr_t)(uint8_t dev_id, uint8_t reg_addr, uint8_t *data, uint16_t len);
/*
* Delay function pointer
* @param[in] period: Time period in milliseconds
*/
typedef void (*bme680_delay_fptr_t)(uint32_t period);
/*!
* @brief Interface selection Enumerations
*/
enum bme680_intf {
/*! SPI interface */
BME680_SPI_INTF,
/*! I2C interface */
BME680_I2C_INTF
};
/* structure definitions */
/*!
* @brief Sensor field data structure
*/
struct bme680_field_data {
/*! Contains new_data, gasm_valid & heat_stab */
uint8_t status;
/*! The index of the heater profile used */
uint8_t gas_index;
/*! Measurement index to track order */
uint8_t meas_index;
/*! Temperature in degree celsius x100 */
int16_t temperature;
/*! Pressure in Pascal */
uint32_t pressure;
/*! Humidity in % relative humidity x1000 */
uint32_t humidity;
/*! Gas resistance in Ohms */
uint32_t gas_resistance;
};
/*!
* @brief Structure to hold the Calibration data
*/
struct bme680_calib_data {
/*! Variable to store calibrated humidity data */
uint16_t par_h1;
/*! Variable to store calibrated humidity data */
uint16_t par_h2;
/*! Variable to store calibrated humidity data */
int8_t par_h3;
/*! Variable to store calibrated humidity data */
int8_t par_h4;
/*! Variable to store calibrated humidity data */
int8_t par_h5;
/*! Variable to store calibrated humidity data */
uint8_t par_h6;
/*! Variable to store calibrated humidity data */
int8_t par_h7;
/*! Variable to store calibrated gas data */
int8_t par_gh1;
/*! Variable to store calibrated gas data */
int16_t par_gh2;
/*! Variable to store calibrated gas data */
int8_t par_gh3;
/*! Variable to store calibrated temperature data */
uint16_t par_t1;
/*! Variable to store calibrated temperature data */
int16_t par_t2;
/*! Variable to store calibrated temperature data */
int8_t par_t3;
/*! Variable to store calibrated pressure data */
uint16_t par_p1;
/*! Variable to store calibrated pressure data */
int16_t par_p2;
/*! Variable to store calibrated pressure data */
int8_t par_p3;
/*! Variable to store calibrated pressure data */
int16_t par_p4;
/*! Variable to store calibrated pressure data */
int16_t par_p5;
/*! Variable to store calibrated pressure data */
int8_t par_p6;
/*! Variable to store calibrated pressure data */
int8_t par_p7;
/*! Variable to store calibrated pressure data */
int16_t par_p8;
/*! Variable to store calibrated pressure data */
int16_t par_p9;
/*! Variable to store calibrated pressure data */
uint8_t par_p10;
/*! Variable to store t_fine size */
int32_t t_fine;
/*! Variable to store heater resistance range */
uint8_t res_heat_range;
/*! Variable to store heater resistance value */
int8_t res_heat_val;
/*! Variable to store error range */
int8_t range_sw_err;
};
/*!
* @brief BME680 sensor settings structure which comprises of ODR,
* over-sampling and filter settings.
*/
struct bme680_tph_sett {
/*! Humidity oversampling */
uint8_t os_hum;
/*! Temperature oversampling */
uint8_t os_temp;
/*! Pressure oversampling */
uint8_t os_pres;
/*! Filter coefficient */
uint8_t filter;
};
/*!
* @brief BME680 gas sensor which comprises of gas settings
* and status parameters
*/
struct bme680_gas_sett {
/*! Variable to store nb conversion */
uint8_t nb_conv;
/*! Variable to store heater control */
uint8_t heatr_ctrl;
/*! Run gas enable value */
uint8_t run_gas;
/*! Pointer to store heater temperature */
uint16_t heatr_temp;
/*! Pointer to store duration profile */
uint16_t heatr_dur;
};
/*!
* @brief BME680 device structure
*/
struct bme680_dev {
/*! Chip Id */
uint8_t chip_id;
/*! Device Id */
uint8_t dev_id;
/*! SPI/I2C interface */
enum bme680_intf intf;
/*! Memory page used */
uint8_t mem_page;
/*! Ambient temperature in Degree C*/
int8_t amb_temp;
/*! Sensor calibration data */
struct bme680_calib_data calib;
/*! Sensor settings */
struct bme680_tph_sett tph_sett;
/*! Gas Sensor settings */
struct bme680_gas_sett gas_sett;
/*! Sensor power modes */
uint8_t power_mode;
/*! New sensor fields */
uint8_t new_fields;
/*! Store the info messages */
uint8_t info_msg;
/*! Burst read structure */
bme680_com_fptr_t read;
/*! Burst write structure */
bme680_com_fptr_t write;
/*! Delay in ms */
bme680_delay_fptr_t delay_ms;
/*! Communication function result */
int8_t com_rslt;
};
#endif /* BME680_DEFS_H_ */
/** @}*/
/** @}*/

View File

@ -1,313 +0,0 @@
/**
*
****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* File : bme680_internal.h
*
* Date: 5 May 2017
*
* Revision : 2.2.0 $
*
* Usage: Sensor Driver for BME680 sensor
*
****************************************************************************
*
* \section Disclaimer
*
* Common:
* Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser.
*
* The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims.
*
* The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents.
*
* Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering
* samples.
*
* Special:
* This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following
* terms and conditions:
*
* The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the
* proper experience or training.
*
* This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose.
*
* Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment
* of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law.
*
* The Information provided is believed to be accurate and reliable.
* Bosch Sensortec 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 Bosch. Specifications mentioned in the Information are
* subject to change without notice.
**************************************************************************/
/*! \file bme680_internal.h
\brief BME680 Sensor Driver internal support Header File */
#ifndef _BME680_INTERNAL_H
#define _BME680_INTERNAL_H
/***************************************************************************
Header files
****************************************************************************/
/***************************************************************************
Macros Enums, Constants only sensor Specific constants
****************************************************************************/
/* bme680_internal.h */
/* Pre-processor switch for separating between I2C and SPI addresses */
#define BME680_CALIB_SPI_ADDR_1 (0x09)
#define BME680_CALIB_SPI_ADDR_2 (0x61)
#define BME680_PAGE0_SPI_ID_REG (0x50)
#define BME680_CALIB_I2C_ADDR_1 (0x89)
#define BME680_CALIB_I2C_ADDR_2 (0xE1)
#define BME680_PAGE0_I2C_ID_REG (0xD0)
#define BME680_OVERSAMP_TEMP_SHIFT (0x03)
#define BME680_GAS_WAIT_STEP_SIZE (477)
#define BME680_SENS_CONF_LEN (0x06)
#define BME680_SENS_HEATR_CONF_LEN (0x15)
#define BME680_TRUE (1)
#define BME680_FALSE (0)
#define BME680_CALIB_PARAM_SIZE ((u8)41)
#define BME680_PAGE0_INTERFACE_SPI ((u8)0)
#define BME680_PAGE1_INTERFACE_SPI ((u8)1)
#define BME680_CALIB_DATA_LENGTH_GAS (25)
#define BME680_CALIB_DATA_LENGTH (16)
#define BME680_BIT_MASK_H1_DATA (0x0F)
#define BME680_FIELD_ZERO (0)
#define BME680_FIELD_ONE (1)
#define BME680_FIELD_TWO (2)
#define BME680_FIELD_ONE_OFFSET (17)
#define BME680_FIELD_TWO_OFFSET (34)
#define BME680_FIELD_SIZE (17)
/* Sensor Specific constants */
#define BME680_GAS_BIT_MASK (0x00C0)
#define BME680_GAS_WAIT_MAX_TIMER_VALUE (0x3F)
#define BME680_GAS_WAIT_MIN_TIMER_VALUE (0x00)
#define BME680_PROFILE_MAX (10)
#define BME680_ADDR_SPI_MEM_PAGE (0x73)
#define BME680_ADDR_OP_MODE (0x74)
#define BME680_ADDR_SENS_CONF_START (0x5A)
#define BME680_ADDR_FIELD_0 (0x1D)
#define BME680_ADDR_SENSOR_CONFIG (0x70)
#define BME680_ADDR_RES_HEAT_VAL (0x00)
#define BME680_ADDR_RES_HEAT_RANGE (0x02)
#define BME680_ADDR_RANGE_SWITCHING_ERR (0x04)
/* Section 3.2: Sub-register addresses, masks and bit shifts */
#define BME680_MASK_OP_MODE (0xFC)
#define BME680_MASK_HEATR_CTRL (0xF7)
#define BME680_MASK_ODR_3 (0x7F)
#define BME680_MASK_ODR_2_0 (0x1F)
#define BME680_MASK_RUN_GAS (0xEF)
#define BME680_MASK_PROF_INDEX (0xF0)
#define BME680_MASK_OSRS_HUM (0xF8)
#define BME680_MASK_OSRS_PRES (0xE3)
#define BME680_MASK_OSRS_TEMP (0x1F)
#define BME680_MASK_FILTER (0xE3)
#define BME680_MASK_NEW_DATA (0x7F)
#define BME680_MASK_GAS_MEAS_STAT (0xBF)
#define BME680_MASK_TPHG_MEAS_STAT (0xDF)
#define BME680_MASK_GAS_MEAS_INDEX (0xF0)
#define BME680_MASK_GAS_RANGE (0xF0)
#define BME680_MASK_GAS_VALID (0xDF)
#define BME680_MASK_HEATR_STAB (0xEF)
#define BME680_MASK_SPI_3W_INT (0xBF)
#define BME680_MASK_SPI_3W_EN (0xFE)
#define BME680_MASK_MEM_PAGE (0xEF)
#define BME680_MASK_RES_HEAT_RANGE (0xCF)
#define BME680_MASK_RANGE_ERR (0x0F)
/* Section : Register settings/values */
/* Lengths to support burst reads/writes */
#define BME680_SINGLE_FIELD_LENGTH (15)
#define BME680_LEN_ALL_FIELD_SIZE (49)
#define BME680_ADDR_FIELD_0_STATUS (0x1D)
#define BME680_ADDR_FIELD_1_STATUS (0x2E)
#define BME680_ADDR_FIELD_2_STATUS (0x3F)
#define BME680_ADDR_FIELD_0_TEMP1 (0x22)
#define BME680_ADDR_FIELD_0_TEMP2 (0x27)
#define BME680_ADDR_FIELD_1_TEMP1 (0x33)
#define BME680_ADDR_FIELD_1_TEMP2 (0x38)
#define BME680_ADDR_FIELD_2_TEMP1 (0x44)
#define BME680_ADDR_FIELD_2_TEMP2 (0x49)
#define BME680_ADDR_FIELD_0_PRESS (0x1F)
#define BME680_ADDR_FIELD_1_PRESS (0x30)
#define BME680_ADDR_FIELD_2_PRESS (0x41)
#define BME680_ADDR_FIELD_0_HUM (0x25)
#define BME680_ADDR_FIELD_1_HUM (0x36)
#define BME680_ADDR_FIELD_2_HUM (0x47)
#define BME680_ADDR_FIELD_0_GAS (0x2A)
#define BME680_ADDR_FIELD_1_GAS (0x3B)
#define BME680_ADDR_FIELD_2_GAS (0x4C)
/*******************************************************/
/* Array Index to Field data mapping*/
/********************************************************/
/* For Calibration Data*/
#define DIG_T2_LSB_REG (1)
#define DIG_T2_MSB_REG (2)
#define DIG_T3_REG (3)
#define DIG_P1_LSB_REG (5)
#define DIG_P1_MSB_REG (6)
#define DIG_P2_LSB_REG (7)
#define DIG_P2_MSB_REG (8)
#define DIG_P3_REG (9)
#define DIG_P4_LSB_REG (11)
#define DIG_P4_MSB_REG (12)
#define DIG_P5_LSB_REG (13)
#define DIG_P5_MSB_REG (14)
#define DIG_P7_REG (15)
#define DIG_P6_REG (16)
#define DIG_P8_LSB_REG (19)
#define DIG_P8_MSB_REG (20)
#define DIG_P9_LSB_REG (21)
#define DIG_P9_MSB_REG (22)
#define DIG_P10_REG (23)
#define DIG_H2_MSB_REG (25)
#define DIG_H2_LSB_REG (26)
#define DIG_H1_LSB_REG (26)
#define DIG_H1_MSB_REG (27)
#define DIG_H3_REG (28)
#define DIG_H4_REG (29)
#define DIG_H5_REG (30)
#define DIG_H6_REG (31)
#define DIG_H7_REG (32)
#define DIG_T1_LSB_REG (33)
#define DIG_T1_MSB_REG (34)
#define DIG_GH2_LSB_REG (35)
#define DIG_GH2_MSB_REG (36)
#define DIG_GH1_REG (37)
#define DIG_GH3_REG (38)
/* For TPHG data */
#define FIELD_0_MEAS_STATUS_0 (0)
#define FIELD_0_MEAS_STATUS_1 (1)
#define FIELD_0_GAS_RL_LSB (14)
/*!
@brief data frame includes temperature, pressure, humidity
and gas data*/
#define BME680_DATA_FRAME_PRESSURE_MSB_DATA ((u8)2)
#define BME680_DATA_FRAME_PRESSURE_LSB_DATA ((u8)3)
#define BME680_DATA_FRAME_PRESSURE_XLSB_DATA ((u8)4)
#define BME680_DATA_FRAME_TEMPERATURE1_MSB_DATA ((u8)5)
#define BME680_DATA_FRAME_TEMPERATURE1_LSB_DATA ((u8)6)
#define BME680_DATA_FRAME_TEMPERATURE1_XLSB_DATA ((u8)7)
#define BME680_DATA_FRAME_HUMIDITY_MSB_DATA ((u8)8)
#define BME680_DATA_FRAME_HUMIDITY_LSB_DATA ((u8)9)
#define BME680_DATA_FRAME_GAS_MSB_DATA ((u8)13)
#define BME680_DATA_FRAME_GAS_LSB_DATA ((u8)14)
/* Positions to support indexing in an array */
#define BME680_INDEX_CTRL_GAS_0 (0)
#define BME680_INDEX_CTRL_GAS_1 (1)
#define BME680_INDEX_CTRL_HUM (2)
#define BME680_INDEX_CTRL_MEAS (4)
#define BME680_INDEX_CONFIG (5)
/* Constants to store the bit shift parameters */
#define BME680_SHIFT_OP_MODE (0)
#define BME680_SHIFT_HEATR_CTRL (3)
#define BME680_SHIFT_ODR_3 (4)
#define BME680_SHIFT_ODR_2_0 (5)
#define BME680_SHIFT_RUN_GAS (4)
#define BME680_SHIFT_PROF_INDEX (0)
#define BME680_SHIFT_OSRS_HUM (0)
#define BME680_SHIFT_OSRS_TEMP (5)
#define BME680_SHIFT_OSRS_PRES (2)
#define BME680_SHIFT_FILTER (2)
#define BME680_SHIFT_NEW_DATA (7)
#define BME680_SHIFT_GAS_MEAS_STAT (6)
#define BME680_SHIFT_TPHG_MEAS_STAT (5)
#define BME680_SHIFT_GAS_MEAS_INDEX (0)
#define BME680_SHIFT_GAS_RANGE (0)
#define BME680_SHIFT_GAS_VALID (5)
#define BME680_SHIFT_HEATR_STAB (4)
#define BME680_SHIFT_SPI_3W_INT (6)
#define BME680_SHIFT_SPI_3W_EN (0)
#define BME680_SHIFT_SPI_MEM_PAGE (4)
#define BME680_SHIFT_RES_HEAT_RANGE (4)
#define BME680_SHIFT_RANGE_ERR (4)
#define BME680_ONE (1)
#define BME680_TWO (2)
#define BME680_THREE (3)
#define BME680_GEN_READ_DATA_LENGTH ((u8)1)
#define BME680_GEN_WRITE_DATA_LENGTH ((u8)1)
/* bme680_internal.h */
/***************************************************************************
Module globals, typedefs
****************************************************************************/
/***************************************************************************
Function definitions
****************************************************************************/
#endif

42
changelog.md Normal file
View File

@ -0,0 +1,42 @@
# Change Log
All notable changes to the BME680 Sensor API will be documented in this file.
## v3.5.1, 5 Jul 2017
### Changed
- Fixed bug with overwriting of the result with communication results
- Added member in the dev structure to store communication results
- Updated set profile duration API to not return a result.
- Added new API to get the duration for the existing profile
- Fixed bug with setting gas configuration. Reduced to writing only relevant bytes
- Updated readme
- Updated documentation for the type definitions
- Removed mode check for get sensor data and setting and getting profile dur
## v3.5.0, 28 Jun 2017
### Changed
- Fixed bug with getting and setting mem pages
- Changed initialization sequence to be more robust
- Added additional tries while reading data in case of inadequate delay
## v3.4.0, 8 Jun 2017
### Changed
- Modified the bme680_get_sensor_data API. User has to now pass the struct that stores the data rather than retrieving from the bme680_dev structure.
- Fixed possible bugs
## v3.3.0, 24 May 2017
### Changed
- Name changes in the BME680 device structure.
- Removed sequential and parallel modes.
- Removed ODR related sensor settings
- Modified get sensor settings API with user selection.
- Removed sort sensor data and swap fields API which are not required.
### Added
- BME680 set profile duration API.
## v3.2.1, 17 May 2017
### Added
- Took the reference as base version 3.2.1 of BME680 sensor and added.

View File

@ -1,340 +0,0 @@
/**
*
****************************************************************************
* Copyright (C) 2017 - 2018 Bosch Sensortec GmbH
*
* File : sensor_api_common_types.h
*
* Date: 5 May 2017
*
* Revision : 2.2.0 $
*
* Usage: Sensor Driver for BME680 sensor
*
****************************************************************************
*
* \section Disclaimer
*
* Common:
* Bosch Sensortec products are developed for the consumer goods industry.
* They may only be used within the parameters of the respective valid
* product data sheet. Bosch Sensortec products are provided with the
* express understanding that there is no warranty of fitness for a
* particular purpose.They are not fit for use in life-sustaining,
* safety or security sensitive systems or any system or device
* that may lead to bodily harm or property damage if the system
* or device malfunctions. In addition,Bosch Sensortec products are
* not fit for use in products which interact with motor vehicle systems.
* The resale and or use of products are at the purchasers own risk and
* his own responsibility. The examination of fitness for the intended use
* is the sole responsibility of the Purchaser.
*
* The purchaser shall indemnify Bosch Sensortec from all third party
* claims, including any claims for incidental, or consequential damages,
* arising from any product use not covered by the parameters of
* the respective valid product data sheet or not approved by
* Bosch Sensortec and reimburse Bosch Sensortec for all costs in
* connection with such claims.
*
* The purchaser must monitor the market for the purchased products,
* particularly with regard to product safety and inform Bosch Sensortec
* without delay of all security relevant incidents.
*
* Engineering Samples are marked with an asterisk (*) or (e).
* Samples may vary from the valid technical specifications of the product
* series. They are therefore not intended or fit for resale to third
* parties or for use in end products. Their sole purpose is internal
* client testing. The testing of an engineering sample may in no way
* replace the testing of a product series. Bosch Sensortec assumes
* no liability for the use of engineering samples.
* By accepting the engineering samples, the Purchaser agrees to indemnify
* Bosch Sensortec from all claims arising from the use of engineering
* samples.
*
* Special:
* This software module (hereinafter called "Software") and any information
* on application-sheets (hereinafter called "Information") is provided
* free of charge for the sole purpose to support your application work.
* The Software and Information is subject to the following
* terms and conditions:
*
* The Software is specifically designed for the exclusive use for
* Bosch Sensortec products by personnel who have special experience
* and training. Do not use this Software if you do not have the
* proper experience or training.
*
* This Software package is provided `` as is `` and without any expressed
* or implied warranties,including without limitation, the implied warranties
* of merchantability and fitness for a particular purpose.
*
* Bosch Sensortec and their representatives and agents deny any liability
* for the functional impairment
* of this Software in terms of fitness, performance and safety.
* Bosch Sensortec and their representatives and agents shall not be liable
* for any direct or indirect damages or injury, except as
* otherwise stipulated in mandatory applicable law.
*
* The Information provided is believed to be accurate and reliable.
* Bosch Sensortec 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 Bosch. Specifications mentioned in the Information are
* subject to change without notice.
**************************************************************************/
/*! \file sensor_api_common_types.h
\brief sensor API common data types Header File */
#ifndef __SENSOR_API_COMMON_TYPES_H__
#define __SENSOR_API_COMMON_TYPES_H__
/***************************************************************************/
/***************************************************************************
Macros, Enum, Constant
****************************************************************************/
/* sensor_api_common_types.h */
/*!
* @brief The following definition is used for defining 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 <linux/types.h>
#include <linux/math64.h>
/* 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 */
typedef signed long long int s64;
#else /* ! __KERNEL__ */
/**********************************************************
* These definitions are used to define the C
* standard version data types
***********************************************************/
# if defined(__STDC_VERSION__)
/************************************************
* compiler is C11 C standard
************************************************/
#if (__STDC_VERSION__ == 201112L)
/************************************************/
#include <stdint.h>
/************************************************/
/*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 */
/*typedef signed long long int s64;*/
/************************************************
* 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 <stdint.h>
/************************************************/
/*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 */
typedef signed long long int s64;
/************************************************
* 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 <limits.h>
/*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 */
#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 */
#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 If 64 bit integers are supported on your platform, \
please set s64 manually.
#endif
/*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 */
/* 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 */
/* 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 */
#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 <limits.h>
/*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 */
#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 */
#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 If 64 bit integers are supported on your platform, \
please set s64 manually.
#endif
/*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 */
/*! @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
- int and long int is same for u32*/
typedef unsigned long long int u64;/**< used for unsigned 64bit */
/* 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 */
#else
#warning The data types defined above which not supported \
define the data types manually
#endif
#endif
#endif
/* sensor_api_common_types.h */
/***************************************************************************
Module globals, typedefs
****************************************************************************/
/***************************************************************************
Function definition
****************************************************************************/
#endif