rename port to rhport for clarification
This commit is contained in:
@@ -63,7 +63,7 @@ typedef struct {
|
||||
uint8_t ep_out;
|
||||
}cdcd_data_t;
|
||||
|
||||
// TODO multiple port
|
||||
// TODO multiple rhport
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) uint8_t _tmp_rx_buf[64];
|
||||
TUSB_CFG_ATTR_USBRAM ATTR_ALIGNED(4) uint8_t _tmp_tx_buf[64];
|
||||
|
||||
@@ -80,33 +80,33 @@ STATIC_VAR cdcd_data_t cdcd_data[CONTROLLER_DEVICE_NUMBER];
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_n_cdc_connected(uint8_t port)
|
||||
bool tud_n_cdc_connected(uint8_t rhport)
|
||||
{
|
||||
return cdcd_data[port].connected;
|
||||
return cdcd_data[rhport].connected;
|
||||
}
|
||||
|
||||
uint32_t tud_n_cdc_available(uint8_t port)
|
||||
uint32_t tud_n_cdc_available(uint8_t rhport)
|
||||
{
|
||||
return fifo_count(&_rx_ff);
|
||||
}
|
||||
|
||||
int tud_n_cdc_read_char(uint8_t port)
|
||||
int tud_n_cdc_read_char(uint8_t rhport)
|
||||
{
|
||||
uint8_t ch;
|
||||
return fifo_read(&_rx_ff, &ch) ? ch : (-1);
|
||||
}
|
||||
|
||||
uint32_t tud_n_cdc_read(uint8_t port, void* buffer, uint32_t bufsize)
|
||||
uint32_t tud_n_cdc_read(uint8_t rhport, void* buffer, uint32_t bufsize)
|
||||
{
|
||||
return fifo_read_n(&_rx_ff, buffer, bufsize);
|
||||
}
|
||||
|
||||
uint32_t tud_n_cdc_write_char(uint8_t port, char ch)
|
||||
uint32_t tud_n_cdc_write_char(uint8_t rhport, char ch)
|
||||
{
|
||||
return fifo_write(&_tx_ff, &ch);
|
||||
}
|
||||
|
||||
uint32_t tud_n_cdc_write(uint8_t port, void const* buffer, uint32_t bufsize)
|
||||
uint32_t tud_n_cdc_write(uint8_t rhport, void const* buffer, uint32_t bufsize)
|
||||
{
|
||||
return fifo_write_n(&_tx_ff, buffer, bufsize);
|
||||
}
|
||||
@@ -130,7 +130,7 @@ void cdcd_init(void)
|
||||
}
|
||||
}
|
||||
|
||||
tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
tusb_error_t cdcd_open(uint8_t rhport, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length)
|
||||
{
|
||||
if ( CDC_COMM_SUBCLASS_ABSTRACT_CONTROL_MODEL != p_interface_desc->bInterfaceSubClass) return TUSB_ERROR_CDC_UNSUPPORTED_SUBCLASS;
|
||||
|
||||
@@ -141,7 +141,7 @@ tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
|
||||
}
|
||||
|
||||
uint8_t const * p_desc = descriptor_next ( (uint8_t const *) p_interface_desc );
|
||||
cdcd_data_t * p_cdc = &cdcd_data[port];
|
||||
cdcd_data_t * p_cdc = &cdcd_data[rhport];
|
||||
|
||||
//------------- Communication Interface -------------//
|
||||
(*p_length) = sizeof(tusb_descriptor_interface_t);
|
||||
@@ -159,7 +159,7 @@ tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
|
||||
|
||||
if ( TUSB_DESC_ENDPOINT == p_desc[DESCRIPTOR_OFFSET_TYPE])
|
||||
{ // notification endpoint if any
|
||||
TU_ASSERT( tusb_dcd_edpt_open(port, (tusb_descriptor_endpoint_t const *) p_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
|
||||
TU_ASSERT( tusb_dcd_edpt_open(rhport, (tusb_descriptor_endpoint_t const *) p_desc), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
|
||||
|
||||
p_cdc->ep_notif = ((tusb_descriptor_endpoint_t const *) p_desc)->bEndpointAddress;
|
||||
|
||||
@@ -181,7 +181,7 @@ tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
|
||||
TU_ASSERT(TUSB_DESC_ENDPOINT == p_endpoint->bDescriptorType, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
TU_ASSERT(TUSB_XFER_BULK == p_endpoint->bmAttributes.xfer, TUSB_ERROR_DESCRIPTOR_CORRUPTED);
|
||||
|
||||
TU_ASSERT( tusb_dcd_edpt_open(port, p_endpoint), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
|
||||
TU_ASSERT( tusb_dcd_edpt_open(rhport, p_endpoint), TUSB_ERROR_DCD_OPEN_PIPE_FAILED);
|
||||
|
||||
if ( p_endpoint->bEndpointAddress & TUSB_DIR_IN_MASK )
|
||||
{
|
||||
@@ -199,22 +199,22 @@ tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_inter
|
||||
p_cdc->interface_number = p_interface_desc->bInterfaceNumber;
|
||||
|
||||
// Prepare for incoming data
|
||||
TU_ASSERT( tusb_dcd_edpt_xfer(port, p_cdc->ep_out, _tmp_rx_buf, sizeof(_tmp_rx_buf)), TUSB_ERROR_DCD_EDPT_XFER);
|
||||
TU_ASSERT( tusb_dcd_edpt_xfer(rhport, p_cdc->ep_out, _tmp_rx_buf, sizeof(_tmp_rx_buf)), TUSB_ERROR_DCD_EDPT_XFER);
|
||||
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
void cdcd_close(uint8_t port)
|
||||
void cdcd_close(uint8_t rhport)
|
||||
{
|
||||
// no need to close opened pipe, dcd bus reset will put controller's endpoints to default state
|
||||
memclr_(&cdcd_data[port], sizeof(cdcd_data_t));
|
||||
memclr_(&cdcd_data[rhport], sizeof(cdcd_data_t));
|
||||
|
||||
fifo_clear(&_rx_ff);
|
||||
fifo_clear(&_tx_ff);
|
||||
}
|
||||
|
||||
tusb_error_t cdcd_control_request_st(uint8_t port, tusb_control_request_t const * p_request)
|
||||
tusb_error_t cdcd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request)
|
||||
{
|
||||
OSAL_SUBTASK_BEGIN
|
||||
|
||||
@@ -225,13 +225,13 @@ tusb_error_t cdcd_control_request_st(uint8_t port, tusb_control_request_t const
|
||||
|
||||
if (CDC_REQUEST_GET_LINE_CODING == p_request->bRequest)
|
||||
{
|
||||
STASK_INVOKE( usbd_control_xfer_st(port, (tusb_dir_t) p_request->bmRequestType_bit.direction,
|
||||
(uint8_t*) &cdcd_line_coding[port], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
|
||||
STASK_INVOKE( usbd_control_xfer_st(rhport, (tusb_dir_t) p_request->bmRequestType_bit.direction,
|
||||
(uint8_t*) &cdcd_line_coding[rhport], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
|
||||
}
|
||||
else if (CDC_REQUEST_SET_LINE_CODING == p_request->bRequest)
|
||||
{
|
||||
STASK_INVOKE( usbd_control_xfer_st(port, (tusb_dir_t) p_request->bmRequestType_bit.direction,
|
||||
(uint8_t*) &cdcd_line_coding[port], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
|
||||
STASK_INVOKE( usbd_control_xfer_st(rhport, (tusb_dir_t) p_request->bmRequestType_bit.direction,
|
||||
(uint8_t*) &cdcd_line_coding[rhport], min16_of(sizeof(cdc_line_coding_t), p_request->wLength)), err );
|
||||
// TODO notify application on xfer complete
|
||||
}
|
||||
else if (CDC_REQUEST_SET_CONTROL_LINE_STATE == p_request->bRequest )
|
||||
@@ -241,7 +241,7 @@ tusb_error_t cdcd_control_request_st(uint8_t port, tusb_control_request_t const
|
||||
ACTIVE_DTE_NOT_PRESENT = 0x0002
|
||||
};
|
||||
|
||||
cdcd_data_t * p_cdc = &cdcd_data[port];
|
||||
cdcd_data_t * p_cdc = &cdcd_data[rhport];
|
||||
|
||||
if (p_request->wValue == ACTIVE_DTE_PRESENT)
|
||||
{
|
||||
@@ -258,51 +258,51 @@ tusb_error_t cdcd_control_request_st(uint8_t port, tusb_control_request_t const
|
||||
p_cdc->connected = false;
|
||||
}
|
||||
|
||||
usbd_control_status(port, p_request->bmRequestType_bit.direction);
|
||||
usbd_control_status(rhport, p_request->bmRequestType_bit.direction);
|
||||
}
|
||||
else
|
||||
{
|
||||
usbd_control_stall(port); // stall unsupported request
|
||||
usbd_control_stall(rhport); // stall unsupported request
|
||||
}
|
||||
|
||||
OSAL_SUBTASK_END
|
||||
}
|
||||
|
||||
tusb_error_t cdcd_xfer_cb(uint8_t port, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes)
|
||||
tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t ep_addr, tusb_event_t event, uint32_t xferred_bytes)
|
||||
{
|
||||
cdcd_data_t const * p_cdc = &cdcd_data[port];
|
||||
cdcd_data_t const * p_cdc = &cdcd_data[rhport];
|
||||
|
||||
if ( ep_addr == p_cdc->ep_out )
|
||||
{
|
||||
fifo_write_n(&_rx_ff, _tmp_rx_buf, xferred_bytes);
|
||||
|
||||
// preparing for next
|
||||
TU_ASSERT(tusb_dcd_edpt_xfer(port, p_cdc->ep_out, _tmp_rx_buf, sizeof(_tmp_rx_buf)), TUSB_ERROR_DCD_EDPT_XFER);
|
||||
TU_ASSERT(tusb_dcd_edpt_xfer(rhport, p_cdc->ep_out, _tmp_rx_buf, sizeof(_tmp_rx_buf)), TUSB_ERROR_DCD_EDPT_XFER);
|
||||
|
||||
// fire callback
|
||||
tud_cdc_rx_cb(port);
|
||||
tud_cdc_rx_cb(rhport);
|
||||
}
|
||||
|
||||
return TUSB_ERROR_NONE;
|
||||
}
|
||||
|
||||
bool tud_n_cdc_flush (uint8_t port)
|
||||
bool tud_n_cdc_flush (uint8_t rhport)
|
||||
{
|
||||
VERIFY( tud_n_cdc_connected(port) );
|
||||
VERIFY( tud_n_cdc_connected(rhport) );
|
||||
|
||||
uint8_t edpt = cdcd_data[port].ep_in;
|
||||
uint8_t edpt = cdcd_data[rhport].ep_in;
|
||||
|
||||
VERIFY( !tusb_dcd_edpt_busy(port, edpt) );
|
||||
VERIFY( !tusb_dcd_edpt_busy(rhport, edpt) );
|
||||
|
||||
uint16_t count = fifo_read_n(&_tx_ff, _tmp_tx_buf, sizeof(_tmp_tx_buf));
|
||||
TU_ASSERT( tusb_dcd_edpt_xfer(port, edpt, _tmp_tx_buf, count) );
|
||||
TU_ASSERT( tusb_dcd_edpt_xfer(rhport, edpt, _tmp_tx_buf, count) );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void cdcd_sof(uint8_t port)
|
||||
void cdcd_sof(uint8_t rhport)
|
||||
{
|
||||
tud_n_cdc_flush(port);
|
||||
tud_n_cdc_flush(rhport);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -55,15 +55,15 @@
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API (Multiple Ports)
|
||||
//--------------------------------------------------------------------+
|
||||
bool tud_n_cdc_connected (uint8_t port);
|
||||
uint32_t tud_n_cdc_available (uint8_t port);
|
||||
bool tud_n_cdc_connected (uint8_t rhport);
|
||||
uint32_t tud_n_cdc_available (uint8_t rhport);
|
||||
|
||||
int tud_n_cdc_read_char (uint8_t port);
|
||||
uint32_t tud_n_cdc_read (uint8_t port, void* buffer, uint32_t bufsize);
|
||||
int tud_n_cdc_read_char (uint8_t rhport);
|
||||
uint32_t tud_n_cdc_read (uint8_t rhport, void* buffer, uint32_t bufsize);
|
||||
|
||||
uint32_t tud_n_cdc_write_char (uint8_t port, char ch);
|
||||
uint32_t tud_n_cdc_write (uint8_t port, void const* buffer, uint32_t bufsize);
|
||||
bool tud_n_cdc_flush (uint8_t port);
|
||||
uint32_t tud_n_cdc_write_char (uint8_t rhport, char ch);
|
||||
uint32_t tud_n_cdc_write (uint8_t rhport, void const* buffer, uint32_t bufsize);
|
||||
bool tud_n_cdc_flush (uint8_t rhport);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION API (Single Port)
|
||||
@@ -81,8 +81,8 @@ static inline bool tud_cdc_flush (void)
|
||||
//--------------------------------------------------------------------+
|
||||
// APPLICATION CALLBACK API
|
||||
//--------------------------------------------------------------------+
|
||||
//void tud_cdc_line_coding_changed_cb(uint8_t port, cdc_line_coding_t* p_line_coding);
|
||||
void tud_cdc_rx_cb(uint8_t port);
|
||||
//void tud_cdc_line_coding_changed_cb(uint8_t rhport, cdc_line_coding_t* p_line_coding);
|
||||
void tud_cdc_rx_cb(uint8_t rhport);
|
||||
|
||||
//--------------------------------------------------------------------+
|
||||
// USBD-CLASS DRIVER API
|
||||
@@ -90,12 +90,12 @@ void tud_cdc_rx_cb(uint8_t port);
|
||||
#ifdef _TINY_USB_SOURCE_FILE_
|
||||
|
||||
void cdcd_init(void);
|
||||
tusb_error_t cdcd_open(uint8_t port, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t cdcd_control_request_st(uint8_t port, tusb_control_request_t const * p_request);
|
||||
tusb_error_t cdcd_xfer_cb(uint8_t port, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void cdcd_close(uint8_t port);
|
||||
tusb_error_t cdcd_open(uint8_t rhport, tusb_descriptor_interface_t const * p_interface_desc, uint16_t *p_length);
|
||||
tusb_error_t cdcd_control_request_st(uint8_t rhport, tusb_control_request_t const * p_request);
|
||||
tusb_error_t cdcd_xfer_cb(uint8_t rhport, uint8_t edpt_addr, tusb_event_t event, uint32_t xferred_bytes);
|
||||
void cdcd_close(uint8_t rhport);
|
||||
|
||||
void cdcd_sof(uint8_t port);
|
||||
void cdcd_sof(uint8_t rhport);
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
Reference in New Issue
Block a user