5#define DPS310_I2CADDR_DEFAULT (0x77)
7#define DPS310_PRSB2 0x00
8#define DPS310_TMPB2 0x03
9#define DPS310_PRSCFG 0x06
10#define DPS310_TMPCFG 0x07
11#define DPS310_MEASCFG 0x08
12#define DPS310_CFGREG 0x09
13#define DPS310_RESET 0x0C
14#define DPS310_PRODREVID 0x0D
15#define DPS310_TMPCOEFSRCE 0x28
63 i2c_.
Init(i2c_config);
66 void Write(uint8_t *data, uint16_t size)
72 void Read(uint8_t *data, uint16_t size)
82 void Write8(uint8_t reg, uint8_t value)
93 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
119 return uint16_t(buffer[0]) << 8 | uint16_t(buffer[1]);
132 return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8
133 | uint32_t(buffer[2]);
195 void Write(uint8_t *data, uint16_t size)
200 void Read(uint8_t *data, uint16_t size)
213 buffer[0] = reg & ~0x80;
220 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
222 reg = uint8_t(reg | 0x80);
247 return uint16_t(buffer[0]) << 8 | uint16_t(buffer[1]);
260 return uint32_t(buffer[0]) << 16 | uint32_t(buffer[1]) << 8
261 | uint32_t(buffer[2]);
280template <
typename Transport>
288 = {524288, 1572864, 3670016, 7864320, 253952, 516096, 1040384, 2088960};
389 if(val & ((uint32_t)1 << (bits - 1)))
391 val -= (uint32_t)1 << bits;
405 for(uint8_t addr = 0; addr < 18; addr++)
407 coeffs[addr] =
Read8(0x10 + addr);
409 _c0 = ((uint16_t)coeffs[0] << 4) | (((uint16_t)coeffs[1] >> 4) & 0x0F);
412 _c1 =
twosComplement((((uint16_t)coeffs[1] & 0x0F) << 8) | coeffs[2],
415 _c00 = ((uint32_t)coeffs[3] << 12) | ((uint32_t)coeffs[4] << 4)
416 | (((uint32_t)coeffs[5] >> 4) & 0x0F);
419 _c10 = (((uint32_t)coeffs[5] & 0x0F) << 16) | ((uint32_t)coeffs[6] << 8)
420 | (uint32_t)coeffs[7];
423 _c01 =
twosComplement(((uint16_t)coeffs[8] << 8) | (uint16_t)coeffs[9],
426 ((uint16_t)coeffs[10] << 8) | (uint16_t)coeffs[11], 16);
428 ((uint16_t)coeffs[12] << 8) | (uint16_t)coeffs[13], 16);
430 ((uint16_t)coeffs[14] << 8) | (uint16_t)coeffs[15], 16);
432 ((uint16_t)coeffs[16] << 8) | (uint16_t)coeffs[17], 16);
458 altitude = 44330 * (1.0 - pow((_pressure / 100) / seaLevelhPa, 0.1903));
528 _scaled_rawtemp = (float)raw_temperature / temp_scale;
529 _temperature = _scaled_rawtemp * _c1 + _c0 / 2.0;
531 _pressure = (float)raw_pressure / pressure_scale;
538 * ((int32_t)_c20 + _pressure * (int32_t)_c30))
542 * ((int32_t)_c11 + _pressure * (int32_t)_c21));
561 return transport_.Write8(reg, value);
565 void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
567 return transport_.ReadReg(reg, buff, size);
574 uint8_t
Read8(uint8_t reg) {
return transport_.Read8(reg); }
580 uint16_t
Read16(uint8_t reg) {
return transport_.Read16(reg); }
586 uint32_t
Read24(uint8_t reg) {
return transport_.Read24(reg); }
594 uint16_t temp =
Read16(reg);
595 return (temp >> 8) | (temp << 8);
611 uint8_t
ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
613 uint8_t val =
Read8(reg);
615 return val & ((1 << (bits)) - 1);
618 void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
620 uint8_t val =
Read8(reg);
623 uint8_t mask = (1 << (bits)) - 1;
628 val |= data << shift;
640 Transport transport_;
642 int16_t _c0, _c1, _c01, _c11, _c20, _c21, _c30;
645 int32_t raw_pressure, raw_temperature;
646 float _temperature, _scaled_rawtemp, _pressure;
647 int32_t temp_scale, pressure_scale;
Device support for DPS310 Barometric Pressure and Altitude Sensor.
Definition dps310.h:282
bool temperatureAvailable(void)
Definition dps310.h:439
static int32_t twosComplement(int32_t val, uint8_t bits)
Definition dps310.h:387
float GetPressure()
Definition dps310.h:553
float GetAltitude(float seaLevelhPa)
Definition dps310.h:452
Result
Definition dps310.h:335
@ OK
Definition dps310.h:336
@ ERR
Definition dps310.h:337
dps310_mode_t
Definition dps310.h:318
@ DPS310_CONT_TEMP
Continuous pressure measurements.
Definition dps310.h:323
@ DPS310_IDLE
Stopped/idle.
Definition dps310.h:319
@ DPS310_CONT_PRESSURE
Continuous pressure measurements.
Definition dps310.h:322
@ DPS310_ONE_PRESSURE
Take single pressure measurement.
Definition dps310.h:320
@ DPS310_CONT_PRESTEMP
Continuous temp+pressure measurements.
Definition dps310.h:324
@ DPS310_ONE_TEMPERATURE
Take single temperature measurement.
Definition dps310.h:321
void Write8(uint8_t reg, uint8_t value)
Definition dps310.h:559
void reset(void)
Definition dps310.h:374
int16_t ReadS16_LE(uint8_t reg)
Definition dps310.h:608
uint16_t Read16_LE(uint8_t reg)
Definition dps310.h:592
int32_t oversample_scalefactor[8]
Definition dps310.h:288
float GetTemperature()
Definition dps310.h:548
Dps310()
Definition dps310.h:284
dps310_oversample_t
Definition dps310.h:305
@ DPS310_16SAMPLES
16 Hz
Definition dps310.h:310
@ DPS310_2SAMPLES
2 Hz
Definition dps310.h:307
@ DPS310_1SAMPLE
1 Hz
Definition dps310.h:306
@ DPS310_8SAMPLES
8 Hz
Definition dps310.h:309
@ DPS310_64SAMPLES
64 Hz
Definition dps310.h:312
@ DPS310_128SAMPLES
128 Hz
Definition dps310.h:313
@ DPS310_4SAMPLES
4 Hz
Definition dps310.h:308
@ DPS310_32SAMPLES
32 Hz
Definition dps310.h:311
uint16_t Read16(uint8_t reg)
Definition dps310.h:580
int16_t ReadS16(uint8_t reg)
Definition dps310.h:602
Result Init(Config config)
Definition dps310.h:343
void setMode(dps310_mode_t mode)
Definition dps310.h:469
void Process(void)
Definition dps310.h:523
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition dps310.h:565
uint32_t Read24(uint8_t reg)
Definition dps310.h:586
void WriteBits(uint8_t reg, uint8_t data, uint8_t bits, uint8_t shift)
Definition dps310.h:618
dps310_rate_t
Definition dps310.h:292
@ DPS310_16HZ
16 Hz
Definition dps310.h:297
@ DPS310_128HZ
128 Hz
Definition dps310.h:300
@ DPS310_8HZ
8 Hz
Definition dps310.h:296
@ DPS310_1HZ
1 Hz
Definition dps310.h:293
@ DPS310_32HZ
32 Hz
Definition dps310.h:298
@ DPS310_2HZ
2 Hz
Definition dps310.h:294
@ DPS310_4HZ
4 Hz
Definition dps310.h:295
@ DPS310_64HZ
64 Hz
Definition dps310.h:299
Result GetTransportError()
Definition dps310.h:636
uint8_t ReadBits(uint8_t reg, uint8_t bits, uint8_t shift)
Definition dps310.h:611
~Dps310()
Definition dps310.h:285
uint8_t Read8(uint8_t reg)
Definition dps310.h:574
void configurePressure(dps310_rate_t rate, dps310_oversample_t os)
Definition dps310.h:476
void configureTemperature(dps310_rate_t rate, dps310_oversample_t os)
Definition dps310.h:498
void _readCalibration(void)
Definition dps310.h:396
bool pressureAvailable(void)
Definition dps310.h:445
uint32_t Read24(uint8_t reg)
Definition dps310.h:126
uint8_t Read8(uint8_t reg)
Definition dps310.h:103
void Read(uint8_t *data, uint16_t size)
Definition dps310.h:72
bool GetError()
Definition dps310.h:136
uint16_t Read16(uint8_t reg)
Definition dps310.h:114
Dps310I2CTransport()
Definition dps310.h:27
void Write(uint8_t *data, uint16_t size)
Definition dps310.h:66
~Dps310I2CTransport()
Definition dps310.h:28
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition dps310.h:93
void Init(Config config)
Definition dps310.h:51
void Write8(uint8_t reg, uint8_t value)
Definition dps310.h:82
Dps310SpiTransport()
Definition dps310.h:155
uint16_t Read16(uint8_t reg)
Definition dps310.h:242
uint32_t Read24(uint8_t reg)
Definition dps310.h:254
void Write(uint8_t *data, uint16_t size)
Definition dps310.h:195
void Init(Config config)
Definition dps310.h:176
uint8_t Read8(uint8_t reg)
Definition dps310.h:231
void Write8(uint8_t reg, uint8_t value)
Definition dps310.h:209
void Read(uint8_t *data, uint16_t size)
Definition dps310.h:200
bool GetError()
Definition dps310.h:264
void ReadReg(uint8_t reg, uint8_t *buff, uint8_t size)
Definition dps310.h:220
~Dps310SpiTransport()
Definition dps310.h:156
Result Init(const Config &config)
Result ReceiveBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Result TransmitBlocking(uint16_t address, uint8_t *data, uint16_t size, uint32_t timeout)
Result BlockingTransmit(uint8_t *buff, size_t size, uint32_t timeout=100)
Result BlockingReceive(uint8_t *buffer, uint16_t size, uint32_t timeout)
Result Init(const Config &config)
static void Delay(uint32_t delay_ms)
#define DPS310_PRODREVID
Register that contains the part ID.
Definition dps310.h:14
#define DPS310_I2CADDR_DEFAULT
Default breakout addres.
Definition dps310.h:5
#define DPS310_TMPB2
Highest byte of temperature data.
Definition dps310.h:8
#define DPS310_PRSB2
Highest byte of pressure data.
Definition dps310.h:7
#define DPS310_CFGREG
Interrupt/FIFO configuration.
Definition dps310.h:12
#define DPS310_TMPCFG
Temperature configuration.
Definition dps310.h:10
#define DPS310_MEASCFG
Sensor configuration.
Definition dps310.h:11
#define DPS310_RESET
Soft reset.
Definition dps310.h:13
#define DPS310_PRSCFG
Pressure configuration.
Definition dps310.h:9
#define DPS310_TMPCOEFSRCE
Temperature calibration src.
Definition dps310.h:15
Hardware defines and helpers for daisy field platform.
Definition index.h:2
@ PORTB
Definition daisy_core.h:178
@ PORTG
Definition daisy_core.h:183
Transport::Config transport_config
Definition dps310.h:329
Config()
Definition dps310.h:331
Config()
Definition dps310.h:39
Pin scl
Definition dps310.h:34
I2CHandle::Config::Speed speed
Definition dps310.h:33
uint8_t address
Definition dps310.h:37
I2CHandle::Config::Peripheral periph
Definition dps310.h:32
Pin sda
Definition dps310.h:35
Config()
Definition dps310.h:166
Pin sclk
Definition dps310.h:161
Pin miso
Definition dps310.h:162
Pin mosi
Definition dps310.h:163
Pin nss
Definition dps310.h:164
SpiHandle::Config::Peripheral periph
Definition dps310.h:160
struct daisy::I2CHandle::Config::@15 pin_config
Mode mode
Definition i2c.h:65
Pin scl
Definition i2c.h:60
Speed speed
Definition i2c.h:64
Peripheral periph
Definition i2c.h:57
Peripheral
Definition i2c.h:40
Pin sda
Definition i2c.h:61
representation of hardware port/pin combination
Definition daisy_core.h:193
ClockPolarity clock_polarity
Definition spi.h:104
Peripheral periph
Definition spi.h:100
Pin nss
Definition spi.h:88
struct daisy::SpiHandle::Config::@18 pin_config
Mode mode
Definition spi.h:101
Peripheral
Definition spi.h:29
Pin mosi
Definition spi.h:87
Pin sclk
Definition spi.h:85
ClockPhase clock_phase
Definition spi.h:105
BaudPrescaler baud_prescaler
Definition spi.h:107
Pin miso
Definition spi.h:86
Direction direction
Definition spi.h:102