23 if (!this->read_byte_16(REG_CONFIG, &config))
26 const bool was_asleep = (config & CONFIG_SLEEP) != 0;
28 if ((config & CONFIG_SAFE_MASK) != CONFIG_POWER_UP_DEFAULT) {
29 ESP_LOGW(TAG,
"CONFIG reads 0x%04X, expected 0x%04X; resetting it", config & CONFIG_SAFE_MASK,
30 CONFIG_POWER_UP_DEFAULT);
34 if (this->read_byte_16(REG_VERSION, &version)) {
35 ESP_LOGCONFIG(TAG,
"IC version: 0x%04X", version);
39 if (!this->write_byte_16(REG_CONFIG, CONFIG_POWER_UP_DEFAULT))
42 this->configured_ =
true;
45 this->set_timeout(WAKE_ALERT_CLEAR_TIMEOUT_ID, WAKE_ALERT_CLEAR_DELAY_MS, [
this]() { this->clear_wake_alert_(); });
51 if (!this->read_byte_16(REG_CONFIG, &config) || !this->write_byte_16(REG_CONFIG, config & ~CONFIG_ALRT)) {
52 this->status_set_warning(LOG_STR(
"Wake alert clear failed"));
57 if (!this->read_byte_16(REG_STATUS, &
status) || !this->write_byte_16(REG_STATUS,
status & ~STATUS_HD))
58 this->status_set_warning(LOG_STR(
"Wake alert clear failed"));
63 if (this->is_failed())
66 if (!this->ready_for_update_())
70 if (this->cancel_timeout(WAKE_ALERT_CLEAR_TIMEOUT_ID))
71 this->clear_wake_alert_();
74 if (!this->write_byte_16(REG_MODE, MODE_EN_SLEEP)) {
75 this->status_set_warning(LOG_STR(
"Unable to enable sleep mode in the mode register"));
80 if (!this->write_byte_16(REG_CONFIG, CONFIG_POWER_UP_DEFAULT | CONFIG_SLEEP))
81 this->status_set_warning(LOG_STR(
"Unable to write the sleep bit to config register"));