Use formula-based description instead of incomplete GPIO pin lists

Addresses review feedback: the hard-coded pin lists only covered RP2040
GPIOs and were incomplete for RP2350 (GPIO up to 47). Now describes the
(gpio / 2) % 2 rule instead.
This commit is contained in:
J. Nick Koston
2026-03-12 13:24:27 -10:00
parent 75a546bd96
commit 32e8efb7b7
2 changed files with 7 additions and 6 deletions
+4 -3
View File
@@ -178,9 +178,10 @@ def _final_validate(config):
if len(set(controllers)) != len(controllers):
raise cv.Invalid(
"Multiple I2C buses are configured to use the same I2C controller. "
"Each bus must use pins on a different controller "
"(I2C0: SDA on GPIO 0,4,8,12,16,20,24,28; "
"I2C1: SDA on GPIO 2,6,10,14,18,22,26)."
"Each bus must use pins on a different controller. "
"The I2C controller is determined by (gpio / 2) % 2: "
"even pin pairs (0-1, 4-5, 8-9, ...) use I2C0, "
"odd pin pairs (2-3, 6-7, 10-11, ...) use I2C1."
)
if CORE.is_esp32 and get_esp32_variant() in ESP32_I2C_CAPABILITIES:
variant = get_esp32_variant()
+3 -3
View File
@@ -21,9 +21,9 @@ void ArduinoI2CBus::setup() {
wire_ = new TwoWire(); // NOLINT(cppcoreguidelines-owning-memory)
#elif defined(USE_RP2040)
// Select Wire instance based on pin assignment, not definition order.
// RP2040 I2C controller is determined by GPIO: (pin / 2) % 2
// See RP2040 datasheet Table 2 (section 1.4.3): https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
// See RP2350 datasheet Table 7 (section 9.4): https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf
// I2C controller = (gpio / 2) % 2: even pairs (0-1,4-5,...) → I2C0, odd pairs (2-3,6-7,...) → I2C1
// RP2040 datasheet Table 2 (section 1.4.3): https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf
// RP2350 datasheet Table 7 (section 9.4): https://datasheets.raspberrypi.com/rp2350/rp2350-datasheet.pdf
if ((this->sda_pin_ / 2) % 2 == 0) {
wire_ = &Wire;
} else {