summaryrefslogtreecommitdiff
path: root/demos
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-04-26 02:08:22 +0700
committerhathach <[email protected]>2013-04-26 02:08:22 +0700
commit33feba5cbc7a344f1bac67508e5658aa615e59bf (patch)
treea3833f483fa7d49af0b23799b9c1731a3733b9d0 /demos
parentc0104b996e9ea0c5c25861ccf24e0255431a8f9c (diff)
add hid_keycode_to_ascii_tbl for hid class
improve keyboard_app, should display all displayable characters improve the de-bouncing keyboard (still got some issues)
Diffstat (limited to 'demos')
-rw-r--r--demos/host/src/keyboard_app.c31
-rw-r--r--demos/host/src/main.c7
2 files changed, 22 insertions, 16 deletions
diff --git a/demos/host/src/keyboard_app.c b/demos/host/src/keyboard_app.c
index e6096d514..169f1bc6d 100644
--- a/demos/host/src/keyboard_app.c
+++ b/demos/host/src/keyboard_app.c
@@ -58,7 +58,7 @@ static osal_queue_handle_t q_kbd_report_hdl;
static tusb_keyboard_report_t usb_keyboard_report TUSB_CFG_ATTR_USBRAM;
// only convert a-z (case insensitive) + 0-9
-static inline uint8_t keycode_to_ascii(uint8_t keycode) ATTR_CONST ATTR_ALWAYS_INLINE;
+static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) ATTR_CONST ATTR_ALWAYS_INLINE;
//--------------------------------------------------------------------+
// tinyusb callback (ISR context)
@@ -106,39 +106,40 @@ void keyboard_app_init(void)
OSAL_TASK_FUNCTION( keyboard_app_task ) (void* p_task_para)
{
tusb_error_t error;
+ static tusb_keyboard_report_t prev_kbd_report = { 0 }; // previous report to check key released
tusb_keyboard_report_t kbd_report;
OSAL_TASK_LOOP_BEGIN
osal_queue_receive(q_kbd_report_hdl, &kbd_report, OSAL_TIMEOUT_WAIT_FOREVER, &error);
- bool has_key = false;
+ //------------- example code ignore modifier key -------------//
for(uint8_t i=0; i<6; i++)
{
- if ( kbd_report.keycode[i] != 0 )
+ if ( kbd_report.keycode[i] != prev_kbd_report.keycode[i] )
{
- printf("%c", keycode_to_ascii(kbd_report.keycode[i]));
- has_key = true;
+ if ( 0 != kbd_report.keycode[i]) // key pressed
+ {
+ printf("%c", keycode_to_ascii(kbd_report.modifier, kbd_report.keycode[i]) );
+ }else
+ {
+ // key released
+ }
}
+ prev_kbd_report.keycode[i] = kbd_report.keycode[i];
}
- if (has_key)
- printf("\n");
-
- memclr_(&kbd_report, sizeof(tusb_keyboard_report_t) );
-
OSAL_TASK_LOOP_END
}
//--------------------------------------------------------------------+
// HELPER
//--------------------------------------------------------------------+
-static inline uint8_t keycode_to_ascii(uint8_t keycode)
+static inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode)
{
- return
- ( KEYBOARD_KEYCODE_a <= keycode && keycode <= KEYBOARD_KEYCODE_z) ? ( (keycode - KEYBOARD_KEYCODE_a) + 'a' ) :
- ( KEYBOARD_KEYCODE_1 <= keycode && keycode < KEYBOARD_KEYCODE_0) ? ( (keycode - KEYBOARD_KEYCODE_1) + '1' ) :
- ( KEYBOARD_KEYCODE_0 == keycode) ? '0' : 'x';
+ // TODO max of keycode_ascii_tbl
+ return keycode > 128 ? 0 :
+ hid_keycode_to_ascii_tbl [modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT) ? 1 : 0] [keycode];
}
#endif
diff --git a/demos/host/src/main.c b/demos/host/src/main.c
index aee0474d7..a88573fb3 100644
--- a/demos/host/src/main.c
+++ b/demos/host/src/main.c
@@ -76,6 +76,10 @@ OSAL_TASK_DEF(led_blinking_task_def, "led blinking", led_blinking_task, 128, LED
int main(void)
{
board_init();
+
+ // print_greeting(); TODO uart output before freeRTOS scheduler start will lead to hardfault
+ // find a way to fix this as tusb_init can output to uart when an error occurred
+
tusb_init();
//------------- application task init -------------//
@@ -95,6 +99,7 @@ int main(void)
#elif TUSB_CFG_OS == TUSB_OS_NONE
print_greeting();
+
while (1)
{
tusb_task_runner();
@@ -122,7 +127,7 @@ int main(void)
void print_greeting(void)
{
printf("\r\n\
---------------------------------------------------------------------\
+--------------------------------------------------------------------\r\n\
- Host Demo (a tinyusb example)\r\n\
- if you find any bugs or get any questions, feel free to file an\r\n\
- issue at https://github.com/hathach/tinyusb\r\n\