hathach 7 лет назад
Родитель
Сommit
1faf0a81e4
3 измененных файлов с 43 добавлено и 11 удалено
  1. 31 0
      src/common/tusb_common.h
  2. 4 4
      src/device/usbd_desc.c
  3. 8 7
      src/portable/nordic/nrf5x/hal_nrf5x.c

+ 31 - 0
src/common/tusb_common.h

@@ -102,6 +102,37 @@
 #define __be2n_16(u16)  __n2be_16(u16)
 #define __be2n_16(u16)  __n2be_16(u16)
 #endif
 #endif
 
 
+
+/*------------------------------------------------------------------*/
+/* Count number of arguments of __VA_ARGS__
+ * - reference https://groups.google.com/forum/#!topic/comp.std.c/d-6Mj5Lko_s
+ * - _GET_NTH_ARG() takes args >= N (64) but only expand to Nth one (64th)
+ * - _RSEQ_N() is reverse sequential to N to add padding to have
+ * Nth position is the same as the number of arguments
+ * - ##__VA_ARGS__ is used to deal with 0 paramerter (swallows comma)
+ *------------------------------------------------------------------*/
+#ifndef VA_ARGS_NUM_
+
+#define VA_ARGS_NUM_(...) 	 NARG_(_0, ##__VA_ARGS__,_RSEQ_N())
+#define NARG_(...)        _GET_NTH_ARG(__VA_ARGS__)
+#define _GET_NTH_ARG( \
+          _1, _2, _3, _4, _5, _6, _7, _8, _9,_10, \
+         _11,_12,_13,_14,_15,_16,_17,_18,_19,_20, \
+         _21,_22,_23,_24,_25,_26,_27,_28,_29,_30, \
+         _31,_32,_33,_34,_35,_36,_37,_38,_39,_40, \
+         _41,_42,_43,_44,_45,_46,_47,_48,_49,_50, \
+         _51,_52,_53,_54,_55,_56,_57,_58,_59,_60, \
+         _61,_62,_63,N,...) N
+#define _RSEQ_N() \
+         62,61,60,                      \
+         59,58,57,56,55,54,53,52,51,50, \
+         49,48,47,46,45,44,43,42,41,40, \
+         39,38,37,36,35,34,33,32,31,30, \
+         29,28,27,26,25,24,23,22,21,20, \
+         19,18,17,16,15,14,13,12,11,10, \
+         9,8,7,6,5,4,3,2,1,0
+#endif
+
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+
 // INLINE FUNCTION
 // INLINE FUNCTION
 //--------------------------------------------------------------------+
 //--------------------------------------------------------------------+

+ 4 - 4
src/device/usbd_desc.c

@@ -324,7 +324,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
           .bEndpointAddress = EP_CDC_OUT,
           .bEndpointAddress = EP_CDC_OUT,
           .bmAttributes     = { .xfer = TUSB_XFER_BULK },
           .bmAttributes     = { .xfer = TUSB_XFER_BULK },
           .wMaxPacketSize   = { .size = EP_CDC_SIZE },
           .wMaxPacketSize   = { .size = EP_CDC_SIZE },
-      .bInterval        = 0
+          .bInterval        = 0
       },
       },
 
 
       .ep_in =
       .ep_in =
@@ -352,7 +352,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
           .bInterfaceClass    = TUSB_CLASS_MSC,
           .bInterfaceClass    = TUSB_CLASS_MSC,
           .bInterfaceSubClass = MSC_SUBCLASS_SCSI,
           .bInterfaceSubClass = MSC_SUBCLASS_SCSI,
           .bInterfaceProtocol = MSC_PROTOCOL_BOT,
           .bInterfaceProtocol = MSC_PROTOCOL_BOT,
-          .iInterface         = 0x05
+          .iInterface         = 0 // ITF_NUM_MSC + 3
       },
       },
 
 
       .ep_out =
       .ep_out =
