BME680 driver release
This commit is contained in:
		
							
								
								
									
										
											BIN
										
									
								
								BME680_SensorAPI_Example_Guide.pdf
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								BME680_SensorAPI_Example_Guide.pdf
									
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										171
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										171
									
								
								README.md
									
									
									
									
									
								
							@@ -1,2 +1,169 @@
 | 
				
			|||||||
# BME680_driver
 | 
					CONTENTS OF THIS FILE
 | 
				
			||||||
BME680 sensor driver / API including example guide
 | 
					======================
 | 
				
			||||||
 | 
						* Introduction
 | 
				
			||||||
 | 
						* Version
 | 
				
			||||||
 | 
						* Integration details
 | 
				
			||||||
 | 
						* Driver files information
 | 
				
			||||||
 | 
						* Supported sensor interface
 | 
				
			||||||
 | 
						* Copy right
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					INTRODUCTION
 | 
				
			||||||
 | 
					=============
 | 
				
			||||||
 | 
						- 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
 | 
				
			||||||
 | 
							* BME680_SensorAPI_Optimization_Example_Guide_External.pdf		
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					VERSION
 | 
				
			||||||
 | 
					========
 | 
				
			||||||
 | 
						- Version of bme680 sensor driver is:
 | 
				
			||||||
 | 
							* bme680.c				- 2.0.0
 | 
				
			||||||
 | 
							* bme680.h				- 2.0.0
 | 
				
			||||||
 | 
							* bme680_calculations.c			- 2.0.0		
 | 
				
			||||||
 | 
							* bme680_calculations.h			- 2.0.0
 | 
				
			||||||
 | 
							* bme680_internal.h			- 2.0.0
 | 
				
			||||||
 | 
							* sensor_api_common_types.h		- 2.0.0
 | 
				
			||||||
 | 
							* BME680_SensorAPI_Example_Guide.pdf	- 2.0.0
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					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.
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						- User has to refer bme680.h to refer the API calls for the integration.
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
						- The BME680_SensorAPI_Example_Guide.pdf contains examples for API use cases.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					DRIVER FILES INFORMATION
 | 
				
			||||||
 | 
					===========================
 | 
				
			||||||
 | 
						bme680.h
 | 
				
			||||||
 | 
						---------
 | 
				
			||||||
 | 
							* This header file has the constant definitions, user data types and supported sensor driver calls declarations which is required by the user.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						bme680.c
 | 
				
			||||||
 | 
						---------
 | 
				
			||||||
 | 
							* 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
 | 
				
			||||||
 | 
					===========================
 | 
				
			||||||
 | 
						- This BME680 sensor driver supports SPI and I2C interfaces
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
					Simple Integration Example
 | 
				
			||||||
 | 
					===========================
 | 
				
			||||||
 | 
						- A simple example for BME680 is given below. 
 | 
				
			||||||
 | 
						- Example meant for Single BME680 sensor in Force Mode with Temperature 
 | 
				
			||||||
 | 
							Pressure, Humidity and Gas Enabled
 | 
				
			||||||
 | 
						- For further examples and details refer BME680_SensorAPI_Example_Guide.pdf 
 | 
				
			||||||
 | 
						- Please refer bme680.h to refer the API calls for the integration.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* include bme680 main header */
 | 
				
			||||||
 | 
						#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<6F>s compensated data structure instance */
 | 
				
			||||||
 | 
						struct bme680_comp_field_data compensate_data_sensor[BME680_MAX_NO_OF_SENSOR][3];
 | 
				
			||||||
 | 
						/* BME680 sensor<6F>s uncompensated data structure instance */
 | 
				
			||||||
 | 
						struct bme680_uncomp_field_data uncompensated_data_of_sensor[BME680_MAX_NO_OF_SENSOR][3];
 | 
				
			||||||
 | 
						/* BME680 sensor<6F>s configuration structure instance */
 | 
				
			||||||
 | 
						struct bme680_sens_conf set_conf_sensor[BME680_MAX_NO_OF_SENSOR];
 | 
				
			||||||
 | 
						/* BME680 sensor<6F>s heater configuration structure instance */
 | 
				
			||||||
 | 
						struct bme680_heater_conf set_heatr_conf_sensor[BME680_MAX_NO_OF_SENSOR];
 | 
				
			||||||
 | 
						
 | 
				
			||||||
 | 
						void main(void)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							unsigned int i = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
							enum bme680_return_type com_rslt = BME680_COMM_RES_ERROR;
 | 
				
			||||||
 | 
							
 | 
				
			||||||
 | 
							/* Do BME680 sensor structure instance initialization*/
 | 
				
			||||||
 | 
							/* Sensor_0 interface over SPI with native chip select line */
 | 
				
			||||||
 | 
							/* USER defined SPI bus read function */
 | 
				
			||||||
 | 
							bme680_sensor_no[0].bme680_bus_read = BME680_SPI_bus_read_user;
 | 
				
			||||||
 | 
							/* USER defined SPI bus write function */
 | 
				
			||||||
 | 
							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 */
 | 
				
			||||||
 | 
							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);
 | 
				
			||||||
 | 
										}
 | 
				
			||||||
 | 
									}
 | 
				
			||||||
 | 
								}
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
							
								
								
									
										643
									
								
								bme680.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										643
									
								
								bme680.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,643 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					* Copyright (C) 2015 Bosch Sensortec GmbH
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* File : bme680.h
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Date : 2016/06/10
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Revision: 2.0.0
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Usage: Sensor Driver for BME680 sensor
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Section Disclaimer
 | 
				
			||||||
 | 
					* License:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					* modification, are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer in the
 | 
				
			||||||
 | 
					*   documentation and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Neither the name of the copyright holder nor the names of the
 | 
				
			||||||
 | 
					*   contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					*   this software without specific prior written permission.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 | 
				
			||||||
 | 
					* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 | 
				
			||||||
 | 
					* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
				
			||||||
 | 
					* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
 | 
				
			||||||
 | 
					* OR CONTRIBUTORS BE LIABLE FOR ANY
 | 
				
			||||||
 | 
					* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 | 
				
			||||||
 | 
					* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
				
			||||||
 | 
					* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
				
			||||||
 | 
					* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 | 
				
			||||||
 | 
					* ANY WAY OUT OF THE USE OF THIS
 | 
				
			||||||
 | 
					* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* The information provided is believed to be accurate and reliable.
 | 
				
			||||||
 | 
					* The copyright holder assumes no responsibility
 | 
				
			||||||
 | 
					* for the consequences of use
 | 
				
			||||||
 | 
					* of such information nor for any infringement of patents or
 | 
				
			||||||
 | 
					* other rights of third parties which may result from its use.
 | 
				
			||||||
 | 
					* No license is granted by implication or otherwise under any patent or
 | 
				
			||||||
 | 
					* patent rights of the copyright holder.
 | 
				
			||||||
 | 
					**************************************************************************/
 | 
				
			||||||
 | 
					/*! \file bme680.h
 | 
				
			||||||
 | 
					    \brief BME680 Sensor Driver Support Header File */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifndef __BME680_H__
 | 
				
			||||||
 | 
					#define __BME680_H__
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					extern "C"
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* BME680 Release version 2.0.0
 | 
				
			||||||
 | 
					BME680 Release Version format major_version.minor_version.point_version
 | 
				
			||||||
 | 
					Example: 2.0.0 */
 | 
				
			||||||
 | 
					#define BME680_API_REL_MAJOR_VERSION (2)
 | 
				
			||||||
 | 
					#define BME680_API_REL_MINOR_VERSION (0)
 | 
				
			||||||
 | 
					#define BME680_API_REL_POINT_VERSION (0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/***************************************************************************
 | 
				
			||||||
 | 
								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
 | 
				
			||||||
 | 
					#define BME680_INIT_VALUE			((u8)0)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/* 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
 | 
				
			||||||
 | 
					**************************************************************/
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*!
 | 
				
			||||||
 | 
					 * @brief This structure holds all
 | 
				
			||||||
 | 
					 * calibration parameters
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					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 {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						u8 heatr_idacv[BME680_MAX_PROFILES];
 | 
				
			||||||
 | 
						/**< used to store the idac parameter */
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 */
 | 
				
			||||||
 | 
					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_DISABLE,
 | 
				
			||||||
 | 
						BME680_HEATR_CTRL_ENABLE
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					/*!
 | 
				
			||||||
 | 
					 *	@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 50 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 50 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
 | 
				
			||||||
 | 
					 * bme680.h then for any sensor_type function will perform
 | 
				
			||||||
 | 
					 * read operation for BME680_ALL.
 | 
				
			||||||
 | 
					 * @note : pressure and humidity depends on temperature.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					enum bme680_return_type bme680_compensate_data(
 | 
				
			||||||
 | 
						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
 | 
				
			||||||
 | 
					 * from function bme680_get_uncomp_data()
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					void bme680_align_uncomp_data(u8 *a_data_u8, u8 field_count, u8 sensor_type,
 | 
				
			||||||
 | 
						struct bme680_uncomp_field_data *uncomp_data,
 | 
				
			||||||
 | 
						struct bme680_t *bme680);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*!
 | 
				
			||||||
 | 
					 * @brief This function is used to read the status according to filed index.
 | 
				
			||||||
 | 
					*/
 | 
				
			||||||
 | 
					enum bme680_return_type bme680_read_status_fields(
 | 
				
			||||||
 | 
						struct bme680_uncomp_field_data *uncomp_data,
 | 
				
			||||||
 | 
						u8 *a_data_u8, u8 *new_data,
 | 
				
			||||||
 | 
						struct bme680_t *bme680);
 | 
				
			||||||
 | 
					/* bme680_calculations.h */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef __cplusplus
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif
 | 
				
			||||||
							
								
								
									
										654
									
								
								bme680_calculations.c
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										654
									
								
								bme680_calculations.c
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,654 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					* Copyright (C) 2015 Bosch Sensortec GmbH
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* File : bme680_calculations.c
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Date : 2016/06/10
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Revision: 2.0.0
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Usage: Sensor Driver for BME680 sensor
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					* \Section Disclaimer
 | 
				
			||||||
 | 
					* License:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					* modification, are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer in the
 | 
				
			||||||
 | 
					*   documentation and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Neither the name of the copyright holder nor the names of the
 | 
				
			||||||
 | 
					*   contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					*   this software without specific prior written permission.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 | 
				
			||||||
 | 
					* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 | 
				
			||||||
 | 
					* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
				
			||||||
 | 
					* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
 | 
				
			||||||
 | 
					* OR CONTRIBUTORS BE LIABLE FOR ANY
 | 
				
			||||||
 | 
					* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 | 
				
			||||||
 | 
					* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
				
			||||||
 | 
					* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
				
			||||||
 | 
					* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 | 
				
			||||||
 | 
					* ANY WAY OUT OF THE USE OF THIS
 | 
				
			||||||
 | 
					* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* The information provided is believed to be accurate and reliable.
 | 
				
			||||||
 | 
					* The copyright holder assumes no responsibility
 | 
				
			||||||
 | 
					* for the consequences of use
 | 
				
			||||||
 | 
					* of such information nor for any infringement of patents or
 | 
				
			||||||
 | 
					* other rights of third parties which may result from its use.
 | 
				
			||||||
 | 
					* No license is granted by implication or otherwise under any patent or
 | 
				
			||||||
 | 
					* patent rights of the copyright holder.
 | 
				
			||||||
 | 
					**************************************************************************/
 | 
				
			||||||
 | 
					/*! \file 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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s64 var1 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s64 var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 gas_res = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 temp_comp = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var1	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var2	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var3	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var4	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var5	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var6	= BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 humidity_comp = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var4 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 pressure_comp = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var4 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 var5 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						s32 res_heat_x100 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						u8 res_heat = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						u16 v_x2_u32 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var1 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var1 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var4 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double data2_d = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double data3_d = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double pressure_comp = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 != BME680_INIT_VALUE) {
 | 
				
			||||||
 | 
							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 BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/*!
 | 
				
			||||||
 | 
					 * @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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double data2_d = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double temperature = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						/* 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 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var2 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var3 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var4 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double var5 = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
						double res_heat = BME680_INIT_VALUE;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						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 */
 | 
				
			||||||
							
								
								
									
										248
									
								
								bme680_calculations.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										248
									
								
								bme680_calculations.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,248 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					 ****************************************************************************
 | 
				
			||||||
 | 
					 * Copyright (C) 2015 Bosch Sensortec GmbH
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * File : bme680_calculations.h
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					* Date : 2016/06/10
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Revision: 2.0.0
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * Usage: Sensor Driver for BME680 sensor
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 ****************************************************************************
 | 
				
			||||||
 | 
					 * \Section Disclaimer
 | 
				
			||||||
 | 
					 *
 | 
				
			||||||
 | 
					 * License:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					* modification, are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer in the
 | 
				
			||||||
 | 
					*   documentation and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Neither the name of the copyright holder nor the names of the
 | 
				
			||||||
 | 
					*   contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					*   this software without specific prior written permission.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 | 
				
			||||||
 | 
					* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 | 
				
			||||||
 | 
					* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
				
			||||||
 | 
					* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
 | 
				
			||||||
 | 
					* OR CONTRIBUTORS BE LIABLE FOR ANY
 | 
				
			||||||
 | 
					* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 | 
				
			||||||
 | 
					* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
				
			||||||
 | 
					* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
				
			||||||
 | 
					* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 | 
				
			||||||
 | 
					* ANY WAY OUT OF THE USE OF THIS
 | 
				
			||||||
 | 
					* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* The information provided is believed to be accurate and reliable.
 | 
				
			||||||
 | 
					* The copyright holder assumes no responsibility
 | 
				
			||||||
 | 
					* for the consequences of use
 | 
				
			||||||
 | 
					* of such information nor for any infringement of patents or
 | 
				
			||||||
 | 
					* other rights of third parties which may result from its use.
 | 
				
			||||||
 | 
					* No license is granted by implication or otherwise under any patent or
 | 
				
			||||||
 | 
					* patent rights of the copyright holder.
 | 
				
			||||||
 | 
					 **************************************************************************/
 | 
				
			||||||
 | 
					/*! \file 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
 | 
				
			||||||
							
								
								
									
										285
									
								
								bme680_internal.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										285
									
								
								bme680_internal.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,285 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					* Copyright (C) 2015 Bosch Sensortec GmbH
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* File : bme680_internal.h
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Date : 2016/06/10
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Revision: 2.0.0
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Usage: Sensor Driver for BME680 sensor
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Section Disclaimer
 | 
				
			||||||
 | 
					* License:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					* modification, are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer in the
 | 
				
			||||||
 | 
					*   documentation and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Neither the name of the copyright holder nor the names of the
 | 
				
			||||||
 | 
					*   contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					*   this software without specific prior written permission.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 | 
				
			||||||
 | 
					* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 | 
				
			||||||
 | 
					* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
				
			||||||
 | 
					* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
 | 
				
			||||||
 | 
					* OR CONTRIBUTORS BE LIABLE FOR ANY
 | 
				
			||||||
 | 
					* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 | 
				
			||||||
 | 
					* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
				
			||||||
 | 
					* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
				
			||||||
 | 
					* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 | 
				
			||||||
 | 
					* ANY WAY OUT OF THE USE OF THIS
 | 
				
			||||||
 | 
					* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* The information provided is believed to be accurate and reliable.
 | 
				
			||||||
 | 
					* The copyright holder assumes no responsibility
 | 
				
			||||||
 | 
					* for the consequences of use
 | 
				
			||||||
 | 
					* of such information nor for any infringement of patents or
 | 
				
			||||||
 | 
					* other rights of third parties which may result from its use.
 | 
				
			||||||
 | 
					* No license is granted by implication or otherwise under any patent or
 | 
				
			||||||
 | 
					* patent rights of the copyright holder.
 | 
				
			||||||
 | 
					**************************************************************************/
 | 
				
			||||||
 | 
					/*! \file 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			(0x1F)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#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			(0x50)
 | 
				
			||||||
 | 
					#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
 | 
				
			||||||
							
								
								
									
										312
									
								
								sensor_api_common_types.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										312
									
								
								sensor_api_common_types.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,312 @@
 | 
				
			|||||||
 | 
					/*
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					* Copyright (C) 2015 Bosch Sensortec GmbH
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* File : sensor_api_common_types.h
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Date : 2016/06/10
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Revision: 2.0.0
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Usage: sensor API common data types Header File
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					****************************************************************************
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Section Disclaimer
 | 
				
			||||||
 | 
					* License:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* Redistribution and use in source and binary forms, with or without
 | 
				
			||||||
 | 
					* modification, are permitted provided that the following conditions are met:
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions of source code must retain the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Redistributions in binary form must reproduce the above copyright
 | 
				
			||||||
 | 
					*   notice, this list of conditions and the following disclaimer in the
 | 
				
			||||||
 | 
					*   documentation and/or other materials provided with the distribution.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					*   Neither the name of the copyright holder nor the names of the
 | 
				
			||||||
 | 
					*   contributors may be used to endorse or promote products derived from
 | 
				
			||||||
 | 
					*   this software without specific prior written permission.
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
 | 
				
			||||||
 | 
					* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
 | 
				
			||||||
 | 
					* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 | 
				
			||||||
 | 
					* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 | 
				
			||||||
 | 
					* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
 | 
				
			||||||
 | 
					* OR CONTRIBUTORS BE LIABLE FOR ANY
 | 
				
			||||||
 | 
					* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
 | 
				
			||||||
 | 
					* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
 | 
				
			||||||
 | 
					* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 | 
				
			||||||
 | 
					* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 | 
				
			||||||
 | 
					* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
 | 
				
			||||||
 | 
					* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 | 
				
			||||||
 | 
					* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 | 
				
			||||||
 | 
					* ANY WAY OUT OF THE USE OF THIS
 | 
				
			||||||
 | 
					* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
 | 
				
			||||||
 | 
					*
 | 
				
			||||||
 | 
					* The information provided is believed to be accurate and reliable.
 | 
				
			||||||
 | 
					* The copyright holder assumes no responsibility
 | 
				
			||||||
 | 
					* for the consequences of use
 | 
				
			||||||
 | 
					* of such information nor for any infringement of patents or
 | 
				
			||||||
 | 
					* other rights of third parties which may result from its use.
 | 
				
			||||||
 | 
					* No license is granted by implication or otherwise under any patent or
 | 
				
			||||||
 | 
					* patent rights of the copyright holder.
 | 
				
			||||||
 | 
					**************************************************************************/
 | 
				
			||||||
 | 
					/*! \file 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 long int u32;/**< used for unsigned 32bit */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/* If your machine support 32 bit
 | 
				
			||||||
 | 
						define the MACHINE_32_BIT*/
 | 
				
			||||||
 | 
					#elif defined MACHINE_32_BIT
 | 
				
			||||||
 | 
						/*signed integer types*/
 | 
				
			||||||
 | 
						typedef signed char  s8;/**< used for signed 8bit */
 | 
				
			||||||
 | 
						typedef signed short int s16;/**< used for signed 16bit */
 | 
				
			||||||
 | 
						typedef signed int s32;/**< used for signed 32bit */
 | 
				
			||||||
 | 
						typedef signed long long int s64;/**< used for signed 64bit */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*unsigned integer types*/
 | 
				
			||||||
 | 
						typedef unsigned char u8;/**< used for unsigned 8bit */
 | 
				
			||||||
 | 
						typedef unsigned short int u16;/**< used for unsigned 16bit */
 | 
				
			||||||
 | 
						typedef unsigned long 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 long int u32;/**< used for unsigned 32bit */
 | 
				
			||||||
 | 
						/*! @brief If your machine support 32 bit
 | 
				
			||||||
 | 
						define the MACHINE_32_BIT*/
 | 
				
			||||||
 | 
					#elif defined MACHINE_32_BIT
 | 
				
			||||||
 | 
						/*signed integer types*/
 | 
				
			||||||
 | 
						typedef signed char  s8;/**< used for signed 8bit */
 | 
				
			||||||
 | 
						typedef signed short int s16;/**< used for signed 16bit */
 | 
				
			||||||
 | 
						typedef signed int s32;/**< used for signed 32bit */
 | 
				
			||||||
 | 
						typedef signed long long int s64;/**< used for signed 64bit */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						/*unsigned integer types*/
 | 
				
			||||||
 | 
						typedef unsigned char u8;/**< used for unsigned 8bit */
 | 
				
			||||||
 | 
						typedef unsigned short int u16;/**< used for unsigned 16bit */
 | 
				
			||||||
 | 
						typedef unsigned long  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
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
		Reference in New Issue
	
	Block a user