diff options
| author | hathach <[email protected]> | 2018-07-23 17:46:07 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2018-07-23 17:46:07 +0700 |
| commit | 3e209f9c20c9251e01af35da4d9e454fcc2f61dd (patch) | |
| tree | cb0c95b6356bb51bec84a18e79498b25495ea89c /examples | |
| parent | 262be103e0478fc70fcc4e392c5ad1ad60bc074b (diff) | |
enhance device hid
- add CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP
- add tud_hid_keyboard_send_keycode(), tud_hid_keyboard_send_char(),
tud_hid_keyboard_send_string()
- add timeout_blocking_wait()
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/device/nrf52840/src/main.c | 27 | ||||
| -rw-r--r-- | examples/device/nrf52840/src/tusb_config.h | 7 |
2 files changed, 34 insertions, 0 deletions
diff --git a/examples/device/nrf52840/src/main.c b/examples/device/nrf52840/src/main.c index 00937d7d2..1993109b4 100644 --- a/examples/device/nrf52840/src/main.c +++ b/examples/device/nrf52840/src/main.c @@ -76,6 +76,9 @@ int main(void) return 0; } +//--------------------------------------------------------------------+ +// USB CDC +//--------------------------------------------------------------------+ void virtual_com_task(void) { // connected and there are data available @@ -91,6 +94,30 @@ void virtual_com_task(void) } } +//--------------------------------------------------------------------+ +// USB CDC +//--------------------------------------------------------------------+ +void usb_hid_task(void) +{ + if ( tud_mounted() ) + { + if ( !tud_hid_keyboard_busy() ) + { + static bool toggle = false; // send either A or B + + tud_hid_keyboard_send_char( toggle ? 'A' : 'B' ); + toggle = !toggle; + } + + if ( !tud_hid_mouse_busy() ) + { + + } + + } +} + + //--------------------------------------------------------------------+ // tinyusb callbacks diff --git a/examples/device/nrf52840/src/tusb_config.h b/examples/device/nrf52840/src/tusb_config.h index da7dc793b..457dceea7 100644 --- a/examples/device/nrf52840/src/tusb_config.h +++ b/examples/device/nrf52840/src/tusb_config.h @@ -126,6 +126,13 @@ */ #define CFG_TUD_HID_BOOT_PROTOCOL 1 +/* Use the HID_ASCII_TO_KEYCODE lookup if CFG_TUD_HID_KEYBOARD is enabled. + * This will occupies 256 bytes of ROM. It will also enable the use of 2 extra APIs + * - tud_hid_keyboard_send_char() + * - tud_hid_keyboard_send_string() + */ +#define CFG_TUD_HID_ASCII_TO_KEYCODE_LOOKUP 1 + //-------------------------------------------------------------------- // USB RAM PLACEMENT //-------------------------------------------------------------------- |
