7 static const uint8_t QMP6988_CHIP_ID = 0x5C;
9 static const uint8_t QMP6988_CHIP_ID_REG = 0xD1;
10 static const uint8_t QMP6988_RESET_REG = 0xE0;
11 static const uint8_t QMP6988_DEVICE_STAT_REG = 0xF3;
12 static const uint8_t QMP6988_CTRLMEAS_REG = 0xF4;
14 static const uint8_t QMP6988_PRESSURE_MSB_REG = 0xF7;
15 static const uint8_t QMP6988_TEMPERATURE_MSB_REG = 0xFA;
18 static const uint8_t QMP6988_CALIBRATION_DATA_START = 0xA0;
19 static const uint8_t QMP6988_CALIBRATION_DATA_LENGTH = 25;
21 static const uint8_t SHIFT_RIGHT_4_POSITION = 4;
22 static const uint8_t SHIFT_LEFT_2_POSITION = 2;
23 static const uint8_t SHIFT_LEFT_4_POSITION = 4;
24 static const uint8_t SHIFT_LEFT_5_POSITION = 5;
25 static const uint8_t SHIFT_LEFT_8_POSITION = 8;
26 static const uint8_t SHIFT_LEFT_12_POSITION = 12;
27 static const uint8_t SHIFT_LEFT_16_POSITION = 16;
30 static const uint8_t QMP6988_SLEEP_MODE = 0x00;
31 static const uint8_t QMP6988_FORCED_MODE = 0x01;
32 static const uint8_t QMP6988_NORMAL_MODE = 0x03;
34 static const uint8_t QMP6988_CTRLMEAS_REG_MODE_POS = 0;
35 static const uint8_t QMP6988_CTRLMEAS_REG_MODE_MSK = 0x03;
36 static const uint8_t QMP6988_CTRLMEAS_REG_MODE_LEN = 2;
38 static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_POS = 5;
39 static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_MSK = 0xE0;
40 static const uint8_t QMP6988_CTRLMEAS_REG_OSRST_LEN = 3;
42 static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_POS = 2;
43 static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_MSK = 0x1C;
44 static const uint8_t QMP6988_CTRLMEAS_REG_OSRSP_LEN = 3;
46 static const uint8_t QMP6988_CONFIG_REG = 0xF1;
47 static const uint8_t QMP6988_CONFIG_REG_FILTER_POS = 0;
48 static const uint8_t QMP6988_CONFIG_REG_FILTER_MSK = 0x07;
49 static const uint8_t QMP6988_CONFIG_REG_FILTER_LEN = 3;
51 static const uint32_t SUBTRACTOR = 8388608;
53 static const char *
const TAG =
"qmp6988";
56 switch (oversampling) {
102 ESP_LOGE(TAG,
"%s: read chip ID (0xD1) failed", __func__);
104 ESP_LOGD(TAG,
"qmp6988 read chip id = 0x%x",
qmp6988_data_.chip_id);
112 uint8_t a_data_uint8_tr[QMP6988_CALIBRATION_DATA_LENGTH] = {0};
115 for (len = 0; len < QMP6988_CALIBRATION_DATA_LENGTH; len += 1) {
116 status = this->
read_register(QMP6988_CALIBRATION_DATA_START + len, &a_data_uint8_tr[len], 1);
118 ESP_LOGE(TAG,
"qmp6988 read calibration data (0xA0) error!");
124 (QMP6988_S32_t) (((a_data_uint8_tr[18] << SHIFT_LEFT_12_POSITION) |
125 (a_data_uint8_tr[19] << SHIFT_LEFT_4_POSITION) | (a_data_uint8_tr[24] & 0x0f))
130 (QMP6988_S16_t) (((a_data_uint8_tr[20]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[21]);
132 (QMP6988_S16_t) (((a_data_uint8_tr[22]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[23]);
135 (QMP6988_S32_t) (((a_data_uint8_tr[0] << SHIFT_LEFT_12_POSITION) | (a_data_uint8_tr[1] << SHIFT_LEFT_4_POSITION) |
136 ((a_data_uint8_tr[24] & 0xf0) >> SHIFT_RIGHT_4_POSITION))
141 (QMP6988_S16_t) (((a_data_uint8_tr[2]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[3]);
143 (QMP6988_S16_t) (((a_data_uint8_tr[4]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[5]);
145 (QMP6988_S16_t) (((a_data_uint8_tr[6]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[7]);
147 (QMP6988_S16_t) (((a_data_uint8_tr[8]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[9]);
149 (QMP6988_S16_t) (((a_data_uint8_tr[10]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[11]);
151 (QMP6988_S16_t) (((a_data_uint8_tr[12]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[13]);
153 (QMP6988_S16_t) (((a_data_uint8_tr[14]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[15]);
155 (QMP6988_S16_t) (((a_data_uint8_tr[16]) << SHIFT_LEFT_8_POSITION) | a_data_uint8_tr[17]);
157 ESP_LOGV(TAG,
"<-----------calibration data-------------->\r\n");
158 ESP_LOGV(TAG,
"COE_a0[%d] COE_a1[%d] COE_a2[%d] COE_b00[%d]\r\n",
qmp6988_data_.qmp6988_cali.COE_a0,
160 ESP_LOGV(TAG,
"COE_bt1[%d] COE_bt2[%d] COE_bp1[%d] COE_b11[%d]\r\n",
qmp6988_data_.qmp6988_cali.COE_bt1,
162 ESP_LOGV(TAG,
"COE_bp2[%d] COE_b12[%d] COE_b21[%d] COE_bp3[%d]\r\n",
qmp6988_data_.qmp6988_cali.COE_bp2,
164 ESP_LOGV(TAG,
"<-----------calibration data-------------->\r\n");
180 ESP_LOGV(TAG,
"<----------- int calibration data -------------->\r\n");
187 ESP_LOGV(TAG,
"<----------- int calibration data -------------->\r\n");
193 QMP6988_S64_t wk1, wk2;
196 wk1 = ((QMP6988_S64_t) ik->a1 * (QMP6988_S64_t) dt);
197 wk2 = ((QMP6988_S64_t) ik->a2 * (QMP6988_S64_t) dt) >> 14;
198 wk2 = (wk2 * (QMP6988_S64_t) dt) >> 10;
199 wk2 = ((wk1 + wk2) / 32767) >> 19;
200 ret = (QMP6988_S16_t) ((ik->a0 + wk2) >> 4);
206 QMP6988_S64_t wk1, wk2, wk3;
209 wk1 = ((QMP6988_S64_t) ik->bt1 * (QMP6988_S64_t) tx);
210 wk2 = ((QMP6988_S64_t) ik->bp1 * (QMP6988_S64_t) dp) >> 5;
212 wk2 = ((QMP6988_S64_t) ik->bt2 * (QMP6988_S64_t) tx) >> 1;
213 wk2 = (wk2 * (QMP6988_S64_t) tx) >> 8;
215 wk2 = ((QMP6988_S64_t) ik->b11 * (QMP6988_S64_t) tx) >> 4;
216 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 1;
218 wk2 = ((QMP6988_S64_t) ik->bp2 * (QMP6988_S64_t) dp) >> 13;
219 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 1;
222 wk2 = ((QMP6988_S64_t) ik->b12 * (QMP6988_S64_t) tx);
223 wk2 = (wk2 * (QMP6988_S64_t) tx) >> 22;
224 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 1;
226 wk2 = ((QMP6988_S64_t) ik->b21 * (QMP6988_S64_t) tx) >> 6;
227 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 23;
228 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 1;
230 wk2 = ((QMP6988_S64_t) ik->bp3 * (QMP6988_S64_t) dp) >> 12;
231 wk2 = (wk2 * (QMP6988_S64_t) dp) >> 23;
232 wk2 = (wk2 * (QMP6988_S64_t) dp);
239 ret = (QMP6988_S32_t) wk1;
246 ret = this->
write_byte(QMP6988_RESET_REG, 0xe6);
248 ESP_LOGE(TAG,
"Software Reset (0xe6) failed");
258 ESP_LOGD(TAG,
"Setting Power mode to: %d", power_mode);
263 if (power_mode == QMP6988_SLEEP_MODE) {
265 }
else if (power_mode == QMP6988_FORCED_MODE) {
267 }
else if (power_mode == QMP6988_NORMAL_MODE) {
272 ESP_LOGD(TAG,
"Set Power mode 0xf4=0x%x \r\n", data);
280 data = (filter & 0x03);
290 data |= (oversampling_p << 2);
300 data |= (oversampling_t << 5);
317 altitude = (pow((101325 / pressure), 1 / 5.257) - 1) * (temp + 273.15) / 0.0065;
323 QMP6988_U32_t p_read, t_read;
324 QMP6988_S32_t p_raw, t_raw;
325 uint8_t a_data_uint8_tr[6] = {0};
326 QMP6988_S32_t t_int, p_int;
330 err = this->
read_register(QMP6988_PRESSURE_MSB_REG, a_data_uint8_tr, 6);
332 ESP_LOGE(TAG,
"Error reading raw pressure/temp values");
335 p_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[0])) << SHIFT_LEFT_16_POSITION) |
336 (((QMP6988_U16_t) (a_data_uint8_tr[1])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[2]));
337 p_raw = (QMP6988_S32_t) (p_read - SUBTRACTOR);
339 t_read = (QMP6988_U32_t) ((((QMP6988_U32_t) (a_data_uint8_tr[3])) << SHIFT_LEFT_16_POSITION) |
340 (((QMP6988_U16_t) (a_data_uint8_tr[4])) << SHIFT_LEFT_8_POSITION) | (a_data_uint8_tr[5]));
341 t_raw = (QMP6988_S32_t) (t_read - SUBTRACTOR);
351 ESP_LOGCONFIG(TAG,
"Setting up QMP6988");
356 ESP_LOGCONFIG(TAG,
"Setup failed - device not found");
368 ESP_LOGCONFIG(TAG,
"QMP6988:");
369 LOG_I2C_DEVICE(
this);
371 ESP_LOGE(TAG,
"Communication with QMP6988 failed!");
373 LOG_UPDATE_INTERVAL(
this);
379 ESP_LOGCONFIG(TAG,
" IIR Filter: %s", iir_filter_to_str(this->
iir_filter_));
386 float pressurehectopascals = this->
qmp6988_data_.pressure / 100;
389 ESP_LOGD(TAG,
"Temperature=%.2f°C, Pressure=%.2fhPa", temperature, pressurehectopascals);
void calculate_altitude_(float pressure, float temp)
QMP6988_S16_t get_compensated_temperature_(qmp6988_ik_data_t *ik, QMP6988_S32_t dt)
void set_temperature_oversampling(QMP6988Oversampling oversampling_t)
const float DATA
For components that import data from directly connected sensors like DHT.
struct Qmp6988IkData { QMP6988_S32_t a0, b00 qmp6988_ik_data_t
void calculate_pressure_()
ErrorCode read_register(uint8_t a_register, uint8_t *data, size_t len, bool stop=true)
reads an array of bytes from a specific register in the I²C device
void set_iir_filter(QMP6988IIRFilter iirfilter)
sensor::Sensor * pressure_sensor_
void write_oversampling_pressure_(unsigned char oversampling_p)
void set_power_mode_(uint8_t power_mode)
void set_pressure_oversampling(QMP6988Oversampling oversampling_p)
QMP6988_S32_t get_compensated_pressure_(qmp6988_ik_data_t *ik, QMP6988_S32_t dp, QMP6988_S16_t tx)
qmp6988_data_t qmp6988_data_
No error found during execution of method.
QMP6988Oversampling pressure_oversampling_
void publish_state(float state)
Publish a new state to the front-end.
void dump_config() override
QMP6988IIRFilter iir_filter_
bool get_calibration_data_()
void write_oversampling_temperature_(unsigned char oversampling_t)
void write_filter_(unsigned char filter)
float get_setup_priority() const override
QMP6988Oversampling temperature_oversampling_
bool write_byte(uint8_t a_register, uint8_t data, bool stop=true)
sensor::Sensor * temperature_sensor_
Implementation of SPI Controller mode.
void IRAM_ATTR HOT delay(uint32_t ms)