Bladeren bron

Move descriptors to usbd.h

Nathan Conrad 6 jaren geleden
bovenliggende
commit
7e0490bbf3

+ 10 - 10
examples/device/usbtmc/src/usb_descriptors.c

@@ -105,16 +105,16 @@ uint8_t const * tud_hid_descriptor_report_cb(void)
 
 #if defined(CFG_TUD_USBTMC)
 
-#  define USBTMC_DESC_MAIN(_itfnum,_bNumEndpoints) \
-     USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints,  /*_stridx = */ 4u, USBTMC_PROTOCOL_USB488), \
-     USBTMC_BULK_DESCRIPTORS(/* OUT = */0x03, /* IN = */ 0x83)
+#  define TUD_USBTMC_DESC_MAIN(_itfnum,_bNumEndpoints) \
+     TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints,  /*_stridx = */ 4u, TUD_USBTMC_PROTOCOL_USB488), \
+     TUD_USBTMC_BULK_DESCRIPTORS(/* OUT = */0x03, /* IN = */ 0x83, /* packet size = */USBTMCD_MAX_PACKET_SIZE)
 
 #if defined(CFG_TUD_USBTMC_ENABLE_INT_EP)
 // Interrupt endpoint should be 2 bytes on a FS USB link
-#  define USBTMC_DESC(_itfnum) \
-     USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \
-     USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x84, /* epMaxSize = */ 2, /* bInterval = */16u )
-#  define USBTMC_DESC_LEN (USBTMC_IF_DESCRIPTOR_LEN + USBTMC_BULK_DESCRIPTORS_LEN + USBTMC_INT_DESCRIPTOR_LEN)
+#  define TUD_USBTMC_DESC(_itfnum) \
+     TUD_USBTMC_DESC_MAIN(_itfnum, /* _epCount = */ 3), \
+     TUD_USBTMC_INT_DESCRIPTOR(/* INT ep # */ 0x84, /* epMaxSize = */ 2, /* bInterval = */16u )
+#  define USBTMC_DESC_LEN (TUD_USBTMC_IF_DESCRIPTOR_LEN + TUD_USBTMC_BULK_DESCRIPTORS_LEN + TUD_USBTMC_INT_DESCRIPTOR_LEN)
 
 #else
 
@@ -174,7 +174,7 @@ uint8_t const desc_configuration[] =
 #endif
 
 #if CFG_TUD_USBTMC
-  USBTMC_DESC(ITF_NUM_USBTMC),
+  TUD_USBTMC_DESC(ITF_NUM_USBTMC),
 #endif
 
 #if CFG_TUD_MSC
@@ -218,7 +218,7 @@ static uint16_t _desc_str[32];
 // Application return pointer to descriptor, whose contents must exist long enough for transfer to complete
 uint16_t const* tud_descriptor_string_cb(uint8_t index)
 {
-  uint8_t chr_count;
+  size_t chr_count;
 
   if ( index == 0)
   {
@@ -246,7 +246,7 @@ uint16_t const* tud_descriptor_string_cb(uint8_t index)
   }
 
   // first byte is length (including header), second byte is string type
-  _desc_str[0] = (((uint16_t)TUSB_DESC_STRING) << 8 ) | (2u*chr_count + 2u);
+  _desc_str[0] = (uint16_t)((((uint16_t)TUSB_DESC_STRING) << 8 ) | (2u*chr_count + 2u));
 
   return _desc_str;
 }

+ 3 - 2
src/class/usbtmc/usbtmc_device.c

@@ -251,9 +251,9 @@ bool usbtmcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16
   usbtmcd_reset(rhport);
 
   // Perhaps there are other application specific class drivers, so don't assert here.
-  if( itf_desc->bInterfaceClass != USBTMC_APP_CLASS)
+  if( itf_desc->bInterfaceClass != TUD_USBTMC_APP_CLASS)
     return false;
-  if( itf_desc->bInterfaceSubClass != USBTMC_APP_SUBCLASS)
+  if( itf_desc->bInterfaceSubClass != TUD_USBTMC_APP_SUBCLASS)
     return false;
 
   // Only 2 or 3 endpoints are allowed for USBTMC.
