rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
injector.h File Reference

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.

Detailed Description

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

Macro Definition Documentation

◆ INJ_ACK_TIMEOUT_MS

#define INJ_ACK_TIMEOUT_MS   100u

a frame not acknowledged by then

◆ INJ_LINE_MAX

#define INJ_LINE_MAX   63u

characters, without the LF

◆ INJ_LIVE_MS

#define INJ_LIVE_MS   100u

a read this recent: panel polling

◆ INJ_MS_MAX

#define INJ_MS_MAX   30000u

the longest gesture

◆ INJ_REPORT_MS

#define INJ_REPORT_MS   10u

least time between two frames

◆ INJ_SWIPE_STEP_PX

#define INJ_SWIPE_STEP_PX   100u

|dx|+|dy| between two swipe frames

◆ INJ_TAP_MS

#define INJ_TAP_MS   100u

a tap's default length

Enumeration Type Documentation

◆ inj_gesture_t

What a contact is doing.

Enumerator
INJ_G_NONE 

idle

INJ_G_TAP 

tap x y [ms]

INJ_G_HOLD 

hold x y ms

INJ_G_SWIPE 

swipe x0 y0 x1 y1 ms

INJ_G_RELEASE 

the lift after release or a closed port

◆ inj_led_t

enum inj_led_t

What the status LED shows.

Enumerator
INJ_LED_LISTEN 

white, blinking 1Hz

INJ_LED_WIRING_BAD 

yellow: swapped, low or noise

INJ_LED_OFF 

active, no read for INJ_LIVE_MS

INJ_LED_POLLED 

dim green: the panel reads 0x14

INJ_LED_DOWN 

blue: a contact is down

INJ_LED_FAILED 

red: the last gesture failed

◆ inj_state_t

The injector's state: LISTEN after a reset, ACTIVE once confirmed.

Enumerator
INJ_LISTEN 

nothing answers on the bus

INJ_ACTIVE 

the target answers at 0x14, gestures run

Function Documentation

◆ inj_gesture_name()

const char * inj_gesture_name ( inj_gesture_t g)

The gesture's word.

Parameters
gThe gesture.
Returns
tap, hold, swipe, release, or idle.

◆ injector_host_closed()

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.

Parameters
inThe injector.

◆ injector_init()

void injector_init ( injector_t * in)

Reset: LISTEN, no contacts, no replies.

Parameters
inThe injector.

◆ injector_input()

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.

Parameters
inThe injector.
bytesThe bytes.
nHow many.
now_msThe clock.

◆ injector_led()

inj_led_t injector_led ( const injector_t * in,
uint32_t now_ms )

What the status LED shows at now_ms.

Parameters
inThe injector.
now_msThe clock.
Returns
The colour.

◆ injector_poll()

void injector_poll ( injector_t * in,
uint32_t now_ms )

Move the gestures on: frames, acknowledges, timeouts. Call often.

Parameters
inThe injector.
now_msThe clock.

◆ injector_take_attach()

bool injector_take_attach ( injector_t * in)

True once after confirm: the glue attaches the I2C target.

Parameters
inThe injector.
Returns
Whether to attach.

◆ injector_take_reply()

bool injector_take_reply ( injector_t * in,
char * out,
size_t n )

The oldest reply.

Parameters
inThe injector.
outWhere it goes.
nThe size of out.
Returns
False when there is none.

◆ injector_take_wiring()

bool injector_take_wiring ( injector_t * in)

True once after wiring: the glue starts listening to the lines.

Parameters
inThe injector.
Returns
Whether to start.

◆ injector_wiring_done()

void injector_wiring_done ( injector_t * in,
const inj_line_result_t * r )

The glue's 500ms of listening, classified.

Parameters
inThe injector.
rThe verdict.