mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
change tuh_control_xfer_t struct
This commit is contained in:
parent
98d4ed0584
commit
68bfd048a5
@ -124,9 +124,7 @@ bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_co
|
|||||||
{
|
{
|
||||||
cdch_data_t const * p_cdc = get_itf(dev_addr);
|
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 =
|
||||||
{
|
{
|
||||||
@ -138,8 +136,12 @@ bool tuh_cdc_set_control_line_state(uint8_t dev_addr, bool dtr, bool rts, tuh_co
|
|||||||
.wValue = (rts ? 2 : 0) | (dtr ? 1 : 0),
|
.wValue = (rts ? 2 : 0) | (dtr ? 1 : 0),
|
||||||
.wIndex = p_cdc->itf_num,
|
.wIndex = p_cdc->itf_num,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = 0
|
.user_arg = 0
|
||||||
|
@ -105,11 +105,11 @@ uint8_t tuh_hid_get_protocol(uint8_t dev_addr, uint8_t instance)
|
|||||||
|
|
||||||
static bool set_protocol_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
static bool set_protocol_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||||
{
|
{
|
||||||
uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
|
uint8_t const itf_num = (uint8_t) xfer->setup->wIndex;
|
||||||
uint8_t const instance = get_instance_id_by_itfnum(dev_addr, 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);
|
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||||
|
|
||||||
if (XFER_RESULT_SUCCESS == result) hid_itf->protocol_mode = (uint8_t) xfer->request.wValue;
|
if (XFER_RESULT_SUCCESS == result) hid_itf->protocol_mode = (uint8_t) xfer->setup->wValue;
|
||||||
|
|
||||||
if (tuh_hid_set_protocol_complete_cb)
|
if (tuh_hid_set_protocol_complete_cb)
|
||||||
{
|
{
|
||||||
@ -124,9 +124,7 @@ static bool _hidh_set_protocol(uint8_t dev_addr, uint8_t itf_num, uint8_t protoc
|
|||||||
{
|
{
|
||||||
TU_LOG2("HID Set Protocol = %d\r\n", protocol);
|
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 =
|
||||||
{
|
{
|
||||||
@ -138,8 +136,12 @@ static bool _hidh_set_protocol(uint8_t dev_addr, uint8_t itf_num, uint8_t protoc
|
|||||||
.wValue = protocol,
|
.wValue = protocol,
|
||||||
.wIndex = itf_num,
|
.wIndex = itf_num,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -163,13 +165,13 @@ static bool set_report_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfe
|
|||||||
|
|
||||||
if (tuh_hid_set_report_complete_cb)
|
if (tuh_hid_set_report_complete_cb)
|
||||||
{
|
{
|
||||||
uint8_t const itf_num = (uint8_t) xfer->request.wIndex;
|
uint8_t const itf_num = (uint8_t) xfer->setup->wIndex;
|
||||||
uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
|
uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
|
||||||
|
|
||||||
uint8_t const report_type = tu_u16_high(xfer->request.wValue);
|
uint8_t const report_type = tu_u16_high(xfer->setup->wValue);
|
||||||
uint8_t const report_id = tu_u16_low(xfer->request.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(dev_addr, instance, report_id, report_type, (result == XFER_RESULT_SUCCESS) ? xfer->setup->wLength : 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
@ -180,9 +182,7 @@ 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);
|
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);
|
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 =
|
||||||
{
|
{
|
||||||
@ -194,8 +194,12 @@ bool tuh_hid_set_report(uint8_t dev_addr, uint8_t instance, uint8_t report_id, u
|
|||||||
.wValue = tu_u16(report_type, report_id),
|
.wValue = tu_u16(report_type, report_id),
|
||||||
.wIndex = hid_itf->itf_num,
|
.wIndex = hid_itf->itf_num,
|
||||||
.wLength = len
|
.wLength = len
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = report,
|
.buffer = report,
|
||||||
.complete_cb = set_report_complete,
|
.complete_cb = set_report_complete,
|
||||||
.user_arg = 0
|
.user_arg = 0
|
||||||
@ -209,9 +213,7 @@ static bool _hidh_set_idle(uint8_t dev_addr, uint8_t itf_num, uint16_t idle_rate
|
|||||||
{
|
{
|
||||||
// SET IDLE request, device can stall if not support this request
|
// SET IDLE request, device can stall if not support this request
|
||||||
TU_LOG2("HID Set Idle \r\n");
|
TU_LOG2("HID Set Idle \r\n");
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -223,8 +225,12 @@ static bool _hidh_set_idle(uint8_t dev_addr, uint8_t itf_num, uint16_t idle_rate
|
|||||||
.wValue = idle_rate,
|
.wValue = idle_rate,
|
||||||
.wIndex = itf_num,
|
.wIndex = itf_num,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -387,24 +393,27 @@ static bool process_set_config(uint8_t dev_addr, tuh_control_xfer_t const * xfer
|
|||||||
|
|
||||||
bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
|
bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||||
{
|
{
|
||||||
|
tusb_control_request_t request;
|
||||||
|
request.wIndex = tu_htole16((uint16_t) itf_num);
|
||||||
|
|
||||||
tuh_control_xfer_t xfer;
|
tuh_control_xfer_t xfer;
|
||||||
xfer.request.wIndex = tu_htole16((uint16_t) itf_num);
|
xfer.setup = &request;
|
||||||
xfer.user_arg = CONFG_SET_IDLE;
|
xfer.user_arg = CONFG_SET_IDLE;
|
||||||
|
|
||||||
// start the set config process
|
// fake request to start the set config process
|
||||||
return process_set_config(dev_addr, &xfer, XFER_RESULT_SUCCESS);
|
return process_set_config(dev_addr, &xfer, XFER_RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool process_set_config(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
static bool process_set_config(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||||
{
|
{
|
||||||
// Stall is a valid response for SET_IDLE, therefore we could ignore its result
|
// Stall is a valid response for SET_IDLE, therefore we could ignore its result
|
||||||
if ( xfer->request.bRequest != HID_REQ_CONTROL_SET_IDLE )
|
if ( xfer->setup->bRequest != HID_REQ_CONTROL_SET_IDLE )
|
||||||
{
|
{
|
||||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
uintptr_t const state = xfer->user_arg;
|
uintptr_t const state = xfer->user_arg;
|
||||||
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->request.wIndex);
|
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
|
||||||
uint8_t const instance = get_instance_id_by_itfnum(dev_addr, 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);
|
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||||
|
|
||||||
@ -441,7 +450,7 @@ static bool process_set_config(uint8_t dev_addr, tuh_control_xfer_t const * xfer
|
|||||||
case CONFIG_COMPLETE:
|
case CONFIG_COMPLETE:
|
||||||
{
|
{
|
||||||
uint8_t const* desc_report = usbh_get_enum_buf();
|
uint8_t const* desc_report = usbh_get_enum_buf();
|
||||||
uint16_t const desc_len = xfer->request.wLength;
|
uint16_t const desc_len = xfer->setup->wLength;
|
||||||
|
|
||||||
config_driver_mount_complete(dev_addr, instance, desc_report, desc_len);
|
config_driver_mount_complete(dev_addr, instance, desc_report, desc_len);
|
||||||
}
|
}
|
||||||
|
@ -405,9 +405,7 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
|
|
||||||
//------------- Get Max Lun -------------//
|
//------------- Get Max Lun -------------//
|
||||||
TU_LOG2("MSC Get Max Lun\r\n");
|
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 =
|
||||||
{
|
{
|
||||||
@ -419,8 +417,12 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
.wValue = 0,
|
.wValue = 0,
|
||||||
.wIndex = itf_num,
|
.wIndex = itf_num,
|
||||||
.wLength = 1
|
.wLength = 1
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = &p_msc->max_lun,
|
.buffer = &p_msc->max_lun,
|
||||||
.complete_cb = config_get_maxlun_complete,
|
.complete_cb = config_get_maxlun_complete,
|
||||||
.user_arg = 0
|
.user_arg = 0
|
||||||
|
@ -80,9 +80,7 @@ static char const* const _hub_feature_str[] =
|
|||||||
bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
||||||
{
|
{
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -94,8 +92,12 @@ bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
|||||||
.wValue = feature,
|
.wValue = feature,
|
||||||
.wIndex = hub_port,
|
.wIndex = hub_port,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -109,9 +111,7 @@ bool hub_port_clear_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
|||||||
bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
||||||
{
|
{
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -123,8 +123,12 @@ bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
|||||||
.wValue = feature,
|
.wValue = feature,
|
||||||
.wIndex = hub_port,
|
.wIndex = hub_port,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -138,9 +142,7 @@ bool hub_port_set_feature(uint8_t hub_addr, uint8_t hub_port, uint8_t feature,
|
|||||||
bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp,
|
bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp,
|
||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
||||||
{
|
{
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -152,8 +154,12 @@ bool hub_port_get_status(uint8_t hub_addr, uint8_t hub_port, void* resp,
|
|||||||
.wValue = 0,
|
.wValue = 0,
|
||||||
.wIndex = hub_port,
|
.wIndex = hub_port,
|
||||||
.wLength = 4
|
.wLength = 4
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = resp,
|
.buffer = resp,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -228,9 +234,7 @@ bool hub_set_config(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
TU_ASSERT(itf_num == p_hub->itf_num);
|
TU_ASSERT(itf_num == p_hub->itf_num);
|
||||||
|
|
||||||
// Get Hub Descriptor
|
// Get Hub Descriptor
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -242,8 +246,12 @@ bool hub_set_config(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
.wValue = 0,
|
.wValue = 0,
|
||||||
.wIndex = 0,
|
.wIndex = 0,
|
||||||
.wLength = sizeof(descriptor_hub_desc_t)
|
.wLength = sizeof(descriptor_hub_desc_t)
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = _hub_buffer,
|
.buffer = _hub_buffer,
|
||||||
.complete_cb = config_set_port_power,
|
.complete_cb = config_set_port_power,
|
||||||
.user_arg = 0
|
.user_arg = 0
|
||||||
@ -277,7 +285,7 @@ static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t con
|
|||||||
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
||||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||||
|
|
||||||
if (xfer->request.wIndex == p_hub->port_count)
|
if (xfer->setup->wIndex == p_hub->port_count)
|
||||||
{
|
{
|
||||||
// All ports are power -> queue notification status endpoint and
|
// All ports are power -> queue notification status endpoint and
|
||||||
// complete the SET CONFIGURATION
|
// complete the SET CONFIGURATION
|
||||||
@ -287,7 +295,7 @@ static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t con
|
|||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
// power next port
|
// power next port
|
||||||
uint8_t const hub_port = (uint8_t) (xfer->request.wIndex + 1);
|
uint8_t const hub_port = (uint8_t) (xfer->setup->wIndex + 1);
|
||||||
return hub_port_set_feature(dev_addr, hub_port, HUB_FEATURE_PORT_POWER, config_port_power_complete, 0);
|
return hub_port_set_feature(dev_addr, hub_port, HUB_FEATURE_PORT_POWER, config_port_power_complete, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -333,7 +341,7 @@ static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t
|
|||||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||||
|
|
||||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||||
uint8_t const port_num = (uint8_t) xfer->request.wIndex;
|
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||||
|
|
||||||
// Connection change
|
// Connection change
|
||||||
if (p_hub->port_status.change.connection)
|
if (p_hub->port_status.change.connection)
|
||||||
@ -361,7 +369,7 @@ static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control
|
|||||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||||
|
|
||||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||||
uint8_t const port_num = (uint8_t) xfer->request.wIndex;
|
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||||
|
|
||||||
if ( p_hub->port_status.status.connection )
|
if ( p_hub->port_status.status.connection )
|
||||||
{
|
{
|
||||||
@ -392,7 +400,7 @@ static bool connection_port_reset_complete (uint8_t dev_addr, tuh_control_xfer_t
|
|||||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||||
|
|
||||||
// hub_interface_t* p_hub = get_itf(dev_addr);
|
// hub_interface_t* p_hub = get_itf(dev_addr);
|
||||||
uint8_t const port_num = (uint8_t) xfer->request.wIndex;
|
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||||
|
|
||||||
// submit attach event
|
// submit attach event
|
||||||
hcd_event_t event =
|
hcd_event_t event =
|
||||||
|
@ -109,6 +109,10 @@ typedef struct {
|
|||||||
|
|
||||||
tu_edpt_state_t ep_status[CFG_TUH_ENDPOINT_MAX][2];
|
tu_edpt_state_t ep_status[CFG_TUH_ENDPOINT_MAX][2];
|
||||||
|
|
||||||
|
#if CFG_TUH_BARE
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
} usbh_device_t;
|
} usbh_device_t;
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -241,7 +245,11 @@ static uint8_t _usbh_ctrl_buf[CFG_TUH_ENUMERATION_BUFSIZE];
|
|||||||
// We will only execute control transfer one at a time.
|
// We will only execute control transfer one at a time.
|
||||||
struct
|
struct
|
||||||
{
|
{
|
||||||
tuh_control_xfer_t xfer;
|
tusb_control_request_t request TU_ATTR_ALIGNED(4);
|
||||||
|
uint8_t* buffer;
|
||||||
|
tuh_control_xfer_cb_t complete_cb;
|
||||||
|
uintptr_t user_arg;
|
||||||
|
|
||||||
uint8_t daddr; // device address that is transferring
|
uint8_t daddr; // device address that is transferring
|
||||||
volatile uint8_t stage;
|
volatile uint8_t stage;
|
||||||
}_ctrl_xfer;
|
}_ctrl_xfer;
|
||||||
@ -304,9 +312,7 @@ void osal_task_delay(uint32_t msec)
|
|||||||
static bool _get_descriptor(uint8_t daddr, uint8_t type, uint8_t index, uint16_t language_id, void* buffer, uint16_t len,
|
static bool _get_descriptor(uint8_t daddr, uint8_t type, uint8_t index, uint16_t language_id, void* buffer, uint16_t len,
|
||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
||||||
{
|
{
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -318,8 +324,12 @@ static bool _get_descriptor(uint8_t daddr, uint8_t type, uint8_t index, uint16_t
|
|||||||
.wValue = tu_htole16( TU_U16(type, index) ),
|
.wValue = tu_htole16( TU_U16(type, index) ),
|
||||||
.wIndex = tu_htole16(language_id),
|
.wIndex = tu_htole16(language_id),
|
||||||
.wLength = tu_htole16(len)
|
.wLength = tu_htole16(len)
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = buffer,
|
.buffer = buffer,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -387,9 +397,7 @@ bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_
|
|||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg)
|
||||||
{
|
{
|
||||||
TU_LOG2("HID Get Report Descriptor\r\n");
|
TU_LOG2("HID Get Report Descriptor\r\n");
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -401,8 +409,12 @@ bool tuh_descriptor_get_hid_report(uint8_t daddr, uint8_t itf_num, uint8_t desc_
|
|||||||
.wValue = tu_htole16(TU_U16(desc_type, index)),
|
.wValue = tu_htole16(TU_U16(desc_type, index)),
|
||||||
.wIndex = tu_htole16((uint16_t) itf_num),
|
.wIndex = tu_htole16((uint16_t) itf_num),
|
||||||
.wLength = len
|
.wLength = len
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = buffer,
|
.buffer = buffer,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -416,9 +428,7 @@ bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
|||||||
{
|
{
|
||||||
TU_LOG2("Set Configuration = %d\r\n", config_num);
|
TU_LOG2("Set Configuration = %d\r\n", config_num);
|
||||||
|
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -430,8 +440,12 @@ bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
|||||||
.wValue = tu_htole16(config_num),
|
.wValue = tu_htole16(config_num),
|
||||||
.wIndex = 0,
|
.wIndex = 0,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = complete_cb,
|
.complete_cb = complete_cb,
|
||||||
.user_arg = user_arg
|
.user_arg = user_arg
|
||||||
@ -895,16 +909,19 @@ bool tuh_control_xfer (uint8_t daddr, tuh_control_xfer_t const* xfer)
|
|||||||
|
|
||||||
const uint8_t rhport = usbh_get_rhport(daddr);
|
const uint8_t rhport = usbh_get_rhport(daddr);
|
||||||
|
|
||||||
TU_LOG2("[%u:%u] %s: ", rhport, daddr, xfer->request.bRequest <= TUSB_REQ_SYNCH_FRAME ? tu_str_std_request[xfer->request.bRequest] : "Unknown Request");
|
TU_LOG2("[%u:%u] %s: ", rhport, daddr, xfer->setup->bRequest <= TUSB_REQ_SYNCH_FRAME ? tu_str_std_request[xfer->setup->bRequest] : "Unknown Request");
|
||||||
TU_LOG2_VAR(&xfer->request);
|
TU_LOG2_VAR(&xfer->setup);
|
||||||
TU_LOG2("\r\n");
|
TU_LOG2("\r\n");
|
||||||
|
|
||||||
_ctrl_xfer.daddr = daddr;
|
_ctrl_xfer.daddr = daddr;
|
||||||
_ctrl_xfer.xfer = (*xfer);
|
_ctrl_xfer.request = (*xfer->setup);
|
||||||
|
_ctrl_xfer.buffer = xfer->buffer;
|
||||||
|
_ctrl_xfer.complete_cb = xfer->complete_cb;
|
||||||
|
_ctrl_xfer.user_arg = xfer->user_arg;
|
||||||
|
|
||||||
if (xfer->complete_cb)
|
if (xfer->complete_cb)
|
||||||
{
|
{
|
||||||
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.xfer.request) );
|
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.request) );
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
// user_arg must point to xfer_result_t to hold result
|
// user_arg must point to xfer_result_t to hold result
|
||||||
@ -914,10 +931,10 @@ bool tuh_control_xfer (uint8_t daddr, tuh_control_xfer_t const* xfer)
|
|||||||
// change callback to internal blocking, and result as user argument
|
// change callback to internal blocking, and result as user argument
|
||||||
volatile xfer_result_t* result = (volatile xfer_result_t*) xfer->user_arg;
|
volatile xfer_result_t* result = (volatile xfer_result_t*) xfer->user_arg;
|
||||||
|
|
||||||
_ctrl_xfer.xfer.complete_cb = _control_blocking_complete_cb;
|
_ctrl_xfer.complete_cb = _control_blocking_complete_cb;
|
||||||
*result = XFER_RESULT_INVALID;
|
*result = XFER_RESULT_INVALID;
|
||||||
|
|
||||||
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.xfer.request) );
|
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.request) );
|
||||||
|
|
||||||
while ((*result) == XFER_RESULT_INVALID)
|
while ((*result) == XFER_RESULT_INVALID)
|
||||||
{
|
{
|
||||||
@ -961,7 +978,16 @@ static void _xfer_complete(uint8_t dev_addr, xfer_result_t result)
|
|||||||
TU_LOG2("\r\n");
|
TU_LOG2("\r\n");
|
||||||
|
|
||||||
// duplicate xfer since user can execute control transfer within callback
|
// duplicate xfer since user can execute control transfer within callback
|
||||||
tuh_control_xfer_t const xfer_temp = _ctrl_xfer.xfer;
|
tusb_control_request_t const request = _ctrl_xfer.request;
|
||||||
|
tuh_control_xfer_t const xfer_temp =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
|
.actual_len = 0,
|
||||||
|
.buffer = _ctrl_xfer.buffer,
|
||||||
|
.complete_cb = _ctrl_xfer.complete_cb,
|
||||||
|
.user_arg = _ctrl_xfer.user_arg
|
||||||
|
};
|
||||||
|
|
||||||
usbh_lock();
|
usbh_lock();
|
||||||
_ctrl_xfer.stage = CONTROL_STAGE_IDLE;
|
_ctrl_xfer.stage = CONTROL_STAGE_IDLE;
|
||||||
@ -979,7 +1005,7 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
|
|||||||
(void) xferred_bytes;
|
(void) xferred_bytes;
|
||||||
|
|
||||||
const uint8_t rhport = usbh_get_rhport(dev_addr);
|
const uint8_t rhport = usbh_get_rhport(dev_addr);
|
||||||
tusb_control_request_t const * request = &_ctrl_xfer.xfer.request;
|
tusb_control_request_t const * request = &_ctrl_xfer.request;
|
||||||
|
|
||||||
if (XFER_RESULT_SUCCESS != result)
|
if (XFER_RESULT_SUCCESS != result)
|
||||||
{
|
{
|
||||||
@ -996,7 +1022,7 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
|
|||||||
{
|
{
|
||||||
// DATA stage: initial data toggle is always 1
|
// DATA stage: initial data toggle is always 1
|
||||||
set_control_xfer_stage(CONTROL_STAGE_DATA);
|
set_control_xfer_stage(CONTROL_STAGE_DATA);
|
||||||
return hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), _ctrl_xfer.xfer.buffer, request->wLength);
|
return hcd_edpt_xfer(rhport, dev_addr, tu_edpt_addr(0, request->bmRequestType_bit.direction), _ctrl_xfer.buffer, request->wLength);
|
||||||
}
|
}
|
||||||
__attribute__((fallthrough));
|
__attribute__((fallthrough));
|
||||||
|
|
||||||
@ -1004,7 +1030,7 @@ static bool usbh_control_xfer_cb (uint8_t dev_addr, uint8_t ep_addr, xfer_result
|
|||||||
if (request->wLength)
|
if (request->wLength)
|
||||||
{
|
{
|
||||||
TU_LOG2("[%u:%u] Control data:\r\n", rhport, dev_addr);
|
TU_LOG2("[%u:%u] Control data:\r\n", rhport, dev_addr);
|
||||||
TU_LOG2_MEM(_ctrl_xfer.xfer.buffer, request->wLength, 2);
|
TU_LOG2_MEM(_ctrl_xfer.buffer, request->wLength, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ACK stage: toggle is always 1
|
// ACK stage: toggle is always 1
|
||||||
@ -1190,7 +1216,7 @@ static bool process_enumeration(uint8_t dev_addr, tuh_control_xfer_t const * xfe
|
|||||||
|
|
||||||
case ENUM_GET_DEVICE_DESC:
|
case ENUM_GET_DEVICE_DESC:
|
||||||
{
|
{
|
||||||
uint8_t const new_addr = (uint8_t) tu_le16toh(xfer->request.wValue);
|
uint8_t const new_addr = (uint8_t) tu_le16toh(xfer->setup->wValue);
|
||||||
|
|
||||||
usbh_device_t* new_dev = get_device(new_addr);
|
usbh_device_t* new_dev = get_device(new_addr);
|
||||||
TU_ASSERT(new_dev);
|
TU_ASSERT(new_dev);
|
||||||
@ -1320,6 +1346,12 @@ static bool enum_new_device(hcd_event_t* event)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TU_ATTR_ALWAYS_INLINE
|
||||||
|
static inline bool is_hub_addr(uint8_t daddr)
|
||||||
|
{
|
||||||
|
return daddr > CFG_TUH_DEVICE_MAX;
|
||||||
|
}
|
||||||
|
|
||||||
static uint8_t get_new_address(bool is_hub)
|
static uint8_t get_new_address(bool is_hub)
|
||||||
{
|
{
|
||||||
uint8_t start;
|
uint8_t start;
|
||||||
@ -1360,9 +1392,7 @@ static bool enum_request_set_addr(void)
|
|||||||
new_dev->connected = 1;
|
new_dev->connected = 1;
|
||||||
new_dev->ep0_size = desc_device->bMaxPacketSize0;
|
new_dev->ep0_size = desc_device->bMaxPacketSize0;
|
||||||
|
|
||||||
tuh_control_xfer_t const xfer =
|
tusb_control_request_t const request =
|
||||||
{
|
|
||||||
.request =
|
|
||||||
{
|
{
|
||||||
.bmRequestType_bit =
|
.bmRequestType_bit =
|
||||||
{
|
{
|
||||||
@ -1374,8 +1404,12 @@ static bool enum_request_set_addr(void)
|
|||||||
.wValue = tu_htole16(new_addr),
|
.wValue = tu_htole16(new_addr),
|
||||||
.wIndex = 0,
|
.wIndex = 0,
|
||||||
.wLength = 0
|
.wLength = 0
|
||||||
},
|
};
|
||||||
|
|
||||||
|
tuh_control_xfer_t const xfer =
|
||||||
|
{
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
.buffer = NULL,
|
.buffer = NULL,
|
||||||
.complete_cb = process_enumeration,
|
.complete_cb = process_enumeration,
|
||||||
.user_arg = ENUM_GET_DEVICE_DESC
|
.user_arg = ENUM_GET_DEVICE_DESC
|
||||||
@ -1503,9 +1537,15 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
{
|
{
|
||||||
enum_full_complete();
|
enum_full_complete();
|
||||||
|
|
||||||
|
#if CFG_TUH_HUB
|
||||||
|
// skip device mount callback for hub
|
||||||
|
if ( !is_hub_addr(dev_addr) )
|
||||||
|
#endif
|
||||||
|
{
|
||||||
// Invoke callback if available
|
// Invoke callback if available
|
||||||
if (tuh_mount_cb) tuh_mount_cb(dev_addr);
|
if (tuh_mount_cb) tuh_mount_cb(dev_addr);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void enum_full_complete(void)
|
static void enum_full_complete(void)
|
||||||
|
@ -46,7 +46,10 @@ typedef bool (*tuh_control_xfer_cb_t)(uint8_t daddr, tuh_control_xfer_t const *
|
|||||||
|
|
||||||
struct tuh_control_xfer_s
|
struct tuh_control_xfer_s
|
||||||
{
|
{
|
||||||
tusb_control_request_t request TU_ATTR_ALIGNED(4);
|
uint8_t ep_addr;
|
||||||
|
tusb_control_request_t const* setup;
|
||||||
|
uint32_t actual_len;
|
||||||
|
|
||||||
uint8_t* buffer;
|
uint8_t* buffer;
|
||||||
tuh_control_xfer_cb_t complete_cb;
|
tuh_control_xfer_cb_t complete_cb;
|
||||||
uintptr_t user_arg;
|
uintptr_t user_arg;
|
||||||
@ -104,14 +107,16 @@ static inline bool tuh_ready(uint8_t daddr)
|
|||||||
return tuh_mounted(daddr) && !tuh_suspended(daddr);
|
return tuh_mounted(daddr) && !tuh_suspended(daddr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Endpoint Asynchronous (non-blocking)
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
// Carry out a control transfer
|
// Carry out a control transfer
|
||||||
// true on success, false if there is on-going control transfer or incorrect parameters
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
||||||
// Blocking if complete callback is NULL, in this case 'user_arg' must contain xfer_result_t variable
|
// Blocking if complete callback is NULL, in this case 'user_arg' must contain xfer_result_t variable
|
||||||
bool tuh_control_xfer (uint8_t daddr, tuh_control_xfer_t const* xfer);
|
bool tuh_control_xfer(uint8_t daddr, tuh_control_xfer_t const* xfer);
|
||||||
|
|
||||||
// Sync (blocking) version of tuh_control_xfer()
|
//bool tuh_edpt_xfer(uint8_t daddr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes);
|
||||||
// return transfer result
|
|
||||||
uint8_t tuh_control_xfer_sync(uint8_t daddr, tuh_control_xfer_t const* xfer, uint32_t timeout_ms);
|
|
||||||
|
|
||||||
// Set Configuration (control transfer)
|
// Set Configuration (control transfer)
|
||||||
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
|
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
|
||||||
@ -120,6 +125,14 @@ uint8_t tuh_control_xfer_sync(uint8_t daddr, tuh_control_xfer_t const* xfer, uin
|
|||||||
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
||||||
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
tuh_control_xfer_cb_t complete_cb, uintptr_t user_arg);
|
||||||
|
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
// Endpoint Synchronous (blocking)
|
||||||
|
//--------------------------------------------------------------------+
|
||||||
|
|
||||||
|
// Sync (blocking) version of tuh_control_xfer()
|
||||||
|
// return transfer result
|
||||||
|
uint8_t tuh_control_xfer_sync(uint8_t daddr, tuh_control_xfer_t const* xfer, uint32_t timeout_ms);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Descriptors Asynchronous (non-blocking)
|
// Descriptors Asynchronous (non-blocking)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -201,10 +214,6 @@ uint8_t tuh_descriptor_get_product_string_sync(uint8_t daddr, uint16_t language_
|
|||||||
// return transfer result
|
// return transfer result
|
||||||
uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
uint8_t tuh_descriptor_get_serial_string_sync(uint8_t daddr, uint16_t language_id, void* buffer, uint16_t len, uint8_t timeout_ms);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
//
|
|
||||||
//--------------------------------------------------------------------+
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user