diff options
Diffstat (limited to 'src/device')
| -rw-r--r-- | src/device/usbd.c | 20 | ||||
| -rw-r--r-- | src/device/usbd.h | 20 | ||||
| -rw-r--r-- | src/device/usbd_pvt.h | 3 |
3 files changed, 29 insertions, 14 deletions
diff --git a/src/device/usbd.c b/src/device/usbd.c index f02b21208..d811c471a 100644 --- a/src/device/usbd.c +++ b/src/device/usbd.c @@ -702,25 +702,25 @@ void dcd_event_xfer_complete (uint8_t rhport, uint8_t ep_addr, uint32_t xferred_ // Helper
//--------------------------------------------------------------------+
-// Helper to parse an pair of endpoint descriptors (IN & OUT)
-bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_desc, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
+// Parse consecutive endpoint descriptors (IN & OUT)
+bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in)
{
- for(int i=0; i<2; i++)
+ for(int i=0; i<ep_count; i++)
{
- TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType &&
- xfer_type == ep_desc->bmAttributes.xfer );
+ tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;
- TU_ASSERT(dcd_edpt_open(rhport, ep_desc));
+ TU_VERIFY(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && xfer_type == desc_ep->bmAttributes.xfer);
+ TU_ASSERT(dcd_edpt_open(rhport, desc_ep));
- if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
+ if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
{
- (*ep_in) = ep_desc->bEndpointAddress;
+ (*ep_in) = desc_ep->bEndpointAddress;
}else
{
- (*ep_out) = ep_desc->bEndpointAddress;
+ (*ep_out) = desc_ep->bEndpointAddress;
}
- ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
+ p_desc = tu_desc_next(p_desc);
}
return true;
diff --git a/src/device/usbd.h b/src/device/usbd.h index de59731a2..8debbf535 100644 --- a/src/device/usbd.h +++ b/src/device/usbd.h @@ -107,7 +107,7 @@ ATTR_WEAK void tud_resume_cb(void); #define TUD_CDC_DESC_LEN (8+9+5+5+4+5+7+9+7+7)
// CDC Descriptor Template
-// interface number, string index, EP notification address and size, EP data address (out,in) and size.
+// Interface number, string index, EP notification address and size, EP data address (out, in) and size.
#define TUD_CDC_DESCRIPTOR(_itfnum, _stridx, _ep_notif, _ep_notif_size, _epout, _epin, _epsize) \
/* Interface Associate */\
8, TUSB_DESC_INTERFACE_ASSOCIATION, _itfnum, 2, TUSB_CLASS_CDC, CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL, CDC_COMM_PROTOCOL_ATCOMMAND, 0,\
@@ -149,15 +149,31 @@ ATTR_WEAK void tud_resume_cb(void); // Length of template descriptor: 25 bytes
#define TUD_HID_DESC_LEN (9 + 9 + 7)
+// HID Input only descriptor
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
#define TUD_HID_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epsize, _ep_interval) \
/* Interface */\
9, TUSB_DESC_INTERFACE, _itfnum, 0, 1, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
/* HID descriptor */\
9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
- /* Endpoint descriptor */\
+ /* Endpoint In */\
7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
+// Length of template descriptor: 32 bytes
+#define TUD_HID_INOUT_DESC_LEN (9 + 9 + 7 + 7)
+
+// HID Input & Output descriptor
+// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
+#define TUD_HID_INOUT_DESCRIPTOR(_itfnum, _stridx, _boot_protocol, _report_desc_len, _epin, _epout, _epsize, _ep_interval) \
+ /* Interface */\
+ 9, TUSB_DESC_INTERFACE, _itfnum, 0, 2, TUSB_CLASS_HID, (_boot_protocol) ? HID_SUBCLASS_BOOT : 0, _boot_protocol, _stridx,\
+ /* HID descriptor */\
+ 9, HID_DESC_TYPE_HID, U16_TO_U8S_LE(0x0111), 0, 1, HID_DESC_TYPE_REPORT, U16_TO_U8S_LE(_report_desc_len),\
+ /* Endpoint In */\
+ 7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval,\
+ /* Endpoint Out */\
+ 7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_epsize), _ep_interval
+
#ifdef __cplusplus
}
#endif
diff --git a/src/device/usbd_pvt.h b/src/device/usbd_pvt.h index 8518ee209..fb3672359 100644 --- a/src/device/usbd_pvt.h +++ b/src/device/usbd_pvt.h @@ -53,9 +53,8 @@ bool usbd_edpt_stalled(uint8_t rhport, uint8_t ep_addr); /*------------------------------------------------------------------*/ /* Helper *------------------------------------------------------------------*/ -// helper to parse an pair of In and Out endpoint descriptors. They must be consecutive -bool usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* p_desc_ep, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); +bool usbd_open_edpt_pair(uint8_t rhport, uint8_t const* p_desc, uint8_t ep_count, uint8_t xfer_type, uint8_t* ep_out, uint8_t* ep_in); void usbd_defer_func( osal_task_func_t func, void* param, bool in_isr ); |
