Skip to content

Commit 2c27d6f

Browse files
committed
Use wiring helper in update_test
1 parent bc1e0cb commit 2c27d6f

1 file changed

Lines changed: 7 additions & 43 deletions

File tree

test/embedded/test_update/update_test.cpp

Lines changed: 7 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -15,69 +15,33 @@
1515
#include <SPI.h>
1616
#include <M5Unified.h>
1717
#include <M5HAL.hpp>
18-
#include <esp32-hal-i2c.h>
18+
#include <wiring/m5_unit_unified_wiring.hpp> // include last; uses M5Unified/M5HAL detected above
1919

2020
using namespace m5::unit;
2121

2222
constexpr uint32_t I2C_FREQ{400000U};
2323

24-
// Board-aware I2C add: same 3-branch logic as I2CComponentTestBase
24+
// Board-aware connection helpers delegate to the m5::unit::wiring helper. Dogfooding it here also
25+
// compile-checks the header and exercises it on real hardware.
2526
static bool add_with_i2c(UnitUnified& units, Component& u)
2627
{
27-
auto board = M5.getBoard();
28-
if (board == m5::board_t::board_ArduinoNessoN1) {
29-
auto sda = M5.getPin(m5::pin_name_t::port_b_out);
30-
auto scl = M5.getPin(m5::pin_name_t::port_b_in);
31-
m5::hal::bus::I2CBusConfig i2c_cfg;
32-
i2c_cfg.pin_sda = m5::hal::gpio::getPin(sda);
33-
i2c_cfg.pin_scl = m5::hal::gpio::getPin(scl);
34-
auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
35-
return units.add(u, i2c_bus ? i2c_bus.value() : nullptr);
36-
}
37-
if (board == m5::board_t::board_M5NanoC6) {
38-
return units.add(u, M5.Ex_I2C);
39-
}
40-
// Standard boards: Wire
41-
auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
42-
auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
43-
if (i2cIsInit(0)) {
44-
Wire.end();
45-
}
46-
Wire.begin(pin_num_sda, pin_num_scl, I2C_FREQ);
47-
return units.add(u, Wire);
28+
return m5::unit::wiring::addI2C(units, u, I2C_FREQ); // default PortB = SoftwareI2C on NessoN1
4829
}
4930

50-
// GPIO add helper
5131
static bool add_with_gpio(UnitUnified& units, Component& u)
5232
{
53-
auto rx = M5.getPin(m5::pin_name_t::port_b_in);
54-
auto tx = M5.getPin(m5::pin_name_t::port_b_out);
55-
if (rx < 0 || tx < 0) {
56-
// Fallback to port_a if port_b unavailable
57-
rx = M5.getPin(m5::pin_name_t::port_a_pin1);
58-
tx = M5.getPin(m5::pin_name_t::port_a_pin2);
59-
}
60-
return units.add(u, rx, tx);
33+
return m5::unit::wiring::addGPIO(units, u);
6134
}
6235

63-
// UART add helper
6436
static bool add_with_uart(UnitUnified& units, Component& u)
6537
{
66-
#if SOC_UART_NUM > 2
67-
auto& s = Serial2;
68-
#elif SOC_UART_NUM > 1
69-
auto& s = Serial1;
70-
#else
71-
#error "Not enough Serial"
72-
#endif
73-
return units.add(u, s);
38+
return m5::unit::wiring::addUART(units, u, m5::unit::wiring::defaultUartSerial());
7439
}
7540

76-
// SPI add helper
7741
static bool add_with_spi(UnitUnified& units, Component& u)
7842
{
7943
SPISettings settings{1000000, MSBFIRST, SPI_MODE0};
80-
return units.add(u, SPI, settings);
44+
return m5::unit::wiring::spiBus(units, u, SPI, settings);
8145
}
8246

8347
// Test: I2C unit add/begin/update lifecycle (success path)

0 commit comments

Comments
 (0)