|
H753_CPP_SPI_Resistive_Touch_Screen_Controller 1.0
STM32H753 SPI resistive touchscreen (Adafruit 333 overlay + 5767 TSC2046 controller) driver and tutorial
|
STM32 HAL driver for a TI/Adafruit TSC2046 resistive touchscreen controller, reached over SPI via an owned STM32SPIDevice. More...
#include <TSC2046.hpp>
Public Member Functions | |
| TSC2046 (SPI_HandleTypeDef *hspi, GPIO_TypeDef *csPort, uint16_t csPin) | |
| Constructs the driver and its underlying STM32SPIDevice. Does not touch hardware – call begin() before any other method. | |
| void | begin (uint32_t xPlateResistance=400) |
| Initializes the driver. Call once before any other method. | |
| void | setVRef (float vref) |
| Sets the voltage connected to the TSC2046's VRef pin, if any. | |
| void | setTouchedThreshold (float touchedThresholdOhms) |
| Sets the pressure threshold used by isTouched(). | |
| TSC2046TouchPoint | getPoint () |
| Reads the current touch position and pressure. | |
| bool | isTouched () |
| Determines if the touchscreen is currently being touched, based on the pressure value from getPoint() and the threshold set by setTouchedThreshold(). | |
| void | enableInterrupts (bool enable) |
| Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch). See the class-level. | |
| float | readTemperatureC () |
| Reads the TSC2046's on-die temperature sensor, in degrees Celsius. | |
| float | readTemperatureF () |
| Same reading as readTemperatureC(), converted to degrees Fahrenheit. | |
| float | readBatteryVoltage () |
| float | readAuxiliaryVoltage () |
STM32 HAL driver for a TI/Adafruit TSC2046 resistive touchscreen controller, reached over SPI via an owned STM32SPIDevice.
Definition at line 68 of file TSC2046.hpp.
| TSC2046::TSC2046 | ( | SPI_HandleTypeDef * | hspi, |
| GPIO_TypeDef * | csPort, | ||
| uint16_t | csPin ) |
Constructs the driver and its underlying STM32SPIDevice. Does not touch hardware – call begin() before any other method.
| hspi | Pointer to the already-initialized SPI handle to use. |
| csPort | GPIO port of the TSC2046's chip-select pin. |
| csPin | GPIO pin number of the TSC2046's chip-select pin. |
Definition at line 53 of file TSC2046.cpp.
| void TSC2046::begin | ( | uint32_t | xPlateResistance = 400 | ) |
Initializes the driver. Call once before any other method.
| xPlateResistance | The resistance, in Ohms, measured across the touchscreen's X- and X+ pins with a multimeter – see the reference library's documentation for how to measure this. Defaults to 400 (a reasonable placeholder if not measured, though getPoint()'s pressure value will be less accurate). |
Definition at line 58 of file TSC2046.cpp.
References STM32SPIDevice::begin().
Referenced by initTSC2046().
| void TSC2046::enableInterrupts | ( | bool | enable | ) |
Enables or disables the TSC2046's own touch interrupt (IRQ pin pulled low on touch). See the class-level.
| enable | true to enable (the default state), false to disable. |
Definition at line 144 of file TSC2046.cpp.
Referenced by tsc2046EnableInterrupts().
| TSC2046TouchPoint TSC2046::getPoint | ( | ) |
Reads the current touch position and pressure.
| The | X, Y, and pressure reading. Meaningless if isTouched() (or an equivalent check on the returned pressure) is false. |
Definition at line 114 of file TSC2046.cpp.
References TSC2046TouchPoint::x.
Referenced by isTouched(), and tsc2046GetPoint().
| bool TSC2046::isTouched | ( | ) |
Determines if the touchscreen is currently being touched, based on the pressure value from getPoint() and the threshold set by setTouchedThreshold().
| true | if touched. |
Definition at line 139 of file TSC2046.cpp.
References getPoint(), and TSC2046TouchPoint::pressure.
Referenced by tsc2046IsTouched().
| float TSC2046::readAuxiliaryVoltage | ( | ) |
| The | voltage on the AUX pin, in volts (0-effectiveVRef() range). |
Definition at line 176 of file TSC2046.cpp.
Referenced by tsc2046ReadAuxiliaryVoltage().
| float TSC2046::readBatteryVoltage | ( | ) |
| The | voltage on the VBAT pin, in volts (0-6V range regardless of Vin/VRef). |
Definition at line 170 of file TSC2046.cpp.
Referenced by tsc2046ReadBatteryVoltage().
| float TSC2046::readTemperatureC | ( | ) |
Reads the TSC2046's on-die temperature sensor, in degrees Celsius.
| The | chip temperature in degrees Celsius (approximate). |
Definition at line 152 of file TSC2046.cpp.
Referenced by readTemperatureF(), and tsc2046ReadTemperatureC().
| float TSC2046::readTemperatureF | ( | ) |
Same reading as readTemperatureC(), converted to degrees Fahrenheit.
| The | chip temperature in degrees Fahrenheit (approximate). |
Definition at line 156 of file TSC2046.cpp.
References readTemperatureC().
| void TSC2046::setTouchedThreshold | ( | float | touchedThresholdOhms | ) |
Sets the pressure threshold used by isTouched().
| touchedThresholdOhms | Resistance readings above this value (in Ohms) are considered "not touching". Defaults to 100000 (100 kOhm) if never called. |
Definition at line 67 of file TSC2046.cpp.
Referenced by tsc2046SetTouchedThreshold().
| void TSC2046::setVRef | ( | float | vref | ) |
Sets the voltage connected to the TSC2046's VRef pin, if any.
| vref | Voltage in volts, or a negative value (the default) if nothing is connected to VRef – in which case the chip's internal 2.5V reference is used for readTemperatureC/F(), readBatteryVoltage(), and readAuxiliaryVoltage(). Has no effect on touch coordinate reads, which always use differential mode. |
Definition at line 63 of file TSC2046.cpp.
Referenced by tsc2046SetVRef().