edeaedeb07
temperature readout must be added and compensation must be checked
157 lines
4.1 KiB
C++
157 lines
4.1 KiB
C++
// --------------------------------------------------------------------------------------------------------------------
|
|
/// \file bme280.h
|
|
/// \brief File description
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
//
|
|
// vbchaos software design
|
|
//
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
/// $Revision: $
|
|
/// $Author: $
|
|
/// $Date: $
|
|
// (c) 2023 vbchaos
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
#ifndef MAIN_INC_BMP280_H_
|
|
#define MAIN_INC_BMP280_H_
|
|
|
|
/**
|
|
* bme280 implementation
|
|
* \defgroup bme280
|
|
* \brief {group_description}
|
|
* \addtogroup {Layer}
|
|
*
|
|
* Detailed description
|
|
* @{
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// Include files
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
// CompilerIncludes
|
|
// All include files that are provided by the compiler directly
|
|
|
|
|
|
|
|
// ProjectIncludes
|
|
// All include files that are provided by the project
|
|
#include "i2c.h"
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// Constant and macro definitions
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
#define BMP280_DEVICE_ID ((uint8_t)0x58)
|
|
#define BMP280_RESET_VALUE ((uint8_t)0xB6)
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// Type definitions.
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// Function declarations
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
class BMP280
|
|
{
|
|
public:
|
|
BMP280(I2C* bus, uint8_t slaveAddress);
|
|
|
|
typedef enum
|
|
{
|
|
STANDBY = 0,
|
|
FORCED = 1,
|
|
NORMAL = 3
|
|
} BMP280_Mode_t;
|
|
typedef enum
|
|
{
|
|
SKIPPED = 0,
|
|
X1 = 1,
|
|
X2 = 2,
|
|
X4 = 3,
|
|
X8 = 4,
|
|
X16 = 5
|
|
} BMP280_Oversampling_t;
|
|
|
|
void resetSensor(void);
|
|
bool initialize(void);
|
|
bool setSensorMode(BMP280_Mode_t mode);
|
|
bool setSensorTemperatureOversampling(BMP280_Oversampling_t oversampling);
|
|
|
|
private:
|
|
|
|
struct CompensationParameters
|
|
{
|
|
// Temperature compensation parameters
|
|
uint16_t dig_T1;
|
|
int16_t dig_T2;
|
|
int16_t dig_T3;
|
|
// Pressure compensation parameters
|
|
uint16_t dig_P1;
|
|
int16_t dig_P2;
|
|
int16_t dig_P3;
|
|
int16_t dig_P4;
|
|
int16_t dig_P5;
|
|
int16_t dig_P6;
|
|
int16_t dig_P7;
|
|
int16_t dig_P8;
|
|
int16_t dig_P9;
|
|
} compensationParameters;
|
|
|
|
struct memorymap
|
|
{
|
|
struct
|
|
{
|
|
uint8_t msb;
|
|
uint8_t lsb;
|
|
uint8_t xlsb;
|
|
} temperature_raw;
|
|
struct
|
|
{
|
|
uint8_t msb;
|
|
uint8_t lsb;
|
|
uint8_t xlsb;
|
|
} pressure_raw;
|
|
struct
|
|
{
|
|
uint8_t mode : 2;
|
|
uint8_t oversampling_pressure : 3;
|
|
uint8_t oversampling_temp : 3;
|
|
} config;
|
|
uint8_t ctrl_meas;
|
|
uint8_t status;
|
|
uint8_t reset;
|
|
uint8_t id;
|
|
} memorymap;
|
|
|
|
int t_fine;
|
|
int temperature;
|
|
|
|
I2C* bus;
|
|
uint8_t slaveAddress;
|
|
BMP280_Mode_t mode;
|
|
|
|
void resetDriver(void);
|
|
|
|
// Communication with Device
|
|
void resetDevice(void);
|
|
void getDeviceID(void);
|
|
void setSensorConfiguration(void);
|
|
|
|
void getCompensationValues(void);
|
|
|
|
void compensateTemperature(void);
|
|
|
|
};
|
|
|
|
|
|
/** @} */
|
|
|
|
#endif /* MAIN_INC_BMP280_H_ */
|