183 lines
5.3 KiB
C++
183 lines
5.3 KiB
C++
// --------------------------------------------------------------------------------------------------------------------
|
|
/// \file bmp280.h
|
|
/// \brief File description
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
//
|
|
// vbchaos software design
|
|
//
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
/// $Revision: $
|
|
/// $Author: $
|
|
/// $Date: $
|
|
// (c) 2023 vbchaos
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
#ifndef MAIN_APPLICATION_INC_BMP280_H_
|
|
#define MAIN_APPLICATION_INC_BMP280_H_
|
|
|
|
/**
|
|
* bmp280 implementation
|
|
* \defgroup bmp280
|
|
* \brief {group_description}
|
|
* \addtogroup {Layer}
|
|
*
|
|
* Detailed description
|
|
* @{
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
// Include files
|
|
// --------------------------------------------------------------------------------------------------------------------
|
|
|
|
// CompilerIncludes
|
|
// All include files that are provided by the compiler directly
|
|
#include <stdint.h>
|
|
|
|
|
|
// ProjectIncludes
|
|
// All include files that are provided by the project
|
|
#include "ISerialBus.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 Section
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
public:
|
|
// Class Constructor
|
|
bmp280(uint8_t slaveAddress, ISerialBus<uint8_t>& serialPort);
|
|
|
|
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);
|
|
|
|
int getTemperature(void);
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
// Protected Section
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
protected:
|
|
|
|
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
// Private Section
|
|
// -----------------------------------------------------------------------------------------------------------------
|
|
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 t_sb: 3;
|
|
uint8_t filter: 3;
|
|
uint8_t unused: 1;
|
|
uint8_t spi3w_en: 1;
|
|
} config;
|
|
struct
|
|
{
|
|
uint8_t mode : 2;
|
|
uint8_t oversampling_pressure : 3;
|
|
uint8_t oversampling_temp : 3;
|
|
} ctrl_meas;
|
|
uint8_t status;
|
|
uint8_t reset;
|
|
uint8_t id;
|
|
} memorymap;
|
|
|
|
int t_fine;
|
|
int temperature;
|
|
|
|
uint8_t slaveAddress;
|
|
ISerialBus<uint8_t>& bus;
|
|
bool initialized;
|
|
BMP280_Mode_t mode;
|
|
|
|
void resetDriver(void);
|
|
|
|
// Communication with Device
|
|
void resetDevice(void);
|
|
void getDeviceID(void);
|
|
void setSensorControlMeasurement(void);
|
|
void setSensorConfiguration(void);
|
|
|
|
void getCompensationValues(void);
|
|
|
|
void compensateTemperature(void);
|
|
|
|
void getPreasureValues(void);
|
|
void getTemperatureValues(void);
|
|
|
|
};
|
|
|
|
/** @} */
|
|
|
|
|
|
#endif /* MAIN_APPLICATION_INC_OTA_H_ */
|