diff options
Diffstat (limited to 'examples/device/cdc_msc_hid/src')
| -rw-r--r-- | examples/device/cdc_msc_hid/src/main.c | 15 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/tusb_config.h | 15 | ||||
| -rw-r--r-- | examples/device/cdc_msc_hid/src/usb_descriptors.c | 21 |
3 files changed, 29 insertions, 22 deletions
diff --git a/examples/device/cdc_msc_hid/src/main.c b/examples/device/cdc_msc_hid/src/main.c index fc2f2aad0..f743026c2 100644 --- a/examples/device/cdc_msc_hid/src/main.c +++ b/examples/device/cdc_msc_hid/src/main.c @@ -49,8 +49,8 @@ static uint32_t blink_interval_ms = BLINK_NOT_MOUNTED; void led_blinking_task(void); -extern void cdc_task(void); -extern void hid_task(void); +void cdc_task(void); +void hid_task(void); /*------------- MAIN -------------*/ int main(void) @@ -196,7 +196,9 @@ void hid_task(void) if ( btn ) { int8_t const delta = 5; - tud_hid_mouse_move(REPORT_ID_MOUSE, delta, delta); // right + down + + // no button, right + down, no scroll pan + tud_hid_mouse_report(REPORT_ID_MOUSE, 0x00, delta, delta, 0, 0); // delay a bit before attempt to send keyboard report board_delay(2); @@ -220,12 +222,15 @@ void hid_task(void) }else { // send empty key report if previously has key pressed - if (has_key) tud_hid_keyboard_key_release(REPORT_ID_KEYBOARD); + if (has_key) tud_hid_keyboard_report(REPORT_ID_KEYBOARD, 0, NULL); has_key = false; } } } +// Invoked when received GET_REPORT control request +// Application must fill buffer report's content and return its length. +// Return zero will cause the stack to STALL request uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t* buffer, uint16_t reqlen) { // TODO not Implemented @@ -237,6 +242,8 @@ uint16_t tud_hid_get_report_cb(uint8_t report_id, hid_report_type_t report_type, return 0; } +// Invoked when received SET_REPORT control request or +// received data on OUT endpoint ( Report ID = 0, Type = 0 ) void tud_hid_set_report_cb(uint8_t report_id, hid_report_type_t report_type, uint8_t const* buffer, uint16_t bufsize) { // TODO not Implemented diff --git a/examples/device/cdc_msc_hid/src/tusb_config.h b/examples/device/cdc_msc_hid/src/tusb_config.h index 400afb620..c1210152e 100644 --- a/examples/device/cdc_msc_hid/src/tusb_config.h +++ b/examples/device/cdc_msc_hid/src/tusb_config.h @@ -77,17 +77,13 @@ #define CFG_TUD_MIDI 0 #define CFG_TUD_CUSTOM_CLASS 0 -//-------------------------------------------------------------------- -// CDC -//-------------------------------------------------------------------- +//------------- CDC -------------// // FIFO size of CDC TX and RX #define CFG_TUD_CDC_RX_BUFSIZE 64 #define CFG_TUD_CDC_TX_BUFSIZE 64 -//-------------------------------------------------------------------- -// MSC -//-------------------------------------------------------------------- +//------------- MSC -------------// // Buffer size of Device Mass storage #define CFG_TUD_MSC_BUFSIZE 512 @@ -101,9 +97,10 @@ // Product revision string included in Inquiry response, max 4 bytes #define CFG_TUD_MSC_PRODUCT_REV "1.0" -//-------------------------------------------------------------------- -// HID -//-------------------------------------------------------------------- +//------------- HID -------------// + +// Should be sufficient to hold ID (if any) + Data +#define CFG_TUD_HID_BUFSIZE 16 #ifdef __cplusplus } diff --git a/examples/device/cdc_msc_hid/src/usb_descriptors.c b/examples/device/cdc_msc_hid/src/usb_descriptors.c index c3bcc6f2b..72d280c2f 100644 --- a/examples/device/cdc_msc_hid/src/usb_descriptors.c +++ b/examples/device/cdc_msc_hid/src/usb_descriptors.c @@ -76,8 +76,8 @@ enum uint8_t const desc_hid_report[] = { - HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), - HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) + TUD_HID_REPORT_DESC_KEYBOARD( HID_REPORT_ID(REPORT_ID_KEYBOARD), ), + TUD_HID_REPORT_DESC_MOUSE ( HID_REPORT_ID(REPORT_ID_MOUSE), ) }; #endif @@ -117,19 +117,22 @@ enum uint8_t const desc_configuration[] = { - // Config: self-powered with remote wakeup support, max power up to 100 mA + // Inteface count, string index, total length, attribute, power in mA TUD_CONFIG_DESCRIPTOR(ITF_NUM_TOTAL, 0, CONFIG_TOTAL_LEN, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, 100), #if CFG_TUD_CDC + // Interface number, string index, EP notification address and size, EP data address (out, in) and size. TUD_CDC_DESCRIPTOR(ITF_NUM_CDC, 4, 0x81, 8, 0x02, 0x82, 64), #endif #if CFG_TUD_MSC + // Interface number, string index, EP Out & EP In address, EP size TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, 5, EPNUM_MSC, 0x80 | EPNUM_MSC, 64), // highspeed 512 #endif #if CFG_TUD_HID - TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_KEYBOARD, sizeof(desc_hid_report), 0x84, 16, 10) + // Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval + TUD_HID_DESCRIPTOR(ITF_NUM_HID, 6, HID_PROTOCOL_NONE, sizeof(desc_hid_report), 0x84, 16, 10) #endif }; @@ -162,13 +165,13 @@ uint16_t const * const string_desc_arr [] = // tud_desc_set is required by tinyusb stack tud_desc_set_t tud_desc_set = { - .device = &desc_device, - .config = desc_configuration, + .device = &desc_device, + .config = desc_configuration, - .string_arr = (uint8_t const **) string_desc_arr, - .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), + .string_arr = (uint8_t const **) string_desc_arr, + .string_count = sizeof(string_desc_arr)/sizeof(string_desc_arr[0]), #if CFG_TUD_HID - .hid_report = desc_hid_report, + .hid_report = desc_hid_report, #endif }; |
