mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-06-12 19:05:58 +00:00
Rewrite API change
This commit is contained in:
parent
c5eb409d79
commit
c7299a8372
@ -28,9 +28,10 @@ namespace sta {
|
|||||||
// Function to get Pressure
|
// Function to get Pressure
|
||||||
// Parameter should be Temperature in Celsius * 100 (e.g. 20.3 deg. C -> 2030)
|
// Parameter should be Temperature in Celsius * 100 (e.g. 20.3 deg. C -> 2030)
|
||||||
// If currently still processing, use old value
|
// If currently still processing, use old value
|
||||||
// If currently not processing, start processing to minmize potential wating times
|
// If currently not processing, start processing to minimize potential waiting times
|
||||||
int32_t getPressure(int32_t temp, uint32_t curTime);
|
int32_t getPressure(int32_t temp, uint32_t curTime);
|
||||||
|
|
||||||
|
// --- DEPRECATED ---
|
||||||
// Parameterless version of function above
|
// Parameterless version of function above
|
||||||
// Calls getTemperature, to get temp
|
// Calls getTemperature, to get temp
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
@ -40,6 +41,7 @@ namespace sta {
|
|||||||
// Deprecated because of time constrains
|
// Deprecated because of time constrains
|
||||||
// NOT RECOMMENDED
|
// NOT RECOMMENDED
|
||||||
int32_t getTemperature();
|
int32_t getTemperature();
|
||||||
|
// --- DEPRECATED ---
|
||||||
|
|
||||||
void changeOsrLevel(OsrLevel newOsr) {
|
void changeOsrLevel(OsrLevel newOsr) {
|
||||||
// Don't I need to write this to the sensor?
|
// Don't I need to write this to the sensor?
|
||||||
@ -54,11 +56,13 @@ namespace sta {
|
|||||||
this->device_->beginTransmission();
|
this->device_->beginTransmission();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Last Presure Value meassured; Used to give any output if still calculating ADC
|
// Last Pressure Value measured; Used to give any output if still calculating ADC
|
||||||
int32_t lastPresVal;
|
int32_t lastPresVal;
|
||||||
// Value to store, when adc was started
|
// Value to store, when adc was started
|
||||||
// On STM32 with HAL_GetTick() (Gives ms since startup)
|
// On STM32 with HAL_GetTick() (Gives ms since startup)
|
||||||
uint32_t adcStartTime;
|
uint32_t adcStartTime;
|
||||||
|
// To prevent calculation of adc without reading value
|
||||||
|
bool presRead;
|
||||||
|
|
||||||
// STA internal object for SPi abstraction
|
// STA internal object for SPi abstraction
|
||||||
SpiDevice* device_;
|
SpiDevice* device_;
|
||||||
@ -87,11 +91,13 @@ namespace sta {
|
|||||||
int32_t calculatePressure(uint32_t d1, int32_t dT);
|
int32_t calculatePressure(uint32_t d1, int32_t dT);
|
||||||
int32_t calculateTemperature(uint32_t d2);
|
int32_t calculateTemperature(uint32_t d2);
|
||||||
|
|
||||||
|
int32_t reverseTempCalc(int32_t temp);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
void readPROM();
|
void readPROM();
|
||||||
|
|
||||||
// Constants for waiting
|
// Constants for waiting
|
||||||
const char RESET_DELAY = 2800; // in uS
|
const uint32_t RESET_DELAY = 2800; // in uS
|
||||||
|
|
||||||
// Function to get the delay times needed for different OSR Levels
|
// Function to get the delay times needed for different OSR Levels
|
||||||
// Values not found in datasheet (facepalm)
|
// Values not found in datasheet (facepalm)
|
||||||
@ -99,7 +105,15 @@ namespace sta {
|
|||||||
static uint8_t delayTimes(OsrLevel level) {
|
static uint8_t delayTimes(OsrLevel level) {
|
||||||
switch (level) {
|
switch (level) {
|
||||||
case _256:
|
case _256:
|
||||||
return
|
return 1;
|
||||||
|
case _512:
|
||||||
|
return 2;
|
||||||
|
case _1024:
|
||||||
|
return 3;
|
||||||
|
case _2048:
|
||||||
|
return 5;
|
||||||
|
case _4096:
|
||||||
|
return 10;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -1,10 +1,15 @@
|
|||||||
#include "sta/MS5607.hpp"
|
#include "sta/MS5607.hpp"
|
||||||
|
|
||||||
namespace sta {
|
namespace sta {
|
||||||
|
// Forward declaration
|
||||||
|
uint16_t uint_8BufferTouint16_t(uint8_t* buffer);
|
||||||
|
|
||||||
MS5607::MS5607(SpiDevice* device, OsrLevel level) {
|
MS5607::MS5607(SpiDevice* device, OsrLevel level) {
|
||||||
this->device_ = device;
|
this->device_ = device;
|
||||||
this->osr_ = level;
|
this->osr_ = level;
|
||||||
this->lastPresVal = -1;
|
this->lastPresVal = -1;
|
||||||
|
this->adcStartTime = -1;
|
||||||
|
this->presRead = true;
|
||||||
|
|
||||||
// Reset device on start-up
|
// Reset device on start-up
|
||||||
this->reset();
|
this->reset();
|
||||||
@ -12,17 +17,44 @@ namespace sta {
|
|||||||
this->readPROM();
|
this->readPROM();
|
||||||
}
|
}
|
||||||
|
|
||||||
void MS5607::requestAdcReadout() {
|
void MS5607::requestAdcReadout(uint32_t time) {
|
||||||
// Get current state of calculation
|
// Get current state of calculation
|
||||||
|
if (time-adcStartTime < delayTimes(this->osr_) || !presRead) {
|
||||||
|
// Time since last adc command is not enough
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
this->device_->beginTransmission();
|
this->device_->beginTransmission();
|
||||||
this->device_->transfer(MS5607::Operations::D1_CONVERSION + 2*this->osr_);
|
this->device_->transfer(MS5607::Operations::D1_CONVERSION + 2*this->osr_);
|
||||||
this->device_->endTransmission();
|
this->device_->endTransmission();
|
||||||
|
|
||||||
|
adcStartTime = time;
|
||||||
|
presRead = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t MS5607::getPressure(int32_t temp) {
|
int32_t MS5607::getPressure(int32_t temp, uint32_t time) {
|
||||||
|
if (time-adcStartTime < delayTimes(this->osr_) || presRead) {
|
||||||
|
// Time since last adc command is not enough
|
||||||
|
return lastPresVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t buffer[3] = { 0 };
|
||||||
|
|
||||||
|
this->device_->beginTransmission();
|
||||||
|
this->device_->transfer(MS5607::Operations::ADC_RESULT);
|
||||||
|
this->device_->receive(buffer, 3);
|
||||||
|
this->device_->endTransmission();
|
||||||
|
this->presRead = true;
|
||||||
|
|
||||||
|
uint32_t d1_val = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||||
|
|
||||||
|
this->requestAdcReadout(time);
|
||||||
|
|
||||||
|
return calculatePressure(d1_val, reverseTempCalc(temp));
|
||||||
|
}
|
||||||
|
|
||||||
|
int32_t MS5607::reverseTempCalc(int32_t temp) {
|
||||||
|
return this->tempsens;
|
||||||
}
|
}
|
||||||
|
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
@ -48,14 +80,8 @@ namespace sta {
|
|||||||
|
|
||||||
// Wait for ADC to finish
|
// Wait for ADC to finish
|
||||||
// Could do sth. else and schedule continuation with scheduler in RTOS
|
// Could do sth. else and schedule continuation with scheduler in RTOS
|
||||||
uint8_t buf[1] = { 0 };
|
// TODO: Find out min
|
||||||
do {
|
sta::delayMs(10);
|
||||||
*buf = 0;
|
|
||||||
uint8_t tx[1] = { 0b11111110 };
|
|
||||||
this->device_->beginTransmission();
|
|
||||||
this->device_->transfer(tx, buf, 1);
|
|
||||||
this->device_->endTransmission();
|
|
||||||
} while (*buf == 0x00);
|
|
||||||
|
|
||||||
// Request readout of ADC value
|
// Request readout of ADC value
|
||||||
uint8_t d1Arr[3];
|
uint8_t d1Arr[3];
|
||||||
@ -99,14 +125,8 @@ namespace sta {
|
|||||||
|
|
||||||
// Wait for ADC to finish
|
// Wait for ADC to finish
|
||||||
// Could do sth. else and schedule continuation with scheduler in RTOS
|
// Could do sth. else and schedule continuation with scheduler in RTOS
|
||||||
uint8_t buf[1] = { 0 };
|
// TODO: Test out min
|
||||||
do {
|
sta::delayMs(10);
|
||||||
*buf = 0;
|
|
||||||
uint8_t tx[1] = { 0b11111110 };
|
|
||||||
this->device_->beginTransmission();
|
|
||||||
this->device_->transfer(tx, buf, 1);
|
|
||||||
this->device_->endTransmission();
|
|
||||||
} while (*buf == 0x00);
|
|
||||||
|
|
||||||
|
|
||||||
// Request ADC readout
|
// Request ADC readout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user