|
H753_CPP_SPI_Resistive_Touch_Screen_Controller 1.0
STM32H753 SPI resistive touchscreen (Adafruit 333 overlay + 5767 TSC2046 controller) driver and tutorial
|
STM32 HAL (C++) driver for the TI TSC2046 resistive touchscreen controller (e.g. Adafruit #5767): reads raw 12-bit touch X/Y coordinates and a pressure-proportional resistance over SPI, plus the chip's temperature, VBAT and AUX readings.
Modeled on Adafruit_TSC2046 as a design reference for the command byte layout and pressure formula. It is an independent STM32 HAL implementation, not a direct port.
Built on STM32_BusIO. Add both to your project as git submodules:
Cloning a project that already includes them:
If you forgot the flag the folders are empty; run git submodule update --init.
In STM32CubeIDE, add both folders as source locations and add ../STM32BusIO and ../TSC2046 to the include paths for both C and C++.
Configure an SPI peripheral in CubeMX (mode 0, 8-bit, MSB first, SCK at or below ~2 MHz) and a GPIO output for chip select, then:
Construct the object after MX_SPIx_Init(), not as a global, so the peripheral is configured first. The PENIRQ pin can be polled as a GPIO input (active low while pressed).
main.cThe classes in this library are C++, but STM32CubeIDE generates main.c as plain C, and you should not rename it to main.cpp (CubeMX regenerates main.c, not main.cpp). Keep main.c as C and reach the driver through a small C-callable wrapper:
extern "C" in a header..cpp file that creates the TSC2046 object with new after MX_SPIx_Init() has run (not as a global, which would construct too early).main.c, and put those calls only inside CubeMX's "safe areas": the code between the /* USER CODE BEGIN ... */ and /* USER CODE END ... */ markers. CubeMX overwrites everything outside those markers whenever it regenerates main.c.The tutorial STM32 C++ Code Integration with STM32CubeIDE walks through this step by step.
readTemperatureC() / readTemperatureF()) is not accurate. It is the chip's own on-die temperature from a two-diode measurement; TI specifies only about 2 C accuracy under ideal conditions, real readings can be off by more, and it has not been checked against a reference thermometer here. It exists because the TSC2046 has the sensor (alongside the VBAT and AUX inputs) and the Adafruit reference library exposes it, so it is ported for parity. Touch handling never uses it. Treat it as a rough indication only.getPoint() disables interrupts around four SPI reads; in an RTOS project replace that with a mutex.The API docs are generated with Doxygen and are not committed to the repo. From this folder, run:
The HTML is written to docs/ (open docs/html/index.html). Graphviz is optional, for call graphs; see the commented HAVE_DOT lines in Doxyfile.
MIT. Design derived from Adafruit_TSC2046, Copyright (c) 2023 Adafruit Industries and Mikaela Szekely (MIT). See LICENSE.