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.cpp
Go to the documentation of this file.
1
9#include "entryPointCPP.hpp"
10#include "TSC2046.hpp"
11
12extern SPI_HandleTypeDef hspi1;
13
15static TSC2046 *tsc2046 = nullptr;
16
18static bool tsc2046Ready = false;
19
20void initTSC2046(void) {
21 tsc2046 = new TSC2046(&hspi1, TSC2046_CS_GPIO_Port, TSC2046_CS_Pin);
22 tsc2046->begin();
23 tsc2046Ready = true;
24}
25
26bool tsc2046IsReady(void) {
27 return tsc2046Ready;
28}
29
30bool tsc2046GetPoint(int16_t *x, int16_t *y, float *pressure) {
31 if (tsc2046 == nullptr || !tsc2046Ready) {
32 return false;
33 }
35 *x = point.x;
36 *y = point.y;
37 *pressure = point.pressure;
38 return true;
39}
40
41bool tsc2046IsTouched(void) {
42 if (tsc2046 == nullptr || !tsc2046Ready) {
43 return false;
44 }
45 return tsc2046->isTouched();
46}
47
48void tsc2046EnableInterrupts(bool enable) {
49 if (tsc2046 == nullptr || !tsc2046Ready) {
50 return;
51 }
53}
54
55void tsc2046SetVRef(float vref) {
56 if (tsc2046 == nullptr || !tsc2046Ready) {
57 return;
58 }
59 tsc2046->setVRef(vref);
60}
61
62void tsc2046SetTouchedThreshold(float touchedThresholdOhms) {
63 if (tsc2046 == nullptr || !tsc2046Ready) {
64 return;
65 }
66 tsc2046->setTouchedThreshold(touchedThresholdOhms);
67}
68
69bool tsc2046ReadTemperatureC(float *celsius) {
70 if (tsc2046 == nullptr || !tsc2046Ready) {
71 return false;
72 }
73 *celsius = tsc2046->readTemperatureC();
74 return true;
75}
76
77bool tsc2046ReadBatteryVoltage(float *volts) {
78 if (tsc2046 == nullptr || !tsc2046Ready) {
79 return false;
80 }
81 *volts = tsc2046->readBatteryVoltage();
82 return true;
83}
84
85bool tsc2046ReadAuxiliaryVoltage(float *volts) {
86 if (tsc2046 == nullptr || !tsc2046Ready) {
87 return false;
88 }
89 *volts = tsc2046->readAuxiliaryVoltage();
90 return true;
91}
STM32 HAL driver for a TI/Adafruit TSC2046 resistive touchscreen controller, reached over SPI via an ...
Definition TSC2046.hpp:68
void setVRef(float vref)
Sets the voltage connected to the TSC2046's VRef pin, if any.
Definition TSC2046.cpp:63
float readAuxiliaryVoltage()
Definition TSC2046.cpp:176
float readBatteryVoltage()
Definition TSC2046.cpp:170
void enableInterrupts(bool enable)
Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch)....
Definition TSC2046.cpp:144
TSC2046TouchPoint getPoint()
Reads the current touch position and pressure.
Definition TSC2046.cpp:114
bool isTouched()
Determines if the touchscreen is currently being touched, based on the pressure value from getPoint()...
Definition TSC2046.cpp:139
void setTouchedThreshold(float touchedThresholdOhms)
Sets the pressure threshold used by isTouched().
Definition TSC2046.cpp:67
float readTemperatureC()
Reads the TSC2046's on-die temperature sensor, in degrees Celsius.
Definition TSC2046.cpp:152
void begin(uint32_t xPlateResistance=400)
Initializes the driver. Call once before any other method.
Definition TSC2046.cpp:58
void initTSC2046(void)
Constructs the TSC2046 driver. Must be called after MX_SPI1_Init() (and therefore after HAL_Init()/Sy...
bool tsc2046ReadBatteryVoltage(float *volts)
Reads the voltage on the VBAT pin.
void tsc2046SetVRef(float vref)
Sets the voltage connected to the TSC2046's VRef pin, if any.
bool tsc2046IsReady(void)
Reports whether initTSC2046() has run. Every other tsc2046* function below returns false without touc...
static bool tsc2046Ready
Set once initTSC2046() runs; guards every bridge function below against use-before-init.
void tsc2046SetTouchedThreshold(float touchedThresholdOhms)
Sets the pressure threshold used by tsc2046IsTouched().
bool tsc2046GetPoint(int16_t *x, int16_t *y, float *pressure)
Reads the current touch position and pressure.
bool tsc2046ReadAuxiliaryVoltage(float *volts)
Reads the voltage on the AUX pin.
bool tsc2046ReadTemperatureC(float *celsius)
Reads the current temperature.
bool tsc2046IsTouched(void)
Determines if the touchscreen is currently being touched.
static TSC2046 * tsc2046
The single TSC2046 driver instance, constructed in initTSC2046().
void tsc2046EnableInterrupts(bool enable)
Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch)....
C-callable entry points bridging CubeMX-generated main.c into the C++ TSC2046 driver.
One touch reading: raw X/Y position and a pressure-proportional resistance value.
Definition TSC2046.hpp:32
int16_t x
Raw 12-bit X coordinate (0-4095). Meaningless if not touched.
Definition TSC2046.hpp:33
int16_t y
Raw 12-bit Y coordinate (0-4095). Meaningless if not touched.
Definition TSC2046.hpp:34