BSP
Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
JoyState
Private function prototypes
Joystick_demo()
Joystick_SetHint()
Joystick_SetCursorPosition()
Files
loading...
SourceVuSTM32 Libraries and SamplesBSPSrc/joystick.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file BSP/Src/joystick.c * @author MCD Application Team * @brief This example code shows how to use the joystick feature in the * stm324xx_nucleo_144 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 ------------------------------------------------------------*/ /* Private macro -------------------------------------------------------------*/ /* Private variables ---------------------------------------------------------*/ static JOYState_TypeDef JoyState = JOY_NONE; /* Private function prototypes -----------------------------------------------*/ static void Joystick_SetHint(void); void Joystick_SetCursorPosition(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Joystick Gpio demo * @param None * @retval None *//* ... */ void Joystick_demo (void) { uint8_t status = 0; Joystick_SetHint(); status = BSP_JOY_Init(); if (status != HAL_OK) { BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 70, (uint8_t *)"ERROR", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 55, (uint8_t *)"Joystick cannot", CENTER_MODE); BSP_LCD_DisplayStringAt(0, BSP_LCD_GetYSize()- 40, (uint8_t *)"be initialized", CENTER_MODE); }if (status != HAL_OK) { ... } while (1) { if (status == HAL_OK) { /* Get the Joystick State */ JoyState = BSP_JOY_GetState(); Joystick_SetCursorPosition(); }if (status == HAL_OK) { ... } if(CheckForUserInput() > 0) { return; }if (CheckForUserInput() > 0) { ... } HAL_Delay(6); }while (1) { ... } }{ ... } /** * @brief Display joystick demo hint * @param None * @retval None *//* ... */ static void Joystick_SetHint(void) { /* Clear the LCD */ BSP_LCD_Clear(LCD_COLOR_WHITE); /* Set Joystick Demo description */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_FillRect(0, 0, BSP_LCD_GetXSize(), 40); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_SetBackColor(LCD_COLOR_BLUE); BSP_LCD_SetFont(&Font24); BSP_LCD_SetFont(&Font12); BSP_LCD_DisplayStringAt(0, 10, (uint8_t *)"Joystick Demo", CENTER_MODE); BSP_LCD_DisplayStringAt(0, 25, (uint8_t *)"Move the pointer", CENTER_MODE); /* Set the LCD Text Color */ BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DrawRect(10, 50, BSP_LCD_GetXSize() - 20, BSP_LCD_GetYSize()- 60); BSP_LCD_DrawRect(11, 51, BSP_LCD_GetXSize() - 22, BSP_LCD_GetYSize()- 62); }{ ... } /** * @brief Joystick cursor position * @param None * @retval None *//* ... */ void Joystick_SetCursorPosition(void) { static uint16_t xPtr = 12; static uint16_t yPtr = 52; static uint16_t old_xPtr = 12; static uint16_t old_yPtr = 52; switch(JoyState) { case JOY_UP: if(yPtr > 52) { yPtr--; }if (yPtr > 52) { ... } break; case JOY_UP: case JOY_DOWN: if(yPtr < (BSP_LCD_GetYSize() - 12 - 11)) { yPtr++; }if (yPtr < (BSP_LCD_GetYSize() - 12 - 11)) { ... } break; case JOY_DOWN: case JOY_LEFT: if(xPtr > 12) { xPtr--; }if (xPtr > 12) { ... } break; case JOY_LEFT: case JOY_RIGHT: if(xPtr < (BSP_LCD_GetXSize() - 8 - 11)) { xPtr++; }if (xPtr < (BSP_LCD_GetXSize() - 8 - 11)) { ... } break; case JOY_RIGHT: default: break; default }switch (JoyState) { ... } BSP_LCD_SetBackColor(LCD_COLOR_WHITE); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); if(JoyState == JOY_SEL) { BSP_LCD_SetTextColor(LCD_COLOR_RED); BSP_LCD_DisplayChar(xPtr, yPtr, 'X'); }if (JoyState == JOY_SEL) { ... } else if(JoyState == JOY_NONE) { BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DisplayChar(xPtr, yPtr, 'X'); }else if (JoyState == JOY_NONE) { ... } else { BSP_LCD_SetTextColor(LCD_COLOR_WHITE); BSP_LCD_DisplayChar(old_xPtr, old_yPtr, 'X'); BSP_LCD_SetTextColor(LCD_COLOR_BLUE); BSP_LCD_DisplayChar(xPtr, yPtr, 'X'); old_xPtr = xPtr; old_yPtr = yPtr; }else { ... } }{ ... } /** * @} *//* ... */ /** * @} *//* ... */
Details