70 lines
2.5 KiB
C++
70 lines
2.5 KiB
C++
#pragma once
|
|
#include <stdint.h>
|
|
|
|
#include "softspim.h"
|
|
|
|
//#define PRECOMP_COMPENSATION
|
|
|
|
class BMP280
|
|
{
|
|
private:
|
|
|
|
static constexpr uint8_t TEMP_REG_LOW = 0xFB;
|
|
static constexpr uint8_t TEMP_REG_HIGH = 0xFA;
|
|
static constexpr uint8_t PRESS_REG_LOW = 0xF8;
|
|
static constexpr uint8_t PRESS_REG_HIGH = 0xF7;
|
|
static constexpr uint8_t CONFIG_REG = 0xF5;
|
|
static constexpr uint8_t CTRL_REG = 0xF4;
|
|
static constexpr uint8_t ID_REG = 0xD0;
|
|
|
|
static constexpr uint8_t DIG_T1 = 0x88;
|
|
static constexpr uint8_t DIG_T2 = 0x8A;
|
|
static constexpr uint8_t DIG_T3 = 0x8C;
|
|
static constexpr uint8_t DIG_P1 = 0x8E;
|
|
static constexpr uint8_t DIG_P2 = 0x90;
|
|
static constexpr uint8_t DIG_P3 = 0x92;
|
|
static constexpr uint8_t DIG_P4 = 0x94;
|
|
static constexpr uint8_t DIG_P5 = 0x96;
|
|
static constexpr uint8_t DIG_P6 = 0x98;
|
|
static constexpr uint8_t DIG_P7 = 0x9A;
|
|
static constexpr uint8_t DIG_P8 = 0x9C;
|
|
static constexpr uint8_t DIG_P9 = 0x9E;
|
|
|
|
static constexpr int32_t t_fine = 102400;
|
|
|
|
#ifdef PRECOMP_COMPENSATION
|
|
static constexpr uint16_t digP1value = 42;
|
|
static constexpr int16_t digP2value = 48;
|
|
static constexpr int16_t digP3value = 49;
|
|
static constexpr int16_t digP4value = 30;
|
|
static constexpr int16_t digP5value = -32;
|
|
static constexpr int16_t digP6value = 58;
|
|
static constexpr int16_t digP7value = 7;
|
|
static constexpr int16_t digP8value = 3;
|
|
static constexpr int16_t digP9value = 58;
|
|
static constexpr int32_t var1StepA = ((((int32_t)t_fine)>>1) - (int32_t)64000);
|
|
static constexpr int32_t var1StepB = ((((32768+((((digP3value *
|
|
(((var1StepA>>2) * (var1StepA>>2)) >> 13 )) >> 3) + ((((int32_t)digP2value) * var1StepA)>>1))>>18)))*
|
|
((int32_t)digP1value))>>15);
|
|
static constexpr int32_t var2StepA = ((((var1StepA>>2) * (var1StepA>>2)) >> 11 ) * ((int32_t)digP6value)) + ((var1StepA*((int32_t)digP5value))<<1);
|
|
static constexpr int16_t var2StepB = ((var2StepA>>2)+(((int32_t)digP4value)<<16))>>12;
|
|
static constexpr int32_t var3 = 52;
|
|
#endif
|
|
|
|
volatile uint8_t * const _port;
|
|
const uint8_t _pin;
|
|
|
|
SpiMaster * const _spi;
|
|
|
|
void write(const uint8_t address, const uint8_t data);
|
|
uint16_t read16b(const uint8_t address);
|
|
uint8_t read8b(const uint8_t address);
|
|
uint32_t compensatePressure(const int32_t adc_P);
|
|
|
|
public:
|
|
|
|
BMP280(SpiMaster * const spi, volatile uint8_t * const port, const uint8_t pin);
|
|
uint16_t getPressure();
|
|
void getCoefficient(uint16_t* coefficients);
|
|
};
|