9static const uint8_t QMP6988_CHIP_ID = 0x5C;
11static const uint8_t QMP6988_CHIP_ID_REG = 0xD1;
12static const uint8_t QMP6988_RESET_REG = 0xE0;
13static const uint8_t QMP6988_DEVICE_STAT_REG = 0xF3;
14static const uint8_t QMP6988_CTRLMEAS_REG = 0xF4;
16static const uint8_t QMP6988_PRESSURE_MSB_REG = 0xF7;
17static const uint8_t QMP6988_TEMPERATURE_MSB_REG = 0xFA;
20static const uint8_t QMP6988_CALIBRATION_DATA_START = 0xA0;
21static const uint8_t QMP6988_CALIBRATION_DATA_LENGTH = 25;
24static const uint8_t QMP6988_SLEEP_MODE = 0x00;
25static const uint8_t QMP6988_FORCED_MODE = 0x01;
26static const uint8_t QMP6988_NORMAL_MODE = 0x03;
28static const uint8_t QMP6988_CTRLMEAS_REG_MODE_POS = 0;
29static const uint8_t QMP6988_CTRLMEAS_REG_MODE_MSK = 0x03;
30static const uint8_t QMP6988_CTRLMEAS_REG_MODE_LEN = 2;
32static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_POS = 5;
33static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_MSK = 0xE0;
34static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_LEN = 3;
36static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_POS = 2;
37static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_MSK = 0x1C;
38static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_LEN = 3;
40static const uint8_t QMP6988_CONFIG_REG = 0xF1;
41static const uint8_t QMP6988_CONFIG_REG_FILTER_POS = 0;
42static const uint8_t QMP6988_CONFIG_REG_FILTER_MSK = 0x07;
43static const uint8_t QMP6988_CONFIG_REG_FILTER_LEN = 3;
45static const uint32_t SUBTRACTOR = 8388608;
53 return OversamplingStrings::get_log_str(
static_cast<uint8_t
>(
value), OversamplingStrings::LAST_INDEX);
60 return IIRFilterStrings::get_log_str(
static_cast<uint8_t
>(
value), IIRFilterStrings::LAST_INDEX);
65 ESP_LOGE(TAG,
"Read chip ID (0xD1) failed");
75 uint8_t a_data_uint8_tr[QMP6988_CALIBRATION_DATA_LENGTH] = {0};
77 for (uint8_t
len = 0;
len < QMP6988_CALIBRATION_DATA_LENGTH;
len += 1) {
79 ESP_LOGE(TAG,
"Read calibration data (0xA0) error");
85 (int32_t)
encode_uint32(a_data_uint8_tr[18], a_data_uint8_tr[19], (a_data_uint8_tr[24] & 0x0f) << 4, 0);
92 (int32_t)
encode_uint32(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[24] & 0xf0, 0);
105 "Calibration data:\n"
106 " COE_a0[%" PRId32
"] COE_a1[%d] COE_a2[%d] COE_b00[%" PRId32
"]\n"
107 " COE_bt1[%d] COE_bt2[%d] COE_bp1[%d] COE_b11[%d]\n"
108 " COE_bp2[%d] COE_b12[%d] COE_b21[%d] COE_bp3[%d]",
129 "Int calibration data:\n"
130 " a0[%" PRId32
"] a1[%" PRId32
"] a2[%" PRId32
"] b00[%" PRId32
"]\n"
131 " bt1[%lld] bt2[%lld] bp1[%lld] b11[%lld]\n"
132 " bp2[%lld] b12[%lld] b21[%lld] bp3[%lld]",
144 wk1 = ((int64_t) ik->a1 * (int64_t) dt);
145 wk2 = ((int64_t) ik->a2 * (int64_t) dt) >> 14;
146 wk2 = (wk2 * (int64_t) dt) >> 10;
147 wk2 = ((wk1 + wk2) / 32767) >> 19;
148 ret = (int16_t) ((ik->a0 + wk2) >> 4);
154 int64_t wk1, wk2, wk3;
157 wk1 = ((int64_t) ik->bt1 * (int64_t) tx);
158 wk2 = ((int64_t) ik->bp1 * (int64_t) dp) >> 5;
160 wk2 = ((int64_t) ik->bt2 * (int64_t) tx) >> 1;
161 wk2 = (wk2 * (int64_t) tx) >> 8;
163 wk2 = ((int64_t) ik->b11 * (int64_t) tx) >> 4;
164 wk2 = (wk2 * (int64_t) dp) >> 1;
166 wk2 = ((int64_t) ik->bp2 * (int64_t) dp) >> 13;
167 wk2 = (wk2 * (int64_t) dp) >> 1;
170 wk2 = ((int64_t) ik->b12 * (int64_t) tx);
171 wk2 = (wk2 * (int64_t) tx) >> 22;
172 wk2 = (wk2 * (int64_t) dp) >> 1;
174 wk2 = ((int64_t) ik->b21 * (int64_t) tx) >> 6;
175 wk2 = (wk2 * (int64_t) dp) >> 23;
176 wk2 = (wk2 * (int64_t) dp) >> 1;
178 wk2 = ((int64_t) ik->bp3 * (int64_t) dp) >> 12;
179 wk2 = (wk2 * (int64_t) dp) >> 23;
180 wk2 = (wk2 * (int64_t) dp);
192 if (!this->
write_byte(QMP6988_RESET_REG, 0xe6)) {
193 ESP_LOGE(TAG,
"Software Reset (0xe6) failed");
203 ESP_LOGD(TAG,
"Setting Power mode to: %d",
power_mode);
210 }
else if (
power_mode == QMP6988_FORCED_MODE) {
212 }
else if (
power_mode == QMP6988_NORMAL_MODE) {
217 ESP_LOGD(TAG,
"Set Power mode 0xf4=0x%x \r\n", data);
225 data = (filter & QMP6988_CONFIG_REG_FILTER_MSK);
235 data |= (oversampling_p << 2);
245 data |= (oversampling_t << 5);
252 altitude = (powf((101325 /
pressure), 1 / 5.257f) - 1) * (temp + 273.15f) / 0.0065f;
259 int32_t p_raw, t_raw;
260 uint8_t a_data_uint8_tr[6] = {0};
261 int32_t t_int, p_int;
263 err = this->
read_register(QMP6988_PRESSURE_MSB_REG, a_data_uint8_tr, 6);
265 ESP_LOGE(TAG,
"Error reading raw pressure/temp values");
269 p_read =
encode_uint24(a_data_uint8_tr[0], a_data_uint8_tr[1], a_data_uint8_tr[2]);
270 p_raw = (int32_t) (p_read - SUBTRACTOR);
272 t_read =
encode_uint24(a_data_uint8_tr[3], a_data_uint8_tr[4], a_data_uint8_tr[5]);
273 t_raw = (int32_t) (t_read - SUBTRACTOR);
297void QMP6988Component::dump_config() {
298 ESP_LOGCONFIG(TAG,
"QMP6988:");
299 LOG_I2C_DEVICE(
this);
300 LOG_UPDATE_INTERVAL(
this);
302 LOG_SENSOR(
" ",
"Temperature", this->temperature_sensor_);
303 ESP_LOGCONFIG(TAG,
" Temperature Oversampling: %s",
305 LOG_SENSOR(
" ",
"Pressure", this->pressure_sensor_);
307 " Pressure Oversampling: %s\n"
310 LOG_STR_ARG(iir_filter_to_str(this->
iir_filter_)));
313void QMP6988Component::update() {
318 float pressurehectopascals = this->
qmp6988_data_.pressure / 100;
321 ESP_LOGD(TAG,
"Temperature=%.2f°C, Pressure=%.2fhPa",
temperature, pressurehectopascals);
322 PUBLISH_STATE(this->temperature_sensor_,
temperature);
323 PUBLISH_STATE(this->pressure_sensor_, pressurehectopascals);
struct Qmp6988IkData { int32_t a0, b00; int32_t a1, a2; int64_t bt1, bt2, bp1, b11, bp2, b12, b21, bp3;} qmp6988_ik_data_t
PROGMEM_STRING_TABLE(OversamplingStrings, "None", "1x", "2x", "4x", "8x", "16x", "32x", "64x", "UNKNOWN")
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 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.