8static const uint8_t QMP6988_CHIP_ID = 0x5C;
10static const uint8_t QMP6988_CHIP_ID_REG = 0xD1;
11static const uint8_t QMP6988_RESET_REG = 0xE0;
12static const uint8_t QMP6988_DEVICE_STAT_REG = 0xF3;
13static const uint8_t QMP6988_CTRLMEAS_REG = 0xF4;
15static const uint8_t QMP6988_PRESSURE_MSB_REG = 0xF7;
16static const uint8_t QMP6988_TEMPERATURE_MSB_REG = 0xFA;
19static const uint8_t QMP6988_CALIBRATION_DATA_START = 0xA0;
20static const uint8_t QMP6988_CALIBRATION_DATA_LENGTH = 25;
23static const uint8_t QMP6988_SLEEP_MODE = 0x00;
24static const uint8_t QMP6988_FORCED_MODE = 0x01;
25static const uint8_t QMP6988_NORMAL_MODE = 0x03;
27static const uint8_t QMP6988_CTRLMEAS_REG_MODE_POS = 0;
28static const uint8_t QMP6988_CTRLMEAS_REG_MODE_MSK = 0x03;
29static const uint8_t QMP6988_CTRLMEAS_REG_MODE_LEN = 2;
31static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_POS = 5;
32static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_MSK = 0xE0;
33static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_LEN = 3;
35static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_POS = 2;
36static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_MSK = 0x1C;
37static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_LEN = 3;
39static const uint8_t QMP6988_CONFIG_REG = 0xF1;
40static const uint8_t QMP6988_CONFIG_REG_FILTER_POS = 0;
41static const uint8_t QMP6988_CONFIG_REG_FILTER_MSK = 0x07;
42static const uint8_t QMP6988_CONFIG_REG_FILTER_LEN = 3;
44static const uint32_t SUBTRACTOR = 8388608;
49 switch (oversampling) {
92 ESP_LOGE(TAG,
"Read chip ID (0xD1) failed");
102 uint8_t a_data_uint8_tr[QMP6988_CALIBRATION_DATA_LENGTH] = {0};
104 for (uint8_t
len = 0;
len < QMP6988_CALIBRATION_DATA_LENGTH;
len += 1) {
106 ESP_LOGE(TAG,
"Read calibration data (0xA0) error");
112 (int32_t)
encode_uint32(a_data_uint8_tr[18], a_data_uint8_tr[19], (a_data_uint8_tr[24] & 0x0f) << 4, 0);
119 (int32_t)
encode_uint32(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[24] & 0xf0, 0);
132 "Calibration data:\n"
133 " COE_a0[%" PRId32
"] COE_a1[%d] COE_a2[%d] COE_b00[%" PRId32
"]\n"
134 " COE_bt1[%d] COE_bt2[%d] COE_bp1[%d] COE_b11[%d]\n"
135 " COE_bp2[%d] COE_b12[%d] COE_b21[%d] COE_bp3[%d]",
156 "Int calibration data:\n"
157 " a0[%" PRId32
"] a1[%" PRId32
"] a2[%" PRId32
"] b00[%" PRId32
"]\n"
158 " bt1[%lld] bt2[%lld] bp1[%lld] b11[%lld]\n"
159 " bp2[%lld] b12[%lld] b21[%lld] bp3[%lld]",
171 wk1 = ((int64_t) ik->a1 * (int64_t) dt);
172 wk2 = ((int64_t) ik->a2 * (int64_t) dt) >> 14;
173 wk2 = (wk2 * (int64_t) dt) >> 10;
174 wk2 = ((wk1 + wk2) / 32767) >> 19;
175 ret = (int16_t) ((ik->a0 + wk2) >> 4);
181 int64_t wk1, wk2, wk3;
184 wk1 = ((int64_t) ik->bt1 * (int64_t) tx);
185 wk2 = ((int64_t) ik->bp1 * (int64_t) dp) >> 5;
187 wk2 = ((int64_t) ik->bt2 * (int64_t) tx) >> 1;
188 wk2 = (wk2 * (int64_t) tx) >> 8;
190 wk2 = ((int64_t) ik->b11 * (int64_t) tx) >> 4;
191 wk2 = (wk2 * (int64_t) dp) >> 1;
193 wk2 = ((int64_t) ik->bp2 * (int64_t) dp) >> 13;
194 wk2 = (wk2 * (int64_t) dp) >> 1;
197 wk2 = ((int64_t) ik->b12 * (int64_t) tx);
198 wk2 = (wk2 * (int64_t) tx) >> 22;
199 wk2 = (wk2 * (int64_t) dp) >> 1;
201 wk2 = ((int64_t) ik->b21 * (int64_t) tx) >> 6;
202 wk2 = (wk2 * (int64_t) dp) >> 23;
203 wk2 = (wk2 * (int64_t) dp) >> 1;
205 wk2 = ((int64_t) ik->bp3 * (int64_t) dp) >> 12;
206 wk2 = (wk2 * (int64_t) dp) >> 23;
207 wk2 = (wk2 * (int64_t) dp);
219 if (!this->
write_byte(QMP6988_RESET_REG, 0xe6)) {
220 ESP_LOGE(TAG,
"Software Reset (0xe6) failed");
230 ESP_LOGD(TAG,
"Setting Power mode to: %d",
power_mode);
237 }
else if (
power_mode == QMP6988_FORCED_MODE) {
239 }
else if (
power_mode == QMP6988_NORMAL_MODE) {
244 ESP_LOGD(TAG,
"Set Power mode 0xf4=0x%x \r\n", data);
252 data = (filter & QMP6988_CONFIG_REG_FILTER_MSK);
262 data |= (oversampling_p << 2);
272 data |= (oversampling_t << 5);
279 altitude = (powf((101325 /
pressure), 1 / 5.257f) - 1) * (temp + 273.15f) / 0.0065f;
286 int32_t p_raw, t_raw;
287 uint8_t a_data_uint8_tr[6] = {0};
288 int32_t t_int, p_int;
290 err = this->
read_register(QMP6988_PRESSURE_MSB_REG, a_data_uint8_tr, 6);
292 ESP_LOGE(TAG,
"Error reading raw pressure/temp values");
296 p_read =
encode_uint24(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[2]);
297 p_raw = (int32_t) (p_read - SUBTRACTOR);
299 t_read =
encode_uint24(a_data_uint8_tr[3], a_data_uint8_tr[4], a_data_uint8_tr[5]);
300 t_raw = (int32_t) (t_read - SUBTRACTOR);
325 ESP_LOGCONFIG(TAG,
"QMP6988:");
326 LOG_I2C_DEVICE(
this);
327 LOG_UPDATE_INTERVAL(
this);
333 " Pressure Oversampling: %s\n"
343 float pressurehectopascals = this->
qmp6988_data_.pressure / 100;
346 ESP_LOGD(TAG,
"Temperature=%.2f°C, Pressure=%.2fhPa",
temperature, pressurehectopascals);
void mark_failed()
Mark this component as failed.
bool status_comm_result(bool ok)
Clears the warning when ok, else sets it with message (default "Communication failed"); returns ok.
bool write_byte(uint8_t a_register, uint8_t data) const
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len)
reads an array of bytes from a specific register in the I²C device
QMP6988IIRFilter iir_filter_
void write_filter_(QMP6988IIRFilter filter)
sensor::Sensor * temperature_sensor_
void calculate_altitude_(float pressure, float temp)
int32_t get_compensated_pressure_(qmp6988_ik_data_t *ik, int32_t dp, int16_t tx)
QMP6988Oversampling pressure_oversampling_
bool calculate_pressure_()
void write_oversampling_pressure_(QMP6988Oversampling oversampling_p)
bool get_calibration_data_()
sensor::Sensor * pressure_sensor_
QMP6988Oversampling temperature_oversampling_
void dump_config() override
int16_t get_compensated_temperature_(qmp6988_ik_data_t *ik, int32_t dt)
void set_power_mode_(uint8_t power_mode)
qmp6988_data_t qmp6988_data_
void write_oversampling_temperature_(QMP6988Oversampling oversampling_t)
void publish_state(float state)
Publish a new state to the front-end.
@ ERROR_OK
No error found during execution of method.
struct Qmp6988IkData { int32_t a0, b00; int32_t a1, a2; int64_t bt1, bt2, bp1, b11, bp2, b12, b21, bp3;} qmp6988_ik_data_t
ESPHOME_LOG_TAG(TAG, "qmp6988")
@ QMP6988_OVERSAMPLING_8X
@ QMP6988_OVERSAMPLING_SKIPPED
@ QMP6988_OVERSAMPLING_16X
@ QMP6988_OVERSAMPLING_32X
@ QMP6988_OVERSAMPLING_2X
@ QMP6988_OVERSAMPLING_64X
@ QMP6988_OVERSAMPLING_1X
@ QMP6988_OVERSAMPLING_4X
constexpr uint32_t encode_uint24(uint8_t byte1, uint8_t byte2, uint8_t byte3)
Encode a 24-bit value given three bytes in most to least significant byte order.
constexpr T encode_value(const uint8_t *bytes)
Encode a value from its constituent bytes (from most to least significant) in an array with length si...
constexpr uint32_t encode_uint32(uint8_t byte1, uint8_t byte2, uint8_t byte3, uint8_t byte4)
Encode a 32-bit value given four bytes in most to least significant byte order.
void HOT delay(uint32_t ms)