11#ifndef M5_UNIT_COMPONENT_GOOGLETEST_TEMPLATE_HPP
12#define M5_UNIT_COMPONENT_GOOGLETEST_TEMPLATE_HPP
18#include <esp32-hal-i2c.h>
41 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
44 virtual void SetUp()
override
48 FAIL() <<
"Failed to get_instance";
51 ustr = m5::utility::formatString(
"%s",
unit->deviceName());
53 FAIL() <<
"Failed to begin " << ustr;
57 virtual void TearDown()
override
66 return m5::unit::wiring::addI2C(Units, *
unit,
unit->component_config().clock) && Units.
begin();
69 bool begin_with_wire(TwoWire& wire, uint32_t wnum = 0)
71 auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
72 auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
73 auto freq =
unit->component_config().clock;
74 if (i2cIsInit(wnum)) {
75 M5_LOGD(
"Already initialized Wire%u. Terminate and restart FREQ %u", wnum, freq);
78 M5_LOGI(
"Wire begin SDA:%u SCL:%u FREQ:%u", pin_num_sda, pin_num_scl, freq);
79 wire.begin(pin_num_sda, pin_num_scl, freq);
83 bool begin_with_ex_i2c()
85 M5_LOGI(
"Using Ex_I2C");
89 bool begin_with_software_i2c(int8_t sda, int8_t scl)
91 m5::hal::bus::I2CBusConfig i2c_cfg;
92 i2c_cfg.pin_sda = m5::hal::gpio::getPin(sda);
93 i2c_cfg.pin_scl = m5::hal::gpio::getPin(scl);
94 auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
95 M5_LOGI(
"Using M5HAL SDA:%u SCL:%u", sda, scl);
96 return Units.
add(*
unit, i2c_bus ? i2c_bus.value() :
nullptr) && Units.
begin();
103 std::unique_ptr<U>
unit{};
114 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
117 virtual void SetUp()
override
121 FAIL() <<
"Failed to get_instance";
124 ustr = m5::utility::formatString(
"%s:GPIO",
unit->deviceName());
126 FAIL() <<
"Failed to begin " << ustr;
130 virtual void TearDown()
override
137 return m5::unit::wiring::addGPIO(Units, *
unit) && Units.
begin();
144 std::unique_ptr<U>
unit{};
155 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
158 virtual void SetUp()
override
162 FAIL() <<
"Failed to get_instance";
165 ustr = m5::utility::formatString(
"%s:UART",
unit->deviceName());
167 FAIL() <<
"Failed to begin " << ustr;
171 virtual void TearDown()
override
178 return serial && Units.
add(*
unit, *serial) && Units.
begin();
187 std::unique_ptr<U>
unit{};
189 HardwareSerial* serial{};
199 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
202 virtual void SetUp()
override
206 FAIL() <<
"Failed to get_instance";
209 ustr = m5::utility::formatString(
"%s:SPI",
unit->deviceName());
211 FAIL() <<
"Failed to begin " << ustr;
215 virtual void TearDown()
override
235 std::unique_ptr<U>
unit{};
Main header of M5UnitComponent.
For managing and leading units.
bool begin()
Begin all units under management.
Definition M5UnitUnified.cpp:263
bool add(Component &u, TwoWire &wire)
Add unit to be managed (I2C via TwoWire)
UnitComponent derived class for testing (GPIO)
Definition test_template.hpp:113
virtual U * get_instance()=0
return m5::unit::Component-derived class instance
UnitComponent derived class for testing (I2C)
Definition test_template.hpp:40
virtual U * get_instance()=0
return m5::unit::Component-derived class instance
UnitComponent derived class for testing (SPI)
Definition test_template.hpp:198
virtual U * get_instance()=0
return m5::unit::Component-derived class instance
virtual SPIClass & get_spi()
return SPIClass to be used (default: SPI)
Definition test_template.hpp:229
virtual SPISettings get_spi_settings()=0
return SPISettings for the unit under test
UnitComponent derived class for testing (UART)
Definition test_template.hpp:154
virtual HardwareSerial * init_serial()=0
Initialize the serial to be used.
virtual U * get_instance()=0
return m5::unit::Component-derived class instance
Opt-in, header-only board-aware connection helpers for M5UnitUnified examples.
Top level namespace of M5Stack.
Definition test_helper.hpp:20