@@ -390,7 +390,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
         .bInterfaceClass    = TUSB_CLASS_HID,
         .bInterfaceClass    = TUSB_CLASS_HID,
         .bInterfaceSubClass = HID_SUBCLASS_BOOT,
         .bInterfaceSubClass = HID_SUBCLASS_BOOT,
         .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
         .bInterfaceProtocol = HID_PROTOCOL_KEYBOARD,
-        .iInterface         = 0x05
+        .iInterface         = ITF_NUM_HID_KEYBOARD + 3,
     },
     },
 
 
     .keyboard_hid =
     .keyboard_hid =
@@ -427,7 +427,7 @@ desc_auto_cfg_t const _desc_auto_config_struct =
         .bInterfaceClass    = TUSB_CLASS_HID,
         .bInterfaceClass    = TUSB_CLASS_HID,
         .bInterfaceSubClass = HID_SUBCLASS_BOOT,
         .bInterfaceSubClass = HID_SUBCLASS_BOOT,
         .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
         .bInterfaceProtocol = HID_PROTOCOL_MOUSE,
-        .iInterface         = 0x06
+        .iInterface         = ITF_NUM_HID_MOUSE+3
     },
     },
 
 
     .mouse_hid =
     .mouse_hid =

+ 8 - 7
src/portable/nordic/nrf5x/hal_nrf5x.c

@@ -74,17 +74,15 @@ void tusb_hal_nrf_power_event(uint32_t event);
 /* HFCLK helper
 /* HFCLK helper
  *------------------------------------------------------------------*/
  *------------------------------------------------------------------*/
 
 
+#ifdef SOFTDEVICE_PRESENT
 // check if SD is present and enabled
 // check if SD is present and enabled
 static bool is_sd_enabled(void)
 static bool is_sd_enabled(void)
 {
 {
   uint8_t sd_en = false;
   uint8_t sd_en = false;
-
-#ifdef SOFTDEVICE_PRESENT
   (void) sd_softdevice_is_enabled(&sd_en);
   (void) sd_softdevice_is_enabled(&sd_en);
-#endif
-
   return sd_en;
   return sd_en;
 }
 }
+#endif
 
 
 static bool hfclk_running(void)
 static bool hfclk_running(void)
 {
 {
@@ -285,9 +283,12 @@ void tusb_hal_nrf_power_event (uint32_t event)
       nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_Half);
       nrf_usbd_isosplit_set(NRF_USBD_ISOSPLIT_Half);
 
 
       // Enable interrupt. SOF is used as CDC auto flush
       // Enable interrupt. SOF is used as CDC auto flush
-      NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk |
-          USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk |
-          USBD_INTEN_EPDATA_Msk | ((CFG_TUD_CDC && CFG_TUD_CDC_FLUSH_ON_SOF) ? USBD_INTEN_SOF_Msk : 0);
+      NRF_USBD->INTENSET = USBD_INTEN_USBRESET_Msk | USBD_INTEN_USBEVENT_Msk | USBD_INTEN_EPDATA_Msk |
+          USBD_INTEN_EP0SETUP_Msk | USBD_INTEN_EP0DATADONE_Msk | USBD_INTEN_ENDEPIN0_Msk | USBD_INTEN_ENDEPOUT0_Msk;
+
+#if CFG_TUD_CDC && CFG_TUD_CDC_FLUSH_ON_SOF
+      NRF_USBD->INTENSET |= USBD_INTEN_SOF_Msk;
+#endif
 
 
       // Enable interrupt, Priorities 0,1,4,5 (nRF52) are reserved for SoftDevice
       // Enable interrupt, Priorities 0,1,4,5 (nRF52) are reserved for SoftDevice
       NVIC_SetPriority(USBD_IRQn, USB_NVIC_PRIO);
       NVIC_SetPriority(USBD_IRQn, USB_NVIC_PRIO);