From 44acbc66291da6a8ade8571b73a10e34341a622b Mon Sep 17 00:00:00 2001 From: Aidan MacDonald Date: Sat, 20 Nov 2021 19:05:16 +0000 Subject: Shanling Q1: enable multi-touch reporting The FT6x06 driver used for the Shanling Q1's touchscreen has been extended to report more than one touch point. It can also return the gesture detected by the controller, but this doesn't seem to report anything useful on the Q1. Multi-touch is only useful in 3x3 grid mode since the Rockbox button API cannot report more than one touch point. The FiiO M3K uses the same driver so it's been updated to the multi-touch API, but functionality is unchanged. Change-Id: I4de42f44808d6eb902e3da212d8f936b7a5042c7 --- firmware/target/mips/ingenic_x1000/debug-x1000.c | 6 ++ .../mips/ingenic_x1000/fiiom3k/button-fiiom3k.c | 5 +- .../ingenic_x1000/shanlingq1/button-shanlingq1.c | 83 +++++++++++++++++++--- 3 files changed, 82 insertions(+), 12 deletions(-) (limited to 'firmware/target/mips/ingenic_x1000') diff --git a/firmware/target/mips/ingenic_x1000/debug-x1000.c b/firmware/target/mips/ingenic_x1000/debug-x1000.c index 1965b0b74e..98b8f95fb5 100644 --- a/firmware/target/mips/ingenic_x1000/debug-x1000.c +++ b/firmware/target/mips/ingenic_x1000/debug-x1000.c @@ -149,6 +149,9 @@ static bool dbg_cpuidle(void) #ifdef FIIO_M3K extern bool dbg_fiiom3k_touchpad(void); #endif +#ifdef SHANLING_Q1 +extern bool dbg_shanlingq1_touchscreen(void); +#endif #ifdef HAVE_AXP_PMU extern bool axp_debug_menu(void); #endif @@ -170,6 +173,9 @@ static const struct { #ifdef FIIO_M3K {"Touchpad", &dbg_fiiom3k_touchpad}, #endif +#ifdef SHANLING_Q1 + {"Touchscreen", &dbg_shanlingq1_touchscreen}, +#endif #ifdef HAVE_AXP_PMU {"Power stats", &axp_debug_menu}, #endif diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c index 04e3102d42..24daf2ef69 100644 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c +++ b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c @@ -318,7 +318,7 @@ static void ft_step_state(uint32_t t, int evt, int tx, int ty) } } -static void ft_event_cb(int evt, int tx, int ty) +static void ft_event_cb(struct ft6x06_state* state) { /* TODO: convert the touch positions to linear positions. * @@ -327,7 +327,8 @@ static void ft_event_cb(int evt, int tx, int ty) * the middle of the touchpad than on the edges, so scrolling feels slow * in the middle and faster near the edge. */ - ft_step_state(__ost_read32(), evt, tx, ty); + struct ft6x06_point* pt = &state->points[0]; + ft_step_state(__ost_read32(), pt->event, pt->pos_x, pt->pos_y); } static void ft_init(void) diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c index 27c49a7bd7..13b0cdd078 100644 --- a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c +++ b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c @@ -32,6 +32,11 @@ #include "i2c-x1000.h" #include +#ifndef BOOTLOADER +# include "lcd.h" +# include "font.h" +#endif + /* Volume wheel rotation */ static volatile int wheel_pos = 0; @@ -109,6 +114,7 @@ void button_init_device(void) int button_read_device(int* data) { + const struct ft6x06_point* point; int r = 0; /* Read GPIO buttons, these are all active low */ @@ -138,16 +144,22 @@ int button_read_device(int* data) reset_poweroff_timer(); } - /* Handle touchscreen - * - * TODO: Support 2-point multitouch (useful for 3x3 grid mode) - * TODO: Support simple gestures by converting them to fake buttons - */ - int t = touchscreen_to_pixels(ft6x06_state.pos_x, ft6x06_state.pos_y, data); - if(ft6x06_state.event == FT6x06_EVT_PRESS || - ft6x06_state.event == FT6x06_EVT_CONTACT) { - /* Only set the button bit if the screen is being touched. */ - r |= t; + if(touchscreen_get_mode() == TOUCHSCREEN_POINT) { + /* Pointing mode can't use multitouch since we can only pass + * along coordinates for one touch event at a time */ + point = &ft6x06_state.points[0]; + int t = touchscreen_to_pixels(point->pos_x, point->pos_y, data); + if(point->event == FT6x06_EVT_PRESS || + point->event == FT6x06_EVT_CONTACT) + r |= t; + } else { + /* 3x3 mode can have simultaneous 'button' presses via multitouch */ + for(int i = 0; i < ft6x06_state.nr_points; ++i) { + point = &ft6x06_state.points[i]; + if(point->event == FT6x06_EVT_PRESS || + point->event == FT6x06_EVT_CONTACT) + r |= touchscreen_to_pixels(point->pos_x, point->pos_y, NULL); + } } return r; @@ -193,3 +205,54 @@ void GPIOD03(void) handle_wheel_irq(); gpio_flip_edge_irq(GPIO_WHEEL2); } + +#ifndef BOOTLOADER +static int getbtn(void) +{ + int btn; + do { + btn = button_get_w_tmo(1); + } while(btn & (BUTTON_REL|BUTTON_REPEAT)); + return btn; +} + +bool dbg_shanlingq1_touchscreen(void) +{ + /* definition of box used to represent the touchpad */ + const int pad_w = LCD_WIDTH; + const int pad_h = LCD_HEIGHT; + const int box_h = pad_h - SYSFONT_HEIGHT*5; + const int box_w = pad_w * box_h / pad_h; + const int box_x = (LCD_WIDTH - box_w) / 2; + const int box_y = SYSFONT_HEIGHT * 9 / 2; + + bool draw_border = true; + + do { + int line = 0; + lcd_clear_display(); + lcd_putsf(0, line++, "nr_points: %d gesture: %d", + ft6x06_state.nr_points, ft6x06_state.gesture); + + /* draw touchpad box borders */ + if(draw_border) + lcd_drawrect(box_x, box_y, box_w, box_h); + + for(int i = 0; i < ft6x06_state.nr_points; ++i) { + const struct ft6x06_point* point = &ft6x06_state.points[i]; + lcd_putsf(0, line++, "pt%d id:%d pos: %d,%d wgt: %d area:%d", + i, point->touch_id, point->pos_x, point->pos_y, + point->weight, point->area); + + /* draw crosshair */ + int tx = box_x + point->pos_x * box_w / pad_w; + int ty = box_y + point->pos_y * box_h / pad_h; + lcd_hline(tx-2, tx+2, ty); + lcd_vline(tx, ty-2, ty+2); + } + + lcd_update(); + } while(getbtn() != BUTTON_POWER); + return false; +} +#endif -- cgit v1.2.3