Select one of the symbols to view example projects that use it.
 
Outline
Includes
#include "main.h"
Private define
#define KYBRD_FIRST_COLUMN
#define KYBRD_LAST_COLUMN
#define KYBRD_FIRST_LINE
#define SMALL_FONT_COLUMN_WIDTH
#define SMALL_FONT_LINE_WIDTH
#define KYBRD_LAST_LINE
Private variables
KeybrdCharYpos
KeybrdCharXpos
CurrentLastXpos
Private function prototypes
HID_KeyboardMenuProcess()
USR_KEYBRD_Init()
USR_KEYBRD_ProcessData(uint8_t)
Files
loading...
CodeScopeSTM32 Libraries and SamplesHID_StandaloneSrc/keyboard.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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
/** ****************************************************************************** * @file USB_Host/HID_Standalone/Src/keyboard.c * @author MCD Application Team * @brief This file implements the HID keyboard functions ****************************************************************************** * @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" Includes /* Private typedef -----------------------------------------------------------*/ /* Private define ------------------------------------------------------------*/ #define KYBRD_FIRST_COLUMN (uint16_t)10 #define KYBRD_LAST_COLUMN (uint16_t)794 #define KYBRD_FIRST_LINE (uint16_t) 80 #define SMALL_FONT_COLUMN_WIDTH 8 #define SMALL_FONT_LINE_WIDTH 20 #define KYBRD_LAST_LINE (uint16_t)320 6 defines/* Private macro -------------------------------------------------------------*/Private define /* Private variables ---------------------------------------------------------*/ extern HID_DEMO_StateMachine hid_demo; extern uint8_t *DEMO_KEYBOARD_menu[]; extern uint8_t prev_select; extern uint32_t hid_demo_ready; uint16_t KeybrdCharYpos = 0; uint16_t KeybrdCharXpos = 0; uint16_t CurrentLastXpos[KYBRD_LAST_LINE] = {0};Private variables /* Private function prototypes -----------------------------------------------*/ static void USR_KEYBRD_Init(void); Private function prototypes /* Private functions ---------------------------------------------------------*/ /** * @brief Manages Keyboard Menu Process. * @param None * @retval None *//* ... */ void HID_KeyboardMenuProcess(void) { switch(hid_demo.keyboard_state) { case HID_KEYBOARD_IDLE: hid_demo.keyboard_state = HID_KEYBOARD_START; HID_SelectItem(DEMO_KEYBOARD_menu, 0); hid_demo.select = 0; prev_select = 0; break; case HID_KEYBOARD_IDLE: case HID_KEYBOARD_WAIT: if(hid_demo.select != prev_select) { prev_select = hid_demo.select; HID_SelectItem(DEMO_KEYBOARD_menu, hid_demo.select & 0x7F); /* Handle select item */ if(hid_demo.select & 0x80) { hid_demo.select &= 0x7F; switch(hid_demo.select) { case 0: hid_demo.keyboard_state = HID_KEYBOARD_START; break; case 0: case 1: /* Return */ LCD_LOG_ClearTextZone(); hid_demo.state = HID_DEMO_REENUMERATE; hid_demo.select = 0; break; case 1: default: break;default }switch (hid_demo.select) { ... } }if (hid_demo.select & 0x80) { ... } }if (hid_demo.select != prev_select) { ... } break; case HID_KEYBOARD_WAIT: case HID_KEYBOARD_START: USR_KEYBRD_Init(); hid_demo.keyboard_state = HID_KEYBOARD_WAIT; break; case HID_KEYBOARD_START: default: break;default }switch (hid_demo.keyboard_state) { ... } }{ ... } /** * @brief Init Keyboard window. * @param None * @retval None *//* ... */ static void USR_KEYBRD_Init(void) { LCD_LOG_ClearTextZone(); BSP_LCD_SetTextColor(LCD_COLOR_YELLOW); BSP_LCD_DisplayStringAtLine(4, (uint8_t *)"Use Keyboard to type characters:"); BSP_LCD_SetTextColor(LCD_COLOR_WHITE); KeybrdCharYpos = KYBRD_FIRST_LINE; KeybrdCharXpos = KYBRD_FIRST_COLUMN; }{ ... } /** * @brief Processes Keyboard data. * @param data: Keyboard data to be displayed * @retval None *//* ... */ void USR_KEYBRD_ProcessData(uint8_t data) { if(data == '\n') { KeybrdCharXpos = KYBRD_FIRST_COLUMN; /* Increment char Y position */ KeybrdCharYpos += SMALL_FONT_LINE_WIDTH; if(KeybrdCharYpos > KYBRD_LAST_LINE) { LCD_LOG_ClearTextZone(); KeybrdCharYpos = KYBRD_FIRST_LINE; KeybrdCharXpos = KYBRD_FIRST_COLUMN; }if (KeybrdCharYpos > KYBRD_LAST_LINE) { ... } }if (data == '\n') { ... } else if(data == '\r') { /* Manage deletion of character and update cursor location */ if(KeybrdCharXpos == KYBRD_FIRST_COLUMN) { /* First character of first line to be deleted */ if(KeybrdCharYpos == KYBRD_FIRST_LINE) { KeybrdCharXpos = KYBRD_FIRST_COLUMN; }if (KeybrdCharYpos == KYBRD_FIRST_LINE) { ... } else { KeybrdCharYpos -= SMALL_FONT_LINE_WIDTH; KeybrdCharXpos = (KYBRD_LAST_COLUMN - SMALL_FONT_COLUMN_WIDTH); }else { ... } }if (KeybrdCharXpos == KYBRD_FIRST_COLUMN) { ... } else { if(CurrentLastXpos[KeybrdCharYpos] > KYBRD_FIRST_COLUMN) { CurrentLastXpos[KeybrdCharYpos] -= SMALL_FONT_COLUMN_WIDTH; KeybrdCharXpos = CurrentLastXpos[KeybrdCharYpos]; }if (CurrentLastXpos[KeybrdCharYpos] > KYBRD_FIRST_COLUMN) { ... } else if(KeybrdCharYpos > KYBRD_FIRST_LINE) { KeybrdCharYpos -= SMALL_FONT_LINE_WIDTH; CurrentLastXpos[KeybrdCharYpos] -= SMALL_FONT_COLUMN_WIDTH; KeybrdCharXpos = CurrentLastXpos[KeybrdCharYpos]; }else if (KeybrdCharYpos > KYBRD_FIRST_LINE) { ... } else { }else { ... } }else { ... } BSP_LCD_DisplayChar(CurrentLastXpos[KeybrdCharYpos], KeybrdCharYpos, ' '); }else if (data == '\r') { ... } else { /* Update the cursor position on LCD */ BSP_LCD_DisplayChar(KeybrdCharXpos, KeybrdCharYpos, data); /* Increment char X position */ KeybrdCharXpos += SMALL_FONT_COLUMN_WIDTH; CurrentLastXpos[KeybrdCharYpos] = KeybrdCharXpos; /* Check if the X position has reached the last column */ if(KeybrdCharXpos == KYBRD_LAST_COLUMN) { KeybrdCharXpos = KYBRD_FIRST_COLUMN; /* Increment char Y position */ KeybrdCharYpos += SMALL_FONT_LINE_WIDTH; }if (KeybrdCharXpos == KYBRD_LAST_COLUMN) { ... } if(KeybrdCharYpos > KYBRD_LAST_LINE) { LCD_LOG_ClearTextZone(); KeybrdCharYpos = KYBRD_FIRST_LINE; /* Start New Display of the cursor position on LCD */ BSP_LCD_DisplayChar(KeybrdCharXpos,KeybrdCharYpos, data); }if (KeybrdCharYpos > KYBRD_LAST_LINE) { ... } }else { ... } }{ ... }