From c47c075bd3aea873db54f302c54aab81e7ae20fe Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 23 Apr 2022 15:13:36 +0100 Subject: [PATCH] touchscreen: Fix event reporting in button driver The way the button driver reported touch events was problematic and made it impossible to detect if a touch started or if it was a continuation of an existing touch. Now, the first detected touch event gets BUTTON_TOUCHSCREEN and all subsequent touch events while the screen is pressed will get the BUTTON_REPEAT bit set. When the screen is released the final event will have the BUTTON_REL bit set. Change-Id: Ia456a22b2180031555a82231c2af32576bc5f2cb --- firmware/drivers/button.c | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 010893619e..a24c4aa1d8 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c @@ -75,8 +75,8 @@ static bool enable_sw_poweroff = true; * real list acceleration kicks in (this smooths acceleration). * * Note that touchscreen pointing events are not subject to this - * acceleration and always use REPEAT_INTERVAL_TOUCH. (Do repeat - * events even do anything sane for touchscreens??) + * acceleration and always use REPEAT_INTERVAL_TOUCH. That value + * essentially determines the touchscreen polling rate. */ /* the speed repeat starts at, in centiseconds */ @@ -324,21 +324,29 @@ static void button_tick(void) } else { - if (count++ > REPEAT_START) + ++count; + if (count > REPEAT_START +#ifdef HAVE_TOUCHSCREEN + /* For touch events we want to repost quickly since + * the coordinates can change */ + || ((btn & BUTTON_TOUCHSCREEN) && + count > REPEAT_INTERVAL_TOUCH) +#endif + ) { post = true; repeat = true; repeat_count = 0; /* initial repeat */ - count = REPEAT_INTERVAL_START; - } #ifdef HAVE_TOUCHSCREEN - else if (lastdata != data && btn == lastbtn) - { /* only coordinates changed, post anyway */ - if (touchscreen_get_mode() == TOUCHSCREEN_POINT) - post = true; - } + if (btn & BUTTON_TOUCHSCREEN) + count = REPEAT_INTERVAL_TOUCH; + else #endif + { + count = REPEAT_INTERVAL_START; + } + } } } if ( post )