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

The register file of a GT911 touch controller as an I2C (Inter-Integrated Circuit) target sees it: the bytes a master writes and reads, one at a time, and the frame handshake. Pure C. The RP2350 build calls the three byte functions from the I2C interrupt; the host suite calls them as a master would. More...

#include <stdbool.h>
#include <stdint.h>

Go to the source code of this file.

Data Structures

struct  gt911_emu_point_t
 One contact of a frame, in the resolution the emulator reports. More...
struct  gt911_emu_frame_t
 One frame: the contacts down, 0 to GT911_EMU_POINTS of them. More...
struct  gt911_emu_t
 The register file and the transfer under way. More...

Macros

#define GT911_EMU_ADDR   0x14u
 The I2C address the emulator answers at.
#define GT911_EMU_PRODUCT_ID   "9INJ"
 The product ID at 0x8140..0x8143, 4 ASCII bytes with no NUL.
#define GT911_EMU_READY   0x80u
 The status byte's frame-ready bit.
#define GT911_EMU_SIZE   24u
 Contact size the emulator reports, in the GT911's units.
#define GT911_EMU_POINTS   5u
 Points in one frame: the GT911's 5.
#define GT911_EMU_STRIDE   8u
 Bytes per point in the register file.
Registers
#define GT911_EMU_REG_COMMAND   0x8040u
#define GT911_EMU_REG_PRODUCT   0x8140u
#define GT911_EMU_REG_STATUS   0x814Eu
#define GT911_EMU_REG_POINT1   0x814Fu

Functions

void gt911_emu_init (gt911_emu_t *e, uint16_t res_x, uint16_t res_y)
 Clear the register file and set the resolution it reports.
void gt911_emu_rx (gt911_emu_t *e, uint8_t b)
 The master wrote b.
uint8_t gt911_emu_tx (gt911_emu_t *e)
 The master reads a byte: the one at the pointer, which then moves on.
void gt911_emu_finish (gt911_emu_t *e)
 A STOP, a repeated START or an abort ended the transfer.
uint8_t gt911_emu_peek (const gt911_emu_t *e, uint16_t reg)
 The byte at reg, as a read would return it, without side effects.
bool gt911_emu_publish (gt911_emu_t *e, const gt911_emu_frame_t *f)
 Make f the frame the master reads next.
bool gt911_emu_withdraw (gt911_emu_t *e)
 Withdraw an unacknowledged frame: the status reads 0x00.

Detailed Description

The register file of a GT911 touch controller as an I2C (Inter-Integrated Circuit) target sees it: the bytes a master writes and reads, one at a time, and the frame handshake. Pure C. The RP2350 build calls the three byte functions from the I2C interrupt; the host suite calls them as a master would.

Register pointer: 16 bit, big endian, set by the first two bytes of a write, and incremented by every byte read or written after it. A read with no pointer write before it continues from the current pointer.

Served (GT911 Programming Guide Rev.10, sections 2 and 3):

0x8040-0x8041 command and ESD check: what was last written 0x8047 config version 0x41 0x8048-0x804B X and Y output maximum, little endian 0x804C touch number 5 0x8140-0x8143 product ID "9INJ" (GT911_EMU_PRODUCT_ID), no NUL 0x8144-0x8145 firmware version 0xE001 0x8146-0x8149 X and Y resolution, little endian 0x814E status: bit 7 frame ready, bits 3..0 point count 0x814F-0x8176 points 1 to 5, 8 bytes each: track ID, X, Y, size, reserved anything else 0x00

A write of any value to 0x814E acknowledges the frame: the status reads 0x00 until the next frame is published. Writes elsewhere are ignored.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ GT911_EMU_PRODUCT_ID

#define GT911_EMU_PRODUCT_ID   "9INJ"

The product ID at 0x8140..0x8143, 4 ASCII bytes with no NUL.

The panel tells the injector from the glass by it, not by the address. A Goodix controller reports its part number there, digits with at most one trailing letter ("911" and a NUL on a GT911); this ID has letters from its second byte on, so no glass reports it. '9' first keeps the panel's GT911 probe accepting it. The panel's copy is TOUCH_MERGE_INJECT_PRODUCT (shared/touch/include/touch_merge.h); the host suite checks that the two match.

◆ GT911_EMU_REG_COMMAND

#define GT911_EMU_REG_COMMAND   0x8040u

command, then the ESD check

◆ GT911_EMU_REG_POINT1

#define GT911_EMU_REG_POINT1   0x814Fu

the first point's track ID

◆ GT911_EMU_REG_PRODUCT

#define GT911_EMU_REG_PRODUCT   0x8140u

product ID "9INJ"

◆ GT911_EMU_REG_STATUS

#define GT911_EMU_REG_STATUS   0x814Eu

ready flag and point count

Function Documentation

◆ gt911_emu_finish()

void gt911_emu_finish ( gt911_emu_t * e)

A STOP, a repeated START or an abort ended the transfer.

Parameters
eThe emulator.

◆ gt911_emu_init()

void gt911_emu_init ( gt911_emu_t * e,
uint16_t res_x,
uint16_t res_y )

Clear the register file and set the resolution it reports.

Parameters
eThe emulator.
res_xColumns.
res_yRows.

◆ gt911_emu_peek()

uint8_t gt911_emu_peek ( const gt911_emu_t * e,
uint16_t reg )

The byte at reg, as a read would return it, without side effects.

Parameters
eThe emulator.
regThe register.
Returns
The byte.

◆ gt911_emu_publish()

bool gt911_emu_publish ( gt911_emu_t * e,
const gt911_emu_frame_t * f )

Make f the frame the master reads next.

Refused while a transfer is under way or the previous frame is not yet acknowledged, so a master never reads the status of one frame and the points of another. Refused too for more than GT911_EMU_POINTS points. Point slots past f->n read 0x00.

Parameters
eThe emulator.
fThe frame.
Returns
Whether it is published.

◆ gt911_emu_rx()

void gt911_emu_rx ( gt911_emu_t * e,
uint8_t b )

The master wrote b.

Parameters
eThe emulator.
bThe byte.

◆ gt911_emu_tx()

uint8_t gt911_emu_tx ( gt911_emu_t * e)

The master reads a byte: the one at the pointer, which then moves on.

Parameters
eThe emulator.
Returns
The byte.

◆ gt911_emu_withdraw()

bool gt911_emu_withdraw ( gt911_emu_t * e)

Withdraw an unacknowledged frame: the status reads 0x00.

Parameters
eThe emulator.
Returns
False while a transfer is under way, and nothing is withdrawn.