Browse Source

change hal_dcd_pipe_open() signature to return bool

- remove endpointhandle_is_valid()
hathach 8 years ago
parent
commit
fbeb30a71d

+ 9 - 10
hw/mcu/nxp/lpc43xx/tusb_port/dcd_lpc43xx.c

@@ -391,13 +391,11 @@ tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr)
   return TUSB_ERROR_NONE;
 }
 
-endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc)
+bool hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, endpoint_handle_t* eh)
 {
   // TODO USB1 only has 4 non-control enpoint (USB0 has 5)
-  endpoint_handle_t const null_handle = { 0 };
-
   // TODO not support ISO yet
-  if (p_endpoint_desc->bmAttributes.xfer == TUSB_XFER_ISOCHRONOUS) return null_handle;
+  VERIFY ( p_endpoint_desc->bmAttributes.xfer != TUSB_XFER_ISOCHRONOUS);
 
   tusb_direction_t dir = (p_endpoint_desc->bEndpointAddress & TUSB_DIR_DEV_TO_HOST_MASK) ? TUSB_DIR_DEV_TO_HOST : TUSB_DIR_HOST_TO_DEV;
 
@@ -414,14 +412,15 @@ endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t c
   //------------- Endpoint Control Register -------------//
   volatile uint32_t * reg_control = get_reg_control_addr(coreid, ep_idx);
 
-  ASSERT_FALSE( (*reg_control) &  (ENDPTCTRL_MASK_ENABLE << (dir ? 16 : 0)), null_handle ); // endpoint must not be already enabled
+  // endpoint must not be already enabled
+  VERIFY( !( (*reg_control) &  (ENDPTCTRL_MASK_ENABLE << (dir ? 16 : 0)) ) );
+
   (*reg_control) |= ((p_endpoint_desc->bmAttributes.xfer << 2) | ENDPTCTRL_MASK_ENABLE | ENDPTCTRL_MASK_TOGGLE_RESET) << (dir ? 16 : 0);
 
-  return (endpoint_handle_t)
-      {
-          .coreid     = coreid,
-          .index      = ep_idx,
-      };
+  eh->coreid = coreid;
+  eh->index  = ep_idx;
+
+  return true;
 }
 
 bool dcd_pipe_is_busy(endpoint_handle_t edpt_hdl)

+ 2 - 5
tinyusb/class/cdc_device.c

@@ -135,12 +135,10 @@ tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
 
   if ( TUSB_DESC_TYPE_ENDPOINT == p_desc[DESCRIPTOR_OFFSET_TYPE])
   { // notification endpoint if any
-    p_cdc->edpt_hdl[CDC_PIPE_NOTIFICATION] = hal_dcd_pipe_open(coreid, (tusb_descriptor_endpoint_t const *) p_desc);
+    VERIFY( hal_dcd_pipe_open(coreid, (tusb_descriptor_endpoint_t const *) p_desc, &p_cdc->edpt_hdl[CDC_PIPE_NOTIFICATION]), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
 
     (*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH];
     p_desc = descriptor_next(p_desc);
-
-    ASSERT(endpointhandle_is_valid(p_cdc->edpt_hdl[CDC_PIPE_NOTIFICATION]), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
   }
 
   //------------- Data Interface (if any) -------------//
@@ -160,8 +158,7 @@ tusb_error_t cdcd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
       endpoint_handle_t * p_edpt_hdl =  ( p_endpoint->bEndpointAddress &  TUSB_DIR_DEV_TO_HOST_MASK ) ?
           &p_cdc->edpt_hdl[CDC_PIPE_DATA_IN] : &p_cdc->edpt_hdl[CDC_PIPE_DATA_OUT] ;
 
-      (*p_edpt_hdl) = hal_dcd_pipe_open(coreid, p_endpoint);
-      ASSERT ( endpointhandle_is_valid(*p_edpt_hdl), TUSB_ERROR_DCD_OPEN_PIPE_FAILED );
+      VERIFY( hal_dcd_pipe_open(coreid, p_endpoint, p_edpt_hdl), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
 
       (*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH];
       p_desc = descriptor_next( p_desc );

+ 1 - 2
tinyusb/class/hid_device.c

@@ -280,8 +280,7 @@ tusb_error_t hidd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
 
         ASSERT_PTR(p_hid, TUSB_ERROR_FAILED);
 
-        p_hid->ept_handle       = hal_dcd_pipe_open(coreid, p_desc_endpoint);
-        ASSERT( endpointhandle_is_valid(p_hid->ept_handle), TUSB_ERROR_DCD_FAILED);
+        VERIFY( hal_dcd_pipe_open(coreid, p_desc_endpoint, &p_hid->ept_handle), TUSB_ERROR_DCD_FAILED );
 
         p_hid->interface_number = p_interface_desc->bInterfaceNumber;
         p_hid->p_report_desc    = (p_interface_desc->bInterfaceProtocol == HID_PROTOCOL_KEYBOARD) ? tusbd_descriptor_pointers.p_hid_keyboard_report : tusbd_descriptor_pointers.p_hid_mouse_report;

+ 1 - 3
tinyusb/class/msc_device.c

@@ -101,9 +101,7 @@ tusb_error_t mscd_open(uint8_t coreid, tusb_descriptor_interface_t const * p_int
     endpoint_handle_t * p_edpt_hdl =  ( p_endpoint->bEndpointAddress &  TUSB_DIR_DEV_TO_HOST_MASK ) ?
         &p_msc->edpt_in : &p_msc->edpt_out;
 
-    (*p_edpt_hdl) = hal_dcd_pipe_open(coreid, p_endpoint);
-    ASSERT( endpointhandle_is_valid(*p_edpt_hdl), TUSB_ERROR_DCD_FAILED);
-
+    VERIFY( hal_dcd_pipe_open(coreid, p_endpoint, p_edpt_hdl), TUSB_ERROR_DCD_FAILED );
     p_endpoint = (tusb_descriptor_endpoint_t const *) descriptor_next( (uint8_t const*)  p_endpoint );
   }
 

+ 1 - 7
tinyusb/device/dcd.h

@@ -63,12 +63,6 @@ typedef struct {
   uint8_t index; // must be zero to indicate control
 } endpoint_handle_t;
 
-static inline bool endpointhandle_is_valid(endpoint_handle_t edpt_hdl)
-{
-  // Control does not use this to check
-  return edpt_hdl.index != 0;
-}
-
 static inline bool endpointhandle_is_equal(endpoint_handle_t x, endpoint_handle_t y)
 {
   return (x.coreid == y.coreid) && (x.index == y.index);
@@ -92,7 +86,7 @@ void hal_dcd_setup_received(uint8_t coreid, uint8_t const* p_request);
 bool hal_dcd_control_xfer(uint8_t coreid, tusb_direction_t dir, uint8_t * p_buffer, uint16_t length, bool int_on_complete);
 void hal_dcd_control_stall(uint8_t coreid);
 
-endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc);
+bool hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, endpoint_handle_t* eh);
 tusb_error_t dcd_pipe_queue_xfer(endpoint_handle_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes); // only queue, not transferring yet
 tusb_error_t dcd_pipe_xfer(endpoint_handle_t edpt_hdl, uint8_t * buffer, uint16_t total_bytes, bool int_on_complete);
 tusb_error_t dcd_pipe_stall(endpoint_handle_t edpt_hdl);