From cb909293151c978ff06fb324984c40e57e8e07e7 Mon Sep 17 00:00:00 2001 From: William Emfinger Date: Mon, 15 Jul 2024 17:36:18 -0500 Subject: [PATCH] fix(esp-box): Ensure touch interrupt is configured properly for ESP-BOX and ESP-BOX-3 (#292) --- components/esp-box/include/esp-box.hpp | 15 ++++++++++++--- components/esp-box/src/esp-box.cpp | 10 ++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/components/esp-box/include/esp-box.hpp b/components/esp-box/include/esp-box.hpp index cbb47839c..a73a5eb0a 100644 --- a/components/esp-box/include/esp-box.hpp +++ b/components/esp-box/include/esp-box.hpp @@ -296,6 +296,9 @@ class EspBox : public BaseComponent { static constexpr bool reset_value = true; // was false on ESP32-S3-BOX static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_45; // was 47 on ESP32-S3-BOX static constexpr bool touch_invert_x = false; // was true on ESP32-S3-BOX + static constexpr auto touch_interrupt_level = espp::Interrupt::ActiveLevel::HIGH; + static constexpr auto touch_interrupt_type = espp::Interrupt::Type::RISING_EDGE; + static constexpr auto touch_interrupt_pullup_enabled = false; }; // struct box3 // box: @@ -304,6 +307,9 @@ class EspBox : public BaseComponent { static constexpr bool reset_value = false; static constexpr gpio_num_t i2s_ws_io = GPIO_NUM_47; static constexpr bool touch_invert_x = true; + static constexpr auto touch_interrupt_level = espp::Interrupt::ActiveLevel::LOW; + static constexpr auto touch_interrupt_type = espp::Interrupt::Type::FALLING_EDGE; + static constexpr auto touch_interrupt_pullup_enabled = true; }; // struct box // set by the detect() method using the box3 and box namespaces @@ -311,6 +317,9 @@ class EspBox : public BaseComponent { bool reset_value; gpio_num_t i2s_ws_io; bool touch_invert_x; + espp::Interrupt::ActiveLevel touch_interrupt_level; + espp::Interrupt::Type touch_interrupt_type; + bool touch_interrupt_pullup_enabled; // common: // internal i2c (touchscreen, audio codec) @@ -369,6 +378,8 @@ class EspBox : public BaseComponent { .sda_pullup_en = GPIO_PULLUP_ENABLE, .scl_pullup_en = GPIO_PULLUP_ENABLE}}; + // NOTE: the active level, interrupt type, and pullup configuration is set by + // detect(), since it depends on the box type espp::Interrupt::PinConfig touch_interrupt_pin_{ .gpio_num = touch_interrupt, .callback = @@ -377,9 +388,7 @@ class EspBox : public BaseComponent { if (touch_callback_) { touch_callback_(touchpad_data()); } - }, - .active_level = espp::Interrupt::ActiveLevel::HIGH, - .interrupt_type = espp::Interrupt::Type::RISING_EDGE}; + }}; // we'll only add each interrupt pin if the initialize method is called espp::Interrupt interrupts_{ diff --git a/components/esp-box/src/esp-box.cpp b/components/esp-box/src/esp-box.cpp index eaaecd24b..1684c92b9 100644 --- a/components/esp-box/src/esp-box.cpp +++ b/components/esp-box/src/esp-box.cpp @@ -39,16 +39,26 @@ void EspBox::detect() { reset_value = box3::reset_value; i2s_ws_io = box3::i2s_ws_io; touch_invert_x = box3::touch_invert_x; + touch_interrupt_level = box3::touch_interrupt_level; + touch_interrupt_type = box3::touch_interrupt_type; + touch_interrupt_pullup_enabled = box3::touch_interrupt_pullup_enabled; break; case BoxType::BOX: backlight_io = box::backlight_io; reset_value = box::reset_value; i2s_ws_io = box::i2s_ws_io; touch_invert_x = box::touch_invert_x; + touch_interrupt_level = box::touch_interrupt_level; + touch_interrupt_type = box::touch_interrupt_type; + touch_interrupt_pullup_enabled = box::touch_interrupt_pullup_enabled; break; default: break; } + // now actually set the touch_interrupt_pin members: + touch_interrupt_pin_.active_level = touch_interrupt_level; + touch_interrupt_pin_.interrupt_type = touch_interrupt_type; + touch_interrupt_pin_.pullup_enabled = touch_interrupt_pullup_enabled; } ////////////////////////