ESPHome  2024.10.2
dps310.h
Go to the documentation of this file.
1 #pragma once
2 
6 
7 namespace esphome {
8 namespace dps310 {
9 
10 static const uint8_t DPS310_REG_PRS_B2 = 0x00; // Highest byte of pressure data
11 static const uint8_t DPS310_REG_TMP_B2 = 0x03; // Highest byte of temperature data
12 static const uint8_t DPS310_REG_PRS_CFG = 0x06; // Pressure configuration
13 static const uint8_t DPS310_REG_TMP_CFG = 0x07; // Temperature configuration
14 static const uint8_t DPS310_REG_MEAS_CFG = 0x08; // Sensor configuration
15 static const uint8_t DPS310_REG_CFG = 0x09; // Interrupt/FIFO configuration
16 static const uint8_t DPS310_REG_RESET = 0x0C; // Soft reset
17 static const uint8_t DPS310_REG_PROD_REV_ID = 0x0D; // Register that contains the part ID
18 static const uint8_t DPS310_REG_COEF = 0x10; // Top of calibration coefficient data space
19 static const uint8_t DPS310_REG_TMP_COEF_SRC = 0x28; // Temperature calibration src
20 
21 static const uint8_t DPS310_BIT_PRS_RDY = 0x10; // Pressure measurement is ready
22 static const uint8_t DPS310_BIT_TMP_RDY = 0x20; // Temperature measurement is ready
23 static const uint8_t DPS310_BIT_SENSOR_RDY = 0x40; // Sensor initialization complete when bit is set
24 static const uint8_t DPS310_BIT_COEF_RDY = 0x80; // Coefficients are available when bit is set
25 static const uint8_t DPS310_BIT_TMP_COEF_SRC = 0x80; // Temperature measurement source (0 = ASIC, 1 = MEMS element)
26 static const uint8_t DPS310_BIT_REQ_PRES = 0x01; // Set this bit to request pressure reading
27 static const uint8_t DPS310_BIT_REQ_TEMP = 0x02; // Set this bit to request temperature reading
28 
29 static const uint8_t DPS310_CMD_RESET = 0x89; // What to write to reset the device
30 
31 static const uint8_t DPS310_VAL_PRS_CFG = 0x01; // Value written to DPS310_REG_PRS_CFG at startup
32 static const uint8_t DPS310_VAL_TMP_CFG = 0x01; // Value written to DPS310_REG_TMP_CFG at startup
33 static const uint8_t DPS310_VAL_REG_CFG = 0x00; // Value written to DPS310_REG_CFG at startup
34 
35 static const uint8_t DPS310_INIT_TIMEOUT = 20; // How long to wait for DPS310 start-up to complete
36 static const uint8_t DPS310_NUM_COEF_REGS = 18; // Number of coefficients we need to read from the device
37 static const int32_t DPS310_SCALE_FACTOR = 1572864; // Measurement compensation scale factor
38 
40  public:
41  void setup() override;
42  void dump_config() override;
43  float get_setup_priority() const override;
44  void update() override;
45 
46  void set_temperature_sensor(sensor::Sensor *temperature_sensor) { temperature_sensor_ = temperature_sensor; }
47  void set_pressure_sensor(sensor::Sensor *pressure_sensor) { pressure_sensor_ = pressure_sensor; }
48 
49  protected:
50  void read_();
51  void read_pressure_();
52  void read_temperature_();
53  void calculate_values_(int32_t raw_temperature, int32_t raw_pressure);
54  static int32_t twos_complement(int32_t val, uint8_t bits);
55 
59  int16_t c0_, c1_, c01_, c11_, c20_, c21_, c30_;
60  uint8_t prod_rev_id_;
62 };
63 
64 } // namespace dps310
65 } // namespace esphome
void dump_config() override
Definition: dps310.cpp:88
sensor::Sensor * temperature_sensor_
Definition: dps310.h:56
mopeka_std_values val[4]
This class simplifies creating components that periodically check a state.
Definition: component.h:283
void calculate_values_(int32_t raw_temperature, int32_t raw_pressure)
Definition: dps310.cpp:163
sensor::Sensor * pressure_sensor_
Definition: dps310.h:57
void set_pressure_sensor(sensor::Sensor *pressure_sensor)
Definition: dps310.h:47
float get_setup_priority() const override
Definition: dps310.cpp:101
Implementation of SPI Controller mode.
Definition: a01nyub.cpp:7
Base-class for all sensors.
Definition: sensor.h:57
void set_temperature_sensor(sensor::Sensor *temperature_sensor)
Definition: dps310.h:46
This Class provides the methods to read/write bytes from/to an i2c device.
Definition: i2c.h:133
static int32_t twos_complement(int32_t val, uint8_t bits)
Definition: dps310.cpp:181