Skip to content

Commit

Permalink
fix(esp-box): Ensure touch interrupt is configured properly for ESP-B…
Browse files Browse the repository at this point in the history
…OX and ESP-BOX-3 (#292)
  • Loading branch information
finger563 authored Jul 15, 2024
1 parent 9120251 commit cb90929
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
15 changes: 12 additions & 3 deletions components/esp-box/include/esp-box.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -304,13 +307,19 @@ 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
gpio_num_t backlight_io;
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)
Expand Down Expand Up @@ -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 =
Expand All @@ -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_{
Expand Down
10 changes: 10 additions & 0 deletions components/esp-box/src/esp-box.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

////////////////////////
Expand Down

0 comments on commit cb90929

Please sign in to comment.