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
touchZones.c
Go to the documentation of this file.
1
9#include "touchZones.h"
10
11/* Accepted touch area. Deliberately generous: the BEEP row sits at the very bottom of
12 * the panel and its presses read Y ~3340-3600, so a tight limit rejected them. Idle
13 * (untouched) junk readings are already rejected by the pressure band in main.c. */
15#define TOUCH_X_MIN 300
17#define TOUCH_X_MAX 3700
19#define TOUCH_Y_MIN 300
21#define TOUCH_Y_MAX 3650
22
24#define TOUCH_X_SPLIT 2060
25
26/* Row boundaries, from measured presses on the panel with the printed layout:
27 * LED1 Y ~580-880, LED2 ~1660-1790, LED3 ~2420-2700, BEEP ~3115-3560. */
29#define TOUCH_Y_LED1_LED2 1285
31#define TOUCH_Y_LED2_LED3 2075
33#define TOUCH_Y_LED3_BEEP 2900
34
35touchZone_t touchZoneFromPoint(int16_t x, int16_t y) {
36 if (x < TOUCH_X_MIN || x > TOUCH_X_MAX || y < TOUCH_Y_MIN || y > TOUCH_Y_MAX) {
37 return TOUCH_ZONE_NONE;
38 }
39
40 if (y >= TOUCH_Y_LED3_BEEP) {
41 return TOUCH_ZONE_BEEP; /* full width: any X */
42 }
43
44 int right = (x >= TOUCH_X_SPLIT);
45
46 if (y < TOUCH_Y_LED1_LED2) {
47 return right ? TOUCH_ZONE_LED1_ON : TOUCH_ZONE_LED1_OFF;
48 }
49 if (y < TOUCH_Y_LED2_LED3) {
50 return right ? TOUCH_ZONE_LED2_ON : TOUCH_ZONE_LED2_OFF;
51 }
52 return right ? TOUCH_ZONE_LED3_ON : TOUCH_ZONE_LED3_OFF;
53}
54
55const char *touchZoneName(touchZone_t zone) {
56 switch (zone) {
57 case TOUCH_ZONE_LED1_OFF: return "LED 1 OFF";
58 case TOUCH_ZONE_LED1_ON: return "LED 1 ON";
59 case TOUCH_ZONE_LED2_OFF: return "LED 2 OFF";
60 case TOUCH_ZONE_LED2_ON: return "LED 2 ON";
61 case TOUCH_ZONE_LED3_OFF: return "LED 3 OFF";
62 case TOUCH_ZONE_LED3_ON: return "LED 3 ON";
63 case TOUCH_ZONE_BEEP: return "BEEP";
64 default: return "none";
65 }
66}
#define TOUCH_Y_MAX
Highest accepted raw Y.
Definition touchZones.c:21
#define TOUCH_X_MAX
Highest accepted raw X.
Definition touchZones.c:17
#define TOUCH_X_SPLIT
Raw X that separates the OFF (left) half from the ON (right) half, from measured button centers.
Definition touchZones.c:24
#define TOUCH_Y_LED3_BEEP
Raw Y boundary between the LED 3 row and the BEEP row.
Definition touchZones.c:33
#define TOUCH_Y_LED2_LED3
Raw Y boundary between the LED 2 row and the LED 3 row.
Definition touchZones.c:31
const char * touchZoneName(touchZone_t zone)
Gives a short printable name for a zone.
Definition touchZones.c:55
#define TOUCH_Y_LED1_LED2
Raw Y boundary between the LED 1 row and the LED 2 row.
Definition touchZones.c:29
touchZone_t touchZoneFromPoint(int16_t x, int16_t y)
Classifies a raw touch position into a button zone.
Definition touchZones.c:35
Maps raw TSC2046 X/Y readings to the printed button zones on the panel overlay.
touchZone_t
The button zones on the printed panel, or TOUCH_ZONE_NONE for a point outside them.
Definition touchZones.h:23