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;
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
event->fingers = 0;
event->finger = 0;
_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->type)
switch (event->raw[0] & FTS4_MASK_EVENT_ID)
{
case FTS4_EV_MULTI_TOUCH_ENTER:
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.
event->touch = true;
else
{
event->touch = false;
event->type = FTS4_EV_MULTI_TOUCH_LEAVE;
}
break;
return 0;
case FTS4_EV_MULTI_TOUCH_LEAVE:
event->touch = false;
_touch_process_contact_event(event, false);
break;
case FTS4_EV_NO_EVENT:
if (event->touch)
event->type = FTS4_EV_MULTI_TOUCH_MOTION;
break;
return 0;
default:
if (event->touch && event->raw[0] == FTS4_EV_MULTI_TOUCH_MOTION)
event->type = FTS4_EV_MULTI_TOUCH_MOTION;
else
event->type = FTS4_EV_MULTI_TOUCH_LEAVE;
break;
return 1; // No event.
}
}
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()

View File

@@ -143,11 +143,10 @@ typedef enum _touch_ito_error {
typedef struct _touch_event_t {
u8 raw[FTS4_EVENT_SIZE];
u8 fingers;
u8 type; // Event type.
u16 x, y; // Coordinates.
u32 z; // Orientation.
bool touch;
int finger;
} touch_event_t;
typedef struct _touch_panel_info_t
@@ -172,7 +171,7 @@ typedef struct _touch_fw_info_t {
u16 fw_rev;
} 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_panel_info_t *touch_get_panel_vendor();
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;
touch_poll(&touchpad);
if (touch_poll(&touchpad))
return false;
rpt->rpt_id = 5;
rpt->count = 1;
// 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->y = touchpad.y;
//rpt->z = touchpad.z;
rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0;
rpt->id = touchpad.finger;
rpt->tip_switch = 1;
break;
case FTS4_EV_MULTI_TOUCH_LEAVE:
}
else
{
rpt->x = touchpad.x;
rpt->y = touchpad.y;
//rpt->z = touchpad.z;
rpt->id = touchpad.fingers ? touchpad.fingers - 1 : 0;
rpt->id = touchpad.finger;
rpt->tip_switch = 0;
break;
case FTS4_EV_NO_EVENT:
return false;
}
return true;