mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-17 05:32:55 +08:00
move result into transfer struct
This commit is contained in:
parent
68bfd048a5
commit
6df420f7f3
@ -115,11 +115,9 @@ static void utf16_to_utf8(uint16_t *temp_buf, size_t buf_len) {
|
||||
((uint8_t*) temp_buf)[utf8_len] = '\0';
|
||||
}
|
||||
|
||||
bool print_device_descriptor(uint8_t daddr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
bool print_device_descriptor(uint8_t daddr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
(void) xfer;
|
||||
|
||||
if ( XFER_RESULT_SUCCESS != result )
|
||||
if ( XFER_RESULT_SUCCESS != xfer->result )
|
||||
{
|
||||
printf("Failed to get device descriptor\r\n");
|
||||
return false;
|
||||
|
@ -103,13 +103,13 @@ 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 bool set_protocol_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
uint8_t const itf_num = (uint8_t) xfer->setup->wIndex;
|
||||
uint8_t const instance = get_instance_id_by_itfnum(dev_addr, itf_num);
|
||||
hidh_interface_t* hid_itf = get_instance(dev_addr, instance);
|
||||
|
||||
if (XFER_RESULT_SUCCESS == result) hid_itf->protocol_mode = (uint8_t) xfer->setup->wValue;
|
||||
if (XFER_RESULT_SUCCESS == xfer->result) hid_itf->protocol_mode = (uint8_t) xfer->setup->wValue;
|
||||
|
||||
if (tuh_hid_set_protocol_complete_cb)
|
||||
{
|
||||
@ -159,7 +159,7 @@ bool tuh_hid_set_protocol(uint8_t dev_addr, uint8_t instance, uint8_t protocol)
|
||||
return _hidh_set_protocol(dev_addr, hid_itf->itf_num, protocol, set_protocol_complete, 0);
|
||||
}
|
||||
|
||||
static bool set_report_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool set_report_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
TU_LOG2("HID Set Report complete\r\n");
|
||||
|
||||
@ -171,7 +171,8 @@ static bool set_report_complete(uint8_t dev_addr, tuh_control_xfer_t const * xfe
|
||||
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->setup->wLength : 0);
|
||||
tuh_hid_set_report_complete_cb(dev_addr, instance, report_id, report_type,
|
||||
(xfer->result == XFER_RESULT_SUCCESS) ? xfer->setup->wLength : 0);
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -389,7 +390,7 @@ enum {
|
||||
};
|
||||
|
||||
static void config_driver_mount_complete(uint8_t dev_addr, uint8_t instance, uint8_t const* desc_report, uint16_t desc_len);
|
||||
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);
|
||||
|
||||
bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||
{
|
||||
@ -397,19 +398,20 @@ bool hidh_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||
request.wIndex = tu_htole16((uint16_t) itf_num);
|
||||
|
||||
tuh_control_xfer_t xfer;
|
||||
xfer.result = XFER_RESULT_SUCCESS;
|
||||
xfer.setup = &request;
|
||||
xfer.user_arg = CONFG_SET_IDLE;
|
||||
|
||||
// fake request to start the set config process
|
||||
return process_set_config(dev_addr, &xfer, XFER_RESULT_SUCCESS);
|
||||
// fake request to kick-off the set config process
|
||||
return process_set_config(dev_addr, &xfer);
|
||||
}
|
||||
|
||||
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)
|
||||
{
|
||||
// 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);
|
||||
}
|
||||
|
||||
uintptr_t const state = xfer->user_arg;
|
||||
|
@ -358,7 +358,7 @@ 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 bool config_get_maxlun_complete (uint8_t dev_addr, tuh_control_xfer_t const * 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);
|
||||
@ -432,14 +432,12 @@ bool msch_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool config_get_maxlun_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool config_get_maxlun_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
(void) xfer;
|
||||
|
||||
msch_interface_t* p_msc = get_itf(dev_addr);
|
||||
|
||||
// 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
|
||||
|
@ -225,8 +225,8 @@ bool hub_edpt_status_xfer(uint8_t dev_addr)
|
||||
// Set Configure
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool config_set_port_power (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
static bool config_set_port_power (uint8_t dev_addr, tuh_control_xfer_t const * xfer);
|
||||
static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer);
|
||||
|
||||
bool hub_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||
{
|
||||
@ -262,10 +262,9 @@ bool hub_set_config(uint8_t dev_addr, uint8_t itf_num)
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool config_set_port_power (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool config_set_port_power (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
(void) xfer;
|
||||
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
||||
TU_ASSERT(XFER_RESULT_SUCCESS == xfer->result);
|
||||
|
||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||
|
||||
@ -280,9 +279,9 @@ static bool config_set_port_power (uint8_t dev_addr, tuh_control_xfer_t const *
|
||||
return hub_port_set_feature(dev_addr, hub_port, HUB_FEATURE_PORT_POWER, config_port_power_complete, 0);
|
||||
}
|
||||
|
||||
static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
TU_ASSERT(XFER_RESULT_SUCCESS == result);
|
||||
TU_ASSERT(XFER_RESULT_SUCCESS == xfer->result);
|
||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||
|
||||
if (xfer->setup->wIndex == p_hub->port_count)
|
||||
@ -306,9 +305,9 @@ static bool config_port_power_complete (uint8_t dev_addr, tuh_control_xfer_t con
|
||||
// Connection Changes
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
static bool connection_port_reset_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer);
|
||||
static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer);
|
||||
static bool connection_port_reset_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer);
|
||||
|
||||
// callback as response of interrupt endpoint polling
|
||||
bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32_t xferred_bytes)
|
||||
@ -336,9 +335,9 @@ bool hub_xfer_cb(uint8_t dev_addr, uint8_t ep_addr, xfer_result_t result, uint32
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||
TU_ASSERT(xfer->result == XFER_RESULT_SUCCESS);
|
||||
|
||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||
@ -364,9 +363,9 @@ static bool connection_get_status_complete (uint8_t dev_addr, tuh_control_xfer_t
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||
TU_ASSERT(xfer->result == XFER_RESULT_SUCCESS);
|
||||
|
||||
hub_interface_t* p_hub = get_itf(dev_addr);
|
||||
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||
@ -395,9 +394,9 @@ static bool connection_clear_conn_change_complete (uint8_t dev_addr, tuh_control
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool connection_port_reset_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool connection_port_reset_complete (uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
TU_ASSERT(result == XFER_RESULT_SUCCESS);
|
||||
TU_ASSERT(xfer->result == XFER_RESULT_SUCCESS);
|
||||
|
||||
// hub_interface_t* p_hub = get_itf(dev_addr);
|
||||
uint8_t const port_num = (uint8_t) xfer->setup->wIndex;
|
||||
|
@ -882,12 +882,12 @@ bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
|
||||
// Control transfer
|
||||
//--------------------------------------------------------------------+
|
||||
|
||||
static bool _control_blocking_complete_cb(uint8_t daddr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool _control_blocking_complete_cb(uint8_t daddr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
(void) daddr;
|
||||
|
||||
// update result
|
||||
*((xfer_result_t*) xfer->user_arg) = result;
|
||||
*((xfer_result_t*) xfer->user_arg) = xfer->result;
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -924,19 +924,17 @@ bool tuh_control_xfer (uint8_t daddr, tuh_control_xfer_t const* xfer)
|
||||
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.request) );
|
||||
}else
|
||||
{
|
||||
// user_arg must point to xfer_result_t to hold result
|
||||
TU_VERIFY(xfer->user_arg);
|
||||
|
||||
// blocking if complete callback is not provided
|
||||
// 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 = XFER_RESULT_INVALID;
|
||||
|
||||
// use user_arg to point to xfer_result_t
|
||||
_ctrl_xfer.user_arg = (uintptr_t) &result;
|
||||
_ctrl_xfer.complete_cb = _control_blocking_complete_cb;
|
||||
*result = XFER_RESULT_INVALID;
|
||||
|
||||
TU_ASSERT( hcd_setup_send(rhport, daddr, (uint8_t*) &_ctrl_xfer.request) );
|
||||
|
||||
while ((*result) == XFER_RESULT_INVALID)
|
||||
while (result == XFER_RESULT_INVALID)
|
||||
{
|
||||
// only need to call task if not preempted RTOS
|
||||
#if CFG_TUSB_OS == OPT_OS_NONE || CFG_TUSB_OS == OPT_OS_PICO
|
||||
@ -982,6 +980,7 @@ static void _xfer_complete(uint8_t dev_addr, xfer_result_t result)
|
||||
tuh_control_xfer_t const xfer_temp =
|
||||
{
|
||||
.ep_addr = 0,
|
||||
.result = result,
|
||||
.setup = &request,
|
||||
.actual_len = 0,
|
||||
.buffer = _ctrl_xfer.buffer,
|
||||
@ -995,7 +994,7 @@ static void _xfer_complete(uint8_t dev_addr, xfer_result_t result)
|
||||
|
||||
if (xfer_temp.complete_cb)
|
||||
{
|
||||
xfer_temp.complete_cb(dev_addr, &xfer_temp, result);
|
||||
xfer_temp.complete_cb(dev_addr, &xfer_temp);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1120,9 +1119,9 @@ static bool parse_configuration_descriptor (uint8_t dev_addr, tusb_desc_configur
|
||||
static void enum_full_complete(void);
|
||||
|
||||
// process device enumeration
|
||||
static bool process_enumeration(uint8_t dev_addr, tuh_control_xfer_t const * xfer, xfer_result_t result)
|
||||
static bool process_enumeration(uint8_t dev_addr, tuh_control_xfer_t const * xfer)
|
||||
{
|
||||
if (XFER_RESULT_SUCCESS != result)
|
||||
if (XFER_RESULT_SUCCESS != xfer->result)
|
||||
{
|
||||
// stop enumeration, maybe we could retry this
|
||||
enum_full_complete();
|
||||
@ -1323,11 +1322,12 @@ static bool enum_new_device(hcd_event_t* event)
|
||||
_dev0.speed = hcd_port_speed_get(_dev0.rhport );
|
||||
TU_LOG2("%s Speed\r\n", tu_str_speed[_dev0.speed]);
|
||||
|
||||
// start the enumeration process
|
||||
// fake transfer to kick-off the enumeration process
|
||||
tuh_control_xfer_t xfer;
|
||||
xfer.result = XFER_RESULT_SUCCESS;
|
||||
xfer.user_arg = ENUM_ADDR0_DEVICE_DESC;
|
||||
|
||||
process_enumeration(0, &xfer, XFER_RESULT_SUCCESS);
|
||||
process_enumeration(0, &xfer);
|
||||
|
||||
}
|
||||
#if CFG_TUH_HUB
|
||||
|
@ -42,15 +42,19 @@
|
||||
struct tuh_control_xfer_s;
|
||||
typedef struct tuh_control_xfer_s tuh_control_xfer_t;
|
||||
|
||||
typedef bool (*tuh_control_xfer_cb_t)(uint8_t daddr, tuh_control_xfer_t const * xfer, xfer_result_t result);
|
||||
typedef bool (*tuh_control_xfer_cb_t)(uint8_t daddr, tuh_control_xfer_t const * xfer);
|
||||
|
||||
struct tuh_control_xfer_s
|
||||
{
|
||||
uint8_t ep_addr;
|
||||
xfer_result_t result;
|
||||
|
||||
tusb_control_request_t const* setup;
|
||||
uint32_t actual_len;
|
||||
|
||||
uint8_t* buffer;
|
||||
|
||||
|
||||
tuh_control_xfer_cb_t complete_cb;
|
||||
uintptr_t user_arg;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user