/**\mainpage
* Copyright (C) 2016 - 2017 Bosch Sensortec GmbH
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* Neither the name of the copyright holder nor the names of the
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
* CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER
* OR CONTRIBUTORS BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
* OR CONSEQUENTIAL DAMAGES(INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
*
* The information provided is believed to be accurate and reliable.
* The copyright holder assumes no responsibility
* for the consequences of use
* of such information nor for any infringement of patents or
* other rights of third parties which may result from its use.
* No license is granted by implication or otherwise under any patent or
* patent rights of the copyright holder.
*
* File bme280.c
* Date 22 Nov 2017
* Version 3.3.2
*
*/
/*! @file bme280.c
@brief Sensor driver for BME280 sensor */
#include "bme280.h"
#include "stm32f4xx.h"
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <ctype.h>
#include <board.h>
#include "stm32f4xx_i2c.h"
#include "myiic.h"
#include "bme_thread.h"
/**\name Internal macros */
/* To identify osr settings selected by user */
#define OVERSAMPLING_SETTINGS UINT8_C(0x07)
/* To identify filter and standby settings selected by user */
#define FILTER_STANDBY_SETTINGS UINT8_C(0x18)
EnvSensorValue g_EnvSensor;
/*!
* @brief This internal API puts the device to sleep mode.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status.
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t put_device_to_sleep(const struct bme280_dev *dev);
/*!
* @brief This internal API writes the power mode in the sensor.
*
* @param[in] dev : Structure instance of bme280_dev.
* @param[in] sensor_mode : Variable which contains the power mode to be set.
*
* @return Result of API execution status.
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t write_power_mode(uint8_t sensor_mode, const struct bme280_dev *dev);
/*!
* @brief This internal API is used to validate the device pointer for
* null conditions.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t null_ptr_check(const struct bme280_dev *dev);
/*!
* @brief This internal API interleaves the register address between the
* register data buffer for burst write operation.
*
* @param[in] reg_addr : Contains the register address array.
* @param[out] temp_buff : Contains the temporary buffer to store the
* register data and register address.
* @param[in] reg_data : Contains the register data to be written in the
* temporary buffer.
* @param[in] len : No of bytes of data to be written for burst write.
*/
static void interleave_reg_addr(const uint8_t *reg_addr, uint8_t *temp_buff, const uint8_t *reg_data, uint8_t len);
/*!
* @brief This internal API reads the calibration data from the sensor, parse
* it and store in the device structure.
*
* @param[in] dev : Structure instance of bme280_dev.
*
* @return Result of API execution status
* @retval zero -> Success / +ve value -> Warning / -ve value -> Error
*/
static int8_t get_calib_data(struct bme280_dev *dev);
/*!
* @brief This internal API is used to parse the temperature and
* pressure calibration data and store it in the device structure.
*
* @param[out] dev : Structure instance of bme280_dev to store the calib data.
* @param[in] reg_data : Contains the calibration data to be parsed.
*/
static void parse_temp_press_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
/*!
* @brief This internal API is used to parse the humidity calibration data
* and store it in device structure.
*
* @param[out] dev : Structure instance of bme280_dev to store the calib data.
* @param[in] reg_data : Contains calibration data to be parsed.
*/
static void parse_humidity_calib_data(const uint8_t *reg_data, struct bme280_dev *dev);
#ifdef BME280_FLOAT_ENABLE
/*!
* @brief This internal API is used to compensate the raw pressure data and
* return the compensated pressure data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated pressure data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated pressure data.
* @retval Compensated pressure data in double.
*/
static double compensate_pressure(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw humidity data and
* return the compensated humidity data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated humidity data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated humidity data.
* @retval Compensated humidity data in double.
*/
static double compensate_humidity(const struct bme280_uncomp_data *uncomp_data,
const struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw temperature data and
* return the compensated temperature data in double data type.
*
* @param[in] uncomp_data : Contains the uncompensated temperature data.
* @param[in] calib_data : Pointer to calibration data structure.
*
* @return Compensated temperature data.
* @retval Compensated temperature data in double.
*/
static double compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
struct bme280_calib_data *calib_data);
#else
/*!
* @brief This internal API is used to compensate the raw temperature data and
* return the compensated temperature data in integer data type.
*
* @param[in] uncomp_data : Contains the uncompensated temperature data.
* @param[in] calib_data : Pointer to calibration data structure.
*
* @return Compensated temperature data.
* @retval Compensated temperature data in integer.
*/
static int32_t compensate_temperature(const struct bme280_uncomp_data *uncomp_data,
struct bme280_calib_data *calib_data);
/*!
* @brief This internal API is used to compensate the raw pressure data and
* return the compensated pressure data in integer data type.
*
* @param[in] uncomp_data : Contains the uncompensated pressure data.
* @param[in] calib_data : Pointer to the calibration data structure.
*
* @return Compensated pressure data.
* @retval Compensated pressure data in integer.
*/
static uint32_t compens
没有合适的资源?快使用搜索试试~ 我知道了~
bme280温湿度大气压强传感器驱动程序
共8个文件
h:5个
c:3个
需积分: 50 58 下载量 120 浏览量
2018-08-06
17:37:20
上传
评论 2
收藏 20KB ZIP 举报
温馨提示
本驱动代码,适用于集合温度测量,湿度测量,以及大气压强测量于一体的bme280模块。亲测稳定有效。IIC
资源推荐
资源详情
资源评论
收起资源包目录
bme280.zip (8个子文件)
bme_thread.c 4KB
bme280.c 45KB
bme280_selftest.h 3KB
bme280_selftest.c 5KB
bitband.h 2KB
bme280_defs.h 10KB
bme_thread.h 1004B
bme280.h 9KB
共 8 条
- 1
资源评论
tqfChina
- 粉丝: 25
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功