1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
22
23
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
171
172
173
174
175
176
177
178
179
180
181
188
189
196
197
/* ... */
#include "main.h"
Includes
#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 definesPrivate define
extern uint8_t *DEMO_KEYBOARD_menu[];
extern uint8_t prev_select;
extern uint32_t hid_demo_ready;
extern DEMO_StateMachine demo;
uint16_t KeybrdCharYpos = 0;
uint16_t KeybrdCharXpos = 0;
uint16_t CurrentLastXpos[KYBRD_LAST_LINE] = {0};Private variables
static void USR_KEYBRD_Init(void);
Private function prototypes
/* ... */
void HID_KeyboardMenuProcess(void)
{
switch(demo.keyboard_state)
{
case HID_KEYBOARD_IDLE:
demo.keyboard_state = HID_KEYBOARD_START;
Demo_SelectItem(DEMO_KEYBOARD_menu, 0);
demo.select = 0;
break;
case HID_KEYBOARD_IDLE:
case HID_KEYBOARD_WAIT:
if(demo.select != prev_select)
{
prev_select = demo.select;
Demo_SelectItem(DEMO_KEYBOARD_menu, demo.select & 0x7F);
if(demo.select & 0x80)
{
demo.select &= 0x7F;
switch(demo.select)
{
case 0:
demo.keyboard_state = HID_KEYBOARD_START;
break;
case 0:
case 1:
LCD_LOG_ClearTextZone();
demo.state = DEMO_IDLE;
LCD_UsrLogY("> HID application closed.\n");
demo.select = 0;
break;
case 1:
default:
break;default
}switch (demo.select) { ... }
}if (demo.select & 0x80) { ... }
}if (demo.select != prev_select) { ... }
break;
case HID_KEYBOARD_WAIT:
case HID_KEYBOARD_START:
USR_KEYBRD_Init();
demo.keyboard_state = HID_KEYBOARD_WAIT;
break;
case HID_KEYBOARD_START:
default:
break;default
}switch (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 type characters:");
BSP_LCD_SetTextColor(LCD_COLOR_WHITE);
KeybrdCharYpos = KYBRD_FIRST_LINE;
KeybrdCharXpos = KYBRD_FIRST_COLUMN;
}{ ... }
/* ... */
void USR_KEYBRD_ProcessData(uint8_t data)
{
if(data == '\n')
{
KeybrdCharXpos = KYBRD_FIRST_COLUMN;
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')
{
if(KeybrdCharXpos == KYBRD_FIRST_COLUMN)
{
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
{
BSP_LCD_DisplayChar(KeybrdCharXpos, KeybrdCharYpos, data);
KeybrdCharXpos += SMALL_FONT_COLUMN_WIDTH;
CurrentLastXpos[KeybrdCharYpos] = KeybrdCharXpos;
if(KeybrdCharXpos == KYBRD_LAST_COLUMN)
{
KeybrdCharXpos = KYBRD_FIRST_COLUMN;
KeybrdCharYpos += SMALL_FONT_LINE_WIDTH;
}if (KeybrdCharXpos == KYBRD_LAST_COLUMN) { ... }
if(KeybrdCharYpos > KYBRD_LAST_LINE)
{
LCD_LOG_ClearTextZone();
KeybrdCharYpos = KYBRD_FIRST_LINE;
BSP_LCD_DisplayChar(KeybrdCharXpos,KeybrdCharYpos, data);
}if (KeybrdCharYpos > KYBRD_LAST_LINE) { ... }
}else { ... }
}{ ... }