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

Touch input for the 7-inch ESP32-P4 display board. More...

#include "esp_err.h"
#include "board_pins.h"
#include "touch_map.h"
#include "touch_types.h"

Go to the source code of this file.

Data Structures

struct  touch_config_t
 How touch_init() sets the touch input up. More...

Macros

#define TOUCH_CONFIG_DEFAULT()
 Polled every 10ms, mirrored as board_pins.h says, 32 events.

Functions

esp_err_t touch_init (const touch_config_t *cfg)
 Reset the controller, probe it and start the polling task.
esp_err_t touch_deinit (void)
 Stop the task and release the controller.
int touch_snapshot (touch_point_t *out, int max)
bool touch_pressed (touch_point_t *out)
bool touch_wait_event (touch_event_t *out, uint32_t *seq, uint32_t timeout_ms)
uint32_t touch_published (void)
void touch_flush_events (void)
uint16_t touch_i2c_address (void)
uint32_t touch_age_ms (void)
bool touch_injector_attached (void)
 Whether a touch injector (testbench/touch-injector) is attached: it answered at start-up and has not been silent for 1000ms since, or a probe has re-attached it. Always true when the injector is the only touch device (nothing at 0x5D, and the product ID "9INJ" at 0x14). Declared in a build with RCBENCH_TOUCH_INJECTOR (the default) only; touch_inject.h has the rest.

Detailed Description

Touch input for the 7-inch ESP32-P4 display board.

A background task polls the GT911 every poll_interval_ms, maps the coordinates into screen space, drops the ones outside the UI's BOARD_UI_H_RES x BOARD_UI_V_RES area and publishes the result two ways:

  • touch_snapshot(): the current contacts, never blocks. A redraw loop polls it every frame.
  • touch_wait_event(): DOWN, MOVE and UP events off a queue, for code that wants edges rather than levels.

SPDX-License-Identifier: MIT

Macro Definition Documentation

◆ TOUCH_CONFIG_DEFAULT

#define TOUCH_CONFIG_DEFAULT ( )
Value:
.rotation = TOUCH_ROTATION_0, \
.mirror_x = BOARD_TOUCH_MIRROR_X, \
.mirror_y = BOARD_TOUCH_MIRROR_Y, \
.poll_interval_ms = 10, \
.event_queue_len = 32, \
.task_priority = 5, \
.task_core = 0, \
}
#define BOARD_TOUCH_MIRROR_X
Touch mirroring, 1 to mirror an axis.
Definition board_pins.h:149
#define BOARD_TOUCH_MIRROR_Y
Definition board_pins.h:150
How touch_init() sets the touch input up.
Definition touch.h:31
@ TOUCH_ROTATION_0
Definition touch_types.h:32

Polled every 10ms, mirrored as board_pins.h says, 32 events.

Function Documentation

◆ touch_age_ms()

uint32_t touch_age_ms ( void )

Milliseconds since the controller last answered a read, or UINT32_MAX when touch never came up.

"Answered" means the I2C (Inter-Integrated Circuit) transaction succeeded, not that a finger was down. An untouched panel is healthy and reports an age near zero, so this separates "nobody is touching it" from "the controller stopped answering", which the event stream cannot.

An application that can act on input, and only on input, treats a large age as a fault rather than as quiet.

◆ touch_deinit()

esp_err_t touch_deinit ( void )

Stop the task and release the controller.

Returns
ESP_OK, also when touch was not up.

◆ touch_flush_events()

void touch_flush_events ( void )

Drop any queued events (useful after a screen change).

◆ touch_i2c_address()

uint16_t touch_i2c_address ( void )

I2C address the controller answered on, or 0 before init.

◆ touch_init()

esp_err_t touch_init ( const touch_config_t * cfg)

Reset the controller, probe it and start the polling task.

Parameters
cfgThe set-up; NULL takes TOUCH_CONFIG_DEFAULT().
Returns
ESP_OK, also when already up; ESP_ERR_NO_MEM for the task, lock or queue; otherwise the board's or the GT911's error.

◆ touch_injector_attached()

bool touch_injector_attached ( void )

Whether a touch injector (testbench/touch-injector) is attached: it answered at start-up and has not been silent for 1000ms since, or a probe has re-attached it. Always true when the injector is the only touch device (nothing at 0x5D, and the product ID "9INJ" at 0x14). Declared in a build with RCBENCH_TOUCH_INJECTOR (the default) only; touch_inject.h has the rest.

Returns
true while an injector is attached

◆ touch_pressed()

bool touch_pressed ( touch_point_t * out)

True when at least one finger is down; fills out if given.

◆ touch_published()

uint32_t touch_published ( void )

The number of the last event the driver offered to its queue, stored after the offer. Read before draining the queue: an event up to it that the drain did not deliver was dropped, which a loss at the end of the stream, with no later event to show the gap, needs.

◆ touch_snapshot()

int touch_snapshot ( touch_point_t * out,
int max )

Copy the current contact set. Returns the number of active contacts, which may exceed max (only max of them are written).

◆ touch_wait_event()

bool touch_wait_event ( touch_event_t * out,
uint32_t * seq,
uint32_t timeout_ms )

Pop the next input event. timeout_ms of 0 polls, UINT32_MAX blocks. Returns false when nothing arrived in time.

seq, when not NULL, receives the event's number. The driver numbers every event it offers to its queue, from 1 and in order, whether or not the queue kept it, so a number skipped is an event the queue dropped because nobody collected it. touch_loss.h turns the numbers into losses.