|
17 | 17 | #include <SPI.h> |
18 | 18 | #include <esp32-hal-i2c.h> |
19 | 19 | #include <M5Unified.h> |
| 20 | +#include "../wiring/m5_unit_unified_wiring.hpp" // board-aware connection helpers (after M5Unified.h) |
20 | 21 |
|
21 | 22 | namespace m5 { |
22 | 23 | namespace unit { |
@@ -59,19 +60,10 @@ class I2CComponentTestBase : public ::testing::Test { |
59 | 60 |
|
60 | 61 | virtual bool begin() |
61 | 62 | { |
62 | | - auto board = M5.getBoard(); |
63 | | - if (board == m5::board_t::board_ArduinoNessoN1) { |
64 | | - // NessoN1: GROVE is port_b (GPIO 5/4). SoftwareI2C via M5HAL |
65 | | - auto sda = M5.getPin(m5::pin_name_t::port_b_out); |
66 | | - auto scl = M5.getPin(m5::pin_name_t::port_b_in); |
67 | | - return begin_with_software_i2c(sda, scl); |
68 | | - } |
69 | | - if (board == m5::board_t::board_M5NanoC6) { |
70 | | - // NanoC6: Use Ex_I2C (avoids Wire/Ex_I2C dual-driver conflict) |
71 | | - return begin_with_ex_i2c(); |
72 | | - } |
73 | | - // Standard boards: Wire (initialized here with unit's clock) |
74 | | - return begin_with_wire(Wire); |
| 63 | + // Board-aware: NessoN1 -> SoftwareI2C (M5HAL), NanoC6 / NanoH2 -> Ex_I2C, others -> Wire. |
| 64 | + // Delegates to the shared wiring helper (adds NanoH2 over the previous hand-written 3-branch). |
| 65 | + // The begin_with_* helpers below remain for tests that override begin() (e.g. DualSensor on Wire1). |
| 66 | + return m5::unit::wiring::addI2C(Units, *unit, unit->component_config().clock) && Units.begin(); |
75 | 67 | } |
76 | 68 |
|
77 | 69 | bool begin_with_wire(TwoWire& wire, uint32_t wnum = 0) |
@@ -141,16 +133,8 @@ class GPIOComponentTestBase : public ::testing::Test { |
141 | 133 |
|
142 | 134 | virtual bool begin() |
143 | 135 | { |
144 | | - auto pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_b_in); |
145 | | - auto pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_b_out); |
146 | | - if (pin_num_gpio_in < 0 || pin_num_gpio_out < 0) { |
147 | | - M5_LOGW("PortB is not available"); |
148 | | - Wire.end(); |
149 | | - pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_a_pin1); |
150 | | - pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_a_pin2); |
151 | | - } |
152 | | - M5_LOGI("getPin: %d,%d", pin_num_gpio_in, pin_num_gpio_out); |
153 | | - return Units.add(*unit, pin_num_gpio_in, pin_num_gpio_out) && Units.begin(); |
| 136 | + // PortB preferred, fallback to PortA. Both pins added (matches the previous default). |
| 137 | + return m5::unit::wiring::addGPIO(Units, *unit) && Units.begin(); |
154 | 138 | } |
155 | 139 |
|
156 | 140 | //! @brief return m5::unit::Component-derived class instance |
|
0 commit comments