1
0
mirror of https://github.com/esphome/esphome.git synced 2025-03-31 07:58:14 +01:00

Update mcp4461.cpp

This commit is contained in:
Oliver Kleinecke 2025-02-06 19:43:51 +01:00 committed by GitHub
parent 6854a4887f
commit ed52a5c551
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -58,14 +58,9 @@ void Mcp4461Component::dump_config() {
// so also invalid for nonvolatile. For these, only print current level.
// reworked to be a one-line intentionally, as output would not be in order
if (i < 4) {
ESP_LOGCONFIG(TAG, " ├── Volatile wiper [%" PRIu8 "] level: %" PRIu16 ", Status: %s, HW: %s, A: %s, B: %s, W: %s",
i,
this->reg_[i].state,
ONOFF(this->reg_[i].terminal_hw),
ONOFF(this->reg_[i].terminal_a),
ONOFF(this->reg_[i].terminal_b),
ONOFF(this->reg_[i].terminal_w),
ONOFF(this->reg_[i].enabled));
ESP_LOGCONFIG(TAG, " ├── Volatile wiper [%" PRIu8 "] level: %" PRIu16 ", Status: %s, HW: %s, A: %s, B: %s, W: %s", i,
this->reg_[i].state, ONOFF(this->reg_[i].terminal_hw), ONOFF(this->reg_[i].terminal_a),
ONOFF(this->reg_[i].terminal_b), ONOFF(this->reg_[i].terminal_w), ONOFF(this->reg_[i].enabled));
} else {
ESP_LOGCONFIG(TAG, " ├── Nonvolatile wiper [%" PRIu8 "] level: %" PRIu16 "", i, this->reg_[i].state);
}
@ -83,19 +78,16 @@ void Mcp4461Component::dump_config() {
// Bit 7+8 are referenced in datasheet as D7 + D8 and both locked to 1
// Default status register reading should be 0x182h or 386 decimal
// "Default" means without any WiperLocks or WriteProtection enabled and EEPRom not active writing
// get_status_register() will automatically check, if D8, D7 & R1 bits (locked to 1) are 1 and bail out using error-routine otherwise
// get_status_register() will automatically check, if D8, D7 & R1 bits (locked to 1) are 1
// and bail out using error-routine otherwise
uint8_t status_register_value;
status_register_value = this->get_status_register();
ESP_LOGCONFIG(TAG, " └── Status register: D7: %" PRIu8 ", WL3: %" PRIu8 ", WL2: %" PRIu8 ", EEWA: %" PRIu8 ", WL1: %" PRIu8 ", WL0: %" PRIu8 ", R1: %" PRIu8 ", WP: %" PRIu8 "",
((status_register_value >> 7) & 0x01),
((status_register_value >> 6) & 0x01),
((status_register_value >> 5) & 0x01),
((status_register_value >> 4) & 0x01),
((status_register_value >> 3) & 0x01),
((status_register_value >> 2) & 0x01),
((status_register_value >> 1) & 0x01),
((status_register_value >> 0) & 0x01)
);
ESP_LOGCONFIG(TAG, " └── Status register: D7: %" PRIu8 ", WL3: %" PRIu8 ", WL2: %" PRIu8 ",
EEWA: %" PRIu8 ", WL1: %" PRIu8 ", WL0: %" PRIu8 ", R1: %" PRIu8 ", WP: %" PRIu8 "",
((status_register_value >> 7) & 0x01), ((status_register_value >> 6) & 0x01),
((status_register_value >> 5) & 0x01), ((status_register_value >> 4) & 0x01),
((status_register_value >> 3) & 0x01), ((status_register_value >> 2) & 0x01),
((status_register_value >> 1) & 0x01), ((status_register_value >> 0) & 0x01));
if (this->is_failed()) {
ESP_LOGE(TAG, "Communication with mcp4461 failed!");
}
@ -151,7 +143,8 @@ uint8_t Mcp4461Component::get_status_register() {
uint8_t lsb;
lsb = static_cast<uint8_t>(buf & 0x00ff);
if (msb != 1 || ((lsb >> 7) & 0x01) != 1 || ((lsb >> 1) & 0x01) != 1) {
// D8, D7 and R1 bits are hardlocked to 1 -> a status msb bit 0 (bit 9 of status register) of 0 or lsb bit 1/7 = 0 indicate device/communication issues, therefore mark component failed
// D8, D7 and R1 bits are hardlocked to 1 -> a status msb bit 0 (bit 9 of status register) of 0 or lsb bit 1/7 = 0
// indicate device/communication issues, therefore mark component failed
this->mark_failed();
return 0;
}
@ -257,7 +250,8 @@ void Mcp4461Component::write_wiper_level_(uint8_t wiper, uint16_t value) {
nonvolatile = true;
}
if (!(this->mcp4461_write_(this->get_wiper_address_(wiper), value, nonvolatile))) {
ESP_LOGW(TAG, "Error writing %swiper %" PRIu8 " level %" PRIu16 "", (wiper > 3) ? "nonvolatile " : "", wiper, value);
ESP_LOGW(TAG, "Error writing %swiper %" PRIu8 " level %" PRIu16 "",
(wiper > 3) ? "nonvolatile " : "", wiper, value);
this->status_set_warning();
}
}