From dd2097a447b4f7a4ccb205fc06dae507e8626aac Mon Sep 17 00:00:00 2001 From: Jared Boone Date: Wed, 27 Jul 2016 21:57:51 -0700 Subject: [PATCH] Touch: Simplify scanning. --- firmware/application/irq_controls.cpp | 27 +++++++++------------------ firmware/application/touch.hpp | 2 +- 2 files changed, 10 insertions(+), 19 deletions(-) diff --git a/firmware/application/irq_controls.cpp b/firmware/application/irq_controls.cpp index cb6a2df5c..d57e9a9a6 100644 --- a/firmware/application/irq_controls.cpp +++ b/firmware/application/irq_controls.cpp @@ -58,27 +58,18 @@ static volatile uint32_t touch_phase { 0 }; * Noise will only occur when the panel is being touched. Not ideal, but * an acceptable improvement. */ -static std::array touch_pins_configs { +static std::array touch_pins_configs { /* State machine will pause here until touch is detected. */ - portapack::IO::TouchPinsConfig::WaitTouch, - portapack::IO::TouchPinsConfig::SensePressure, portapack::IO::TouchPinsConfig::SenseX, portapack::IO::TouchPinsConfig::SenseY, - portapack::IO::TouchPinsConfig::SenseX, - portapack::IO::TouchPinsConfig::SenseY, - portapack::IO::TouchPinsConfig::SensePressure, - portapack::IO::TouchPinsConfig::SenseX, - portapack::IO::TouchPinsConfig::SenseY, - portapack::IO::TouchPinsConfig::SenseX, - portapack::IO::TouchPinsConfig::SenseY, }; static touch::Frame temp_frame; static touch::Frame touch_frame; static uint32_t touch_debounce = 0; -static uint32_t touch_debounce_mask = (1U << 1) - 1; +static uint32_t touch_debounce_mask = (1U << 4) - 1; static bool touch_detected = false; static bool touch_cycle = false; @@ -87,22 +78,22 @@ static bool touch_update() { const auto current_phase = touch_pins_configs[touch_phase]; switch(current_phase) { - case portapack::IO::TouchPinsConfig::WaitTouch: + case portapack::IO::TouchPinsConfig::SensePressure: { - /* Debounce touches. */ - const bool touch_raw = (samples.yp < touch::touch_threshold) && (samples.yn < touch::touch_threshold); + const auto z1 = samples.xp - samples.xn; + const auto z2 = samples.yp - samples.yn; + const auto touch_raw = (z1 > touch::touch_threshold) || (z2 > touch::touch_threshold); touch_debounce = (touch_debounce << 1) | (touch_raw ? 1U : 0U); touch_detected = ((touch_debounce & touch_debounce_mask) == touch_debounce_mask); if( !touch_detected && !touch_cycle ) { + temp_frame.pressure = { }; return false; + } else { + temp_frame.pressure += samples; } } break; - case portapack::IO::TouchPinsConfig::SensePressure: - temp_frame.pressure += samples; - break; - case portapack::IO::TouchPinsConfig::SenseX: temp_frame.x += samples; break; diff --git a/firmware/application/touch.hpp b/firmware/application/touch.hpp index f862cf188..6f0895d7f 100644 --- a/firmware/application/touch.hpp +++ b/firmware/application/touch.hpp @@ -38,7 +38,7 @@ using sample_t = uint16_t; constexpr sample_t sample_max = 1023; -constexpr sample_t touch_threshold = sample_max * 0.5f; +constexpr sample_t touch_threshold = sample_max / 5; struct Samples { sample_t xp;