Make some minor changes to I²C so rp2040 works (#3959)

This commit is contained in:
Jesse Hills 2022-10-28 12:33:49 +13:00 committed by GitHub
parent bf4d3df906
commit 40e0cd0f03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 4 deletions

View file

@ -14,7 +14,7 @@ static const char *const TAG = "i2c.arduino";
void ArduinoI2CBus::setup() { void ArduinoI2CBus::setup() {
recover_(); recover_();
#ifdef USE_ESP32 #if defined(USE_ESP32)
static uint8_t next_bus_num = 0; static uint8_t next_bus_num = 0;
if (next_bus_num == 0) { if (next_bus_num == 0) {
wire_ = &Wire; wire_ = &Wire;
@ -22,11 +22,25 @@ void ArduinoI2CBus::setup() {
wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory) wire_ = new TwoWire(next_bus_num); // NOLINT(cppcoreguidelines-owning-memory)
} }
next_bus_num++; next_bus_num++;
#else #elif defined(USE_ESP8266)
wire_ = &Wire; // NOLINT(cppcoreguidelines-prefer-member-initializer) 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 #endif
#ifdef USE_RP2040
wire_->setSDA(this->sda_pin_);
wire_->setSCL(this->scl_pin_);
wire_->begin();
#else
wire_->begin(static_cast<int>(sda_pin_), static_cast<int>(scl_pin_)); wire_->begin(static_cast<int>(sda_pin_), static_cast<int>(scl_pin_));
#endif
wire_->setClock(frequency_); wire_->setClock(frequency_);
initialized_ = true; initialized_ = true;
if (this->scan_) { if (this->scan_) {

View file

@ -1,7 +1,19 @@
RP2040_BASE_PINS = {} RP2040_BASE_PINS = {}
RP2040_BOARD_PINS = { RP2040_BOARD_PINS = {
"pico": {"LED": 25}, "pico": {
"SDA": 4,
"SCL": 5,
"LED": 25,
"SDA1": 26,
"SCL1": 27,
},
"rpipico": "pico", "rpipico": "pico",
"rpipicow": {"LED": 32}, "rpipicow": {
"SDA": 4,
"SCL": 5,
"LED": 32,
"SDA1": 26,
"SCL1": 27,
},
} }