summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhathach <[email protected]>2018-12-12 12:01:15 +0700
committerhathach <[email protected]>2018-12-12 12:01:15 +0700
commit6c0b0917e15ca0acf7ce9bed0f3735a794abb807 (patch)
tree0fb72ad69c8c38b5bbee83f3a0e5b63295caed3f
parent6d86db3977aa60963d78d1bceaa7e3def60f1957 (diff)
rename descriptor_* helper to tu_desc_*
-rw-r--r--src/class/cdc/cdc_device.c18
-rw-r--r--src/class/cdc/cdc_host.c10
-rw-r--r--src/class/custom/custom_device.c2
-rw-r--r--src/class/custom/custom_host.c4
-rw-r--r--src/class/msc/msc_device.c10
-rw-r--r--src/class/msc/msc_host.c4
-rw-r--r--src/common/tusb_types.h13
-rw-r--r--src/device/usbd.c14
-rw-r--r--src/host/hub.c8
-rw-r--r--src/host/usbh.c14
10 files changed, 49 insertions, 48 deletions
diff --git a/src/class/cdc/cdc_device.c b/src/class/cdc/cdc_device.c
index d477a0d23..a865ba3c5 100644
--- a/src/class/cdc/cdc_device.c
+++ b/src/class/cdc/cdc_device.c
@@ -229,13 +229,13 @@ void cdcd_reset(uint8_t rhport)
}
}
-tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface_desc, uint16_t *p_length)
+tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_length)
{
- if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS;
+ if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != itf_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS;
// Only support AT commands, no protocol and vendor specific commands.
- if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, p_interface_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) ||
- p_interface_desc->bInterfaceProtocol == 0xff ) )
+ if ( !(tu_within(CDC_COMM_PROTOCOL_NONE, itf_desc->bInterfaceProtocol, CDC_COMM_PROTOCOL_ATCOMMAND_CDMA) ||
+ itf_desc->bInterfaceProtocol == 0xff ) )
{
return TUSB_ERROR_CDC_UNSUPPORTED_PROTOCOL;
}
@@ -252,16 +252,16 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface
}
//------------- Control Interface -------------//
- p_cdc->itf_num = p_interface_desc->bInterfaceNumber;
+ p_cdc->itf_num = itf_desc->bInterfaceNumber;
- uint8_t const * p_desc = descriptor_next ( (uint8_t const *) p_interface_desc );
+ uint8_t const * p_desc = tu_desc_next( itf_desc );
(*p_length) = sizeof(tusb_desc_interface_t);
// Communication Functional Descriptors
while( TUSB_DESC_CLASS_SPECIFIC == p_desc[DESC_OFFSET_TYPE] )
{
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
@@ -271,7 +271,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface
p_cdc->ep_notif = ((tusb_desc_endpoint_t const *) p_desc)->bEndpointAddress;
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
//------------- Data Interface (if any) -------------//
@@ -280,7 +280,7 @@ tusb_error_t cdcd_open(uint8_t rhport, tusb_desc_interface_t const * p_interface
{
// next to endpoint descritpor
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
// Open endpoint pair with usbd helper
tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) p_desc;
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index d660cc39f..d6767d0a7 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -146,7 +146,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
uint8_t const * p_desc;
cdch_data_t * p_cdc;
- p_desc = descriptor_next ( (uint8_t const *) itf_desc );
+ p_desc = tu_desc_next(itf_desc);
p_cdc = &cdch_data[dev_addr-1];
p_cdc->itf_num = itf_desc->bInterfaceNumber;
@@ -165,7 +165,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
}
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
if ( TUSB_DESC_ENDPOINT == p_desc[DESC_OFFSET_TYPE])
@@ -177,7 +177,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
p_cdc->ep_notif = ep_desc->bEndpointAddress;
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
//------------- Data Interface (if any) -------------//
@@ -185,7 +185,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
(TUSB_CLASS_CDC_DATA == ((tusb_desc_interface_t const *) p_desc)->bInterfaceClass) )
{
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
// data endpoints expected to be in pairs
for(uint32_t i=0; i<2; i++)
@@ -205,7 +205,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
}
(*p_length) += p_desc[DESC_OFFSET_LEN];
- p_desc = descriptor_next( p_desc );
+ p_desc = tu_desc_next( p_desc );
}
}
diff --git a/src/class/custom/custom_device.c b/src/class/custom/custom_device.c
index 5abffacf6..bec6f42d1 100644
--- a/src/class/custom/custom_device.c
+++ b/src/class/custom/custom_device.c
@@ -76,7 +76,7 @@ tusb_error_t cusd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf,
cusd_interface_t* p_itf = &_cusd_itf;
// Open endpoint pair with usbd helper
- tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf );
+ tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( (uint8_t const*) p_desc_itf );
TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_itf->ep_out, &p_itf->ep_in) );
p_itf->itf_num = p_desc_itf->bInterfaceNumber;
diff --git a/src/class/custom/custom_host.c b/src/class/custom/custom_host.c
index e840a2829..894e641e8 100644
--- a/src/class/custom/custom_host.c
+++ b/src/class/custom/custom_host.c
@@ -111,7 +111,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
{
// FIXME quick hack to test lpc1k custom class with 2 bulk endpoints
uint8_t const *p_desc = (uint8_t const *) p_interface_desc;
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
//------------- Bulk Endpoints Descriptor -------------//
for(uint32_t i=0; i<2; i++)
@@ -124,7 +124,7 @@ tusb_error_t cush_open_subtask(uint8_t dev_addr, tusb_desc_interface_t const *p_
*p_pipe_hdl = hcd_edpt_open(dev_addr, p_endpoint, TUSB_CLASS_VENDOR_SPECIFIC);
TU_ASSERT ( pipehandle_is_valid(*p_pipe_hdl), TUSB_ERROR_HCD_OPEN_PIPE_FAILED );
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
(*p_length) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
diff --git a/src/class/msc/msc_device.c b/src/class/msc/msc_device.c
index 83c9990d8..48f23688d 100644
--- a/src/class/msc/msc_device.c
+++ b/src/class/msc/msc_device.c
@@ -150,19 +150,19 @@ void mscd_reset(uint8_t rhport)
tu_memclr(&_mscd_itf, sizeof(mscd_interface_t));
}
-tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * p_desc_itf, uint16_t *p_len)
+tusb_error_t mscd_open(uint8_t rhport, tusb_desc_interface_t const * itf_desc, uint16_t *p_len)
{
// only support SCSI's BOT protocol
- TU_VERIFY( ( MSC_SUBCLASS_SCSI == p_desc_itf->bInterfaceSubClass &&
- MSC_PROTOCOL_BOT == p_desc_itf->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL );
+ TU_VERIFY( ( MSC_SUBCLASS_SCSI == itf_desc->bInterfaceSubClass &&
+ MSC_PROTOCOL_BOT == itf_desc->bInterfaceProtocol ), TUSB_ERROR_MSC_UNSUPPORTED_PROTOCOL );
mscd_interface_t * p_msc = &_mscd_itf;
// Open endpoint pair with usbd helper
- tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_desc_itf );
+ tusb_desc_endpoint_t const *p_desc_ep = (tusb_desc_endpoint_t const *) tu_desc_next( itf_desc );
TU_ASSERT_ERR( usbd_open_edpt_pair(rhport, p_desc_ep, TUSB_XFER_BULK, &p_msc->ep_out, &p_msc->ep_in) );
- p_msc->itf_num = p_desc_itf->bInterfaceNumber;
+ p_msc->itf_num = itf_desc->bInterfaceNumber;
(*p_len) = sizeof(tusb_desc_interface_t) + 2*sizeof(tusb_desc_endpoint_t);
//------------- Queue Endpoint OUT for Command Block Wrapper -------------//
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c
index dd771440d..86669b279 100644
--- a/src/class/msc/msc_host.c
+++ b/src/class/msc/msc_host.c
@@ -300,7 +300,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
msch_interface_t* p_msc = &msch_data[dev_addr-1];
//------------- Open Data Pipe -------------//
- tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) itf_desc );
+ tusb_desc_endpoint_t const * ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
for(uint32_t i=0; i<2; i++)
{
@@ -317,7 +317,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
p_msc->ep_out = ep_desc->bEndpointAddress;
}
- ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc );
+ ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
}
p_msc->itf_numr = itf_desc->bInterfaceNumber;
diff --git a/src/common/tusb_types.h b/src/common/tusb_types.h
index cbddd4156..cf02952ab 100644
--- a/src/common/tusb_types.h
+++ b/src/common/tusb_types.h
@@ -395,19 +395,20 @@ static inline uint8_t tu_edpt_addr(uint8_t num, uint8_t dir)
//--------------------------------------------------------------------+
// Descriptor helper
//--------------------------------------------------------------------+
-static inline uint8_t const * descriptor_next(uint8_t const p_desc[])
+static inline uint8_t const * tu_desc_next(void const* desc)
{
- return p_desc + p_desc[DESC_OFFSET_LEN];
+ uint8_t const* desc8 = (uint8_t const*) desc;
+ return desc8 + desc8[DESC_OFFSET_LEN];
}
-static inline uint8_t descriptor_type(uint8_t const p_desc[])
+static inline uint8_t tu_desc_type(void const* desc)
{
- return p_desc[DESC_OFFSET_TYPE];
+ return ((uint8_t const*) desc)[DESC_OFFSET_TYPE];
}
-static inline uint8_t descriptor_len(uint8_t const p_desc[])
+static inline uint8_t tu_desc_len(void const* desc)
{
- return p_desc[DESC_OFFSET_LEN];
+ return ((uint8_t const*) desc)[DESC_OFFSET_LEN];
}
// Length of the string descriptors in bytes with slen characters
diff --git a/src/device/usbd.c b/src/device/usbd.c
index b63dcb131..096437747 100644
--- a/src/device/usbd.c
+++ b/src/device/usbd.c
@@ -436,12 +436,12 @@ static bool process_set_config(uint8_t rhport)
while( p_desc < desc_cfg + cfg_len )
{
// Each interface always starts with Interface or Association descriptor
- if ( TUSB_DESC_INTERFACE_ASSOCIATION == descriptor_type(p_desc) )
+ if ( TUSB_DESC_INTERFACE_ASSOCIATION == tu_desc_type(p_desc) )
{
- p_desc = descriptor_next(p_desc); // ignore Interface Association
+ p_desc = tu_desc_next(p_desc); // ignore Interface Association
}else
{
- TU_ASSERT( TUSB_DESC_INTERFACE == descriptor_type(p_desc) );
+ TU_ASSERT( TUSB_DESC_INTERFACE == tu_desc_type(p_desc) );
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc;
@@ -480,15 +480,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc,
while( len < desc_len )
{
- if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) )
+ if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
{
uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
ep2drv[tu_edpt_number(ep_addr)][tu_edpt_dir(ep_addr)] = driver_id;
}
- len += descriptor_len(p_desc);
- p_desc = descriptor_next(p_desc);
+ len += tu_desc_len(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
}
@@ -641,7 +641,7 @@ tusb_error_t usbd_open_edpt_pair(uint8_t rhport, tusb_desc_endpoint_t const* ep_
(*ep_out) = ep_desc->bEndpointAddress;
}
- ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) ep_desc );
+ ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(ep_desc);
}
return TUSB_ERROR_NONE;
diff --git a/src/host/hub.c b/src/host/hub.c
index e2e91d73d..e9f9dc7de 100644
--- a/src/host/hub.c
+++ b/src/host/hub.c
@@ -156,21 +156,21 @@ void hub_init(void)
// hub_enum_sem_hdl = osal_semaphore_create( OSAL_SEM_REF(hub_enum_semaphore) );
}
-bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *p_interface_desc, uint16_t *p_length)
+bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t *p_length)
{
// not support multiple TT yet
- if ( p_interface_desc->bInterfaceProtocol > 1 ) return false;
+ if ( itf_desc->bInterfaceProtocol > 1 ) return false;
//------------- Open Interrupt Status Pipe -------------//
tusb_desc_endpoint_t const *ep_desc;
- ep_desc = (tusb_desc_endpoint_t const *) descriptor_next( (uint8_t const*) p_interface_desc );
+ ep_desc = (tusb_desc_endpoint_t const *) tu_desc_next(itf_desc);
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType);
TU_ASSERT(TUSB_XFER_INTERRUPT == ep_desc->bmAttributes.xfer);
TU_ASSERT(hcd_edpt_open(rhport, dev_addr, ep_desc));
- hub_data[dev_addr-1].itf_num = p_interface_desc->bInterfaceNumber;
+ hub_data[dev_addr-1].itf_num = itf_desc->bInterfaceNumber;
hub_data[dev_addr-1].ep_status = ep_desc->bEndpointAddress;
(*p_length) = sizeof(tusb_desc_interface_t) + sizeof(tusb_desc_endpoint_t);
diff --git a/src/host/usbh.c b/src/host/usbh.c
index 369ddd2a5..bbe60362a 100644
--- a/src/host/usbh.c
+++ b/src/host/usbh.c
@@ -560,9 +560,9 @@ bool enum_task(hcd_event_t* event)
while( p_desc < _usbh_ctrl_buf + ((tusb_desc_configuration_t*)_usbh_ctrl_buf)->wTotalLength )
{
// skip until we see interface descriptor
- if ( TUSB_DESC_INTERFACE != descriptor_type(p_desc) )
+ if ( TUSB_DESC_INTERFACE != tu_desc_type(p_desc) )
{
- p_desc = descriptor_next(p_desc); // skip the descriptor, increase by the descriptor's length
+ p_desc = tu_desc_next(p_desc); // skip the descriptor, increase by the descriptor's length
}else
{
tusb_desc_interface_t* desc_itf = (tusb_desc_interface_t*) p_desc;
@@ -577,7 +577,7 @@ bool enum_task(hcd_event_t* event)
if( drv_id >= USBH_CLASS_DRIVER_COUNT )
{
// skip unsupported class
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
else
{
@@ -589,7 +589,7 @@ bool enum_task(hcd_event_t* event)
{
// TODO Attach hub to Hub is not currently supported
// skip this interface
- p_desc = descriptor_next(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
else
{
@@ -685,15 +685,15 @@ static void mark_interface_endpoint(uint8_t ep2drv[8][2], uint8_t const* p_desc,
while( len < desc_len )
{
- if ( TUSB_DESC_ENDPOINT == descriptor_type(p_desc) )
+ if ( TUSB_DESC_ENDPOINT == tu_desc_type(p_desc) )
{
uint8_t const ep_addr = ((tusb_desc_endpoint_t const*) p_desc)->bEndpointAddress;
ep2drv[ tu_edpt_number(ep_addr) ][ tu_edpt_dir(ep_addr) ] = driver_id;
}
- len += descriptor_len(p_desc);
- p_desc = descriptor_next(p_desc);
+ len += tu_desc_len(p_desc);
+ p_desc = tu_desc_next(p_desc);
}
}