H753_CPP_SPI_Resistive_Touch_Screen_Controller 1.0
STM32H753 SPI resistive touchscreen (Adafruit 333 overlay + 5767 TSC2046 controller) driver and tutorial
Loading...
Searching...
No Matches
entryPointCPP.hpp File Reference

C-callable entry points bridging CubeMX-generated main.c into the C++ TSC2046 driver. More...

#include "main.h"
#include "stdbool.h"

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.
 

Detailed Description

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.

Function Documentation

◆ initTSC2046()

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.

Note
Check tsc2046IsReady() to confirm initialization ran.

Definition at line 20 of file entryPointCPP.cpp.

References TSC2046::begin(), tsc2046, and tsc2046Ready.

Referenced by main().

◆ tsc2046EnableInterrupts()

void tsc2046EnableInterrupts ( bool enable)

Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch). See TSC2046's class-level.

Note
for why this matters even if the IRQ pin isn't wired up.
Parameters
enabletrue to enable (the default state), false to disable.
Note
Silently does nothing if not ready.

Definition at line 48 of file entryPointCPP.cpp.

References TSC2046::enableInterrupts(), tsc2046, and tsc2046Ready.

◆ tsc2046GetPoint()

bool tsc2046GetPoint ( int16_t * x,
int16_t * y,
float * pressure )

Reads the current touch position and pressure.

Parameters
xDestination for the raw X coordinate (0-4095). Left unmodified if this returns false.
yDestination for the raw Y coordinate (0-4095). Left unmodified if this returns false.
pressureDestination for the touch resistance in Ohms – LOWER means MORE pressure; 0, NaN, or infinite means "not touching". Left unmodified if this returns false.
Return values
trueif 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().

◆ tsc2046IsReady()

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().

Return values
trueif the driver is constructed and ready for use.

Definition at line 26 of file entryPointCPP.cpp.

References tsc2046Ready.

◆ tsc2046IsTouched()

bool tsc2046IsTouched ( void )

Determines if the touchscreen is currently being touched.

Return values
trueif touched. false if not ready or not touched.

Definition at line 41 of file entryPointCPP.cpp.

References TSC2046::isTouched(), tsc2046, and tsc2046Ready.

◆ tsc2046ReadAuxiliaryVoltage()

bool tsc2046ReadAuxiliaryVoltage ( float * volts)

Reads the voltage on the AUX pin.

Parameters
voltsDestination for the voltage, in volts (0-effective VRef range). Left unmodified if this returns false.
Return values
trueon success, false if not ready.

Definition at line 85 of file entryPointCPP.cpp.

References TSC2046::readAuxiliaryVoltage(), tsc2046, and tsc2046Ready.

◆ tsc2046ReadBatteryVoltage()

bool tsc2046ReadBatteryVoltage ( float * volts)

Reads the voltage on the VBAT pin.

Parameters
voltsDestination for the voltage, in volts (0-6V range). Left unmodified if this returns false.
Return values
trueon success, false if not ready.

Definition at line 77 of file entryPointCPP.cpp.

References TSC2046::readBatteryVoltage(), tsc2046, and tsc2046Ready.

◆ tsc2046ReadTemperatureC()

bool tsc2046ReadTemperatureC ( float * celsius)

Reads the current temperature.

Parameters
celsiusDestination for the temperature in degrees Celsius. Left unmodified if this returns false.
Return values
trueon success, false if not ready.

Definition at line 69 of file entryPointCPP.cpp.

References TSC2046::readTemperatureC(), tsc2046, and tsc2046Ready.

◆ tsc2046SetTouchedThreshold()

void tsc2046SetTouchedThreshold ( float touchedThresholdOhms)

Sets the pressure threshold used by tsc2046IsTouched().

Parameters
touchedThresholdOhmsResistance readings above this value (in Ohms) are considered "not touching".
Note
Silently does nothing if not ready.

Definition at line 62 of file entryPointCPP.cpp.

References TSC2046::setTouchedThreshold(), tsc2046, and tsc2046Ready.

◆ tsc2046SetVRef()

void tsc2046SetVRef ( float vref)

Sets the voltage connected to the TSC2046's VRef pin, if any.

Parameters
vrefVoltage in volts, or a negative value if nothing is connected to VRef (the default state after initTSC2046()).
Note
Silently does nothing if not ready.

Definition at line 55 of file entryPointCPP.cpp.

References TSC2046::setVRef(), tsc2046, and tsc2046Ready.