bdk: touch: simplify input reporting

Additionally, touch polling now returns 1 for no event result.
This commit is contained in:
CTCaer
2026-02-20 02:50:18 +02:00
parent c067c113e6
commit 3e141fba20
3 changed files with 23 additions and 38 deletions

View File

@@ -113,19 +113,17 @@ static void _touch_process_contact_event(touch_event_t *event, bool touching)
tmp = event->raw[6] & 0x3F; tmp = event->raw[6] & 0x3F;
event->z /= tmp + 0x40; event->z /= tmp + 0x40;
event->fingers = ((event->raw[0] & FTS4_MASK_TOUCH_ID) >> 4) + 1; event->finger = ((event->raw[0] & FTS4_MASK_TOUCH_ID) >> 4) + 1;
} }
else else
event->fingers = 0; event->finger = 0;
_touch_compensate_limits(event, touching); _touch_compensate_limits(event, touching);
} }
static void _touch_parse_input_event(touch_event_t *event) static int _touch_parse_input_event(touch_event_t *event)
{ {
event->type = event->raw[0] & FTS4_MASK_EVENT_ID; switch (event->raw[0] & FTS4_MASK_EVENT_ID)
switch (event->type)
{ {
case FTS4_EV_MULTI_TOUCH_ENTER: case FTS4_EV_MULTI_TOUCH_ENTER:
case FTS4_EV_MULTI_TOUCH_MOTION: case FTS4_EV_MULTI_TOUCH_MOTION:
@@ -133,36 +131,27 @@ static void _touch_parse_input_event(touch_event_t *event)
if (event->z < 255) // Reject palm rest. if (event->z < 255) // Reject palm rest.
event->touch = true; event->touch = true;
else else
{
event->touch = false; event->touch = false;
event->type = FTS4_EV_MULTI_TOUCH_LEAVE; return 0;
}
break;
case FTS4_EV_MULTI_TOUCH_LEAVE: case FTS4_EV_MULTI_TOUCH_LEAVE:
event->touch = false; event->touch = false;
_touch_process_contact_event(event, false); _touch_process_contact_event(event, false);
break; return 0;
case FTS4_EV_NO_EVENT:
if (event->touch)
event->type = FTS4_EV_MULTI_TOUCH_MOTION;
break;
default: default:
if (event->touch && event->raw[0] == FTS4_EV_MULTI_TOUCH_MOTION) return 1; // No event.
event->type = FTS4_EV_MULTI_TOUCH_MOTION;
else
event->type = FTS4_EV_MULTI_TOUCH_LEAVE;
break;
} }
} }
void touch_poll(touch_event_t *event) int touch_poll(touch_event_t *event)
{ {
i2c_recv_buf_big(event->raw, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_LATEST_EVENT); int res = !i2c_recv_buf_big(event->raw, FTS4_EVENT_SIZE, I2C_3, FTS4_I2C_ADDR, FTS4_CMD_LATEST_EVENT);
_touch_parse_input_event(event); if (!res)
res = _touch_parse_input_event(event);
return res;
} }
touch_info_t *touch_get_chip_info() touch_info_t *touch_get_chip_info()

View File

@@ -143,11 +143,10 @@ typedef enum _touch_ito_error {
typedef struct _touch_event_t { typedef struct _touch_event_t {
u8 raw[FTS4_EVENT_SIZE]; u8 raw[FTS4_EVENT_SIZE];
u8 fingers;
u8 type; // Event type.
u16 x, y; // Coordinates. u16 x, y; // Coordinates.
u32 z; // Orientation. u32 z; // Orientation.
bool touch; bool touch;
int finger;
} touch_event_t; } touch_event_t;
typedef struct _touch_panel_info_t typedef struct _touch_panel_info_t
@@ -172,7 +171,7 @@ typedef struct _touch_fw_info_t {
u16 fw_rev; u16 fw_rev;
} touch_fw_info_t; } touch_fw_info_t;
void touch_poll(touch_event_t *event); int touch_poll(touch_event_t *event);
touch_info_t *touch_get_chip_info(); touch_info_t *touch_get_chip_info();
touch_panel_info_t *touch_get_panel_vendor(); touch_panel_info_t *touch_get_panel_vendor();
int touch_get_fw_info(touch_fw_info_t *fw); int touch_get_fw_info(touch_fw_info_t *fw);

View File

@@ -317,31 +317,28 @@ static bool _fts_touch_read(touchpad_report_t *rpt)
{ {
static touch_event_t touchpad; static touch_event_t touchpad;
touch_poll(&touchpad); if (touch_poll(&touchpad))
return false;
rpt->rpt_id = 5; rpt->rpt_id = 5;
rpt->count = 1; rpt->count = 1;
// Decide touch enable. // Decide touch enable.
switch (touchpad.type & FTS4_MASK_EVENT_ID) if (touchpad.touch)
{ {
//case FTS4_EV_MULTI_TOUCH_ENTER:
case FTS4_EV_MULTI_TOUCH_MOTION:
rpt->x = touchpad.x; rpt->x = touchpad.x;
rpt->y = touchpad.y; rpt->y = touchpad.y;
//rpt->z = touchpad.z; //rpt->z = touchpad.z;
rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0; rpt->id = touchpad.finger;
rpt->tip_switch = 1; rpt->tip_switch = 1;
break; }
case FTS4_EV_MULTI_TOUCH_LEAVE: else
{
rpt->x = touchpad.x; rpt->x = touchpad.x;
rpt->y = touchpad.y; rpt->y = touchpad.y;
//rpt->z = touchpad.z; //rpt->z = touchpad.z;
rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0; rpt->id = touchpad.finger;
rpt->tip_switch = 0; rpt->tip_switch = 0;
break;
case FTS4_EV_NO_EVENT:
return false;
} }
return true; return true;