more API update

- remove tuh_n_hid_n_get_report()
- usbh auto queue get report and invoke callback when received data
This commit is contained in:
hathach
2021-05-14 17:47:02 +07:00
parent dfa8b41b96
commit 93661042d9
4 changed files with 38 additions and 64 deletions

View File

@@ -108,7 +108,6 @@ void cdc_task(void)
//--------------------------------------------------------------------+
// USB HID
//--------------------------------------------------------------------+
CFG_TUSB_MEM_SECTION static hid_keyboard_report_t usb_keyboard_report;
uint8_t const keycode2ascii[128][2] = { HID_KEYCODE_TO_ASCII };
// look up new key in previous keys
@@ -156,10 +155,6 @@ void tuh_hid_mounted_cb(uint8_t dev_addr, uint8_t instance)
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);
// printf("A Mouse device (address %d) is mounted\r\n", dev_addr);
if (instance == 0) {
tuh_n_hid_n_get_report(dev_addr, instance, &usb_keyboard_report, sizeof(usb_keyboard_report));
}
}
void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance)
@@ -169,9 +164,6 @@ void tuh_hid_unmounted_cb(uint8_t dev_addr, uint8_t instance)
// printf("A Mouse device (address %d) is unmounted\r\n", dev_addr);
}
CFG_TUSB_MEM_SECTION static hid_mouse_report_t usb_mouse_report;
void cursor_movement(int8_t x, int8_t y, int8_t wheel)
{
//------------- X -------------//
@@ -220,32 +212,13 @@ static inline void process_mouse_report(hid_mouse_report_t const * p_report)
cursor_movement(p_report->x, p_report->y, p_report->wheel);
}
void tuh_hid_get_report_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len)
{
process_kbd_report( (hid_keyboard_report_t*) report );
}
void hid_task(void)
{
uint8_t const daddr = 1;
uint8_t const instance = 0;
if ( tuh_n_hid_n_keyboard_mounted(daddr, instance) )
{
if ( tuh_n_hid_n_ready(daddr, instance) )
{
process_kbd_report(&usb_keyboard_report);
tuh_n_hid_n_get_report(daddr, instance, &usb_keyboard_report, sizeof(usb_keyboard_report));
}
}
// #if CFG_TUH_HID_MOUSE
(void) usb_mouse_report;
// if ( tuh_n_hid_n_mouse_mounted(daddr, instance) )
// {
// if ( tuh_n_hid_n_ready(daddr, instance) )
// {
// process_mouse_report(&usb_mouse_report);
// tuh_n_hid_n_get_report(daddr, instance, &usb_mouse_report, sizeof(usb_mouse_report));
// }
// }
}
//--------------------------------------------------------------------+

View File

@@ -84,7 +84,7 @@
//------------- HID -------------//
//#define CFG_TUH_HID_EP_BUFSIZE 64
#define CFG_TUH_HID_EP_BUFSIZE 64
// Max number of reports per interface
// E.g composite HID with keyboard + mouse + gamepad will have 3 reports