summaryrefslogtreecommitdiff
path: root/src/class
diff options
context:
space:
mode:
authorHa Thach <[email protected]>2022-03-20 00:17:39 +0700
committerGitHub <[email protected]>2022-03-20 00:17:39 +0700
commitae531a79f654d566790a4daae350730cdc0a01e9 (patch)
treea67cd9c595a0038f7eecf6f4fcaadf4064a9ac9b /src/class
parent1915d69cb8da8372b35a5067420c57ddb65d2cb1 (diff)
parenta270d8d6236124244f5a1447d57b35f4cfa4909c (diff)
Merge pull request #1403 from hathach/host-edpt-xfer
Host edpt xfer
Diffstat (limited to 'src/class')
-rw-r--r--src/class/cdc/cdc_host.c38
-rw-r--r--src/class/cdc/cdc_host.h6
-rw-r--r--src/class/hid/hid.h2
-rw-r--r--src/class/hid/hid_host.c317
-rw-r--r--src/class/msc/msc_host.c51
5 files changed, 219 insertions, 195 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index 8ca3dfbcb..044085e81 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -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);
}
//--------------------------------------------------------------------+
@@ -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
@@ -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);
@@ -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 )
{
diff --git a/src/class/cdc/cdc_host.h b/src/class/cdc/cdc_host.h
index 67162a0ca..33dbd2efb 100644
--- a/src/class/cdc/cdc_host.h
+++ b/src/class/cdc/cdc_host.h
@@ -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);
}
diff --git a/src/class/hid/hid.h b/src/class/hid/hid.h
index 940454bd9..44a464be1 100644
--- a/src/class/hid/hid.h
+++ b/src/class/hid/hid.h
@@ -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 */
diff --git a/src/class/hid/hid_host.c b/src/class/hid/hid_host.c
index a825858ab..ce3d1598c 100644
--- a/src/class/hid/hid_host.c
+++ b/src/class/hid/hid_host.c
@@ -103,70 +103,80 @@ uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t instance)
return hid_itf->protocol_mode;
}
-static bool set_protocol_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
+static void set_protocol_complete(tuh_xfer_t* xfer)
{
- uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
+ uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
+ uint8_t const daddr = xfer->daddr;
+ uint8_t const instance = get_instance_id_by_itfnum(daddr, itf_num);
+ hidh_interface_t* hid_itf = get_instance(daddr, instance);
- if (XFER_RESULT_SUCCESS == result) hid_itf->protocol_mode = (uint8_t) xfer->request.wValue;
+ if (XFER_RESULT_SUCCESS == xfer->result)
+ {
+ hid_itf->protocol_mode = (uint8_t) tu_le16toh(xfer->setup->wValue);
+ }
if (tuh_hid_set_protocol_complete_cb)
{
- tuh_hid_set_protocol_complete_cb(dev_addr, instance, hid_itf->protocol_mode);
+ tuh_hid_set_protocol_complete_cb(daddr, instance, hid_itf->protocol_mode);
}
-
- return true;
}
-bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol)
-{
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
- TU_VERIFY(hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE);
+static bool _hidh_set_protocol(uint8_t dev_addr, uint8_t itf_num, uint8_t protocol, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
+{
TU_LOG2("HID Set Protocol = %d\r\n", protocol);
- 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 = HID_REQ_CONTROL_SET_PROTOCOL,
- .wValue = protocol,
- .wIndex = hid_itf->itf_num,
- .wLength = 0
+ .recipient = TUSB_REQ_RCPT_INTERFACE,
+ .type = TUSB_REQ_TYPE_CLASS,
+ .direction = TUSB_DIR_OUT
},
+ .bRequest = HID_REQ_CONTROL_SET_PROTOCOL,
+ .wValue = protocol,
+ .wIndex = itf_num,
+ .wLength = 0
+ };
+ tuh_xfer_t xfer =
+ {
+ .daddr = dev_addr,
+ .ep_addr = 0,
+ .setup = &request,
.buffer = NULL,
- .complete_cb = set_protocol_complete,
- .user_arg = 0
+ .complete_cb = complete_cb,
+ .user_data = user_data
};
- TU_ASSERT( tuh_control_xfer(dev_addr, &xfer) );
+ TU_ASSERT( tuh_control_xfer(&xfer) );
return true;
}
-static bool set_report_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
+bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol)
+{
+ hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
+ TU_VERIFY(hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE);
+
+ return _hidh_set_protocol(dev_addr, hid_itf->itf_num, protocol, set_protocol_complete, 0);
+}
+
+static void set_report_complete(tuh_xfer_t* xfer)
{
TU_LOG2("HID Set Report complete\r\n");
if (tuh_hid_set_report_complete_cb)
{
- uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
+ uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
+ uint8_t const instance = get_instance_id_by_itfnum(xfer->daddr, itf_num);
- uint8_t const report_type = tu_u16_high(xfer->request.wValue);
- uint8_t const report_id = tu_u16_low(xfer->request.wValue);
+ uint8_t const report_type = tu_u16_high(xfer->setup->wValue);
+ uint8_t const report_id = tu_u16_low(xfer->setup->wValue);
- tuh_hid_set_report_complete_cb(dev_addr, instance, report_id, report_type, (result == XFER_RESULT_SUCCESS) ? xfer->request.wLength : 0);
+ tuh_hid_set_report_complete_cb(xfer->daddr, instance, report_id, report_type,
+ (xfer->result == XFER_RESULT_SUCCESS) ? xfer->setup->wLength : 0);
}
-
- return true;
}
bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, uint8_t report_type, void* report, uint16_t len)
@@ -174,28 +184,64 @@ bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, u
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
TU_LOG2("HID Set Report: id = %u, type = %u, len = %u\r\n", report_id, report_type, len);
- 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 = HID_REQ_CONTROL_SET_REPORT,
- .wValue = tu_u16(report_type, report_id),
- .wIndex = hid_itf->itf_num,
- .wLength = len
+ .recipient = TUSB_REQ_RCPT_INTERFACE,
+ .type = TUSB_REQ_TYPE_CLASS,
+ .direction = TUSB_DIR_OUT
},
+ .bRequest = HID_REQ_CONTROL_SET_REPORT,
+ .wValue = tu_u16(report_type, report_id),
+ .wIndex = hid_itf->itf_num,
+ .wLength = len
+ };
+ tuh_xfer_t xfer =
+ {
+ .daddr = dev_addr,
+ .ep_addr = 0,
+ .setup = &request,
.buffer = report,
.complete_cb = set_report_complete,
- .user_arg = 0
+ .user_data = 0
+ };
+
+ TU_ASSERT( tuh_control_xfer(&xfer) );
+ return true;
+}
+
+static bool _hidh_set_idle(uint8_t dev_addr, uint8_t itf_num, uint16_t idle_rate, tuh_xfer_cb_t complete_cb, uintptr_t user_data)
+{
+ // SET IDLE request, device can stall if not support this request
+ TU_LOG2("HID Set Idle \r\n");
+ tusb_control_request_t const request =
+ {
+ .bmRequestType_bit =
+ {
+ .recipient = TUSB_REQ_RCPT_INTERFACE,
+ .type = TUSB_REQ_TYPE_CLASS,
+ .direction = TUSB_DIR_OUT
+ },
+ .bRequest = HID_REQ_CONTROL_SET_IDLE,
+ .wValue = idle_rate,
+ .wIndex = itf_num,
+ .wLength = 0
};
- TU_ASSERT( tuh_control_xfer(dev_addr, &xfer) );
+ tuh_xfer_t xfer =
+ {
+ .daddr = dev_addr,
+ .ep_addr = 0,
+ .setup = &request,
+ .buffer = NULL,
+ .complete_cb = complete_cb,
+ .user_data = user_data
+ };
+
+ TU_ASSERT( tuh_control_xfer(&xfer) );
+
return true;
}
@@ -210,7 +256,13 @@ bool tuh_hid_receive_report(uint8_t dev_addr, uint8_t instance)
// claim endpoint
TU_VERIFY( usbh_edpt_claim(dev_addr, hid_itf->ep_in) );
- return usbh_edpt_xfer(dev_addr, hid_itf->ep_in, hid_itf->epin_buf, hid_itf->epin_size);
+ if ( !usbh_edpt_xfer(dev_addr, hid_itf->ep_in, hid_itf->epin_buf, hid_itf->epin_size) )
+ {
+ usbh_edpt_claim(dev_addr, hid_itf->ep_in);
+ return false;
+ }
+
+ return true;
}
//bool tuh_n_hid_n_ready(uint8_t dev_addr, uint8_t instance)
@@ -270,14 +322,9 @@ void hidh_close(uint8_t dev_addr)
// Enumeration
//--------------------------------------------------------------------+
-static bool config_set_protocol (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
-static bool config_get_report_desc (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
-static bool config_get_report_desc_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
-
-static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len);
-
bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
{
+ (void) rhport;
(void) max_len;
TU_VERIFY(TUSB_CLASS_HID == desc_itf->bInterfaceClass);
@@ -309,7 +356,7 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
for(int i = 0; i < desc_itf->bNumEndpoints; i++)
{
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType);
- 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)
{
@@ -341,121 +388,93 @@ bool hidh_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
return true;
}
-bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
-{
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
-
- // Idle rate = 0 mean only report when there is changes
- uint16_t const idle_rate = 0;
-
- // SET IDLE request, device can stall if not support this request
- TU_LOG2("HID Set Idle \r\n");
- tuh_control_xfer_t const xfer =
- {
- .request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_IDLE,
- .wValue = idle_rate,
- .wIndex = itf_num,
- .wLength = 0
- },
-
- .buffer = NULL,
- .complete_cb = (hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE) ? config_set_protocol : config_get_report_desc,
- .user_arg = 0
- };
+//--------------------------------------------------------------------+
+// Set Configure
+//--------------------------------------------------------------------+
- TU_ASSERT( tuh_control_xfer(dev_addr, &xfer) );
+enum {
+ CONFG_SET_IDLE,
+ CONFIG_SET_PROTOCOL,
+ CONFIG_GET_REPORT_DESC,
+ CONFIG_COMPLETE
+};
- return true;
-}
+static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len);
+static void process_set_config(tuh_xfer_t* xfer);
-// Force device to work in BOOT protocol
-static bool config_set_protocol(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
+bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
{
- // Stall is a valid response for SET_IDLE, therefore we could ignore its result
- (void) result;
-
- uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
+ tusb_control_request_t request;
+ request.wIndex = tu_htole16((uint16_t) itf_num);
- TU_LOG2("HID Set Protocol to Boot Mode\r\n");
- hid_itf->protocol_mode = HID_PROTOCOL_BOOT;
- tuh_control_xfer_t const new_xfer =
- {
- .request =
- {
- .bmRequestType_bit =
- {
- .recipient = TUSB_REQ_RCPT_INTERFACE,
- .type = TUSB_REQ_TYPE_CLASS,
- .direction = TUSB_DIR_OUT
- },
- .bRequest = HID_REQ_CONTROL_SET_PROTOCOL,
- .wValue = HID_PROTOCOL_BOOT,
- .wIndex = hid_itf->itf_num,
- .wLength = 0
- },
+ tuh_xfer_t xfer;
+ xfer.daddr = dev_addr;
+ xfer.result = XFER_RESULT_SUCCESS;
+ xfer.setup = &request;
+ xfer.user_data = CONFG_SET_IDLE;
- .buffer = NULL,
- .complete_cb = config_get_report_desc,
- .user_arg = 0
- };
+ // fake request to kick-off the set config process
+ process_set_config(&xfer);
- TU_ASSERT( tuh_control_xfer(dev_addr, &new_xfer) );
return true;
}
-static bool config_get_report_desc(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
+static void process_set_config(tuh_xfer_t* xfer)
{
- // We can be here after SET_IDLE or SET_PROTOCOL (boot device)
- // Trigger assert if result is not successful with set protocol
- if ( xfer->request.bRequest != HID_REQ_CONTROL_SET_IDLE )
+ // Stall is a valid response for SET_IDLE, therefore we could ignore its result
+ if ( xfer->setup->bRequest != HID_REQ_CONTROL_SET_IDLE )
{
- TU_ASSERT(result == XFER_RESULT_SUCCESS);
+ TU_ASSERT(xfer->result == XFER_RESULT_SUCCESS, );
}
- uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
- hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
+ uintptr_t const state = xfer->user_data;
+ uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
+ uint8_t const daddr = xfer->daddr;
- // Get Report Descriptor if possible
- // using usbh enumeration buffer since report descriptor can be very long
- if( hid_itf->report_desc_len > CFG_TUH_ENUMERATION_BUFSIZE )
- {
- TU_LOG2("HID Skip Report Descriptor since it is too large %u bytes\r\n", hid_itf->report_desc_len);
+ uint8_t const instance = get_instance_id_by_itfnum(daddr, itf_num);
+ hidh_interface_t* hid_itf = get_instance(daddr, instance);
- // Driver is mounted without report descriptor
- config_driver_mount_complete(dev_addr, instance, NULL, 0);
- }else
+ switch(state)
{
- TU_ASSERT(tuh_descriptor_get_hid_report(dev_addr, itf_num, hid_itf->report_desc_type, 0, usbh_get_enum_buf(), hid_itf->report_desc_len, config_get_report_desc_complete, 0));
- }
+ case CONFG_SET_IDLE:
+ {
+ // Idle rate = 0 mean only report when there is changes
+ const uint16_t idle_rate = 0;
+ const uintptr_t next_state = (hid_itf->itf_protocol != HID_ITF_PROTOCOL_NONE) ? CONFIG_SET_PROTOCOL : CONFIG_GET_REPORT_DESC;
+ _hidh_set_idle(daddr, itf_num, idle_rate, process_set_config, next_state);
+ }
+ break;
- return true;
-}
+ case CONFIG_SET_PROTOCOL:
+ _hidh_set_protocol(daddr, hid_itf->itf_num, HID_PROTOCOL_BOOT, process_set_config, CONFIG_GET_REPORT_DESC);
+ break;
-static bool config_get_report_desc_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
-{
- TU_ASSERT(XFER_RESULT_SUCCESS == result);
+ case CONFIG_GET_REPORT_DESC:
+ // Get Report Descriptor if possible
+ // using usbh enumeration buffer since report descriptor can be very long
+ if( hid_itf->report_desc_len > CFG_TUH_ENUMERATION_BUFSIZE )
+ {
+ TU_LOG2("HID Skip Report Descriptor since it is too large %u bytes\r\n", hid_itf->report_desc_len);
- uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
- uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
+ // Driver is mounted without report descriptor
+ config_driver_mount_complete(daddr, instance, NULL, 0);
+ }else
+ {
+ tuh_descriptor_get_hid_report(daddr, itf_num, hid_itf->report_desc_type, 0, usbh_get_enum_buf(), hid_itf->report_desc_len, process_set_config, CONFIG_COMPLETE);
+ }
+ break;
- uint8_t const* desc_report = usbh_get_enum_buf();
- uint16_t const desc_len = xfer->request.wLength;
+ case CONFIG_COMPLETE:
+ {
+ uint8_t const* desc_report = usbh_get_enum_buf();
+ uint16_t const desc_len = tu_le16toh(xfer->setup->wLength);
- config_driver_mount_complete(dev_addr, instance, desc_report, desc_len);
+ config_driver_mount_complete(daddr, instance, desc_report, desc_len);
+ }
+ break;
- return true;
+ default: break;
+ }
}
static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len)
diff --git a/src/class/msc/msc_host.c b/src/class/msc/msc_host.c
index c009e5088..c54a63f37 100644
--- a/src/class/msc/msc_host.c
+++ b/src/class/msc/msc_host.c
@@ -358,13 +358,14 @@ bool msch_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t event, uint32
// MSC Enumeration
//--------------------------------------------------------------------+
-static bool config_get_maxlun_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
+static void config_get_maxlun_complete (tuh_xfer_t* xfer);
static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
static bool config_request_sense_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw);
bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *desc_itf, uint16_t max_len)
{
+ (void) rhport;
TU_VERIFY (MSC_SUBCLASS_SCSI == desc_itf->bInterfaceSubClass &&
MSC_PROTOCOL_BOT == desc_itf->bInterfaceProtocol);
@@ -378,7 +379,7 @@ bool msch_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *de
for(uint32_t i=0; i<2; i++)
{
TU_ASSERT(TUSB_DESC_ENDPOINT == ep_desc->bDescriptorType && TUSB_XFER_BULK == ep_desc->bmAttributes.xfer);
- TU_ASSERT(usbh_edpt_open(rhport, dev_addr, ep_desc));
+ TU_ASSERT(tuh_edpt_open(dev_addr, ep_desc));
if ( tu_edpt_dir(ep_desc->bEndpointAddress) == TUSB_DIR_IN )
{
@@ -405,47 +406,47 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
//------------- Get Max Lun -------------//
TU_LOG2("MSC Get Max Lun\r\n");
- 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_IN
- },
- .bRequest = MSC_REQ_GET_MAX_LUN,
- .wValue = 0,
- .wIndex = itf_num,
- .wLength = 1
+ .recipient = TUSB_REQ_RCPT_INTERFACE,
+ .type = TUSB_REQ_TYPE_CLASS,
+ .direction = TUSB_DIR_IN
},
+ .bRequest = MSC_REQ_GET_MAX_LUN,
+ .wValue = 0,
+ .wIndex = itf_num,
+ .wLength = 1
+ };
+ tuh_xfer_t xfer =
+ {
+ .daddr = dev_addr,
+ .ep_addr = 0,
+ .setup = &request,
.buffer = &p_msc->max_lun,
.complete_cb = config_get_maxlun_complete,
- .user_arg = 0
+ .user_data = 0
};
- TU_ASSERT(tuh_control_xfer(dev_addr, &xfer));
+ TU_ASSERT(tuh_control_xfer(&xfer));
return true;
}
-static bool config_get_maxlun_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
+static void config_get_maxlun_complete (tuh_xfer_t* xfer)
{
- (void) xfer;
-
- msch_interface_t* p_msc = get_itf(dev_addr);
+ uint8_t const daddr = xfer->daddr;
+ msch_interface_t* p_msc = get_itf(daddr);
// STALL means zero
- p_msc->max_lun = (XFER_RESULT_SUCCESS == result) ? _msch_buffer[0] : 0;
+ p_msc->max_lun = (XFER_RESULT_SUCCESS == xfer->result) ? _msch_buffer[0] : 0;
p_msc->max_lun++; // MAX LUN is minus 1 by specs
// TODO multiple LUN support
TU_LOG2("SCSI Test Unit Ready\r\n");
uint8_t const lun = 0;
- tuh_msc_test_unit_ready(dev_addr, lun, config_test_unit_ready_complete);
-
- return true;
+ tuh_msc_test_unit_ready(daddr, lun, config_test_unit_ready_complete);
}
static bool config_test_unit_ready_complete(uint8_t dev_addr, msc_cbw_t const* cbw, msc_csw_t const* csw)
@@ -483,7 +484,7 @@ static bool config_read_capacity_complete(uint8_t dev_addr, msc_cbw_t const* cbw
// Capacity response field: Block size and Last LBA are both Big-Endian
scsi_read_capacity10_resp_t* resp = (scsi_read_capacity10_resp_t*) ((void*) _msch_buffer);
p_msc->capacity[cbw->lun].block_count = tu_ntohl(resp->last_lba) + 1;
- p_msc->capacity[cbw->lun].block_size = tu_ntohl(resp->block_size);
+ p_msc->capacity[cbw->lun].block_size = tu_ntohl(resp->block_size);
// Mark enumeration is complete
p_msc->mounted = true;