summaryrefslogtreecommitdiff
path: root/demos/device/src
diff options
context:
space:
mode:
authorhathach <[email protected]>2014-03-06 23:26:40 +0700
committerhathach <[email protected]>2014-03-06 23:26:40 +0700
commit4b8c0d97c6e7694dbab39d155e1ebda0db11b5ff (patch)
tree1180c32b2f02fde7e2114660a1965efc3e447a1b /demos/device/src
parentf39444a0653ab7c33938dcf8f4867ba14e0af776 (diff)
add board_buttons API and refractor device keyboard app
Diffstat (limited to 'demos/device/src')
-rw-r--r--demos/device/src/keyboardd_app.c29
-rw-r--r--demos/device/src/tusb_config.h8
2 files changed, 17 insertions, 20 deletions
diff --git a/demos/device/src/keyboardd_app.c b/demos/device/src/keyboardd_app.c
index b072d7e12..9c00972a4 100644
--- a/demos/device/src/keyboardd_app.c
+++ b/demos/device/src/keyboardd_app.c
@@ -127,29 +127,28 @@ OSAL_TASK_FUNCTION( keyboardd_app_task ) (void* p_task_para)
{
OSAL_TASK_LOOP_BEGIN
- if (tusbd_is_configured(0) && (keyboardd_report_count++ < 5) )
+ osal_task_delay(100);
+
+ if ( tusbd_is_configured(0) )
{
- if (!tusbd_hid_keyboard_is_busy(0))
+ static uint32_t button_mask = 0;
+
+ uint32_t new_button_mask = board_buttons();
+
+ //------------- Key pressed -------------//
+ if ( (button_mask != new_button_mask) && !tusbd_hid_keyboard_is_busy(0) )
{
- //------------- Key pressed -------------//
- keyboard_report.keycode[0] = 0x04;
- tusbd_hid_keyboard_send(0, &keyboard_report );
+ button_mask = new_button_mask;
- while( tusbd_hid_keyboard_is_busy(0) )
- { // delay for transfer complete
- osal_task_delay(10);
+ for (uint8_t i=0; i<6; i++)
+ { // demo support up to 6 buttons, button0 = 'a', button1 = 'b', etc ...
+ keyboard_report.keycode[i] = BIT_TEST_(button_mask, i) ? (0x04+i) : 0;
}
- //------------- Key released -------------//
- if (!tusbd_hid_keyboard_is_busy(0))
- {
- keyboard_report.keycode[0] = 0x00;
- tusbd_hid_keyboard_send(0, &keyboard_report );
- }
+ tusbd_hid_keyboard_send(0, &keyboard_report );
}
}
- osal_task_delay(1000);
OSAL_TASK_LOOP_END
}
diff --git a/demos/device/src/tusb_config.h b/demos/device/src/tusb_config.h
index 41aaf468a..bfc225351 100644
--- a/demos/device/src/tusb_config.h
+++ b/demos/device/src/tusb_config.h
@@ -82,11 +82,11 @@
#define TUSB_CFG_DEVICE_FULLSPEED 1 // TODO refractor, remove
//------------- CLASS -------------//
-#define TUSB_CFG_DEVICE_HID_KEYBOARD 0
+#define TUSB_CFG_DEVICE_HID_KEYBOARD 1
#define TUSB_CFG_DEVICE_HID_MOUSE 0
#define TUSB_CFG_DEVICE_HID_GENERIC 0
#define TUSB_CFG_DEVICE_MSC 0
-#define TUSB_CFG_DEVICE_CDC 1
+#define TUSB_CFG_DEVICE_CDC 0
//--------------------------------------------------------------------+
// COMMON CONFIGURATION
@@ -99,12 +99,10 @@
#define TUSB_CFG_OS_TICKS_PER_SECOND 1000
#ifdef __CODE_RED // compiled with lpcxpresso
- #if (TUSB_CFG_MCU == MCU_LPC11UXX) || (TUSB_CFG_MCU == MCU_LPC13UXX)
+ #if (TUSB_CFG_MCU == MCU_LPC11UXX) || (TUSB_CFG_MCU == MCU_LPC13UXX) || (TUSB_CFG_MCU == MCU_LPC175X_6X)
#define TUSB_RAM_SECTION ".data.$RAM2"
#elif (TUSB_CFG_MCU == MCU_LPC43XX)
#define TUSB_RAM_SECTION ".data.$RAM3"
- #elif (TUSB_CFG_MCU == MCU_LPC175X_6X)
- #define TUSB_RAM_SECTION ".data.$RAM2"
#else
#error Please define USB RAM section
#endif