summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2013-05-31 14:53:26 +0700
committerhathach <[email protected]>2013-05-31 14:53:26 +0700
commit376482558a943434b13c155962e78923ba46cbbc (patch)
tree882952a7c64ad849e315767386908047e318a68d
parented64401e6157b283f1921bbb8460da5f7a822ed6 (diff)
clean up device main.c demo code
-rw-r--r--demos/device/keyboard/main.c50
1 files changed, 34 insertions, 16 deletions
diff --git a/demos/device/keyboard/main.c b/demos/device/keyboard/main.c
index 659fc0a33..22ceffb0d 100644
--- a/demos/device/keyboard/main.c
+++ b/demos/device/keyboard/main.c
@@ -16,6 +16,9 @@
void print_greeting(void);
+void led_blinking_task(void * p_para);
+void keyboard_device_app_task(void * p_para);
+
int main(void)
{
uint32_t current_tick = system_ticks;
@@ -28,29 +31,20 @@ int main(void)
{
if (current_tick + 1000 < system_ticks)
{
- static uint32_t led_on_mask = 0;
-
current_tick += 1000;
- board_leds(led_on_mask, 1 - led_on_mask);
- led_on_mask = 1 - led_on_mask; // toggle
+ led_blinking_task(NULL);
+
+ #if TUSB_CFG_DEVICE_HID_KEYBOARD
+ keyboard_device_app_task(NULL);
+ #endif
+ #if TUSB_CFG_DEVICE_HID_MOUSE
if (usb_isConfigured())
{
- #if TUSB_CFG_DEVICE_HID_KEYBOARD
- static uint32_t count =0;
- if (count < 4)
- {
- uint8_t keys[6] = {0x04}; // A character
- tusbd_hid_keyboard_send_report(0x00, keys, 1);
- count++;
- }
- #endif
-
- #if TUSB_CFG_DEVICE_HID_MOUSE
tusb_hid_mouse_send(0, 10, 10);
- #endif
}
+ #endif
}
#if defined TUSB_CFG_DEVICE_CDC && 0
@@ -90,6 +84,30 @@ int main(void)
return 0;
}
+void led_blinking_task(void * p_para)
+{
+ static uint32_t led_on_mask = 0;
+
+ board_leds(led_on_mask, 1 - led_on_mask);
+ led_on_mask = 1 - led_on_mask; // toggle
+}
+
+#if TUSB_CFG_DEVICE_HID_KEYBOARD
+void keyboard_device_app_task(void * p_para)
+{
+ if (usb_isConfigured())
+ {
+ static uint32_t count =0;
+ if (count < 4)
+ {
+ uint8_t keys[6] = {0x04}; // A character
+ tusbd_hid_keyboard_send_report(0x00, keys, 1);
+ count++;
+ }
+ }
+}
+#endif
+
//--------------------------------------------------------------------+
// HELPER FUNCTION
//--------------------------------------------------------------------+