mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-06-10 01:55:59 +00:00
124 lines
3.8 KiB
C++
124 lines
3.8 KiB
C++
#ifndef STA_SENSORS_MS5607_HPP
|
|
#define STA_SENSORS_MS5607_HPP
|
|
|
|
#include<sta/devices/stm32/bus/spi.hpp>
|
|
#include<sta/endian.hpp>
|
|
#include<sta/devices/stm32/delay.hpp>
|
|
|
|
namespace sta {
|
|
// Class to represent a MS5607 pressure sensor which is used with SPI
|
|
class MS5607 {
|
|
public:
|
|
// Different OSR levels for the sensor
|
|
enum OsrLevel {
|
|
_256 = 0,
|
|
_512 = 1,
|
|
_1024 = 2,
|
|
_2048 = 3,
|
|
_4096 = 4
|
|
};
|
|
|
|
MS5607(STM32SPIDevice* device, OsrLevel osr=OsrLevel::_1024);
|
|
|
|
// Request Calculation of uncompensated pressure
|
|
// Takes a few ms -> Call, then do sth. else, then get Pressure with function
|
|
// If calculation already running, do nothing
|
|
void requestAdcReadout(uint32_t curTime);
|
|
|
|
// Function to get Pressure
|
|
// Parameter should be Temperature in Celsius * 100 (e.g. 20.3 deg. C -> 2030)
|
|
// If currently still processing, use old value
|
|
// If currently not processing, start processing to minimize potential waiting times
|
|
int32_t getPressure(int32_t temp, uint32_t curTime);
|
|
|
|
// --- DEPRECATED ---
|
|
// Parameterless version of function above
|
|
// Calls getTemperature, to get temp
|
|
// NOT RECOMMENDED
|
|
int32_t getPressure();
|
|
|
|
// Getter for temperature
|
|
// Deprecated because of time constrains
|
|
// NOT RECOMMENDED
|
|
int32_t getTemperature();
|
|
// --- DEPRECATED ---
|
|
|
|
void changeOsrLevel(OsrLevel newOsr) {
|
|
// Don't I need to write this to the sensor?
|
|
this->osr_ = newOsr;
|
|
}
|
|
|
|
private:
|
|
// Helper method to keep code clean
|
|
void pulseCS(uint32_t ms=1) {
|
|
this->device_->endTransmission();
|
|
sta::delayMs(ms);
|
|
this->device_->beginTransmission();
|
|
}
|
|
|
|
// Last Pressure Value measured; Used to give any output if still calculating ADC
|
|
int32_t lastPresVal;
|
|
// Value to store, when adc was started
|
|
// On STM32 with HAL_GetTick() (Gives ms since startup)
|
|
uint32_t adcStartTime;
|
|
// To prevent calculation of adc without reading value
|
|
bool presRead;
|
|
|
|
// STA internal object for SPi abstraction
|
|
STM32SPIDevice* device_;
|
|
OsrLevel osr_;
|
|
|
|
// 6 Different constants; Includes Offsets, references etc.
|
|
uint16_t sens, off, tcs, tco, t_ref, tempsens;
|
|
|
|
// All possible commands to send to the sensor
|
|
enum Operations {
|
|
RESET = 0x1E,
|
|
READ_PROM = 0xA2,
|
|
D1_CONVERSION = 0x40,
|
|
D2_CONVERSION = 0x50,
|
|
ADC_RESULT = 0x00
|
|
};
|
|
|
|
// Request pure ADC converted values from the sensor
|
|
// Calculations with offset required
|
|
uint32_t readPressure();
|
|
|
|
// Read temp should not be used, rather give temp from e.g. SCA3300 as parameter to readPres
|
|
uint32_t readTemp();
|
|
|
|
// Calculate pure ADC values to final pressure/temperature values
|
|
int32_t calculatePressure(uint32_t d1, int32_t dT);
|
|
int32_t calculateTemperature(uint32_t d2);
|
|
|
|
int32_t reverseTempCalc(int32_t temp);
|
|
|
|
void reset();
|
|
void readPROM();
|
|
|
|
// Constants for waiting
|
|
const uint32_t RESET_DELAY = 2800; // in uS
|
|
|
|
// Function to get the delay times needed for different OSR Levels
|
|
// Values not found in datasheet (facepalm)
|
|
// Thus partly googled, partly tested out
|
|
static uint8_t delayTimes(OsrLevel level) {
|
|
switch (level) {
|
|
case _256:
|
|
return 1;
|
|
case _512:
|
|
return 2;
|
|
case _1024:
|
|
return 3;
|
|
case _2048:
|
|
return 5;
|
|
case _4096:
|
|
return 10;
|
|
}
|
|
}
|
|
};
|
|
|
|
}
|
|
|
|
#endif // ifndef STA_SENSORS_MS5607_HPP
|