diff options
| author | hathach <[email protected]> | 2021-05-12 21:40:17 +0700 |
|---|---|---|
| committer | hathach <[email protected]> | 2021-05-18 12:58:24 +0700 |
| commit | b7a8b278c83b9b8e03a328e17f4b833f925226a2 (patch) | |
| tree | 34616a149b0d4d8a0d4ffb8649a2c8ccacb6d980 /examples | |
| parent | 69defb5edc34979c9476533ba3bb49e070879ceb (diff) | |
rename tuh_device_is_configured() to tuh_device_configured()
- remove tuh_device_get_state()
- more hid mouse clean up
Diffstat (limited to 'examples')
| -rw-r--r-- | examples/host/cdc_msc_hid/src/keyboard_helper.h | 59 | ||||
| -rw-r--r-- | examples/host/cdc_msc_hid/src/main.c | 12 |
2 files changed, 7 insertions, 64 deletions
diff --git a/examples/host/cdc_msc_hid/src/keyboard_helper.h b/examples/host/cdc_msc_hid/src/keyboard_helper.h deleted file mode 100644 index 1fde2768c..000000000 --- a/examples/host/cdc_msc_hid/src/keyboard_helper.h +++ /dev/null @@ -1,59 +0,0 @@ -#ifndef KEYBOARD_HELPER_H -#define KEYBAORD_HELPER_H - -#include <stdbool.h> -#include <stdint.h> - -#include "tusb.h" - -// look up new key in previous keys -inline bool find_key_in_report(hid_keyboard_report_t const *p_report, uint8_t keycode) -{ - for(uint8_t i = 0; i < 6; i++) - { - if (p_report->keycode[i] == keycode) return true; - } - - return false; -} - -inline uint8_t keycode_to_ascii(uint8_t modifier, uint8_t keycode) -{ - return keycode > 128 ? 0 : - hid_keycode_to_ascii_tbl [keycode][modifier & (KEYBOARD_MODIFIER_LEFTSHIFT | KEYBOARD_MODIFIER_RIGHTSHIFT) ? 1 : 0]; -} - -void print_kbd_report(hid_keyboard_report_t *prev_report, hid_keyboard_report_t const *new_report) -{ - - printf("Report: "); - uint8_t c; - - // I assume it's possible to have up to 6 keypress events per report? - for (uint8_t i = 0; i < 6; i++) - { - // Check for key presses - if (new_report->keycode[i]) - { - // If not in prev report then it is newly pressed - if ( !find_key_in_report(prev_report, new_report->keycode[i]) ) - c = keycode_to_ascii(new_report->modifier, new_report->keycode[i]); - printf("press %c ", c); - } - - // Check for key depresses (i.e. was present in prev report but not here) - if (prev_report->keycode[i]) - { - // If not present in the current report then depressed - if (!find_key_in_report(new_report, prev_report->keycode[i])) - { - c = keycode_to_ascii(prev_report->modifier, prev_report->keycode[i]); - printf("depress %c ", c); - } - } - } - - printf("\n"); -} - -#endif
\ No newline at end of file diff --git a/examples/host/cdc_msc_hid/src/main.c b/examples/host/cdc_msc_hid/src/main.c index ccc50bbf2..6b2d0affb 100644 --- a/examples/host/cdc_msc_hid/src/main.c +++ b/examples/host/cdc_msc_hid/src/main.c @@ -156,16 +156,18 @@ static inline void process_kbd_report(hid_keyboard_report_t const *p_new_report) void tuh_hid_mounted_cb(uint8_t dev_addr, uint8_t instance) { - // application set-up - printf("A Keyboard device (address %d) is mounted\r\n", dev_addr); + printf("HID device address = %d, instance = %d is mounted\r\n", dev_addr, instance); +// printf("A Keyboard device (address %d) is mounted\r\n", dev_addr); + if (instance == 0) { tuh_hid_keyboard_get_report(dev_addr, &usb_keyboard_report); + } } void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance) { - // application tear-down - printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr); + printf("HID device address = %d, instance = %d is unmounted\r\n", dev_addr, instance); +// printf("A Keyboard device (address %d) is unmounted\r\n", dev_addr); } #endif @@ -255,7 +257,7 @@ void hid_task(void) #endif #if CFG_TUH_HID_MOUSE - if ( tuh_hid_mouse_mounted(addr) ) + if ( tuh_n_hid_n_mouse_mounted(addr, 0) ) { if ( !tuh_hid_mouse_is_busy(addr) ) { |
