Skip to content

daisy::Dps310

Module: External

Device support for DPS310 Barometric Pressure and Altitude Sensor. More...

#include <dps310.h>

Public Classes

Name
struct Config

Public Types

Name
enum dps310_rate_t
enum dps310_oversample_t
enum dps310_mode_t
enum Result

Public Functions

Name
Dps310()
~Dps310()
Result Init(Config config)
void reset(void )
void _readCalibration(void )
bool temperatureAvailable(void )
bool pressureAvailable(void )
float GetAltitude(float seaLevelhPa)
void setMode(dps310_mode_t mode)
void configurePressure(dps310_rate_t rate, dps310_oversample_t os)
void configureTemperature(dps310_rate_t rate, dps310_oversample_t os)
void Process(void )
float GetTemperature()
float GetPressure()
void Write8(uint8_t reg, uint8_t value)
void ReadReg(uint8_t reg, uint8_t * buff, uint8_t size)
uint8_t Read8(uint8_t reg)
uint16_t Read16(uint8_t reg)
uint32_t Read24(uint8_t reg)
uint16_t Read16_LE(uint8_t reg)
int16_t ReadS16(uint8_t reg)
int16_t ReadS16_LE(uint8_t reg)
uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
Result GetTransportError()
int32_t twosComplement(int32_t val, uint8_t bits)

Public Attributes

Name
int32_t[8] oversample_scalefactor

Detailed Description

template <typename Transport >
class daisy::Dps310;

Device support for DPS310 Barometric Pressure and Altitude Sensor.

Author: beserge

Date: January 2022

Public Types Documentation

enum dps310_rate_t

Enumerator Value Description
DPS310_1HZ 1 Hz
DPS310_2HZ 2 Hz
DPS310_4HZ 4 Hz
DPS310_8HZ 8 Hz
DPS310_16HZ 16 Hz
DPS310_32HZ 32 Hz
DPS310_64HZ 64 Hz
DPS310_128HZ 128 Hz

The measurement rate ranges

enum dps310_oversample_t

Enumerator Value Description
DPS310_1SAMPLE 1 Hz
DPS310_2SAMPLES 2 Hz
DPS310_4SAMPLES 4 Hz
DPS310_8SAMPLES 8 Hz
DPS310_16SAMPLES 16 Hz
DPS310_32SAMPLES 32 Hz
DPS310_64SAMPLES 64 Hz
DPS310_128SAMPLES 128 Hz

The oversample rate ranges

enum dps310_mode_t

Enumerator Value Description
DPS310_IDLE 0b000 Stopped/idle.
DPS310_ONE_PRESSURE 0b001 Take single pressure measurement.
DPS310_ONE_TEMPERATURE 0b010 Take single temperature measurement.
DPS310_CONT_PRESSURE 0b101 Continuous pressure measurements.
DPS310_CONT_TEMP 0b110 Continuous pressure measurements.
DPS310_CONT_PRESTEMP 0b111 Continuous temp+pressure measurements.

The oversample rate ranges

enum Result

Enumerator Value Description
OK 0
ERR

Public Functions Documentation

function Dps310

inline Dps310()

function ~Dps310

inline ~Dps310()

function Init

inline Result Init(
    Config config
)

Parameters:

  • config Configuration settings

Initialize the Dps310 device


function reset

inline void reset(
    void 
)

Performs a software reset


function _readCalibration

inline void _readCalibration(
    void 
)

function temperatureAvailable

inline bool temperatureAvailable(
    void 
)

Return: True if new data available to read

Whether new temperature data is available


function pressureAvailable

inline bool pressureAvailable(
    void 
)

Return: True if new data available to read

Whether new pressure data is available


function GetAltitude

inline float GetAltitude(
    float seaLevelhPa
)

Parameters:

  • seaLevelhPa The current hPa at sea level.

Return: The approximate altitude above sea level in meters.

Calculates the approximate altitude using barometric pressure and the supplied sea level hPa as a reference.


function setMode

inline void setMode(
    dps310_mode_t mode
)

Parameters:

  • mode can be DPS310_IDLE, one shot: DPS310_ONE_PRESSURE or DPS310_ONE_TEMPERATURE, continuous: DPS310_CONT_PRESSURE, DPS310_CONT_TEMP, DPS310_CONT_PRESTEMP

Set the operational mode of the sensor (continuous or one-shot)


function configurePressure

inline void configurePressure(
    dps310_rate_t rate,
    dps310_oversample_t os
)

Parameters:

  • rate How many samples per second to take
  • os How many oversamples to average

Set the sample rate and oversampling averaging for pressure


function configureTemperature

inline void configureTemperature(
    dps310_rate_t rate,
    dps310_oversample_t os
)

Parameters:

  • rate How many samples per second to take
  • os How many oversamples to average

Set the sample rate and oversampling averaging for temperature


function Process

inline void Process(
    void 
)

Read the XYZ data from the sensor and store in the internal raw_pressure, raw_temperature, _pressure and _temperature variables.


function GetTemperature

inline float GetTemperature()

Return: temp in degrees Centigrade

Get last temperature reading


function GetPressure

inline float GetPressure()

Return: Pressure in hPa

Get the last pressure reading


function Write8

inline void Write8(
    uint8_t reg,
    uint8_t value
)

Parameters:

  • reg the register address to write to
  • value the value to write to the register

Writes an 8 bit value


function ReadReg

inline void ReadReg(
    uint8_t reg,
    uint8_t * buff,
    uint8_t size
)

Read from a reg address a defined number of bytes


function Read8

inline uint8_t Read8(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the data uint8_t read from the device

Reads an 8 bit value


function Read16

inline uint16_t Read16(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 16 bit data value read from the device

Reads a 16 bit value over I2C or SPI


function Read24

inline uint32_t Read24(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 24 bit data value read from the device

Reads a 24 bit value


function Read16_LE

inline uint16_t Read16_LE(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 16 bit data value read from the device

Reads a signed 16 bit little endian value over I2C or SPI


function ReadS16

inline int16_t ReadS16(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 16 bit data value read from the device

Reads a signed 16 bit value over I2C or SPI


function ReadS16_LE

inline int16_t ReadS16_LE(
    uint8_t reg
)

Parameters:

  • reg the register address to read from

Return: the 16 bit data value read from the device

Reads a signed little endian 16 bit value over I2C or SPI


function ReadBits

inline uint8_t ReadBits(
    uint8_t reg,
    uint8_t bits,
    uint8_t shift
)

function WriteBits

inline void WriteBits(
    uint8_t reg,
    uint8_t data,
    uint8_t bits,
    uint8_t shift
)

function GetTransportError

inline Result GetTransportError()

Return: Whether the transport has errored since the last check

Get and reset the transport error flag


function twosComplement

static inline int32_t twosComplement(
    int32_t val,
    uint8_t bits
)

Public Attributes Documentation

variable oversample_scalefactor

int32_t[8] oversample_scalefactor = {524288, 1572864, 3670016, 7864320, 253952, 516096, 1040384, 2088960};

Updated on 2024-01-03 at 19:41:01 +0000