|
H753_CPP_SPI_Resistive_Touch_Screen_Controller 1.0
STM32H753 SPI resistive touchscreen (Adafruit 333 overlay + 5767 TSC2046 controller) driver and tutorial
|
C-callable entry points bridging CubeMX-generated main.c into the C++ TSC2046 driver. More...
Go to the source code of this file.
Functions | |
| void | initTSC2046 (void) |
| Constructs the TSC2046 driver. Must be called after MX_SPI1_Init() (and therefore after HAL_Init()/SystemClock_Config()) so the SPI1 peripheral and the TSC2046_CS pin are already configured before the driver touches them. | |
| bool | tsc2046IsReady (void) |
| Reports whether initTSC2046() has run. Every other tsc2046* function below returns false without touching hardware if this is false, guarding against a call made before initTSC2046(). | |
| bool | tsc2046GetPoint (int16_t *x, int16_t *y, float *pressure) |
| Reads the current touch position and pressure. | |
| bool | tsc2046IsTouched (void) |
| Determines if the touchscreen is currently being touched. | |
| void | tsc2046EnableInterrupts (bool enable) |
| Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch). See TSC2046's class-level. | |
| void | tsc2046SetVRef (float vref) |
| Sets the voltage connected to the TSC2046's VRef pin, if any. | |
| void | tsc2046SetTouchedThreshold (float touchedThresholdOhms) |
| Sets the pressure threshold used by tsc2046IsTouched(). | |
| bool | tsc2046ReadTemperatureC (float *celsius) |
| Reads the current temperature. | |
| bool | tsc2046ReadBatteryVoltage (float *volts) |
| Reads the voltage on the VBAT pin. | |
| bool | tsc2046ReadAuxiliaryVoltage (float *volts) |
| Reads the voltage on the AUX pin. | |
C-callable entry points bridging CubeMX-generated main.c into the C++ TSC2046 driver.
C-callable entry points bridging CubeMX-generated main.c (plain C, subject to regeneration whenever the .ioc changes) into the C++ TSC2046 driver.
extern "C" here prevents C++ name mangling on these declarations, so main.c can call them directly by name. The driver object itself is constructed inside initTSC2046(), deliberately called from main() after HAL_Init()/MX_GPIO_Init()/MX_SPI1_Init() have already run – not as a global static C++ object, which would construct too early (C++ global constructors run in __libc_init_array() before main() even starts, before any peripheral is configured).
Created on: Sep 15, 2026 Author: johng
Definition in file entryPointCPP.hpp.
| void initTSC2046 | ( | void | ) |
Constructs the TSC2046 driver. Must be called after MX_SPI1_Init() (and therefore after HAL_Init()/SystemClock_Config()) so the SPI1 peripheral and the TSC2046_CS pin are already configured before the driver touches them.
Definition at line 20 of file entryPointCPP.cpp.
References TSC2046::begin(), tsc2046, and tsc2046Ready.
Referenced by main().
| void tsc2046EnableInterrupts | ( | bool | enable | ) |
Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch). See TSC2046's class-level.
| enable | true to enable (the default state), false to disable. |
Definition at line 48 of file entryPointCPP.cpp.
References TSC2046::enableInterrupts(), tsc2046, and tsc2046Ready.
| bool tsc2046GetPoint | ( | int16_t * | x, |
| int16_t * | y, | ||
| float * | pressure ) |
Reads the current touch position and pressure.
| x | Destination for the raw X coordinate (0-4095). Left unmodified if this returns false. |
| y | Destination for the raw Y coordinate (0-4095). Left unmodified if this returns false. |
| pressure | Destination for the touch resistance in Ohms – LOWER means MORE pressure; 0, NaN, or infinite means "not touching". Left unmodified if this returns false. |
| true | if the driver was ready and the read was performed. Does NOT mean the screen is actually being touched – check *pressure (or call tsc2046IsTouched() instead) for that. |
Definition at line 30 of file entryPointCPP.cpp.
References TSC2046::getPoint(), TSC2046TouchPoint::pressure, tsc2046, tsc2046Ready, TSC2046TouchPoint::x, and TSC2046TouchPoint::y.
Referenced by main().
| bool tsc2046IsReady | ( | void | ) |
Reports whether initTSC2046() has run. Every other tsc2046* function below returns false without touching hardware if this is false, guarding against a call made before initTSC2046().
| true | if the driver is constructed and ready for use. |
Definition at line 26 of file entryPointCPP.cpp.
References tsc2046Ready.
| bool tsc2046IsTouched | ( | void | ) |
Determines if the touchscreen is currently being touched.
| true | if touched. false if not ready or not touched. |
Definition at line 41 of file entryPointCPP.cpp.
References TSC2046::isTouched(), tsc2046, and tsc2046Ready.
| bool tsc2046ReadAuxiliaryVoltage | ( | float * | volts | ) |
Reads the voltage on the AUX pin.
| volts | Destination for the voltage, in volts (0-effective VRef range). Left unmodified if this returns false. |
| true | on success, false if not ready. |
Definition at line 85 of file entryPointCPP.cpp.
References TSC2046::readAuxiliaryVoltage(), tsc2046, and tsc2046Ready.
| bool tsc2046ReadBatteryVoltage | ( | float * | volts | ) |
Reads the voltage on the VBAT pin.
| volts | Destination for the voltage, in volts (0-6V range). Left unmodified if this returns false. |
| true | on success, false if not ready. |
Definition at line 77 of file entryPointCPP.cpp.
References TSC2046::readBatteryVoltage(), tsc2046, and tsc2046Ready.
| bool tsc2046ReadTemperatureC | ( | float * | celsius | ) |
Reads the current temperature.
| celsius | Destination for the temperature in degrees Celsius. Left unmodified if this returns false. |
| true | on success, false if not ready. |
Definition at line 69 of file entryPointCPP.cpp.
References TSC2046::readTemperatureC(), tsc2046, and tsc2046Ready.
| void tsc2046SetTouchedThreshold | ( | float | touchedThresholdOhms | ) |
Sets the pressure threshold used by tsc2046IsTouched().
| touchedThresholdOhms | Resistance readings above this value (in Ohms) are considered "not touching". |
Definition at line 62 of file entryPointCPP.cpp.
References TSC2046::setTouchedThreshold(), tsc2046, and tsc2046Ready.
| void tsc2046SetVRef | ( | float | vref | ) |
Sets the voltage connected to the TSC2046's VRef pin, if any.
| vref | Voltage in volts, or a negative value if nothing is connected to VRef (the default state after initTSC2046()). |
Definition at line 55 of file entryPointCPP.cpp.
References TSC2046::setVRef(), tsc2046, and tsc2046Ready.