8 static const char *
const TAG =
"dps310";
11 uint8_t coef_data_raw[DPS310_NUM_COEF_REGS];
12 auto timer = DPS310_INIT_TIMEOUT;
15 ESP_LOGCONFIG(TAG,
"Setting up DPS310...");
17 if (!this->
write_byte(DPS310_REG_RESET, DPS310_CMD_RESET)) {
23 while (timer-- && (!(reg & DPS310_BIT_SENSOR_RDY) || !(reg & DPS310_BIT_COEF_RDY))) {
24 reg = this->
read_byte(DPS310_REG_MEAS_CFG).value_or(0);
28 if (!(reg & DPS310_BIT_SENSOR_RDY) || !(reg & DPS310_BIT_COEF_RDY)) {
38 if (!this->
read_bytes(DPS310_REG_COEF, coef_data_raw, DPS310_NUM_COEF_REGS)) {
43 if (!this->
read_byte(DPS310_REG_TMP_COEF_SRC, ®)) {
48 if (!this->
write_byte(DPS310_REG_PRS_CFG, DPS310_VAL_PRS_CFG)) {
52 if (!this->
write_byte(DPS310_REG_TMP_CFG, DPS310_VAL_TMP_CFG | (reg & DPS310_BIT_TMP_COEF_SRC))) {
56 if (!this->
write_byte(DPS310_REG_CFG, DPS310_VAL_REG_CFG)) {
60 if (!this->
write_byte(DPS310_REG_MEAS_CFG, 0x07)) {
67 int16_t(((uint16_t) coef_data_raw[0] << 4) | (((uint16_t) coef_data_raw[1] >> 4) & 0x0F)), 12) /
73 this->
c00_ = ((uint32_t) coef_data_raw[3] << 12) | ((uint32_t) coef_data_raw[4] << 4) |
74 (((uint32_t) coef_data_raw[5] >> 4) & 0x0F);
78 (((uint32_t) coef_data_raw[5] & 0x0F) << 16) | ((uint32_t) coef_data_raw[6] << 8) | (uint32_t) coef_data_raw[7];
81 this->
c01_ = int16_t(((uint16_t) coef_data_raw[8] << 8) | (uint16_t) coef_data_raw[9]);
82 this->
c11_ = int16_t(((uint16_t) coef_data_raw[10] << 8) | (uint16_t) coef_data_raw[11]);
83 this->
c20_ = int16_t(((uint16_t) coef_data_raw[12] << 8) | (uint16_t) coef_data_raw[13]);
84 this->
c21_ = int16_t(((uint16_t) coef_data_raw[14] << 8) | (uint16_t) coef_data_raw[15]);
85 this->
c30_ = int16_t(((uint16_t) coef_data_raw[16] << 8) | (uint16_t) coef_data_raw[17]);
89 ESP_LOGCONFIG(TAG,
"DPS310:");
90 ESP_LOGCONFIG(TAG,
" Product ID: %u", this->
prod_rev_id_ & 0x0F);
91 ESP_LOGCONFIG(TAG,
" Revision ID: %u", (this->
prod_rev_id_ >> 4) & 0x0F);
94 ESP_LOGE(TAG,
"Communication with DPS310 failed!");
96 LOG_UPDATE_INTERVAL(
this);
112 if (!this->
read_byte(DPS310_REG_MEAS_CFG, ®)) {
117 if ((!this->
got_pres_) && (reg & DPS310_BIT_PRS_RDY)) {
121 if ((!this->
got_temp_) && (reg & DPS310_BIT_TMP_RDY)) {
139 if (!this->
read_bytes(DPS310_REG_PRS_B2, bytes, 3)) {
145 int32_t((uint32_t(bytes[0]) << 16) | (uint32_t(bytes[1]) << 8) | (uint32_t(bytes[2]))), 24);
150 if (!this->
read_bytes(DPS310_REG_TMP_B2, bytes, 3)) {
156 int32_t((uint32_t(bytes[0]) << 16) | (uint32_t(bytes[1]) << 8) | (uint32_t(bytes[2]))), 24);
164 const float t_raw_sc = (float) raw_temperature / DPS310_SCALE_FACTOR;
165 const float p_raw_sc = (float) raw_pressure / DPS310_SCALE_FACTOR;
170 t_raw_sc * this->
c01_ + t_raw_sc * p_raw_sc * (this->
c11_ + p_raw_sc * this->
c21_)) /
182 if (val & ((uint32_t) 1 << (bits - 1))) {
183 val -= (uint32_t) 1 << bits;
bool read_byte(uint8_t a_register, uint8_t *data, bool stop=true)
const float DATA
For components that import data from directly connected sensors like DHT.
void dump_config() override
void status_set_warning(const char *message="unspecified")
I2CRegister reg(uint8_t a_register)
calls the I2CRegister constructor
void set_timeout(const std::string &name, uint32_t timeout, std::function< void()> &&f)
Set a timeout function with a unique name.
bool read_bytes(uint8_t a_register, uint8_t *data, uint8_t len)
Compat APIs All methods below have been added for compatibility reasons.
sensor::Sensor * temperature_sensor_
void calculate_values_(int32_t raw_temperature, int32_t raw_pressure)
void status_clear_warning()
void publish_state(float state)
Publish a new state to the front-end.
sensor::Sensor * pressure_sensor_
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
virtual void mark_failed()
Mark this component as failed.
float get_setup_priority() const override
Implementation of SPI Controller mode.
std::vector< uint8_t > bytes
static int32_t twos_complement(int32_t val, uint8_t bits)
void IRAM_ATTR HOT delay(uint32_t ms)