@@ -272,6 +272,7 @@ bool usbtmcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16
       tusb_desc_endpoint_t const *ep_desc = (tusb_desc_endpoint_t const *)p_desc;
       switch(ep_desc->bmAttributes.xfer) {
         case TUSB_XFER_BULK:
+          TU_ASSERT(ep_desc->wMaxPacketSize.size == USBTMCD_MAX_PACKET_SIZE);
           if (tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN)
           {
             usbtmc_state.ep_bulk_in = ep_desc->bEndpointAddress;

+ 0 - 30
src/class/usbtmc/usbtmc_device.h

@@ -107,35 +107,5 @@ void usbtmcd_init(void);
  * USBTMC Descriptor Templates
  *************************************************************/
 
-#define USBTMC_APP_CLASS    TUSB_CLASS_APPLICATION_SPECIFIC
-#define USBTMC_APP_SUBCLASS 0x03u
-
-#define USBTMC_PROTOCOL_STD    0x00u
-#define USBTMC_PROTOCOL_USB488 0x01u
-
-//   Interface number, number of endpoints, EP string index, USB_TMC_PROTOCOL*, bulk-out endpoint ID,
-//   bulk-in endpoint ID
-#define USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, _stridx, _itfProtocol) \
-/* Interface */ \
-  0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, _bNumEndpoints, USBTMC_APP_CLASS, USBTMC_APP_SUBCLASS, _itfProtocol, _stridx
-
-#define USBTMC_IF_DESCRIPTOR_LEN 9u
-
-// bulk-out Size must be a multiple of 4 bytes
-#define USBTMC_BULK_DESCRIPTORS(_epout, _epin) \
-/* Endpoint Out */ \
-7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(USBTMCD_MAX_PACKET_SIZE), 0u, \
-/* Endpoint In */ \
-7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(USBTMCD_MAX_PACKET_SIZE), 0u
-
-#define USBTMC_BULK_DESCRIPTORS_LEN (7u+7u)
-
-/* optional interrupt endpoint */ \
-// _int_pollingInterval : for LS/FS, expressed in frames (1ms each). 16 may be a good number?
-#define USBTMC_INT_DESCRIPTOR(_ep_interrupt, _ep_interrupt_size, _int_pollingInterval ) \
-7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), 0x16
-
-#define USBTMC_INT_DESCRIPTOR_LEN (7u)
-
 
 #endif /* CLASS_USBTMC_USBTMC_DEVICE_H_ */

+ 2 - 1
src/device/usbd.c

@@ -151,7 +151,8 @@ static usbd_class_driver_t const usbd_class_drivers[] =
   // We maybe need to add subclass codes here, or a callback to ask if a driver can
   // handle a particular interface.
   {
-      .class_code       = TUSB_CLASS_APPLICATION_SPECIFIC,
+      .class_code       = TUD_USBTMC_APP_CLASS,
+    //.subclass_code    = TUD_USBTMC_APP_SUBCLASS
       .init             = usbtmcd_init,
       .reset            = usbtmcd_reset,
       .open             = usbtmcd_open,

+ 31 - 0
src/device/usbd.h

@@ -261,6 +261,37 @@ TU_ATTR_WEAK bool tud_vendor_control_complete_cb(uint8_t rhport, tusb_control_re
   /* MS Endpoint (connected to embedded jack out) */\
   5, TUSB_DESC_CS_ENDPOINT, MIDI_CS_ENDPOINT_GENERAL, 1, 3
 
+//------------- TUD_USBTMC/USB488 -------------//
+#define TUD_USBTMC_APP_CLASS    (TUSB_CLASS_APPLICATION_SPECIFIC)
+#define TUD_USBTMC_APP_SUBCLASS 0x03u
+
+#define TUD_USBTMC_PROTOCOL_STD    0x00u
+#define TUD_USBTMC_PROTOCOL_USB488 0x01u
+
+//   Interface number, number of endpoints, EP string index, USB_TMC_PROTOCOL*, bulk-out endpoint ID,
+//   bulk-in endpoint ID
+#define TUD_USBTMC_IF_DESCRIPTOR(_itfnum, _bNumEndpoints, _stridx, _itfProtocol) \
+/* Interface */ \
+  0x09, TUSB_DESC_INTERFACE, _itfnum, 0x00, _bNumEndpoints, TUD_USBTMC_APP_CLASS, TUD_USBTMC_APP_SUBCLASS, _itfProtocol, _stridx
+
+#define TUD_USBTMC_IF_DESCRIPTOR_LEN 9u
+
+#define TUD_USBTMC_BULK_DESCRIPTORS(_epout, _epin, _bulk_epsize) \
+/* Endpoint Out */ \
+7, TUSB_DESC_ENDPOINT, _epout, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u, \
+/* Endpoint In */ \
+7, TUSB_DESC_ENDPOINT, _epin, TUSB_XFER_BULK, U16_TO_U8S_LE(_bulk_epsize), 0u
+
+#define TUD_USBTMC_BULK_DESCRIPTORS_LEN (7u+7u)
+
+/* optional interrupt endpoint */ \
+// _int_pollingInterval : for LS/FS, expressed in frames (1ms each). 16 may be a good number?
+#define TUD_USBTMC_INT_DESCRIPTOR(_ep_interrupt, _ep_interrupt_size, _int_pollingInterval ) \
+7, TUSB_DESC_ENDPOINT, _ep_interrupt, TUSB_XFER_INTERRUPT, U16_TO_U8S_LE(_ep_interrupt_size), 0x16
+
+#define TUD_USBTMC_INT_DESCRIPTOR_LEN (7u)
+
+
 //------------- Vendor -------------//
 #define TUD_VENDOR_DESC_LEN  (9+7+7)