|
rcbench
Servo and ESC test bench: panel, IOmcu and shared C
|
The touch injector: a GT911 emulator at 0x14 that presses where a USB (Universal Serial Bus) command line tells it to. Pure C; the RP2350 build (../rp2350) wires it to the I2C (Inter-Integrated Circuit) target, the USB serial port and the status LED, and the host suite drives it as a panel and a host would. More...
#include <stdbool.h>#include <stddef.h>#include <stdint.h>#include "gt911_emu.h"#include "inj_line_id.h"Go to the source code of this file.
Data Structures | |
| struct | inj_contact_t |
| One contact id's gesture. More... | |
| struct | injector_t |
| The whole injector: protocol, contacts, frames and replies. More... | |
Macros | |
| #define | INJ_PROTOCOL 1 |
| The line protocol's version, in the ping's reply. | |
| #define | INJ_RES_X 1024u |
| The resolution the injector reports: the panel's 1024 columns. | |
| #define | INJ_RES_Y 600u |
| The resolution the injector reports: the panel's 600 rows. | |
| #define | INJ_LINE_MAX 63u |
| #define | INJ_REPORT_MS 10u |
| #define | INJ_ACK_TIMEOUT_MS 100u |
| #define | INJ_TAP_MS 100u |
| #define | INJ_MS_MAX 30000u |
| #define | INJ_SWIPE_STEP_PX 100u |
| #define | INJ_LIVE_MS 100u |
| #define | INJ_CONTACTS GT911_EMU_POINTS |
| Contacts down at once: the GT911's 5 points. | |
| #define | INJ_ID_MAX 15u |
| The highest contact id: ids are 0 to 15. | |
| #define | INJ_REPLY_LEN 128u |
| A reply line's buffer: 128 characters. | |
| #define | INJ_REPLIES 8u |
| The replies queued: 8. | |
Enumerations | |
| enum | inj_state_t { INJ_LISTEN = 0 , INJ_ACTIVE } |
| The injector's state: LISTEN after a reset, ACTIVE once confirmed. More... | |
| enum | inj_gesture_t { INJ_G_NONE = 0 , INJ_G_TAP , INJ_G_HOLD , INJ_G_SWIPE , INJ_G_RELEASE } |
| What a contact is doing. More... | |
| enum | inj_led_t { INJ_LED_LISTEN = 0 , INJ_LED_WIRING_BAD , INJ_LED_OFF , INJ_LED_POLLED , INJ_LED_DOWN , INJ_LED_FAILED } |
| What the status LED shows. More... | |
Functions | |
| void | injector_init (injector_t *in) |
| Reset: LISTEN, no contacts, no replies. | |
| void | injector_input (injector_t *in, const char *bytes, size_t n, uint32_t now_ms) |
| Bytes from the host. A full line runs at once. | |
| void | injector_poll (injector_t *in, uint32_t now_ms) |
| Move the gestures on: frames, acknowledges, timeouts. Call often. | |
| bool | injector_take_wiring (injector_t *in) |
| True once after wiring: the glue starts listening to the lines. | |
| void | injector_wiring_done (injector_t *in, const inj_line_result_t *r) |
| The glue's 500ms of listening, classified. | |
| bool | injector_take_attach (injector_t *in) |
| True once after confirm: the glue attaches the I2C target. | |
| void | injector_host_closed (injector_t *in) |
| The host closed the port (DTR, data terminal ready, fell). | |
| bool | injector_take_reply (injector_t *in, char *out, size_t n) |
| The oldest reply. | |
| inj_led_t | injector_led (const injector_t *in, uint32_t now_ms) |
What the status LED shows at now_ms. | |
| const char * | inj_gesture_name (inj_gesture_t g) |
| The gesture's word. | |
The touch injector: a GT911 emulator at 0x14 that presses where a USB (Universal Serial Bus) command line tells it to. Pure C; the RP2350 build (../rp2350) wires it to the I2C (Inter-Integrated Circuit) target, the USB serial port and the status LED, and the host suite drives it as a panel and a host would.
States:
LISTEN after every reset. GP4 and GP5 are inputs and nothing answers on the bus. wiring asks the glue to listen to the bus for 500ms and report which line carries SCL; confirm scl=GP5 after an ok verdict asks it to attach the I2C target. ACTIVE the target answers at 0x14 and gestures run.
Commands (one line each, at most INJ_LINE_MAX characters, LF or CRLF):
ping pong rcbench-touch 1 addr=0x14 res=1024x600 state=listen|active id=9INJ wiring ok wiring, then the verdict line confirm scl=GP5 ok confirm status status <state> reads= acks= last_read_ms= down= x= y= (contact 0) contacts contacts n= <id>=<gesture>,<down>,<x>,<y> for each contact under way tap x y [ms] [id=N] ok tap, then done tap frames= ms= hold x y ms [id=N] ok hold, then done hold frames= ms= swipe x0 y0 x1 y1 ms [id=N] ok swipe, then done swipe frames= ms= slowed= release [id=N] ok release (each gesture under way first gets fail <gesture> released)
Contacts: up to INJ_CONTACTS gestures run at once, one per contact id 0..INJ_ID_MAX, each a GT911 track ID. A command without id= drives contact 0, and its replies are the ones of protocol 1. A gesture started with id=N names the contact in every reply about it: ok tap id=N, done tap id=N frames= ms=, fail tap id=N released. release without id= releases every contact. A frame carries every contact that is down; a contact's frames= counts the frames that put it down, moved it or lifted it.
Coordinates are panel pixels, x 0..INJ_RES_X-1 and y 0..INJ_RES_Y-1; ms is 1..INJ_MS_MAX. Errors are one line, err <code> [detail], and the command is not run. A gesture that fails after its ok gets fail <gesture> no_master, panel_reset or released; no_master and panel_reset end every contact.
Concurrency: the byte functions of the emulator (gt911_emu.h) run in the I2C interrupt. injector_input() and injector_poll() read and change the same state, so the glue calls them with that interrupt masked.
SPDX-License-Identifier: MIT
| #define INJ_ACK_TIMEOUT_MS 100u |
a frame not acknowledged by then
| #define INJ_LINE_MAX 63u |
characters, without the LF
| #define INJ_LIVE_MS 100u |
a read this recent: panel polling
| #define INJ_MS_MAX 30000u |
the longest gesture
| #define INJ_REPORT_MS 10u |
least time between two frames
| #define INJ_SWIPE_STEP_PX 100u |
|dx|+|dy| between two swipe frames
| #define INJ_TAP_MS 100u |
a tap's default length
| enum inj_gesture_t |
| enum inj_led_t |
| enum inj_state_t |
| const char * inj_gesture_name | ( | inj_gesture_t | g | ) |
The gesture's word.
| g | The gesture. |
| void injector_host_closed | ( | injector_t * | in | ) |
The host closed the port (DTR, data terminal ready, fell).
Every contact that is down is released; nothing is replied.
| in | The injector. |
| void injector_init | ( | injector_t * | in | ) |
Reset: LISTEN, no contacts, no replies.
| in | The injector. |
| void injector_input | ( | injector_t * | in, |
| const char * | bytes, | ||
| size_t | n, | ||
| uint32_t | now_ms ) |
Bytes from the host. A full line runs at once.
| in | The injector. |
| bytes | The bytes. |
| n | How many. |
| now_ms | The clock. |
| inj_led_t injector_led | ( | const injector_t * | in, |
| uint32_t | now_ms ) |
What the status LED shows at now_ms.
| in | The injector. |
| now_ms | The clock. |
| void injector_poll | ( | injector_t * | in, |
| uint32_t | now_ms ) |
Move the gestures on: frames, acknowledges, timeouts. Call often.
| in | The injector. |
| now_ms | The clock. |
| bool injector_take_attach | ( | injector_t * | in | ) |
True once after confirm: the glue attaches the I2C target.
| in | The injector. |
| bool injector_take_reply | ( | injector_t * | in, |
| char * | out, | ||
| size_t | n ) |
The oldest reply.
| in | The injector. |
| out | Where it goes. |
| n | The size of out. |
| bool injector_take_wiring | ( | injector_t * | in | ) |
True once after wiring: the glue starts listening to the lines.
| in | The injector. |
| void injector_wiring_done | ( | injector_t * | in, |
| const inj_line_result_t * | r ) |
The glue's 500ms of listening, classified.
| in | The injector. |
| r | The verdict. |