[canbus] Fix multiple MCP component bugs (#14461)

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Jonathan Swoboda
2026-03-09 18:15:33 -04:00
committed by GitHub
co-authored by Claude Opus 4.6
parent 468ce74c8e
commit d2686b49be
6 changed files with 14 additions and 12 deletions
+2 -1
View File
@@ -1,4 +1,5 @@
#include "canbus.h"
#include <algorithm>
#include "esphome/core/log.h"
namespace esphome {
@@ -82,7 +83,7 @@ void Canbus::loop() {
std::vector<uint8_t> data;
// show data received
for (int i = 0; i < can_message.can_data_length_code; i++) {
for (int i = 0; i < std::min(can_message.can_data_length_code, CAN_MAX_DATA_LENGTH); i++) {
ESP_LOGV(TAG, " can_message.data[%d]=%02x", i, can_message.data[i]);
data.push_back(can_message.data[i]);
}
@@ -47,12 +47,12 @@ void MCP23X08Base::pin_interrupt_mode(uint8_t pin, mcp23xxx_base::MCP23XXXInterr
case mcp23xxx_base::MCP23XXX_RISING:
this->update_reg(pin, true, gpinten);
this->update_reg(pin, true, intcon);
this->update_reg(pin, true, defval);
this->update_reg(pin, false, defval);
break;
case mcp23xxx_base::MCP23XXX_FALLING:
this->update_reg(pin, true, gpinten);
this->update_reg(pin, true, intcon);
this->update_reg(pin, false, defval);
this->update_reg(pin, true, defval);
break;
case mcp23xxx_base::MCP23XXX_NO_INTERRUPT:
this->update_reg(pin, false, gpinten);
@@ -59,12 +59,12 @@ void MCP23X17Base::pin_interrupt_mode(uint8_t pin, mcp23xxx_base::MCP23XXXInterr
case mcp23xxx_base::MCP23XXX_RISING:
this->update_reg(pin, true, gpinten);
this->update_reg(pin, true, intcon);
this->update_reg(pin, true, defval);
this->update_reg(pin, false, defval);
break;
case mcp23xxx_base::MCP23XXX_FALLING:
this->update_reg(pin, true, gpinten);
this->update_reg(pin, true, intcon);
this->update_reg(pin, false, defval);
this->update_reg(pin, true, defval);
break;
case mcp23xxx_base::MCP23XXX_NO_INTERRUPT:
this->update_reg(pin, false, gpinten);
+1
View File
@@ -506,6 +506,7 @@ canbus::Error MCP2515::set_bitrate_(canbus::CanSpeed can_speed, CanClock can_clo
cfg3 = MCP_12MHZ_40KBPS_CFG3;
break;
case (canbus::CAN_50KBPS): // 50Kbps
cfg1 = MCP_12MHZ_50KBPS_CFG1;
cfg2 = MCP_12MHZ_50KBPS_CFG2;
cfg3 = MCP_12MHZ_50KBPS_CFG3;
break;
+6 -6
View File
@@ -79,8 +79,8 @@ void Mcp4461Component::dump_config() {
// reworked to be a one-line intentionally, as output would not be in order
if (i < 4) {
ESP_LOGCONFIG(TAG, " ├── Volatile wiper [%u] level: %u, 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));
this->reg_[i].state, ONOFF(this->reg_[i].enabled), ONOFF(this->reg_[i].terminal_hw),
ONOFF(this->reg_[i].terminal_a), ONOFF(this->reg_[i].terminal_b), ONOFF(this->reg_[i].terminal_w));
} else {
ESP_LOGCONFIG(TAG, " ├── Nonvolatile wiper [%u] level: %u", i, this->reg_[i].state);
}
@@ -315,9 +315,9 @@ void Mcp4461Component::disable_wiper_(Mcp4461WiperIdx wiper) {
return;
}
ESP_LOGV(TAG, "Disabling wiper %u", wiper_idx);
this->reg_[wiper_idx].enabled = true;
this->reg_[wiper_idx].enabled = false;
if (wiper_idx < 4) {
this->reg_[wiper_idx].terminal_hw = true;
this->reg_[wiper_idx].terminal_hw = false;
this->reg_[wiper_idx].update_terminal = true;
}
}
@@ -490,7 +490,7 @@ void Mcp4461Component::enable_terminal_(Mcp4461WiperIdx wiper, char terminal) {
ESP_LOGW(TAG, "Unknown terminal %c specified", terminal);
return;
}
this->reg_[wiper_idx].update_terminal = false;
this->reg_[wiper_idx].update_terminal = true;
}
void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) {
@@ -517,7 +517,7 @@ void Mcp4461Component::disable_terminal_(Mcp4461WiperIdx wiper, char terminal) {
ESP_LOGW(TAG, "Unknown terminal %c specified", terminal);
return;
}
this->reg_[wiper_idx].update_terminal = false;
this->reg_[wiper_idx].update_terminal = true;
}
uint16_t Mcp4461Component::get_eeprom_value(Mcp4461EepromLocation location) {
+1 -1
View File
@@ -58,7 +58,7 @@ class MCP4728Component : public Component, public i2c::I2CDevice {
void select_gain_(MCP4728ChannelIdx channel, MCP4728Gain gain);
private:
DACInputData reg_[4];
DACInputData reg_[4]{};
bool store_in_eeprom_ = false;
bool update_ = false;
};