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 TwoWire* w[2] = {&Wire, &Wire1};
44 if (i2cIsInit(WNUM)) {
45 M5_LOGW(
"Already inititlized Wire. Terminate and restart");
48 w[WNUM]->begin(pin_num_sda, pin_num_scl, FREQ);
58template <
typename U,
typename TP>
60 static_assert(std::is_base_of<m5::unit::Component, U>::value,
"U must be derived from Component");
63 virtual void SetUp()
override
67 FAIL() <<
"Failed to get_instance";
71 ustr = m5::utility::formatString(
"%s:%s",
unit->deviceName(),
is_using_hal() ?
"HAL" :
"Wire");
73 FAIL() <<
"Failed to begin " << ustr;
78 virtual void TearDown()
override
86 auto pin_num_sda = M5.getPin(m5::pin_name_t::port_a_sda);
87 auto pin_num_scl = M5.getPin(m5::pin_name_t::port_a_scl);
88 m5::hal::bus::I2CBusConfig i2c_cfg;
89 i2c_cfg.pin_sda = m5::hal::gpio::getPin(pin_num_sda);
90 i2c_cfg.pin_scl = m5::hal::gpio::getPin(pin_num_scl);
91 auto i2c_bus = m5::hal::bus::i2c::getBus(i2c_cfg);
92 return Units.add(*
unit, i2c_bus ? i2c_bus.value() :
nullptr) && Units.
begin();
95 return Units.add(*
unit, Wire) && Units.
begin();
104 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:59
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