Skip to content

Commit 0ed20b9

Browse files
committed
Use wiring helper in I2CComponentTestBase
1 parent 0319845 commit 0ed20b9

1 file changed

Lines changed: 7 additions & 23 deletions

File tree

src/googletest/test_template.hpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <SPI.h>
1818
#include <esp32-hal-i2c.h>
1919
#include <M5Unified.h>
20+
#include "../wiring/m5_unit_unified_wiring.hpp" // board-aware connection helpers (after M5Unified.h)
2021

2122
namespace m5 {
2223
namespace unit {
@@ -59,19 +60,10 @@ class I2CComponentTestBase : public ::testing::Test {
5960

6061
virtual bool begin()
6162
{
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();
7567
}
7668

7769
bool begin_with_wire(TwoWire& wire, uint32_t wnum = 0)
@@ -141,16 +133,8 @@ class GPIOComponentTestBase : public ::testing::Test {
141133

142134
virtual bool begin()
143135
{
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();
154138
}
155139

156140
//! @brief return m5::unit::Component-derived class instance

0 commit comments

Comments
 (0)