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();
99 return Units.add(*
unit, Wire) && Units.
begin();
108 std::unique_ptr<U>
unit{};
Main header of M5UnitComponent.
For managing and leading units.
Definition M5UnitUnified.hpp:42
bool begin()
Begin of all units under management.
Definition M5UnitUnified.cpp:102
UnitComponent Derived class for testing.
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)
Overall test environment configuration.
Definition test_template.hpp:34
Top level namespace of M5stack.
Definition test_helper.hpp:18