From ae52b2132e34ae97cfb212d29c78b2ba5e79a2c6 Mon Sep 17 00:00:00 2001 From: Bosch Sensortec Date: Wed, 8 Nov 2017 07:47:27 +0100 Subject: [PATCH] Changed - Created the following user APIs which were previously static * bme280_parse_sensor_data * bme280_compensate_data --- README.md | 10 +-- bme280.c | 169 +++++++++++++++++++++----------------------------- bme280.h | 33 +++++++++- bme280_defs.h | 12 ++-- changelog.md | 6 ++ 5 files changed, 119 insertions(+), 111 deletions(-) diff --git a/README.md b/README.md index 9da74b1..df453d2 100644 --- a/README.md +++ b/README.md @@ -5,11 +5,11 @@ This package contains the Bosch Sensortec's BME280 pressure sensor driver (senso The sensor driver package includes bme280.c, bme280.h and bme280_defs.h files. ## Version -File | Version | Date ------|---------|----- -bme280.c | 3.3.0 | 13 Jul 2017 -bme280.h | 3.3.0 | 13 Jul 2017 -bme280_defs.h | 3.3.0 | 13 Jul 2017 +File | Version | Date +--------------|---------|------------ +bme280.c | 3.3.1 | 07 Nov 2017 +bme280.h | 3.3.1 | 07 Nov 2017 +bme280_defs.h | 3.3.1 | 07 Nov 2017 ## Integration details * Integrate bme280.h, bme280_defs.h and bme280.c file in to the project. diff --git a/bme280.c b/bme280.c index 7625496..e4b6cbb 100644 --- a/bme280.c +++ b/bme280.c @@ -40,8 +40,8 @@ * patent rights of the copyright holder. * * File bme280.c - * Date 13 Jul 2017 - * Version 3.3.0 + * Date 07 Nov 2017 + * Version 3.3.1 * */ @@ -129,35 +129,6 @@ static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_d */ static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev); -/*! - * @brief This internal API is used to parse the pressure, temperature and - * humidity data and store it in the bme280_uncomp_data structure instance. - * - * @param[in] reg_data : Contains the register data which needs to be parsed. - * @param[out] uncomp_data : Contains the uncompensated pressure, temperature - * and humidity data. - */ -static void parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data); - -/*! - * @brief This internal API is used to compensate the pressure and/or - * temperature and/or humidity data according to the component selected by the - * user. - * - * @param[in] sensor_comp : Used to select pressure and/or temperature and/or - * humidity. - * @param[in] uncomp_data : Contains the uncompensated pressure, temperature and - * humidity data. - * @param[out] comp_data : Contains the compensated pressure and/or temperature - * and/or humidity data. - * @param[in] calib_data : Pointer to the calibration data structure. - * - * @return Result of API execution status. - * @retval zero -> Success / -ve value -> Error - */ -static int8_t compensate_data(uint8_t sensor_comp, const struct bme280_uncomp_data *uncomp_data, - struct bme280_data *comp_data, struct bme280_calib_data *calib_data); - #ifdef BME280_FLOAT_ENABLE /*! * @brief This internal API is used to compensate the raw pressure data and @@ -446,7 +417,8 @@ int8_t bme280_set_regs(uint8_t *reg_addr, const uint8_t *reg_data, uint8_t len, { int8_t rslt; uint8_t temp_buff[20]; /* Typically not to write more than 10 registers */ - if(len > 10) + + if (len > 10) len = 10; uint16_t temp_len; @@ -629,10 +601,75 @@ int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data if (rslt == BME280_OK) { /* Parse the read data from the sensor */ - parse_sensor_data(reg_data, &uncomp_data); + bme280_parse_sensor_data(reg_data, &uncomp_data); /* Compensate the pressure and/or temperature and/or humidity data from the sensor */ - rslt = compensate_data(sensor_comp, &uncomp_data, comp_data, &dev->calib_data); + rslt = bme280_compensate_data(sensor_comp, &uncomp_data, comp_data, &dev->calib_data); + } + } else { + rslt = BME280_E_NULL_PTR; + } + + return rslt; +} + +/*! + * @brief This API is used to parse the pressure, temperature and + * humidity data and store it in the bme280_uncomp_data structure instance. + */ +void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data) +{ + /* Variables to store the sensor data */ + uint32_t data_xlsb; + uint32_t data_lsb; + uint32_t data_msb; + + /* Store the parsed register values for pressure data */ + data_msb = (uint32_t)reg_data[0] << 12; + data_lsb = (uint32_t)reg_data[1] << 4; + data_xlsb = (uint32_t)reg_data[2] >> 4; + uncomp_data->pressure = data_msb | data_lsb | data_xlsb; + + /* Store the parsed register values for temperature data */ + data_msb = (uint32_t)reg_data[3] << 12; + data_lsb = (uint32_t)reg_data[4] << 4; + data_xlsb = (uint32_t)reg_data[5] >> 4; + uncomp_data->temperature = data_msb | data_lsb | data_xlsb; + + /* Store the parsed register values for temperature data */ + data_lsb = (uint32_t)reg_data[6] << 8; + data_msb = (uint32_t)reg_data[7]; + uncomp_data->humidity = data_msb | data_lsb; +} + + +/*! + * @brief This API is used to compensate the pressure and/or + * temperature and/or humidity data according to the component selected + * by the user. + */ +int8_t bme280_compensate_data(uint8_t sensor_comp, const struct bme280_uncomp_data *uncomp_data, + struct bme280_data *comp_data, struct bme280_calib_data *calib_data) +{ + int8_t rslt = BME280_OK; + + if ((uncomp_data != NULL) && (comp_data != NULL) && (calib_data != NULL)) { + /* Initialize to zero */ + comp_data->temperature = 0; + comp_data->pressure = 0; + comp_data->humidity = 0; + /* If pressure or temperature component is selected */ + if (sensor_comp & (BME280_PRESS | BME280_TEMP | BME280_HUM)) { + /* Compensate the temperature data */ + comp_data->temperature = compensate_temperature(uncomp_data, calib_data); + } + if (sensor_comp & BME280_PRESS) { + /* Compensate the pressure data */ + comp_data->pressure = compensate_pressure(uncomp_data, calib_data); + } + if (sensor_comp & BME280_HUM) { + /* Compensate the humidity data */ + comp_data->humidity = compensate_humidity(uncomp_data, calib_data); } } else { rslt = BME280_E_NULL_PTR; @@ -839,70 +876,6 @@ static int8_t reload_device_settings(const struct bme280_settings *settings, con return rslt; } -/*! - * @brief This internal API is used to parse the pressure, temperature and - * humidity data and store it in the bme280_uncomp_data structure instance. - */ -static void parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data) -{ - /* Variables to store the sensor data */ - uint32_t data_xlsb; - uint32_t data_lsb; - uint32_t data_msb; - - /* Store the parsed register values for pressure data */ - data_msb = (uint32_t)reg_data[0] << 12; - data_lsb = (uint32_t)reg_data[1] << 4; - data_xlsb = (uint32_t)reg_data[2] >> 4; - uncomp_data->pressure = data_msb | data_lsb | data_xlsb; - - /* Store the parsed register values for temperature data */ - data_msb = (uint32_t)reg_data[3] << 12; - data_lsb = (uint32_t)reg_data[4] << 4; - data_xlsb = (uint32_t)reg_data[5] >> 4; - uncomp_data->temperature = data_msb | data_lsb | data_xlsb; - - /* Store the parsed register values for temperature data */ - data_lsb = (uint32_t)reg_data[6] << 8; - data_msb = (uint32_t)reg_data[7]; - uncomp_data->humidity = data_msb | data_lsb; -} - -/*! - * @brief This internal API is used to compensate the pressure and/or - * temperature and/or humidity data according to the component selected - * by the user. - */ -static int8_t compensate_data(uint8_t sensor_comp, const struct bme280_uncomp_data *uncomp_data, - struct bme280_data *comp_data, struct bme280_calib_data *calib_data) -{ - int8_t rslt = BME280_OK; - - if ((uncomp_data != NULL) && (comp_data != NULL) && (calib_data != NULL)) { - /* Initialize to zero */ - comp_data->temperature = 0; - comp_data->pressure = 0; - comp_data->humidity = 0; - /* If pressure or temperature component is selected */ - if (sensor_comp & (BME280_PRESS | BME280_TEMP | BME280_HUM)) { - /* Compensate the temperature data */ - comp_data->temperature = compensate_temperature(uncomp_data, calib_data); - } - if (sensor_comp & BME280_PRESS) { - /* Compensate the pressure data */ - comp_data->pressure = compensate_pressure(uncomp_data, calib_data); - } - if (sensor_comp & BME280_HUM) { - /* Compensate the humidity data */ - comp_data->humidity = compensate_humidity(uncomp_data, calib_data); - } - } else { - rslt = BME280_E_NULL_PTR; - } - - return rslt; -} - #ifdef BME280_FLOAT_ENABLE /*! * @brief This internal API is used to compensate the raw temperature data and diff --git a/bme280.h b/bme280.h index 4c123ad..77008b3 100644 --- a/bme280.h +++ b/bme280.h @@ -40,8 +40,8 @@ * patent rights of the copyright holder. * * @file bme280.h - * @date 13 Jul 2017 - * @version 3.3.0 + * @date 07 Nov 2017 + * @version 3.3.1 * @brief * */ @@ -204,6 +204,35 @@ int8_t bme280_soft_reset(const struct bme280_dev *dev); */ int8_t bme280_get_sensor_data(uint8_t sensor_comp, struct bme280_data *comp_data, struct bme280_dev *dev); +/*! + * @brief This API is used to parse the pressure, temperature and + * humidity data and store it in the bme280_uncomp_data structure instance. + * + * @param[in] reg_data : Contains register data which needs to be parsed + * @param[out] uncomp_data : Contains the uncompensated pressure, temperature + * and humidity data. + */ +void bme280_parse_sensor_data(const uint8_t *reg_data, struct bme280_uncomp_data *uncomp_data); + +/*! + * @brief This API is used to compensate the pressure and/or + * temperature and/or humidity data according to the component selected by the + * user. + * + * @param[in] sensor_comp : Used to select pressure and/or temperature and/or + * humidity. + * @param[in] uncomp_data : Contains the uncompensated pressure, temperature and + * humidity data. + * @param[out] comp_data : Contains the compensated pressure and/or temperature + * and/or humidity data. + * @param[in] calib_data : Pointer to the calibration data structure. + * + * @return Result of API execution status. + * @retval zero -> Success / -ve value -> Error + */ +int8_t bme280_compensate_data(uint8_t sensor_comp, const struct bme280_uncomp_data *uncomp_data, + struct bme280_data *comp_data, struct bme280_calib_data *calib_data); + #ifdef __cplusplus } #endif /* End of CPP guard */ diff --git a/bme280_defs.h b/bme280_defs.h index 2398b2c..4e35d16 100644 --- a/bme280_defs.h +++ b/bme280_defs.h @@ -40,8 +40,8 @@ * patent rights of the copyright holder. * * @file bme280_defs.h - * @date 13 Jul 2017 - * @version 3.3.0 + * @date 07 Nov 2017 + * @version 3.3.1 * @brief * */ @@ -121,13 +121,13 @@ #endif #ifndef BME280_FLOAT_ENABLE -//#define BME280_FLOAT_ENABLE +/* #define BME280_FLOAT_ENABLE */ #endif #ifndef BME280_FLOAT_ENABLE -# ifndef BME280_64BIT_ENABLE -# define BME280_64BIT_ENABLE -# endif +#ifndef BME280_64BIT_ENABLE +#define BME280_64BIT_ENABLE +#endif #endif #ifndef TRUE diff --git a/changelog.md b/changelog.md index a30b796..98d1671 100644 --- a/changelog.md +++ b/changelog.md @@ -1,6 +1,12 @@ # Change Log All notable changes to BME280 Sensor API will be documented in this file. +## v3.3.1, 07 Nov 2017 +### Changed + - Created the following user APIs which were previously static + * bme280_parse_sensor_data + * bme280_compensate_data + ## v3.3.0, 13 Jul 2017 ### Changed - Changed macro FLOATING_POINT_REPRESENTATION to BME280_FLOAT_ENABLE -- 2.45.0