Touch: Simplify scanning.

This commit is contained in:
Jared Boone 2016-07-27 21:57:51 -07:00
parent 8a8e84d763
commit dd2097a447
2 changed files with 10 additions and 19 deletions

View File

@ -58,27 +58,18 @@ static volatile uint32_t touch_phase { 0 };
* Noise will only occur when the panel is being touched. Not ideal, but * Noise will only occur when the panel is being touched. Not ideal, but
* an acceptable improvement. * an acceptable improvement.
*/ */
static std::array<portapack::IO::TouchPinsConfig, 11> touch_pins_configs { static std::array<portapack::IO::TouchPinsConfig, 3> touch_pins_configs {
/* State machine will pause here until touch is detected. */ /* State machine will pause here until touch is detected. */
portapack::IO::TouchPinsConfig::WaitTouch,
portapack::IO::TouchPinsConfig::SensePressure, portapack::IO::TouchPinsConfig::SensePressure,
portapack::IO::TouchPinsConfig::SenseX, portapack::IO::TouchPinsConfig::SenseX,
portapack::IO::TouchPinsConfig::SenseY, 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 temp_frame;
static touch::Frame touch_frame; static touch::Frame touch_frame;
static uint32_t touch_debounce = 0; 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_detected = false;
static bool touch_cycle = false; static bool touch_cycle = false;
@ -87,22 +78,22 @@ static bool touch_update() {
const auto current_phase = touch_pins_configs[touch_phase]; const auto current_phase = touch_pins_configs[touch_phase];
switch(current_phase) { switch(current_phase) {
case portapack::IO::TouchPinsConfig::WaitTouch: case portapack::IO::TouchPinsConfig::SensePressure:
{ {
/* Debounce touches. */ const auto z1 = samples.xp - samples.xn;
const bool touch_raw = (samples.yp < touch::touch_threshold) && (samples.yn < touch::touch_threshold); 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_debounce = (touch_debounce << 1) | (touch_raw ? 1U : 0U);
touch_detected = ((touch_debounce & touch_debounce_mask) == touch_debounce_mask); touch_detected = ((touch_debounce & touch_debounce_mask) == touch_debounce_mask);
if( !touch_detected && !touch_cycle ) { if( !touch_detected && !touch_cycle ) {
temp_frame.pressure = { };
return false; return false;
} else {
temp_frame.pressure += samples;
} }
} }
break; break;
case portapack::IO::TouchPinsConfig::SensePressure:
temp_frame.pressure += samples;
break;
case portapack::IO::TouchPinsConfig::SenseX: case portapack::IO::TouchPinsConfig::SenseX:
temp_frame.x += samples; temp_frame.x += samples;
break; break;

View File

@ -38,7 +38,7 @@ using sample_t = uint16_t;
constexpr sample_t sample_max = 1023; 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 { struct Samples {
sample_t xp; sample_t xp;