1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
30
31
38
39
40
43
44
47
48
49
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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
167
168
/* ... */
#include "main.h"
/* ... */
/* ... */
Includes
#define CIRCLE_RADIUS 37
#define LINE_LENGHT 30
Private define
#define CIRCLE_XPOS(i) ((i * BSP_LCD_GetXSize()) / 5)
#define CIRCLE_YPOS(i) (BSP_LCD_GetYSize() - CIRCLE_RADIUS - 60)
Private macro
TS_StateTypeDef TS_State = {0};
Global variables
static void Touchscreen_SetHint_Demo(void);
Private function prototypes
/* ... */
void TS_demo(void)
{
uint16_t x1, y1;
uint32_t ts_status = TS_OK;
ts_status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize());
if(ts_status == TS_OK)
{
Touchscreen_SetHint_Demo();
while (CheckForUserInput() == 0)
{
ts_status = BSP_TS_GetState(&TS_State);
if(TS_State.touchDetected)
{
x1 = TS_State.touchX[0];
y1 = TS_State.touchY[0];
if((y1>83) && (y1<157))
{
if ((x1 > 23) && (x1 < 97))
{
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillCircle(60, 120, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillCircle(180, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(60, 200, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(180, 200, CIRCLE_RADIUS-1);
}if ((x1 > 23) && (x1 < 97)) { ... }
if ((x1 > 143) && (x1 < 217))
{
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_FillCircle(180, 120, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillCircle(60, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(60, 200, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(180, 200, CIRCLE_RADIUS-1);
}if ((x1 > 143) && (x1 < 217)) { ... }
}if ((y1>83) && (y1<157)) { ... }
if((y1>163) && (y1<237))
{
if ((x1 > 23) && (x1 < 97))
{
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_FillCircle(60, 200, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillCircle(180, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(60, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(180, 200, CIRCLE_RADIUS-1);
}if ((x1 > 23) && (x1 < 97)) { ... }
if ((x1 > 143) && (x1 < 217))
{
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_FillCircle(180, 200, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_FillCircle(180, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(60, 120, CIRCLE_RADIUS-1);
BSP_LCD_FillCircle(60, 200, CIRCLE_RADIUS-1);
}if ((x1 > 143) && (x1 < 217)) { ... }
}if ((y1>163) && (y1<237)) { ... }
}if (TS_State.touchDetected) { ... }
}while (CheckForUserInput() == 0) { ... }
return;
}if (ts_status == TS_OK) { ... }
}{ ... }
/* ... */
static void Touchscreen_SetHint_Demo(void)
{
BSP_LCD_Clear(LCD_COLOR_WHITE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 80);
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
BSP_LCD_SetBackColor(LCD_COLOR_BLUE);
BSP_LCD_SetFont(&Font16);
BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"TS basic polling", CENTER_MODE);
BSP_LCD_SetFont(&Font12);
BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"Touch the screen to activate", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"the colored circle inside the", CENTER_MODE);
BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"rectangle. Then press User button", CENTER_MODE);
BSP_LCD_SetTextColor(LCD_COLOR_BLUE);
BSP_LCD_DrawCircle(60, 120, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_RED);
BSP_LCD_DrawCircle(180, 120, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_DrawCircle(60, 200, CIRCLE_RADIUS);
BSP_LCD_SetTextColor(LCD_COLOR_GREEN);
BSP_LCD_DrawCircle(180, 200, CIRCLE_RADIUS);
}{ ... }
/* ... */
/* ... */