1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
21
22
30
38
41
42
43
48
96
97
102
103
104
105
106
107
108
109
110
111
112
113
114
119
120
121
122
123
124
125
126
127
128
134
135
157
158
159
160
161
162
163
164
165
166
173
174
181
182
/* ... */
#include "main.h"
Includes
#define KYBRD_FIRST_COLUMN (uint16_t)7
#define KYBRD_LAST_COLUMN (uint16_t)479
#define KYBRD_FIRST_LINE (uint8_t) 70
#define SMALL_FONT_COLUMN_WIDTH 8
#define SMALL_FONT_LINE_WIDTH 15
#define KYBRD_LAST_LINE (uint16_t)200
6 definesPrivate 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(4, (uint8_t *)"Use Keyboard to tape 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 { ... }
}{ ... }