F439_CPP_SPI_RA8875_TFT_LCD_04 1.0
STM32F439 SPI RA8875 7-inch TFT display with FRAM-backed touch calibration, built on the STM32_GFX, STM32_RA8875 and STM32_MB85RS64V libraries
Loading...
Searching...
No Matches
touchCalibration.cpp File Reference

Three-point touch-screen calibration. See touchCalibration.hpp. More...

#include <stdio.h>
#include "main.h"
#include "touchCalibration.hpp"

Go to the source code of this file.

Functions

bool touchCalibrationCompute (const tsPoint_t *display, const tsPoint_t *screen, tsMatrix_t *matrix)
 Calculates the calibration matrix from three known display points and the raw touch readings taken at those points.
 
bool touchCalibrationApply (const tsMatrix_t *matrix, const tsPoint_t *raw, tsPoint_t *display)
 Converts one raw touch reading into a display pixel position.
 
bool touchCalibrationRun (Adafruit_RA8875 *display, UART_HandleTypeDef *uart, tsMatrix_t *matrix)
 Runs the interactive calibration: draws three targets one at a time, waits for the user to touch each, and computes the matrix.
 

Variables

volatile uint8_t uartRxChar
 The one character the interrupt receive waits for (see main.c).
 
volatile uint8_t uartKeyPressed
 Set by HAL_UART_RxCpltCallback() in main.c: 0 = none yet, otherwise ' ' or 0x1B (Esc).
 

Detailed Description

Three-point touch-screen calibration. See touchCalibration.hpp.

Created on: Oct 5, 2026 Author: johng

Definition in file touchCalibration.cpp.

Function Documentation

◆ touchCalibrationApply()

bool touchCalibrationApply ( const tsMatrix_t * matrix,
const tsPoint_t * raw,
tsPoint_t * display )

Converts one raw touch reading into a display pixel position.

Parameters
matrixCalibration matrix from touchCalibrationCompute().
rawRaw touch reading (the 10-bit values from touchRead()).
displayReceives the display position in pixels (may fall outside the screen).
Returns
true on success; false if an argument is null or the matrix divider is zero.

Definition at line 207 of file touchCalibration.cpp.

References tsMatrix_t::An, tsMatrix_t::Bn, tsMatrix_t::Cn, tsMatrix_t::Divider, tsMatrix_t::Dn, tsMatrix_t::En, tsMatrix_t::Fn, Point::x, and Point::y.

Referenced by testTouch().

◆ touchCalibrationCompute()

bool touchCalibrationCompute ( const tsPoint_t * display,
const tsPoint_t * screen,
tsMatrix_t * matrix )

Calculates the calibration matrix from three known display points and the raw touch readings taken at those points.

Parameters
displayArray of three points: where the targets were drawn on the display, in pixels.
screenArray of three points: the raw touch readings for those targets.
matrixReceives the calibration coefficients.
Returns
true on success; false if an argument is null or the three raw points lie on one line (the divider is zero), in which case the matrix is not usable.

Definition at line 172 of file touchCalibration.cpp.

References tsMatrix_t::An, tsMatrix_t::Bn, tsMatrix_t::Cn, tsMatrix_t::Divider, tsMatrix_t::Dn, tsMatrix_t::En, tsMatrix_t::Fn, Point::x, and Point::y.

Referenced by touchCalibrationRun().

◆ touchCalibrationRun()

bool touchCalibrationRun ( Adafruit_RA8875 * display,
UART_HandleTypeDef * uart,
tsMatrix_t * matrix )

Runs the interactive calibration: draws three targets one at a time, waits for the user to touch each, and computes the matrix.

Parameters
displayThe RA8875 display object, already started with begin() and with touch enabled.
uartThe UART handle of the serial terminal (USART1 here); the terminal must be open.
matrixReceives the calibration coefficients.
Returns
true when a usable matrix was calculated; false if an argument is null or the three touches could not give a usable matrix after three attempts (for example because the targets were not touched where they were drawn).

After the first and the second target the terminal asks for the space bar and the next target appears only then, so an extra tap cannot be taken as the next touch. Pressing Esc there instead throws that touch away and shows the same target again. Each target counts only when the pen is held on it for about 0.3 seconds: a green ring then appears and the pen can be lifted. Short taps are ignored, and the readings taken during the hold are averaged. Each attempt waits for the user as long as it takes. Only a bad set of touches, which a new attempt can fix, is retried.

Definition at line 217 of file touchCalibration.cpp.

References Adafruit_RA8875::fillScreen(), Adafruit_RA8875::height(), RA8875_WHITE, touchCalibrationCompute(), and Adafruit_RA8875::width().

Referenced by testTouch().

Variable Documentation

◆ uartKeyPressed

volatile uint8_t uartKeyPressed
extern

Set by HAL_UART_RxCpltCallback() in main.c: 0 = none yet, otherwise ' ' or 0x1B (Esc).

Set by HAL_UART_RxCpltCallback() in main.c: 0 = none yet, otherwise ' ' or 0x1B (Esc).

Definition at line 89 of file main.c.

Referenced by HAL_UART_RxCpltCallback().

◆ uartRxChar

volatile uint8_t uartRxChar
extern

The one character the interrupt receive waits for (see main.c).

The one character the interrupt receive waits for (see main.c).

Definition at line 87 of file main.c.

Referenced by HAL_UART_ErrorCallback(), and HAL_UART_RxCpltCallback().