11#ifndef M5_UNIT_COMPONENT_GOOGLETEST_TEMPLATE_HPP
12#define M5_UNIT_COMPONENT_GOOGLETEST_TEMPLATE_HPP
17#include <esp32-hal-i2c.h>
33template <u
int32_t FREQ, u
int32_t WNUM = 0>
35 static_assert(WNUM < 2,
"Wire number must be lesser than 2");
40 auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
41 auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
43#if defined(CONFIG_IDF_TARGET_ESP32C6)
44 TwoWire* w[1] = {&Wire};
46 TwoWire* w[2] = {&Wire, &Wire1};
48 if (WNUM < m5::stl::size(w) && i2cIsInit(WNUM)) {
49 M5_LOGW(
"Already inititlized Wire %d. Terminate and restart FREQ %u", WNUM, FREQ);
52 w[WNUM]->begin(pin_num_sda, pin_num_scl, FREQ);
62template <
typename U,
typename TP>
64 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
67 virtual void SetUp()
override
71 FAIL() <<
"Failed to get_instance";
75 ustr = m5::utility::formatString(
"%s:%s",
unit->deviceName(),
is_using_hal() ?
"HAL" :
"Wire");
77 FAIL() <<
"Failed to begin " << ustr;
82 virtual void TearDown()
override
90 auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
91 auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
92 m5::hal::bus::I2CBusConfig i2c_cfg;
93 i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
94 i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
95 auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
96 return Units.
add(*
unit, i2c_bus ? i2c_bus.value() :
nullptr) && Units.
begin();
108 std::unique_ptr<U>
unit{};
118template <
typename U,
typename TP>
120 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
123 virtual void SetUp()
override
127 FAIL() <<
"Failed to get_instance";
131 ustr = m5::utility::formatString(
"%s:%s",
unit->deviceName(),
is_using_hal() ?
"HAL" :
"GPIO");
133 FAIL() <<
"Failed to begin " << ustr;
138 virtual void TearDown()
override
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");
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);
152 M5_LOGI(
"getPin: %d,%d", pin_num_gpio_in, pin_num_gpio_out);
160 return Units.
add(*
unit, pin_num_gpio_in, pin_num_gpio_out) && Units.
begin();
169 std::unique_ptr<U>
unit{};
Main header of M5UnitComponent.
For managing and leading units.
bool begin()
Begin of all units under management.
Definition M5UnitUnified.cpp:105
bool add(Component &u, TwoWire &wire)
Adding unit to be managed (I2C)
Definition M5UnitUnified.cpp:41
UnitComponent Derived class for testing (I2C)
Definition test_template.hpp:63
virtual U * get_instance()=0
return m5::unit::Component-derived class instance (decision based on TP)
virtual bool is_using_hal() const =0
Function returning true if M5HAL is used (decision based on TP)
UnitComponent Derived class for testing (GPIO)
Definition test_template.hpp:119
virtual U * get_instance()=0
return m5::unit::Component-derived class instance (decision based on TP)
virtual bool is_using_hal() const =0
Function returning true if M5HAL is used (decision based on TP)
Overall test environment configuration.
Definition test_template.hpp:34
Top level namespace of M5stack.
Definition test_helper.hpp:18