M5Unit-ENV 1.6.0 git rev:f6fd6b0
Loading...
Searching...
No Matches
unit_SPA06_data.hpp File Reference

SPA06-003 measurement data + calibration/compensation (framework independent) More...

#include <array>
#include <cstdint>
#include <cmath>
#include <limits>

Go to the source code of this file.

Classes

struct  m5::unit::spa06::coeffs_t
 Factory calibration coefficients (all 2's complement, already sign-extended) More...
 
struct  m5::unit::spa06::Data
 One SPA06 sample: a 6-byte burst from PSR_B2 (0x00) = PSR(24) + TMP(24), big-endian. More...
 

Namespaces

namespace  m5
 Top level namespace of M5Stack.
 

Enumerations

enum class  m5::unit::spa06::Oversampling : uint8_t {
  X1 , X2 , X4 , X8 ,
  X16 , X32 , X64 , X128
}
 Oversampling factor; the enum value is the PM_PRC/TM_PRC nibble (datasheet Table 4) More...
 
enum class  m5::unit::spa06::Rate : uint8_t {
  Rate1 , Rate2 , Rate4 , Rate8 ,
  Rate16 , Rate32 , Rate64 , Rate128
}
 Measurement rate; the enum value is the PM_RATE/TMP_RATE nibble (measurements per second) More...
 
enum class  m5::unit::spa06::Mode : uint8_t { Pressure = 0x05 , Temperature = 0x06 , PressureAndTemperature = 0x07 }
 Continuous measurement type; the enum value is the MEAS_CFG MEAS_CTRL[2:0] background-mode code. More...
 

Functions

float m5::unit::spa06::scale_factor (const Oversampling oversampling)
 Compensation scale factor kP/kT for an oversampling rate (datasheet Table 4)
 
uint32_t m5::unit::spa06::measurement_time_x10 (const Oversampling oversampling)
 Measurement time (ms x10) for an oversampling rate (datasheet Table 8), indexed by nibble.
 
bool m5::unit::spa06::valid_combination (const Oversampling osrs_p, const Oversampling osrs_t, const Rate rate, const Mode mode)
 True if a rate/oversampling/mode combination fits the datasheet timing budget.
 
int32_t m5::unit::spa06::sign_extend (const uint32_t v, const uint8_t bits)
 Sign-extend the low bits of v (2's complement)
 
coeffs_t m5::unit::spa06::parse_coeffs (const std::array< uint8_t, 21 > &r)
 Parse the 21 COEF register bytes (0x10..0x24) into coeffs_t (datasheet Table 10)
 
float m5::unit::spa06::compensate_temperature (const int32_t tmp_raw, const coeffs_t &c, const float kt)
 Compensated temperature (degC) from a raw TMP reading and scale kT.
 
float m5::unit::spa06::compensate_pressure (const int32_t psr_raw, const int32_t tmp_raw, const coeffs_t &c, const float kp, const float kt)
 Compensated pressure (Pa) from raw PSR/TMP readings and scales kP/kT (datasheet 4.6.1)
 
float m5::unit::spa06::altitude_m (const float pressure_hpa, const float sea_level_hpa)
 Relative altitude (m) from a pressure and a reference (both hPa), barometric formula.
 

Variables

constexpr int32_t m5::unit::spa06::NOT_MEASURED {-8388608}
 Sentinel value of psr_raw()/tmp_raw() for a register not measured yet (reset value 0x800000)
 

Detailed Description

SPA06-003 measurement data + calibration/compensation (framework independent)

PSR/TMP are 24-bit 2's complement; 11 calibration coefficients (c0,c1 12-bit; c00,c10 20-bit; c01,c11,c20,c21,c30 16-bit; c31,c40 12-bit) drive a high-order compensation polynomial. Pressure is returned in Pa; the UnitSPA06 driver converts to hPa.

Enumeration Type Documentation

◆ Mode

enum class m5::unit::spa06::Mode : uint8_t
strong

Continuous measurement type; the enum value is the MEAS_CFG MEAS_CTRL[2:0] background-mode code.

Enumerator
Pressure 

Continuous pressure only (temperature() returns NaN)

Temperature 

Continuous temperature only (pressure() returns NaN)

PressureAndTemperature 

Continuous pressure and temperature (both valid)

◆ Oversampling

enum class m5::unit::spa06::Oversampling : uint8_t
strong

Oversampling factor; the enum value is the PM_PRC/TM_PRC nibble (datasheet Table 4)

Enumerator
X1 

x1 (single, lowest precision)

X2 

x2

X4 

x4

X8 

x8

X16 

x16 (standard)

X32 

x32

X64 

x64

X128 

x128 (highest precision)

◆ Rate

enum class m5::unit::spa06::Rate : uint8_t
strong

Measurement rate; the enum value is the PM_RATE/TMP_RATE nibble (measurements per second)

Enumerator
Rate1 

1 measurement/s

Rate2 

2 measurements/s

Rate4 

4 measurements/s

Rate8 

8 measurements/s

Rate16 

16 measurements/s

Rate32 

32 measurements/s

Rate64 

64 measurements/s

Rate128 

128 measurements/s

Function Documentation

◆ valid_combination()

bool m5::unit::spa06::valid_combination ( const Oversampling osrs_p,
const Oversampling osrs_t,
const Rate rate,
const Mode mode )
inline

True if a rate/oversampling/mode combination fits the datasheet timing budget.

Background mode shares a 1-second timeline between pressure and temperature (single ADC). The active measurement type(s) must fit: Rate x (sum of active measurement times) < 1 second (datasheet 7.3 Note under Table 9). Pressure and temperature run at the same Rate in this driver.