BSP
Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define CIRCLE_RADIUS
Private macro
#define CIRCLE_XPOS
#define CIRCLE_YPOS
Private variables
TS_State
Private function prototypes
Touchscreen_demo()
Touchscreen_SetHint()
Touchscreen_DrawBackground(uint8_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesBSPSrc/touchscreen.c
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
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
130
131
132
133
134
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file BSP/Src/touchscreen.c * @author MCD Application Team * @brief This example code shows how to use the touchscreen driver. ****************************************************************************** * @attention * * Copyright (c) 2017 STMicroelectronics. * All rights reserved. * * This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component. * If no LICENSE file comes with this software, it is provided AS-IS. * ****************************************************************************** *//* ... */ /* Includes ------------------------------------------------------------------*/ #include "main.h" /** @addtogroup STM32F4xx_HAL_Examples * @{ *//* ... */ /** @addtogroup BSP * @{ *//* ... */ Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define CIRCLE_RADIUS 30 Private define /* Private macro -------------------------------------------------------------*/ #define CIRCLE_XPOS(i) ((i * BSP_LCD_GetXSize()) / 5) #define CIRCLE_YPOS(i) (BSP_LCD_GetYSize() - CIRCLE_RADIUS - 60) Private macro /* Private variables ---------------------------------------------------------*/ static TS_StateTypeDef TS_State; Private variables /* Private function prototypes -----------------------------------------------*/ static void Touchscreen_SetHint(void); static void Touchscreen_DrawBackground (uint8_t state); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Touchscreen Demo * @param None * @retval None *//* ... */ void Touchscreen_demo(void) { uint16_t x,y; uint8_t status = 0; uint8_t state = 0; if(IsCalibrationDone() == 0) { Touchscreen_Calibration(); }if (IsCalibrationDone() == 0) { ... } Touchscreen_SetHint(); status = BSP_TS_Init(BSP_LCD_GetXSize(), BSP_LCD_GetYSize()); if (status != TS_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 95, (uint8_t *)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 80, (uint8_t *)"Touchscreen cannot be initialized", CENTER_MODE); }if (status != TS_OK) { ... } else { Touchscreen_DrawBackground(state); }else { ... } while(1) { if (status == TS_OK) { BSP_TS_GetState(&TS_State); x = Calibration_GetX(TS_State.x); y = Calibration_GetX(TS_State.y); if((TS_State.TouchDetected) && (y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS))&& (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS))) { if((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS))) { if((state & 1) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS); state = 1; }if ((state & 1) == 0) { ... } }if ((x > (CIRCLE_XPOS(1) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(1) + CIRCLE_RADIUS))) { ... } if((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS))) { if((state & 2) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS); state = 2; }if ((state & 2) == 0) { ... } }if ((x > (CIRCLE_XPOS(2) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(2) + CIRCLE_RADIUS))) { ... } if((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS))) { if((state & 4) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS); state = 4; }if ((state & 4) == 0) { ... } }if ((x > (CIRCLE_XPOS(3) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(3) + CIRCLE_RADIUS))) { ... } if((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS))) { if((state & 8) == 0) { Touchscreen_DrawBackground(state); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS); state = 8; }if ((state & 8) == 0) { ... } }if ((x > (CIRCLE_XPOS(4) - CIRCLE_RADIUS))&& (x < (CIRCLE_XPOS(4) + CIRCLE_RADIUS))) { ... } }if ((TS_State.TouchDetected) && (y > (CIRCLE_YPOS(1) - CIRCLE_RADIUS))&& (y < (CIRCLE_YPOS(1) + CIRCLE_RADIUS))) { ... } }if (status == TS_OK) { ... } if(CheckForUserInput() > 0) { return; }if (CheckForUserInput() > 0) { ... } HAL_Delay(100); }while (1) { ... } }{ ... } /** * @brief Display TS Demo Hint * @param None * @retval None *//* ... */ static void Touchscreen_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Touchscreen Demo description */ 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(&Font24); BSP_LCD_DisplayStringAt(0, 0, (uint8_t *)"Touchscreen", CENTER_MODE); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 30, (uint8_t *)"Please use the Touchscreen to", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 45, (uint8_t *)"activate the colored circle", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 60, (uint8_t *)"inside the rectangle", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 90, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 100); BSP_LCD_DrawRect(11, 91, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 102); }{ ... } /** * @brief Draw Touchscreen Background * @param state: touch zone state * @retval None *//* ... */ static void Touchscreen_DrawBackground (uint8_t state) { switch(state) { case 0: BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2); break; case 0: case 1: BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(CIRCLE_XPOS(1), CIRCLE_YPOS(1), CIRCLE_RADIUS - 2); break; case 1: case 2: BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(CIRCLE_XPOS(2), CIRCLE_YPOS(2), CIRCLE_RADIUS - 2); break; case 2: case 4: BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(CIRCLE_XPOS(3), CIRCLE_YPOS(3), CIRCLE_RADIUS - 2); break; case 4: case 8: BSP_LCD_SetTextColor(LCD_COLOR_GREEN); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(4), CIRCLE_RADIUS); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_FillCircle(CIRCLE_XPOS(4), CIRCLE_YPOS(4), CIRCLE_RADIUS - 2); break;case 8: }switch (state) { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */