Skip to content

Commit

Permalink
Merge pull request #1403 from hathach/host-edpt-xfer
Browse files Browse the repository at this point in the history
Host edpt xfer
  • Loading branch information
hathach authored Mar 19, 2022
2 parents 1915d69 + a270d8d commit ae531a7
Show file tree
Hide file tree
Showing 15 changed files with 1,340 additions and 917 deletions.
360 changes: 286 additions & 74 deletions examples/host/bare_api/src/main.c

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions examples/host/bare_api/src/tusb_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,11 @@
// 1 hub typically has 4 ports
#define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1)

#define CFG_TUH_ENDPOINT_MAX 8
// Max endpoint per device
#define CFG_TUH_ENDPOINT_MAX 8

//------------- HID -------------//

#define CFG_TUH_HID_EP_BUFSIZE 64
// Enable tuh_edpt_xfer() API
#define CFG_TUH_API_EDPT_XFER 1

#ifdef __cplusplus
}
Expand Down
38 changes: 21 additions & 17 deletions src/class/cdc/cdc_host.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,32 +120,35 @@ bool tuh_cdc_receive(uint8_t dev_addr, void * p_buffer, uint32_t length, bool is
return usbh_edpt_xfer(dev_addr, ep_in, p_buffer, length);
}

bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_xfer_cb_t complete_cb)
bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_xfer_cb_t complete_cb)
{
cdch_data_t const * p_cdc = get_itf(dev_addr);

tuh_control_xfer_t const xfer =
tusb_control_request_t const request =
{
.request =
.bmRequestType_bit =
{
.bmRequestType_bit =
{
.recipient = TUSB_REQ_RCPT_INTERFACE,
.type = TUSB_REQ_TYPE_CLASS,
.direction = TUSB_DIR_OUT
},
.bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE,
.wValue = (rts ? 2 : 0) | (dtr ? 1 : 0),
.wIndex = p_cdc->itf_num,
.wLength = 0
.recipient = TUSB_REQ_RCPT_INTERFACE,
.type = TUSB_REQ_TYPE_CLASS,
.direction = TUSB_DIR_OUT
},
.bRequest = CDC_REQUEST_SET_CONTROL_LINE_STATE,
.wValue = (rts ? 2 : 0) | (dtr ? 1 : 0),
.wIndex = p_cdc->itf_num,
.wLength = 0
};

tuh_xfer_t xfer =
{
.daddr = dev_addr,
.ep_addr = 0,
.setup = &request,
.buffer = NULL,
.complete_cb = complete_cb,
.user_arg = 0
.user_data = 0
};

return tuh_control_xfer(dev_addr, &xfer);
return tuh_control_xfer(&xfer);
}

//--------------------------------------------------------------------+
Expand All @@ -158,6 +161,7 @@ void cdch_init(void)

bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
(void) rhport;
(void) max_len;

// Only support ACM subclass
Expand Down Expand Up @@ -193,7 +197,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
// notification endpoint
tusb_desc_endpoint_t const * desc_ep = (tusb_desc_endpoint_t const *) p_desc;

TU_ASSERT( usbh_edpt_open(rhport, dev_addr, desc_ep) );
TU_ASSERT( tuh_edpt_open(dev_addr, desc_ep) );
p_cdc->ep_notif = desc_ep->bEndpointAddress;

drv_len += tu_desc_len(p_desc);
Expand All @@ -214,7 +218,7 @@ bool cdch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *it
tusb_desc_endpoint_t const *desc_ep = (tusb_desc_endpoint_t const *) p_desc;
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType && TUSB_XFER_BULK == desc_ep->bmAttributes.xfer);

TU_ASSERT(usbh_edpt_open(rhport, dev_addr, desc_ep));
TU_ASSERT(tuh_edpt_open(dev_addr, desc_ep));

if ( tu_edpt_dir(desc_ep->bEndpointAddress) == TUSB_DIR_IN )
{
Expand Down
6 changes: 3 additions & 3 deletions src/class/cdc/cdc_host.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@
* \defgroup CDC_Serial_Host Host
* @{ */

bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_control_xfer_cb_t complete_cb);
bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_xfer_cb_t complete_cb);

static inline bool tuh_cdc_connect(uint8_t dev_addr, tuh_control_xfer_cb_t complete_cb)
static inline bool tuh_cdc_connect(uint8_t dev_addr, tuh_xfer_cb_t complete_cb)
{
return tuh_cdc_set_control_line_state(dev_addr, true, true, complete_cb);
}

static inline bool tuh_cdc_disconnect(uint8_t dev_addr, tuh_control_xfer_cb_t complete_cb)
static inline bool tuh_cdc_disconnect(uint8_t dev_addr, tuh_xfer_cb_t complete_cb)
{
return tuh_cdc_set_control_line_state(dev_addr, false, false, complete_cb);
}
Expand Down
2 changes: 1 addition & 1 deletion src/class/hid/hid.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
/** \defgroup ClassDriver_HID_Common Common Definitions
* @{ */

/// USB HID Descriptor
/// USB HID Descriptor
typedef struct TU_ATTR_PACKED
{
uint8_t bLength; /**< Numeric expression that is the total size of the HID descriptor */
Expand Down
Loading

0 comments on commit ae531a7

Please sign in to comment.