rcbench
Servo and ESC test bench: panel, IOmcu and shared C
Loading...
Searching...
No Matches
gt911_emu.h
Go to the documentation of this file.
1
32
33#pragma once
34
35#include <stdbool.h>
36#include <stdint.h>
37
38#ifdef __cplusplus
39extern "C" {
40#endif
41
43#define GT911_EMU_ADDR 0x14u
44
56#define GT911_EMU_PRODUCT_ID "9INJ"
57
60#define GT911_EMU_REG_COMMAND 0x8040u
61#define GT911_EMU_REG_PRODUCT 0x8140u
62#define GT911_EMU_REG_STATUS 0x814Eu
63#define GT911_EMU_REG_POINT1 0x814Fu
65
67#define GT911_EMU_READY 0x80u
68
70#define GT911_EMU_SIZE 24u
71
73#define GT911_EMU_POINTS 5u
74
76#define GT911_EMU_STRIDE 8u
77
79typedef struct {
80 uint8_t id;
81 uint16_t x;
82 uint16_t y;
84
90
92typedef struct {
93 uint16_t res_x;
94 uint16_t res_y;
95
96 uint8_t command[2];
97 uint16_t ptr;
98 uint8_t wbytes;
99 bool reading;
100 bool busy;
101
102 uint8_t status;
106
107 /* Counted by the byte functions, read by the injector. Each wraps. */
108 uint32_t reads;
109 uint32_t acks;
110 uint32_t product_reads;
112
119void gt911_emu_init(gt911_emu_t *e, uint16_t res_x, uint16_t res_y);
120
126void gt911_emu_rx(gt911_emu_t *e, uint8_t b);
127
133uint8_t gt911_emu_tx(gt911_emu_t *e);
134
140
147uint8_t gt911_emu_peek(const gt911_emu_t *e, uint16_t reg);
148
162
169
170#ifdef __cplusplus
171}
172#endif
bool gt911_emu_publish(gt911_emu_t *e, const gt911_emu_frame_t *f)
Make f the frame the master reads next.
Definition gt911_emu.c:105
void gt911_emu_rx(gt911_emu_t *e, uint8_t b)
The master wrote b.
Definition gt911_emu.c:56
uint8_t gt911_emu_tx(gt911_emu_t *e)
The master reads a byte: the one at the pointer, which then moves on.
Definition gt911_emu.c:83
bool gt911_emu_withdraw(gt911_emu_t *e)
Withdraw an unacknowledged frame: the status reads 0x00.
Definition gt911_emu.c:128
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.
Definition gt911_emu.c:24
void gt911_emu_finish(gt911_emu_t *e)
A STOP, a repeated START or an abort ended the transfer.
Definition gt911_emu.c:98
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.
Definition gt911_emu.c:12
#define GT911_EMU_STRIDE
Bytes per point in the register file.
Definition gt911_emu.h:76
#define GT911_EMU_POINTS
Points in one frame: the GT911's 5.
Definition gt911_emu.h:73
One frame: the contacts down, 0 to GT911_EMU_POINTS of them.
Definition gt911_emu.h:86
uint8_t n
Definition gt911_emu.h:87
gt911_emu_point_t pt[GT911_EMU_POINTS]
Definition gt911_emu.h:88
One contact of a frame, in the resolution the emulator reports.
Definition gt911_emu.h:79
uint8_t id
Definition gt911_emu.h:80
uint16_t y
Definition gt911_emu.h:82
uint16_t x
Definition gt911_emu.h:81
The register file and the transfer under way.
Definition gt911_emu.h:92
uint32_t reads
Definition gt911_emu.h:108
uint16_t res_y
Definition gt911_emu.h:94
uint32_t product_reads
Definition gt911_emu.h:110
bool reading
Definition gt911_emu.h:99
uint32_t acks
Definition gt911_emu.h:109
uint8_t wbytes
Definition gt911_emu.h:98
uint16_t res_x
Definition gt911_emu.h:93
uint8_t point[GT911_EMU_POINTS *GT911_EMU_STRIDE]
0x814F..0x8176: GT911_EMU_POINTS points of GT911_EMU_STRIDE bytes each.
Definition gt911_emu.h:105
uint8_t command[2]
Definition gt911_emu.h:96
uint8_t status
Definition gt911_emu.h:102
uint16_t ptr
Definition gt911_emu.h:97
bool busy
Definition gt911_emu.h:100