/*****************************************************************************
* File : bmp280.h
* Date : 2016/07/01
* Revision : 2.0.5( Pressure and Temperature compensation code revision is 1.1 )
*
****************************************************************************/
#ifndef __BMP280_H__
#define __BMP280_H__
#include "i2c_8051.h"
/*
Keil C51:
Data Types Bits Bytes Value Range
===================================================================
bit 1 0 to 1
signed char 8 1 -128 to +127
unsigned char 8 1 0 to 255
enum 8/16 1/2 -128 to +127 or -32768 to +32767
signed short 16 2 -32768 to +32767
unsigned short 16 2 0 to 65535
signed int 16 2 -32768 to +32767
unsigned int 16 2 0 to 65535
signed long 32 4 -2147483648 to +2147483647
unsigned long 32 4 0 to 4294967295
float 32 4 +/- 1.175494E-38 to +/- 3.402823E+38
sbit 1 0 or 1
sfr 8 1 0 to 255
sfr16 16 2 0 to 65535
*/
// unsigned integer types
typedef unsigned char u8; // used for unsigned 8 bit
typedef unsigned short int u16; // used for unsigned 16 bit
typedef unsigned long int u32; // used for unsigned 32 bit
// signed integer types
typedef signed char s8; // used for signed 8 bit
typedef signed short int s16; // used for signed 16 bit
typedef signed long int s32; // used for signed 32 bit
#define BMP280_ADDR 0xEC
#define BMP280_GET_BITSLICE( regvar, bitname )\
( ( regvar & bitname##__MSK ) >> bitname##__POS )
#define BMP280_SET_BITSLICE( regvar, bitname, val )\
( ( regvar & ~bitname##__MSK ) | ( ( val << bitname##__POS ) & bitname##__MSK ) )
// **************************************************************
// COMMON USED CONSTANTS
// **************************************************************
// numeric definitions
#define BMP280_CALIB_D_LEN ( 24 )
#define BMP280_TEMPER_D_LEN ( 3 )
#define BMP280_PRESS_D_LEN ( 3 )
// ***********************************************
// CHIP ID DEFINITION
// **********************************************
#define BMP280_CHIP_ID1 ( 0x56 )
#define BMP280_CHIP_ID2 ( 0x57 )
#define BMP280_CHIP_ID3 ( 0x58 )
// ***********************************************
// POWER MODE DEFINITION
// **********************************************
// Sensor Specific constants
#define BMP280_SLEEP_MODE ( 0x00 )
#define BMP280_FORCED_MODE ( 0x01 )
#define BMP280_NORMAL_MODE ( 0x03 )
#define BMP280_SOFT_RESET_CODE ( 0xB6 )
// ***********************************************
// STANDBY TIME DEFINITION
// **********************************************
#define BMP280_STANDBY_TIME_1_MS ( 0x00 )
#define BMP280_STANDBY_TIME_63_MS ( 0x01 )
#define BMP280_STANDBY_TIME_125_MS ( 0x02 )
#define BMP280_STANDBY_TIME_250_MS ( 0x03 )
#define BMP280_STANDBY_TIME_500_MS ( 0x04 )
#define BMP280_STANDBY_TIME_1000_MS ( 0x05 )
#define BMP280_STANDBY_TIME_2000_MS ( 0x06 )
#define BMP280_STANDBY_TIME_4000_MS ( 0x07 )
// ***********************************************
// OVERSAMPLING DEFINITION
// **********************************************
#define BMP280_OVERSAMP_SKIPPED ( 0x00 )
#define BMP280_OVERSAMP_1X ( 0x01 )
#define BMP280_OVERSAMP_2X ( 0x02 )
#define BMP280_OVERSAMP_4X ( 0x03 )
#define BMP280_OVERSAMP_8X ( 0x04 )
#define BMP280_OVERSAMP_16X ( 0x05 )
// ***********************************************
// WORKING MODE DEFINITION
// **********************************************
#define BMP280_ULTRA_LOW_POWER_MODE ( 0x00 )
#define BMP280_LOW_POWER_MODE ( 0x01 )
#define BMP280_STANDARD_RESOLUTION_MODE ( 0x02 )
#define BMP280_HIGH_RESOLUTION_MODE ( 0x03 )
#define BMP280_ULTRA_HIGH_RESOLUTION_MODE ( 0x04 )
#define BMP280_ULTRALOWPOWER_OVERSAMP_PRESSURE BMP280_OVERSAMP_1X
#define BMP280_ULTRALOWPOWER_OVERSAMP_TEMPER BMP280_OVERSAMP_1X
#define BMP280_LOWPOWER_OVERSAMP_PRESSURE BMP280_OVERSAMP_2X
#define BMP280_LOWPOWER_OVERSAMP_TEMPER BMP280_OVERSAMP_1X
#define BMP280_STANDARDRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_4X
#define BMP280_STANDARDRESOLUTION_OVERSAMP_TEMPER BMP280_OVERSAMP_1X
#define BMP280_HIGHRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_8X
#define BMP280_HIGHRESOLUTION_OVERSAMP_TEMPER BMP280_OVERSAMP_1X
#define BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_PRESSURE BMP280_OVERSAMP_16X
#define BMP280_ULTRAHIGHRESOLUTION_OVERSAMP_TEMPER BMP280_OVERSAMP_2X
// ***********************************************
// FILTER DEFINITION
// **********************************************
#define BMP280_FILTER_COEFF_OFF ( 0x00 )
#define BMP280_FILTER_COEFF_2 ( 0x01 )
#define BMP280_FILTER_COEFF_4 ( 0x02 )
#define BMP280_FILTER_COEFF_8 ( 0x03 )
#define BMP280_FILTER_COEFF_16 ( 0x04 )
// ***********************************************
// DELAY TIME DEFINITION
// **********************************************
#define T_INIT_MAX ( 20 )
// 20/16 = 1.25 ms
#define T_MEASURE_PER_OSRS_MAX ( 37 )
// 37/16 = 2.3125 ms
#define T_SETUP_PRESSURE_MAX ( 10 )
// 10/16 = 0.625 ms
// ***********************************************
// CALIBRATION PARAMETERS DEFINITION
// **********************************************
#define BMP280_CALIB_BASE_REG ( 0x88 )
// ***********************************************
// REGISTER ADDRESS DEFINITION
// **********************************************
#define BMP280_CHIP_ID_REG ( 0xD0 ) // Chip ID Register
#define BMP280_RST_REG ( 0xE0 ) // Softreset Register
#define BMP280_STAT_REG ( 0xF3 ) // Status Register
#define BMP280_CTRL_MEAS_REG ( 0xF4 ) // Ctrl Measure Register
#define BMP280_CONFIG_REG ( 0xF5 ) // Configuration Register
#define BMP280_PRESS_MSB_REG ( 0xF7 ) // Pressure MSB Register
#define BMP280_PRESS_LSB_REG ( 0xF8 ) // Pressure LSB Register
#define BMP280_PRESS_XLSB_REG ( 0xF9 ) // Pressure XLSB Register
#define BMP280_TEMPER_MSB_REG ( 0xFA ) // Temperature MSB Reg
#define BMP280_TEMPER_LSB_REG ( 0xFB ) // Temperature LSB Reg
#define BMP280_TEMPER_XLSB_REG ( 0xFC ) // Temperature XLSB Reg
// ***********************************************
// BIT LENGTH, POSITION AND MASK DEFINITION
// **********************************************
// Status Register
#define BMP280_STATUS_REG_MEASURING__POS ( 3 )
#define BMP280_STATUS_REG_MEASURING__MSK ( 0x08 )
#define BMP280_STATUS_REG_MEASURING__LEN ( 1 )
#define BMP280_STATUS_REG_MEASURING__REG ( BMP280_STAT_REG )
#define BMP280_STATUS_REG_IM_UPDATE__POS ( 0 )
#define BMP280_STATUS_REG_IM_UPDATE__MSK ( 0x01 )
#define BMP280_STATUS_REG_IM_UPDATE__LEN ( 1 )
#define BMP280_STATUS_REG_IM_UPDATE__REG ( BMP280_STAT_REG )
// ***********************************************
// BIT LENGTH, POSITION AND MASK DEFINITION FOR TEMPERATURE OVERSAMPLING
// **********