summaryrefslogtreecommitdiff
path: root/tinyusb
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-03-06 16:50:50 +0700
committerhathach <[email protected]>2018-03-06 16:50:50 +0700
commitc5cb58b2bb229e88747786d4c61cc145322bff8b (patch)
treed2b7d78d375105371400f5cafec1714cff9398de /tinyusb
parent85511e288d04d7ab9921e58b58f1628b4d18833c (diff)
remove class code in pipe open()
Diffstat (limited to 'tinyusb')
-rw-r--r--tinyusb/class/cdc_device.c4
-rw-r--r--tinyusb/class/hid_device.c2
-rw-r--r--tinyusb/class/msc_device.c4
-rw-r--r--tinyusb/device/dcd.h13
-rw-r--r--tinyusb/device/dcd_lpc175x_6x.c2
-rw-r--r--tinyusb/device/dcd_lpc_11uxx_13uxx.c2
-rw-r--r--tinyusb/device/usbd.c14
7 files changed, 21 insertions, 20 deletions
diff --git a/tinyusb/class/cdc_device.c b/tinyusb/class/cdc_device.c
index b938b6c55..84027b5a6 100644
--- a/tinyusb/class/cdc_device.c
+++ b/tinyusb/class/cdc_device.c
@@ -135,7 +135,7 @@ 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] = dcd_pipe_open(coreid, (tusb_descriptor_endpoint_t const *) p_desc, TUSB_CLASS_CDC);
+ p_cdc->edpt_hdl[CDC_PIPE_NOTIFICATION] = hal_dcd_pipe_open(coreid, (tusb_descriptor_endpoint_t const *) p_desc);
(*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH];
p_desc = descriptor_next(p_desc);
@@ -160,7 +160,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) = dcd_pipe_open(coreid, p_endpoint, TUSB_CLASS_CDC);
+ (*p_edpt_hdl) = hal_dcd_pipe_open(coreid, p_endpoint);
ASSERT ( endpointhandle_is_valid(*p_edpt_hdl), TUSB_ERROR_DCD_OPEN_PIPE_FAILED );
(*p_length) += p_desc[DESCRIPTOR_OFFSET_LENGTH];
diff --git a/tinyusb/class/hid_device.c b/tinyusb/class/hid_device.c
index 43f1546af..83c064115 100644
--- a/tinyusb/class/hid_device.c
+++ b/tinyusb/class/hid_device.c
@@ -280,7 +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 = dcd_pipe_open(coreid, p_desc_endpoint, p_interface_desc->bInterfaceClass);
+ p_hid->ept_handle = hal_dcd_pipe_open(coreid, p_desc_endpoint);
ASSERT( endpointhandle_is_valid(p_hid->ept_handle), TUSB_ERROR_DCD_FAILED);
p_hid->interface_number = p_interface_desc->bInterfaceNumber;
diff --git a/tinyusb/class/msc_device.c b/tinyusb/class/msc_device.c
index 5ac927fa1..d3ac68e83 100644
--- a/tinyusb/class/msc_device.c
+++ b/tinyusb/class/msc_device.c
@@ -101,7 +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) = dcd_pipe_open(coreid, p_endpoint, p_interface_desc->bInterfaceClass);
+ (*p_edpt_hdl) = hal_dcd_pipe_open(coreid, p_endpoint);
ASSERT( endpointhandle_is_valid(*p_edpt_hdl), TUSB_ERROR_DCD_FAILED);
p_endpoint = (tusb_descriptor_endpoint_t const *) descriptor_next( (uint8_t const*) p_endpoint );
@@ -152,6 +152,8 @@ tusb_error_t mscd_xfer_cb(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32
msc_cmd_block_wrapper_t * const p_cbw = &p_msc->cbw;
msc_cmd_status_wrapper_t * const p_csw = &p_msc->csw;
+ VERIFY(endpointhandle_is_equal(edpt_hdl, p_msc->edpt_out) || endpointhandle_is_equal(edpt_hdl, p_msc->edpt_in), TUSB_ERROR_INVALID_PARA);
+
//------------- new CBW received -------------//
if ( !is_waiting_read10_write10 )
{
diff --git a/tinyusb/device/dcd.h b/tinyusb/device/dcd.h
index 2fa8f1b86..d9b339740 100644
--- a/tinyusb/device/dcd.h
+++ b/tinyusb/device/dcd.h
@@ -60,21 +60,18 @@ typedef enum
// TODO move Hal
typedef struct {
uint8_t coreid;
- uint8_t reserved; // TODO redundant, cannot be control as control uses separated API
- uint8_t index;
- uint8_t class_code;
+ uint8_t index; // must be zero to indicate control
} endpoint_handle_t;
-static inline bool endpointhandle_is_valid(endpoint_handle_t edpt_hdl) ATTR_CONST ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool endpointhandle_is_valid(endpoint_handle_t edpt_hdl)
{
- return (edpt_hdl.class_code != 0);
+ // 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) ATTR_CONST ATTR_ALWAYS_INLINE ATTR_WARN_UNUSED_RESULT;
static inline bool endpointhandle_is_equal(endpoint_handle_t x, endpoint_handle_t y)
{
- return (x.coreid == y.coreid) && (x.index == y.index) && (x.class_code == y.class_code);
+ return (x.coreid == y.coreid) && (x.index == y.index);
}
@@ -95,7 +92,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 dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code);
+endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc);
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);
diff --git a/tinyusb/device/dcd_lpc175x_6x.c b/tinyusb/device/dcd_lpc175x_6x.c
index dbd25106e..ac2e40172 100644
--- a/tinyusb/device/dcd_lpc175x_6x.c
+++ b/tinyusb/device/dcd_lpc175x_6x.c
@@ -412,7 +412,7 @@ bool hal_dcd_control_xfer(uint8_t coreid, tusb_direction_t dir, uint8_t * p_buff
//--------------------------------------------------------------------+
// BULK/INTERRUPT/ISO PIPE API
//--------------------------------------------------------------------+
-endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code)
+endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code)
{
(void) coreid;
diff --git a/tinyusb/device/dcd_lpc_11uxx_13uxx.c b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
index 66fabec2c..b0e73ac98 100644
--- a/tinyusb/device/dcd_lpc_11uxx_13uxx.c
+++ b/tinyusb/device/dcd_lpc_11uxx_13uxx.c
@@ -460,7 +460,7 @@ tusb_error_t dcd_pipe_clear_stall(uint8_t coreid, uint8_t edpt_addr)
return TUSB_ERROR_NONE;
}
-endpoint_handle_t dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code)
+endpoint_handle_t hal_dcd_pipe_open(uint8_t coreid, tusb_descriptor_endpoint_t const * p_endpoint_desc, uint8_t class_code)
{
(void) coreid;
endpoint_handle_t const null_handle = { 0 };
diff --git a/tinyusb/device/usbd.c b/tinyusb/device/usbd.c
index 4428948fe..3a3bb6220 100644
--- a/tinyusb/device/usbd.c
+++ b/tinyusb/device/usbd.c
@@ -221,11 +221,11 @@ static tusb_error_t usbd_body_subtask(void)
OSAL_SUBTASK_INVOKED_AND_WAIT( usbd_control_request_subtask(event.coreid, &event.setup_received), error );
}else if (USBD_EVENTID_XFER_DONE == event.event_id)
{
- uint8_t class_index;
- class_index = std_class_code_to_index( event.xfer_done.edpt_hdl.class_code );
-
- SUBTASK_ASSERT(usbd_class_drivers[class_index].xfer_cb != NULL);
- usbd_class_drivers[class_index].xfer_cb( event.xfer_done.edpt_hdl, (tusb_event_t) event.sub_event_id, event.xfer_done.xferred_byte);
+ // Call class handling function, Class that endpoint not belong to should check and return
+ for (uint8_t class_code = TUSB_CLASS_AUDIO; class_code < USBD_CLASS_DRIVER_COUNT; class_code++)
+ {
+ if ( usbd_class_drivers[class_code].xfer_cb ) usbd_class_drivers[class_code].xfer_cb( event.xfer_done.edpt_hdl, (tusb_event_t) event.sub_event_id, event.xfer_done.xferred_byte);
+ }
}else
{
SUBTASK_ASSERT(false);
@@ -445,8 +445,10 @@ void hal_dcd_setup_received(uint8_t coreid, uint8_t const* p_request)
void usbd_xfer_isr(endpoint_handle_t edpt_hdl, tusb_event_t event, uint32_t xferred_bytes)
{
- if (edpt_hdl.class_code == 0 ) // Control Transfer
+// if (edpt_hdl.class_code == 0 )
+ if (edpt_hdl.index == 0 )
{
+ // Control Transfer
osal_semaphore_post( usbd_control_xfer_sem_hdl );
}else
{