1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
27
28
32
33
34
35
36
37
38
39
40
41
42
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
113
114
120
126
127
128
129
130
131
134
135
/* ... */
#include "k_bsp.h"
#include "k_calibration.h"
#include "GUI.h"
#include "DIALOG.h"
/* ... */
/* ... */
Includes
/* ... */
void k_BspInit(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
__HAL_RCC_GPIOC_CLK_ENABLE();
GPIO_InitStructure.Pin = GPIO_PIN_1;
GPIO_InitStructure.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStructure.Pull = GPIO_NOPULL;
GPIO_InitStructure.Speed = GPIO_SPEED_MEDIUM;
HAL_GPIO_Init(GPIOC, &GPIO_InitStructure);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_1, GPIO_PIN_SET);
BSP_LED_Init(LED3);
BSP_LED_Init(LED4);
BSP_SDRAM_Init();
BSP_TS_Init(240, 320);
__HAL_RCC_CRC_CLK_ENABLE();
__HAL_RCC_BKPSRAM_CLK_ENABLE();
}{ ... }
/* ... */
void k_TouchUpdate(void)
{
GUI_PID_STATE TS_State;
static TS_StateTypeDef prev_state;
__IO TS_StateTypeDef ts;
uint16_t xDiff, yDiff;
BSP_TS_GetState((TS_StateTypeDef *)&ts);
TS_State.Pressed = ts.TouchDetected;
xDiff = (prev_state.X > ts.X) ? (prev_state.X - ts.X) : (ts.X - prev_state.X);
yDiff = (prev_state.Y > ts.Y) ? (prev_state.Y - ts.Y) : (ts.Y - prev_state.Y);
if((prev_state.TouchDetected != ts.TouchDetected )||
(xDiff > 3 )||
(yDiff > 3))
{
prev_state.TouchDetected = ts.TouchDetected;
if((ts.X != 0) && (ts.Y != 0))
{
prev_state.X = ts.X;
prev_state.Y = ts.Y;
}if ((ts.X != 0) && (ts.Y != 0)) { ... }
if(k_CalibrationIsDone())
{
TS_State.Layer = 0;
TS_State.x = k_CalibrationGetX (prev_state.X);
TS_State.y = k_CalibrationGetY (prev_state.Y);
}if (k_CalibrationIsDone()) { ... }
else
{
TS_State.Layer = 0;
TS_State.x = prev_state.X;
TS_State.y = prev_state.Y;
}else { ... }
GUI_TOUCH_StoreStateEx(&TS_State);
}if ((prev_state.TouchDetected != ts.TouchDetected )|| (xDiff > 3 )|| (yDiff > 3)) { ... }
}{ ... }
/* ... */
/* ... */