updated libraries
This commit is contained in:
parent
d5d5d000b3
commit
3b7e68065a
102 changed files with 3020 additions and 1624 deletions
|
|
@ -55,7 +55,7 @@ public:
|
|||
|
||||
/*!
|
||||
@class ComponentTestBase
|
||||
@brief UnitComponent Derived class for testing
|
||||
@brief UnitComponent Derived class for testing (I2C)
|
||||
@tparam U m5::unit::Component-derived classes to be tested
|
||||
@tparam TP parameter type for testing. see also INSTANTIATE_TEST_SUITE_P
|
||||
*/
|
||||
|
|
@ -109,6 +109,67 @@ protected:
|
|||
m5::unit::UnitUnified Units;
|
||||
};
|
||||
|
||||
/*!
|
||||
@class GPIOComponentTestBase
|
||||
@brief UnitComponent Derived class for testing (GPIO)
|
||||
@tparam U m5::unit::Component-derived classes to be tested
|
||||
@tparam TP parameter type for testing. see also INSTANTIATE_TEST_SUITE_P
|
||||
*/
|
||||
template <typename U, typename TP>
|
||||
class GPIOComponentTestBase : public ::testing::TestWithParam<TP> {
|
||||
static_assert(std::is_base_of<m5::unit::Component, U>::value, "U must be derived from Component");
|
||||
|
||||
protected:
|
||||
virtual void SetUp() override
|
||||
{
|
||||
unit.reset(get_instance());
|
||||
if (!unit) {
|
||||
FAIL() << "Failed to get_instance";
|
||||
GTEST_SKIP();
|
||||
return;
|
||||
}
|
||||
ustr = m5::utility::formatString("%s:%s", unit->deviceName(), is_using_hal() ? "HAL" : "GPIO");
|
||||
if (!begin()) {
|
||||
FAIL() << "Failed to begin " << ustr;
|
||||
GTEST_SKIP();
|
||||
}
|
||||
}
|
||||
|
||||
virtual void TearDown() override
|
||||
{
|
||||
}
|
||||
|
||||
virtual bool begin()
|
||||
{
|
||||
auto pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_b_in);
|
||||
auto pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_b_out);
|
||||
if (pin_num_gpio_in < 0 || pin_num_gpio_out < 0) {
|
||||
M5_LOGW("PortB is not available");
|
||||
Wire.end();
|
||||
pin_num_gpio_in = M5.getPin(m5::pin_name_t::port_a_pin1);
|
||||
pin_num_gpio_out = M5.getPin(m5::pin_name_t::port_a_pin2);
|
||||
}
|
||||
M5_LOGI("getPin: %d,%d", pin_num_gpio_in, pin_num_gpio_out);
|
||||
|
||||
if (is_using_hal()) {
|
||||
// Using M5HAL
|
||||
// TODO Not yet
|
||||
return false;
|
||||
}
|
||||
// Using TwoWire
|
||||
return Units.add(*unit, pin_num_gpio_in, pin_num_gpio_out) && Units.begin();
|
||||
}
|
||||
|
||||
//!@brief Function returning true if M5HAL is used (decision based on TP)
|
||||
virtual bool is_using_hal() const = 0;
|
||||
//! @brief return m5::unit::Component-derived class instance (decision based on TP)
|
||||
virtual U* get_instance() = 0;
|
||||
|
||||
std::string ustr{};
|
||||
std::unique_ptr<U> unit{};
|
||||
m5::unit::UnitUnified Units;
|
||||
};
|
||||
|
||||
} // namespace googletest
|
||||
} // namespace unit
|
||||
} // namespace m5
|
||||
|
|
|
|||
|
|
@ -462,7 +462,7 @@ m5::hal::error::error_t AdapterGPIOBase::GPIOImpl::read_analog(uint16_t& value,
|
|||
}
|
||||
|
||||
m5::hal::error::error_t AdapterGPIOBase::GPIOImpl::pulse_in(uint32_t& duration, const gpio_num_t pin, const int state,
|
||||
const uint32_t timeout_us = 30000)
|
||||
const uint32_t timeout_us)
|
||||
{
|
||||
duration = 0;
|
||||
auto start = esp_timer_get_time();
|
||||
|
|
|
|||
|
|
@ -87,7 +87,7 @@ public:
|
|||
}
|
||||
|
||||
inline virtual m5::hal::error::error_t pulseInRX(uint32_t& duration, const int state,
|
||||
const uint32_t timeout_us) override
|
||||
const uint32_t timeout_us = 30000) override
|
||||
{
|
||||
return pulse_in(duration, rx_pin(), state, timeout_us);
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ public:
|
|||
return read_analog(v, tx_pin());
|
||||
}
|
||||
inline virtual m5::hal::error::error_t pulseInTX(uint32_t& duration, const int state,
|
||||
const uint32_t timeout_us) override
|
||||
const uint32_t timeout_us = 30000) override
|
||||
{
|
||||
return pulse_in(duration, tx_pin(), state, timeout_us);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,13 @@ bool declrare_use_rmt_channel(const int ch)
|
|||
return false;
|
||||
}
|
||||
|
||||
void clear_use_rmt_channel(const int ch)
|
||||
{
|
||||
if (ch >= 0 && ch < RMT_CHANNEL_MAX) {
|
||||
using_rmt_channel_bits &= ~(1U << ch);
|
||||
}
|
||||
}
|
||||
|
||||
rmt_config_t to_rmt_config_tx(const adapter_config_t& cfg, const uint32_t apb_freq_hz)
|
||||
{
|
||||
rmt_config_t out{};
|
||||
|
|
@ -78,6 +85,16 @@ public:
|
|||
GPIOImplV1(const int8_t rx_pin, const int8_t tx_pin) : AdapterGPIOBase::GPIOImpl(rx_pin, tx_pin)
|
||||
{
|
||||
}
|
||||
virtual ~GPIOImplV1()
|
||||
{
|
||||
rmt_tx_stop(_tx_config.channel);
|
||||
rmt_driver_uninstall(_tx_config.channel);
|
||||
clear_use_rmt_channel(_tx_config.channel);
|
||||
|
||||
rmt_rx_stop(_rx_config.channel);
|
||||
rmt_driver_uninstall(_rx_config.channel);
|
||||
clear_use_rmt_channel(_rx_config.channel);
|
||||
}
|
||||
|
||||
virtual bool begin(const gpio::adapter_config_t& cfg) override
|
||||
{
|
||||
|
|
@ -137,8 +154,8 @@ public:
|
|||
}
|
||||
return err == ESP_OK ? m5::hal::error::error_t::OK : m5::hal::error::error_t::UNKNOWN_ERROR;
|
||||
}
|
||||
M5_LIB_LOGE("Failed invalid config");
|
||||
|
||||
M5_LIB_LOGE("Failed invalid config");
|
||||
return m5::hal::error::error_t::UNKNOWN_ERROR;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -48,6 +48,17 @@ public:
|
|||
GPIOImplV2(const int8_t rx_pin, const int8_t tx_pin) : AdapterGPIOBase::GPIOImpl(rx_pin, tx_pin)
|
||||
{
|
||||
}
|
||||
virtual ~GPIOImplV2()
|
||||
{
|
||||
if (_tx_handle) {
|
||||
rmt_disable(_tx_handle);
|
||||
rmt_del_channel(_tx_handle);
|
||||
}
|
||||
if (_rx_handle) {
|
||||
rmt_disable(_rx_handle);
|
||||
rmt_del_channel(_rx_handle);
|
||||
}
|
||||
}
|
||||
|
||||
bool begin(const gpio::adapter_config_t& cfg)
|
||||
{
|
||||
|
|
@ -88,6 +99,9 @@ public:
|
|||
rmt_transmit_config_t tx_config = {};
|
||||
auto err = rmt_transmit(_tx_handle, copy_encoder, (gpio::m5_rmt_item_t*)data, len * sizeof(gpio::m5_rmt_item_t),
|
||||
&tx_config);
|
||||
if (err != ESP_OK) {
|
||||
M5_LIB_LOGE("Failed to transmit %d:%s", err, esp_err_to_name(err));
|
||||
}
|
||||
if (err == ESP_OK && waitMs) {
|
||||
err = rmt_tx_wait_all_done(_tx_handle, waitMs);
|
||||
if (err != ESP_OK) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue