From 40e0cd0f03f50bf254d44a2b71713ae5facac522 Mon Sep 17 00:00:00 2001 From: Jesse Hills <3060199+jesserockz@users.noreply.github.com> Date: Fri, 28 Oct 2022 12:33:49 +1300 Subject: [PATCH] =?UTF-8?q?Make=20some=20minor=20changes=20to=20I=C2=B2C?= =?UTF-8?q?=20so=20rp2040=20works=20(#3959)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esphome/components/i2c/i2c_bus_arduino.cpp | 18 ++++++++++++++++-- esphome/components/rp2040/boards.py | 16 ++++++++++++++-- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/esphome/components/i2c/i2c_bus_arduino.cpp b/esphome/components/i2c/i2c_bus_arduino.cpp index 2e92468659..16d89c3450 100644 --- a/esphome/components/i2c/i2c_bus_arduino.cpp +++ b/esphome/components/i2c/i2c_bus_arduino.cpp @@ -14,7 +14,7 @@ static const char *const TAG = "i2c.arduino"; void ArduinoI2CBus::setup() { recover_(); -#ifdef USE_ESP32 +#if defined(USE_ESP32) static uint8_t next_bus_num = 0; if (next_bus_num == 0) { wire_ = &Wire; @@ -22,11 +22,25 @@ void ArduinoI2CBus::setup() { wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory) } next_bus_num++; -#else +#elif defined(USE_ESP8266) wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer) +#elif defined(USE_RP2040) + static bool first = true; + if (first) { + wire_ = &Wire; + first = false; + } else { + wire_ = &Wire1; // NOLINT(cppcoreguidelines-owning-memory) + } #endif +#ifdef USE_RP2040 + wire_->setSDA(this->sda_pin_); + wire_->setSCL(this->scl_pin_); + wire_->begin(); +#else wire_->begin(static_cast(sda_pin_), static_cast(scl_pin_)); +#endif wire_->setClock(frequency_); initialized_ = true; if (this->scan_) { diff --git a/esphome/components/rp2040/boards.py b/esphome/components/rp2040/boards.py index e2d34bc02a..6063b6d77d 100644 --- a/esphome/components/rp2040/boards.py +++ b/esphome/components/rp2040/boards.py @@ -1,7 +1,19 @@ RP2040_BASE_PINS = {} RP2040_BOARD_PINS = { - "pico": {"LED": 25}, + "pico": { + "SDA": 4, + "SCL": 5, + "LED": 25, + "SDA1": 26, + "SCL1": 27, + }, "rpipico": "pico", - "rpipicow": {"LED": 32}, + "rpipicow": { + "SDA": 4, + "SCL": 5, + "LED": 32, + "SDA1": 26, + "SCL1": 27, + }, }