1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
31
39
42
43
44
49
97
98
103
104
105
106
107
108
109
110
111
112
113
114
115
120
121
122
123
124
125
126
127
128
129
135
136
158
159
160
161
162
163
164
165
166
167
174
175
182
183
/* ... */
#include "main.h"
Includes
#define KYBRD_FIRST_COLUMN 7
#define KYBRD_LAST_COLUMN 121
#define KYBRD_FIRST_LINE 50
#define SMALL_FONT_COLUMN_WIDTH 6
#define SMALL_FONT_LINE_WIDTH 10
#define KYBRD_LAST_LINE 81
6 defines
Private define
extern HID_DEMO_StateMachine hid_demo;
extern uint8_t *DEMO_KEYBOARD_menu[];
extern uint8_t prev_select;
extern uint32_t hid_demo_ready;
uint8_t KeybrdCharXpos = 0;
uint16_t KeybrdCharYpos = 0;
Private variables
static void USR_KEYBRD_Init(void);
Private function prototypes
/* ... */
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);
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:
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) { ... }
}{ ... }
/* ... */
static void USR_KEYBRD_Init(void)
{
LCD_LOG_ClearTextZone();
BSP_LCD_SetTextColor(LCD_COLOR_YELLOW);
BSP_LCD_DisplayStringAtLine(5, (uint8_t *)"Use Keyboard to type characters: ");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
KeybrdCharXpos = KYBRD_FIRST_LINE;
KeybrdCharYpos = KYBRD_FIRST_COLUMN;
}{ ... }
/* ... */
void USR_KEYBRD_ProcessData(uint8_t data)
{
if(data == '\n')
{
KeybrdCharYpos = KYBRD_FIRST_COLUMN;
KeybrdCharXpos += SMALL_FONT_LINE_WIDTH;
if(KeybrdCharXpos > KYBRD_LAST_LINE)
{
LCD_LOG_ClearTextZone();
KeybrdCharXpos = KYBRD_FIRST_LINE;
KeybrdCharYpos = KYBRD_FIRST_COLUMN;
}if (KeybrdCharXpos > KYBRD_LAST_LINE) { ... }
}if (data == '\n') { ... }
else if(data == '\r')
{
if( KeybrdCharYpos == KYBRD_FIRST_COLUMN)
{
if(KeybrdCharXpos == KYBRD_FIRST_LINE)
{
KeybrdCharYpos = KYBRD_FIRST_COLUMN;
}if (KeybrdCharXpos == KYBRD_FIRST_LINE) { ... }
else
{
KeybrdCharXpos -= SMALL_FONT_LINE_WIDTH;
KeybrdCharYpos = (KYBRD_LAST_COLUMN - SMALL_FONT_COLUMN_WIDTH);
}else { ... }
}if (KeybrdCharYpos == KYBRD_FIRST_COLUMN) { ... }
else
{
KeybrdCharYpos -= SMALL_FONT_COLUMN_WIDTH;
}else { ... }
BSP_LCD_DisplayChar(KeybrdCharYpos, KeybrdCharXpos, ' ');
}else if (data == '\r') { ... }
else
{
BSP_LCD_DisplayChar(KeybrdCharYpos, KeybrdCharXpos, data);
KeybrdCharYpos += SMALL_FONT_COLUMN_WIDTH;
if(KeybrdCharYpos >= KYBRD_LAST_COLUMN)
{
KeybrdCharYpos = KYBRD_FIRST_COLUMN;
KeybrdCharXpos += SMALL_FONT_LINE_WIDTH;
}if (KeybrdCharYpos >= KYBRD_LAST_COLUMN) { ... }
if(KeybrdCharXpos > KYBRD_LAST_LINE)
{
LCD_LOG_ClearTextZone();
KeybrdCharXpos = KYBRD_FIRST_LINE;
BSP_LCD_DisplayChar(KeybrdCharYpos,KeybrdCharXpos, data);
}if (KeybrdCharXpos > KYBRD_LAST_LINE) { ... }
}else { ... }
}{ ... }