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
main.c
Go to the documentation of this file.
1/* USER CODE BEGIN Header */
18/* USER CODE END Header */
19/* Includes ------------------------------------------------------------------*/
20#include "main.h"
21
22/* Private includes ----------------------------------------------------------*/
23/* USER CODE BEGIN Includes */
24#include <stdio.h>
25#include <math.h>
26#include "entryPointCPP.hpp"
27#include "touchZones.h"
28#ifdef TOUCH_SELFTEST_ENABLE
29#include "touchSelfTest.h"
30#endif
31
32/* #define TSC2046_DEBUG_POLL */ /* temporary raw-read diagnostic; enable to debug */
33
34/* USER CODE END Includes */
35
36/* Private typedef -----------------------------------------------------------*/
37/* USER CODE BEGIN PTD */
38
39/* USER CODE END PTD */
40
41/* Private define ------------------------------------------------------------*/
42/* USER CODE BEGIN PD */
44#define OUT_ON GPIO_PIN_RESET
46#define OUT_OFF GPIO_PIN_SET
47
48
49/* USER CODE END PD */
50
51/* Private macro -------------------------------------------------------------*/
52/* USER CODE BEGIN PM */
53
54/* USER CODE END PM */
55
56/* Private variables ---------------------------------------------------------*/
57
58SPI_HandleTypeDef hspi1;
59
60UART_HandleTypeDef huart1;
61
62/* USER CODE BEGIN PV */
63
64/* USER CODE END PV */
65
66/* Private function prototypes -----------------------------------------------*/
67void SystemClock_Config(void);
68static void MX_GPIO_Init(void);
69static void MX_USART1_UART_Init(void);
70static void MX_SPI1_Init(void);
71/* USER CODE BEGIN PFP */
72static void outputsAllOff(void);
73static void applyZoneAction(touchZone_t zone);
74#ifdef TSC2046_DEBUG_POLL
75static void tsc2046RawDebug(const char *name, uint8_t cmd);
76#endif
77
78/* USER CODE END PFP */
79
80/* Private user code ---------------------------------------------------------*/
81/* USER CODE BEGIN 0 */
82
83#ifdef REDIRECT_PRINTF
84#define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
85
86PUTCHAR_PROTOTYPE
87{
88 HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
89
90 return ch;
91}
92#endif
93
94/* USER CODE END 0 */
95
100int main(void)
101{
102
103 /* USER CODE BEGIN 1 */
104
105 /* USER CODE END 1 */
106
107 /* MCU Configuration--------------------------------------------------------*/
108
109 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */
110 HAL_Init();
111
112 /* USER CODE BEGIN Init */
113
114 /* USER CODE END Init */
115
116 /* Configure the system clock */
117 SystemClock_Config();
118
119 /* USER CODE BEGIN SysInit */
120
121 /* USER CODE END SysInit */
122
123 /* Initialize all configured peripherals */
124 MX_GPIO_Init();
125 MX_USART1_UART_Init();
126 MX_SPI1_Init();
127 /* USER CODE BEGIN 2 */
128
129 printf("\x1b[2J\x1b[H"); // Clear the dumb terminal screen
130
132 initTSC2046();
133 printf("TSC2046 touch controller initialized.\r\n");
134#ifdef TOUCH_SELFTEST_ENABLE
136#endif
137 printf("Touch the panel...\r\n");
138
139 /* Poll state: only report while touched, plus one line on release. */
140 bool wasTouched = false;
141 uint32_t lastPrintMs = 0;
142 touchZone_t lastZone = TOUCH_ZONE_NONE;
143 touchZone_t candidateZone = TOUCH_ZONE_NONE;
144 uint8_t candidateCount = 0;
145
146 /* USER CODE END 2 */
147
148 /* Infinite loop */
149 /* USER CODE BEGIN WHILE */
150 while (1)
151 {
152 /* USER CODE END WHILE */
153
154 /* USER CODE BEGIN 3 */
155
156#ifdef TSC2046_DEBUG_POLL
157 // TEMPORARY diagnostic: every 500 ms print pin levels and a raw read
158 // regardless of IRQ, to see whether the panel responds to polled reads.
159 {
160 static uint32_t lastDbgMs = 0;
161 if (HAL_GetTick() - lastDbgMs >= 500)
162 {
163 lastDbgMs = HAL_GetTick();
164 int16_t dx = 0, dy = 0;
165 float dp = 0.0f;
166 tsc2046GetPoint(&dx, &dy, &dp);
167 printf("DBG irq=%d busy=%d raw X=%4d Y=%4d P=%ld\r\n",
168 (int)HAL_GPIO_ReadPin(TSC2046_IRQ_GPIO_Port, TSC2046_IRQ_Pin),
169 (int)HAL_GPIO_ReadPin(TSC2046_BUSY_GPIO_Port, TSC2046_BUSY_Pin),
170 dx, dy, (long)dp);
171 tsc2046RawDebug("X ", 0xD0);
172 tsc2046RawDebug("Y ", 0x90);
173 tsc2046RawDebug("Z1", 0xB0);
174 tsc2046RawDebug("Z2", 0xC0);
175 }
176 }
177#endif
178
179 // Poll every 10 ms. "Touched" needs ALL of:
180 // - pressure in a real-touch band: >= 40 ohm (idle/untouched junk reads 0-18 ohm,
181 // measured) and < 1500 ohm (light touches); real touches measured ~110-600 ohm.
182 // - the point inside the accepted touch area (idle junk gives X=0 / X=3855 etc.).
183 // PENIRQ is NOT used: on this panel it is disturbed by the polled SPI reads.
184 // A zone is acted on after 2 consecutive samples agree (fast enough for quick taps),
185 // and a press ends after 3 consecutive untouched samples. The LED/buzzer action runs
186 // BEFORE any printf: at 19200 baud one printed line blocks the loop for ~25 ms.
187 static uint32_t lastPollMs = 0;
188 static uint8_t untouchedCount = 0;
189 if (HAL_GetTick() - lastPollMs >= 10)
190 {
191 lastPollMs = HAL_GetTick();
192 int16_t x = 0, y = 0;
193 float pressure = 0.0f;
194 bool rawTouched = false;
195 touchZone_t zone = TOUCH_ZONE_NONE;
196 if (tsc2046GetPoint(&x, &y, &pressure))
197 {
198 zone = touchZoneFromPoint(x, y);
199 rawTouched = isfinite(pressure) && pressure >= 40.0f && pressure < 1500.0f
200 && zone != TOUCH_ZONE_NONE;
201 }
202
203 if (rawTouched)
204 {
205 untouchedCount = 0;
206
207 if (zone == candidateZone)
208 {
209 if (candidateCount < 255) candidateCount++;
210 }
211 else
212 {
213 candidateZone = zone;
214 candidateCount = 1;
215 }
216
217 if (candidateCount >= 2 && candidateZone != lastZone)
218 {
219 lastZone = candidateZone;
220 wasTouched = true;
221 applyZoneAction(lastZone); // act first...
222 printf("Zone: %s\r\n", touchZoneName(lastZone)); // ...then print
223 }
224 else if (wasTouched && HAL_GetTick() - lastPrintMs >= 200)
225 {
226 lastPrintMs = HAL_GetTick();
227 printf("Touch: X=%4d Y=%4d Pressure=%ld ohm\r\n", x, y, (long)pressure);
228 }
229 }
230 else
231 {
232 if (untouchedCount < 255) untouchedCount++;
233 candidateCount = 0;
234 candidateZone = TOUCH_ZONE_NONE;
235
236 if (wasTouched && untouchedCount >= 3)
237 {
238 wasTouched = false;
239 lastZone = TOUCH_ZONE_NONE;
240 HAL_GPIO_WritePin(Buzzer_GPIO_Port, Buzzer_Pin, OUT_OFF); // release ends the beep
241 printf("Released\r\n");
242 }
243 }
244 }
245 }
246 /* USER CODE END 3 */
247}
248
253void SystemClock_Config(void)
254{
255 RCC_OscInitTypeDef RCC_OscInitStruct = {0};
256 RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
257
260 HAL_PWREx_ConfigSupply(PWR_LDO_SUPPLY);
261
264 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE0);
265
266 while(!__HAL_PWR_GET_FLAG(PWR_FLAG_VOSRDY)) {}
267
271 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI;
272 RCC_OscInitStruct.HSIState = RCC_HSI_DIV1;
273 RCC_OscInitStruct.HSICalibrationValue = RCC_HSICALIBRATION_DEFAULT;
274 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
275 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI;
276 RCC_OscInitStruct.PLL.PLLM = 4;
277 RCC_OscInitStruct.PLL.PLLN = 60;
278 RCC_OscInitStruct.PLL.PLLP = 2;
279 RCC_OscInitStruct.PLL.PLLQ = 5;
280 RCC_OscInitStruct.PLL.PLLR = 2;
281 RCC_OscInitStruct.PLL.PLLRGE = RCC_PLL1VCIRANGE_3;
282 RCC_OscInitStruct.PLL.PLLVCOSEL = RCC_PLL1VCOWIDE;
283 RCC_OscInitStruct.PLL.PLLFRACN = 0;
284 if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
285 {
286 Error_Handler();
287 }
288
291 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
292 |RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2
293 |RCC_CLOCKTYPE_D3PCLK1|RCC_CLOCKTYPE_D1PCLK1;
294 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
295 RCC_ClkInitStruct.SYSCLKDivider = RCC_SYSCLK_DIV1;
296 RCC_ClkInitStruct.AHBCLKDivider = RCC_HCLK_DIV2;
297 RCC_ClkInitStruct.APB3CLKDivider = RCC_APB3_DIV2;
298 RCC_ClkInitStruct.APB1CLKDivider = RCC_APB1_DIV2;
299 RCC_ClkInitStruct.APB2CLKDivider = RCC_APB2_DIV2;
300 RCC_ClkInitStruct.APB4CLKDivider = RCC_APB4_DIV2;
301
302 if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
303 {
304 Error_Handler();
305 }
306}
307
313static void MX_SPI1_Init(void)
314{
315
316 /* USER CODE BEGIN SPI1_Init 0 */
317
318 /* USER CODE END SPI1_Init 0 */
319
320 /* USER CODE BEGIN SPI1_Init 1 */
321
322 /* USER CODE END SPI1_Init 1 */
323 /* SPI1 parameter configuration*/
324 hspi1.Instance = SPI1;
325 hspi1.Init.Mode = SPI_MODE_MASTER;
326 hspi1.Init.Direction = SPI_DIRECTION_2LINES;
327 hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
328 hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
329 hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
330 hspi1.Init.NSS = SPI_NSS_SOFT;
331 hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_128;
332 hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
333 hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
334 hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
335 hspi1.Init.CRCPolynomial = 0x0;
336 hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
337 hspi1.Init.NSSPolarity = SPI_NSS_POLARITY_LOW;
338 hspi1.Init.FifoThreshold = SPI_FIFO_THRESHOLD_01DATA;
339 hspi1.Init.TxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
340 hspi1.Init.RxCRCInitializationPattern = SPI_CRC_INITIALIZATION_ALL_ZERO_PATTERN;
341 hspi1.Init.MasterSSIdleness = SPI_MASTER_SS_IDLENESS_00CYCLE;
342 hspi1.Init.MasterInterDataIdleness = SPI_MASTER_INTERDATA_IDLENESS_00CYCLE;
343 hspi1.Init.MasterReceiverAutoSusp = SPI_MASTER_RX_AUTOSUSP_DISABLE;
344 hspi1.Init.MasterKeepIOState = SPI_MASTER_KEEP_IO_STATE_DISABLE;
345 hspi1.Init.IOSwap = SPI_IO_SWAP_DISABLE;
346 if (HAL_SPI_Init(&hspi1) != HAL_OK)
347 {
348 Error_Handler();
349 }
350 /* USER CODE BEGIN SPI1_Init 2 */
351
352 /* USER CODE END SPI1_Init 2 */
353
354}
355
361static void MX_USART1_UART_Init(void)
362{
363
364 /* USER CODE BEGIN USART1_Init 0 */
365
366 /* USER CODE END USART1_Init 0 */
367
368 /* USER CODE BEGIN USART1_Init 1 */
369
370 /* USER CODE END USART1_Init 1 */
371 huart1.Instance = USART1;
372 huart1.Init.BaudRate = 19200;
373 huart1.Init.WordLength = UART_WORDLENGTH_8B;
374 huart1.Init.StopBits = UART_STOPBITS_1;
375 huart1.Init.Parity = UART_PARITY_NONE;
376 huart1.Init.Mode = UART_MODE_TX_RX;
377 huart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
378 huart1.Init.OverSampling = UART_OVERSAMPLING_16;
379 huart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
380 huart1.Init.ClockPrescaler = UART_PRESCALER_DIV1;
381 huart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
382 if (HAL_UART_Init(&huart1) != HAL_OK)
383 {
384 Error_Handler();
385 }
386 if (HAL_UARTEx_SetTxFifoThreshold(&huart1, UART_TXFIFO_THRESHOLD_1_8) != HAL_OK)
387 {
388 Error_Handler();
389 }
390 if (HAL_UARTEx_SetRxFifoThreshold(&huart1, UART_RXFIFO_THRESHOLD_1_8) != HAL_OK)
391 {
392 Error_Handler();
393 }
394 if (HAL_UARTEx_DisableFifoMode(&huart1) != HAL_OK)
395 {
396 Error_Handler();
397 }
398 /* USER CODE BEGIN USART1_Init 2 */
399
400 /* USER CODE END USART1_Init 2 */
401
402}
403
409static void MX_GPIO_Init(void)
410{
411 GPIO_InitTypeDef GPIO_InitStruct = {0};
412 /* USER CODE BEGIN MX_GPIO_Init_1 */
413
414 /* USER CODE END MX_GPIO_Init_1 */
415
416 /* GPIO Ports Clock Enable */
417 __HAL_RCC_GPIOC_CLK_ENABLE();
418 __HAL_RCC_GPIOH_CLK_ENABLE();
419 __HAL_RCC_GPIOA_CLK_ENABLE();
420 __HAL_RCC_GPIOF_CLK_ENABLE();
421 __HAL_RCC_GPIOG_CLK_ENABLE();
422 __HAL_RCC_GPIOB_CLK_ENABLE();
423 __HAL_RCC_GPIOE_CLK_ENABLE();
424
425 /*Configure GPIO pin Output Level */
426 HAL_GPIO_WritePin(LED01_GPIO_Port, LED01_Pin, GPIO_PIN_SET);
427
428 /*Configure GPIO pin Output Level */
429 HAL_GPIO_WritePin(Buzzer_GPIO_Port, Buzzer_Pin, GPIO_PIN_SET);
430
431 /*Configure GPIO pin Output Level */
432 HAL_GPIO_WritePin(LED03_GPIO_Port, LED03_Pin, GPIO_PIN_SET);
433
434 /*Configure GPIO pin Output Level */
435 HAL_GPIO_WritePin(TSC2046_CS_GPIO_Port, TSC2046_CS_Pin, GPIO_PIN_RESET);
436
437 /*Configure GPIO pin Output Level */
438 HAL_GPIO_WritePin(LED02_GPIO_Port, LED02_Pin, GPIO_PIN_SET);
439
440 /*Configure GPIO pin : LED01_Pin */
441 GPIO_InitStruct.Pin = LED01_Pin;
442 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
443 GPIO_InitStruct.Pull = GPIO_NOPULL;
444 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
445 HAL_GPIO_Init(LED01_GPIO_Port, &GPIO_InitStruct);
446
447 /*Configure GPIO pins : Buzzer_Pin LED03_Pin */
448 GPIO_InitStruct.Pin = Buzzer_Pin|LED03_Pin;
449 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
450 GPIO_InitStruct.Pull = GPIO_NOPULL;
451 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
452 HAL_GPIO_Init(GPIOG, &GPIO_InitStruct);
453
454 /*Configure GPIO pin : TSC2046_IRQ_Pin */
455 GPIO_InitStruct.Pin = TSC2046_IRQ_Pin;
456 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
457 GPIO_InitStruct.Pull = GPIO_NOPULL;
458 HAL_GPIO_Init(TSC2046_IRQ_GPIO_Port, &GPIO_InitStruct);
459
460 /*Configure GPIO pin : TSC2046_BUSY_Pin */
461 GPIO_InitStruct.Pin = TSC2046_BUSY_Pin;
462 GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
463 GPIO_InitStruct.Pull = GPIO_NOPULL;
464 HAL_GPIO_Init(TSC2046_BUSY_GPIO_Port, &GPIO_InitStruct);
465
466 /*Configure GPIO pin : TSC2046_CS_Pin */
467 GPIO_InitStruct.Pin = TSC2046_CS_Pin;
468 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
469 GPIO_InitStruct.Pull = GPIO_NOPULL;
470 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
471 HAL_GPIO_Init(TSC2046_CS_GPIO_Port, &GPIO_InitStruct);
472
473 /*Configure GPIO pin : LED02_Pin */
474 GPIO_InitStruct.Pin = LED02_Pin;
475 GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
476 GPIO_InitStruct.Pull = GPIO_NOPULL;
477 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
478 HAL_GPIO_Init(LED02_GPIO_Port, &GPIO_InitStruct);
479
480 /* USER CODE BEGIN MX_GPIO_Init_2 */
481
482 /* USER CODE END MX_GPIO_Init_2 */
483}
484
485/* USER CODE BEGIN 4 */
486
490static void outputsAllOff(void)
491{
492 HAL_GPIO_WritePin(LED01_GPIO_Port, LED01_Pin, OUT_OFF);
493 HAL_GPIO_WritePin(LED02_GPIO_Port, LED02_Pin, OUT_OFF);
494 HAL_GPIO_WritePin(LED03_GPIO_Port, LED03_Pin, OUT_OFF);
495 HAL_GPIO_WritePin(Buzzer_GPIO_Port, Buzzer_Pin, OUT_OFF);
496}
497
505{
506 switch (zone)
507 {
508 case TOUCH_ZONE_LED1_ON: HAL_GPIO_WritePin(LED01_GPIO_Port, LED01_Pin, OUT_ON); break;
509 case TOUCH_ZONE_LED1_OFF: HAL_GPIO_WritePin(LED01_GPIO_Port, LED01_Pin, OUT_OFF); break;
510 case TOUCH_ZONE_LED2_ON: HAL_GPIO_WritePin(LED02_GPIO_Port, LED02_Pin, OUT_ON); break;
511 case TOUCH_ZONE_LED2_OFF: HAL_GPIO_WritePin(LED02_GPIO_Port, LED02_Pin, OUT_OFF); break;
512 case TOUCH_ZONE_LED3_ON: HAL_GPIO_WritePin(LED03_GPIO_Port, LED03_Pin, OUT_ON); break;
513 case TOUCH_ZONE_LED3_OFF: HAL_GPIO_WritePin(LED03_GPIO_Port, LED03_Pin, OUT_OFF); break;
514 default: break;
515 }
516 HAL_GPIO_WritePin(Buzzer_GPIO_Port, Buzzer_Pin, (zone == TOUCH_ZONE_BEEP) ? OUT_ON : OUT_OFF);
517}
518
519#ifdef TSC2046_DEBUG_POLL
525static void tsc2046RawDebug(const char *name, uint8_t cmd)
526{
527 uint8_t tx[3] = { cmd, 0x00, 0x00 };
528 uint8_t rx[3] = { 0xAA, 0xAA, 0xAA }; // sentinel: shows if HAL never wrote rx
529
530 HAL_GPIO_WritePin(TSC2046_CS_GPIO_Port, TSC2046_CS_Pin, GPIO_PIN_RESET);
531 HAL_StatusTypeDef st = HAL_SPI_TransmitReceive(&hspi1, tx, rx, 3, 100);
532 HAL_GPIO_WritePin(TSC2046_CS_GPIO_Port, TSC2046_CS_Pin, GPIO_PIN_SET);
533
534 unsigned value = (((unsigned)rx[1] << 8 | rx[2]) >> 3) & 0xFFF;
535 printf("RAW %s cmd=%02X hal=%d state=%d err=0x%lX rx=%02X %02X %02X -> %4u\r\n",
536 name, cmd, (int)st, (int)HAL_SPI_GetState(&hspi1),
537 (unsigned long)HAL_SPI_GetError(&hspi1), rx[0], rx[1], rx[2], value);
538}
539#endif
540
541
548void _Error_Handler(const char *file, int line)
549{
550 __disable_irq();
551
552#ifdef REDIRECT_PRINTF
553 char buf[80];
554
555 snprintf(buf, sizeof(buf),
556 "Trapped in _Error_Handler(). Called from: %s, line: %d\r\n",
557 file, line);
558 printf("%s", buf);
559#endif
560
561 /* User can add an implementation to report the HAL error return state. */
562 while(1)
563 {
564 }
565}
566
567/* USER CODE END 4 */
568
569
570#ifdef USE_FULL_ASSERT
578void assert_failed(uint8_t *file, uint32_t line)
579{
580 /* USER CODE BEGIN 6 */
581 /* assert_param() can fire from inside any HAL call -- including before
582 * REDIRECT_PRINTF's UART is fully set up, or from an unusual calling
583 * context -- so this only attempts to report when REDIRECT_PRINTF is
584 * available, then halts either way. Continuing after a failed HAL
585 * parameter check is undefined behavior, not something safe to log
586 * and ignore. */
587 __disable_irq();
588
589#ifdef REDIRECT_PRINTF
590 {
591 char buf[96];
592
593 snprintf(buf, sizeof(buf),
594 "assert_param failed: file %s, line %lu\r\n",
595 (char *)file, (unsigned long)line);
596 printf("%s", buf);
597 }
598#endif
599
600 while (1)
601 {
602 }
603 /* USER CODE END 6 */
604}
605#endif /* USE_FULL_ASSERT */
C-callable entry points bridging CubeMX-generated main.c into the C++ TSC2046 driver.
void initTSC2046(void)
Constructs the TSC2046 driver. Must be called after MX_SPI1_Init() (and therefore after HAL_Init()/Sy...
bool tsc2046GetPoint(int16_t *x, int16_t *y, float *pressure)
Reads the current touch position and pressure.
#define OUT_OFF
Pin level that turns an output OFF (LED dark, buzzer silent).
Definition main.c:46
int main(void)
The application entry point.
Definition main.c:100
static void outputsAllOff(void)
Drives all three LEDs and the buzzer to their OFF level (LEDs dark, buzzer silent).
Definition main.c:490
static void applyZoneAction(touchZone_t zone)
Applies the action for a settled touch zone. LEDs latch: an ON zone turns that LED on and an OFF zone...
Definition main.c:504
#define OUT_ON
Pin level that turns an output ON. LEDs are wired 5V -> resistor -> LED -> GPIO, so low = lit; the bu...
Definition main.c:44
: Header for main.c file. This file contains the common defines of the application.
Startup self-test for the TSC2046 touch controller.
const touchSelfTestReport_t * touchSelfTestRunAll(void)
Runs every self-test in order, stopping at the first failure, and prints progress and a PASS/FAIL ver...
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
const char * touchZoneName(touchZone_t zone)
Gives a short printable name for a zone.
Definition touchZones.c:55
touchZone_t touchZoneFromPoint(int16_t x, int16_t y)
Classifies a raw touch position into a button zone.
Definition touchZones.c:35