rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
touch_merge.h
Go to the documentation of this file.
1
53
54#pragma once
55
56#include <stdbool.h>
57#include <stdint.h>
58
59#include "touch_map.h"
60#include "touch_types.h"
61
62#ifdef __cplusplus
63extern "C" {
64#endif
65
67#define TOUCH_MERGE_GLASS_ADDR 0x5Du
68
72#define TOUCH_MERGE_INJECT_ADDR 0x14u
73
85#define TOUCH_MERGE_INJECT_PRODUCT "9INJ"
86
93
99bool touch_merge_is_injector(const char *product_id);
100
118touch_role_t touch_merge_role(uint16_t addr, bool glass_found,
119 const char *product_id);
120
133 const touch_map_t *inject, bool turned);
134
136#define TOUCH_MERGE_INJECT_ID 0x80u
137
139#define TOUCH_MERGE_FAIL_DROP 3u
140
142#define TOUCH_MERGE_RETRY_MS 100u
143
145#define TOUCH_MERGE_DETACH_MS 1000u
146
148#define TOUCH_MERGE_PROBE_MS 1000u
149
164
170
176void touch_merge_attach(touch_merge_t *m, uint32_t now_ms);
177
189void touch_merge_start(touch_merge_t *m, bool answered, uint32_t now_ms);
190
198
206bool touch_merge_expire(touch_merge_t *m, uint32_t now_ms);
207
216bool touch_merge_probe_due(const touch_merge_t *m, uint32_t now_ms);
217
225bool touch_merge_probe(touch_merge_t *m, bool answered, uint32_t now_ms);
226
235void touch_merge_glass(touch_merge_t *m, const touch_point_t *pts, int n);
236
245bool touch_merge_inject_due(const touch_merge_t *m, uint32_t now_ms);
246
261bool touch_merge_inject(touch_merge_t *m, const touch_point_t *pts, int n,
262 bool fresh, uint32_t now_ms);
263
271bool touch_merge_inject_failed(touch_merge_t *m, uint32_t now_ms);
272
281int touch_merge_frame(const touch_merge_t *m, touch_point_t *out, int max);
282
295int touch_merge_mark_cut(const touch_merge_t *m, touch_event_t *evts, int n);
296
303static inline uint32_t touch_merge_age(uint32_t glass_age_ms,
304 uint32_t inject_age_ms)
305{
306 return glass_age_ms > inject_age_ms ? glass_age_ms : inject_age_ms;
307}
308
318static inline uint32_t touch_merge_inject_age(bool attached, uint32_t ok_ms,
319 uint32_t now_ms)
320{
321 const uint32_t age = (uint32_t)(now_ms - ok_ms);
322 return (attached && age < TOUCH_MERGE_DETACH_MS) ? age : 0u;
323}
324
325#ifdef __cplusplus
326}
327#endif
A DOWN, MOVE or UP of one contact.
Definition touch_types.h:69
Definition touch_map.h:17
The two sources' last sets and the injector's health.
Definition touch_merge.h:151
touch_point_t glass[TOUCH_MAX_POINTS]
Definition touch_merge.h:152
bool detached
Definition touch_merge.h:160
uint8_t inject_n
Definition touch_merge.h:155
bool cut[TOUCH_MAX_POINTS]
Definition touch_merge.h:156
bool absent
Definition touch_merge.h:161
uint8_t glass_n
Definition touch_merge.h:153
bool shown[TOUCH_MAX_POINTS]
Definition touch_merge.h:157
uint8_t fails
Definition touch_merge.h:158
uint32_t last_try_ms
Definition touch_merge.h:159
touch_point_t inject[TOUCH_MAX_POINTS]
Definition touch_merge.h:154
uint32_t ok_ms
Definition touch_merge.h:162
One contact.
Definition touch_types.h:23
Coordinate mapping and press/move/release tracking. Pure C; the unit tests are in test/host.
bool touch_merge_attached(const touch_merge_t *m)
Whether the injector is attached: false once detached, until a probe.
Definition touch_merge.c:61
void touch_merge_start(touch_merge_t *m, bool answered, uint32_t now_ms)
The start-up look for the injector.
Definition touch_merge.c:45
int touch_merge_mark_cut(const touch_merge_t *m, touch_event_t *evts, int n)
Mark the UP of every cut injected contact TOUCH_FLAG_NO_TAP.
Definition touch_merge.c:247
bool touch_merge_inject(touch_merge_t *m, const touch_point_t *pts, int n, bool fresh, uint32_t now_ms)
The injector answered at now_ms.
Definition touch_merge.c:171
touch_map_t touch_merge_role_map(touch_role_t role, const touch_map_t *glass, const touch_map_t *inject, bool turned)
The map for one report of a controller with role role.
Definition touch_merge.c:290
bool touch_merge_probe(touch_merge_t *m, bool answered, uint32_t now_ms)
A detached injector was probed.
Definition touch_merge.c:87
void touch_merge_attach(touch_merge_t *m, uint32_t now_ms)
Reset, with the injector attached and answering at now_ms.
Definition touch_merge.c:35
void touch_merge_glass(touch_merge_t *m, const touch_point_t *pts, int n)
The glass reported a new contact set (0 points when every finger lifted). Injected contacts the frame...
Definition touch_merge.c:132
static uint32_t touch_merge_inject_age(bool attached, uint32_t ok_ms, uint32_t now_ms)
The injector's share of touch age.
Definition touch_merge.h:318
touch_role_t touch_merge_role(uint16_t addr, bool glass_found, const char *product_id)
The role of a controller that answered as a GT911 at start-up.
Definition touch_merge.c:275
bool touch_merge_expire(touch_merge_t *m, uint32_t now_ms)
Detach the injector when its last good read is TOUCH_MERGE_DETACH_MS or more old. Detaching drops its...
Definition touch_merge.c:66
void touch_merge_reset(touch_merge_t *m)
Forget both sets: no contacts, the injector attached at 0ms.
Definition touch_merge.c:28
static uint32_t touch_merge_age(uint32_t glass_age_ms, uint32_t inject_age_ms)
How old touch is: the older of the two sources' ages.
Definition touch_merge.h:303
int touch_merge_frame(const touch_merge_t *m, touch_point_t *out, int max)
The merged set: the glass's contacts, then the injector's that are not cut, TOUCH_MAX_POINTS at most.
Definition touch_merge.c:230
touch_role_t
What a controller found at start-up is to the touch task.
Definition touch_merge.h:88
@ TOUCH_ROLE_GLASS
Definition touch_merge.h:90
@ TOUCH_ROLE_INJECTOR
Definition touch_merge.h:91
@ TOUCH_ROLE_NONE
Definition touch_merge.h:89
bool touch_merge_inject_due(const touch_merge_t *m, uint32_t now_ms)
Whether the injector is due to be asked: on every poll while it answers, and every TOUCH_MERGE_RETRY_...
Definition touch_merge.c:145
bool touch_merge_is_injector(const char *product_id)
Whether product_id is the touch injector's.
Definition touch_merge.c:269
bool touch_merge_probe_due(const touch_merge_t *m, uint32_t now_ms)
Whether a detached injector is due to be probed: TOUCH_MERGE_PROBE_MS after the detach and after ever...
Definition touch_merge.c:81
bool touch_merge_inject_failed(touch_merge_t *m, uint32_t now_ms)
An injector read failed.
Definition touch_merge.c:214
#define TOUCH_MERGE_DETACH_MS
An injector with no good read for this many ms is detached.
Definition touch_merge.h:145
Plain data types shared by the touch controller driver, the coordinate mapper and the event tracker....
#define TOUCH_MAX_POINTS
The GT911 reports at most five simultaneous contacts.
Definition touch_types.h:20