mirror of
https://github.com/hathach/tinyusb.git
synced 2025-01-31 05:52:55 +08:00
add tuh_set_interface
This commit is contained in:
parent
cbcf5d8c08
commit
e44e461ce3
@ -97,7 +97,7 @@ static inline uint8_t get_idx_by_ep_addr(uint8_t daddr, uint8_t ep_addr)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return TU_INDEX_INVALID_8;
|
return TUSB_INDEX_INVALID_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -124,7 +124,7 @@ uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num)
|
|||||||
if (p_cdc->daddr == daddr && p_cdc->bInterfaceNumber == itf_num) return i;
|
if (p_cdc->daddr == daddr && p_cdc->bInterfaceNumber == itf_num) return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return TU_INDEX_INVALID_8;
|
return TUSB_INDEX_INVALID_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
|
bool tuh_cdc_itf_get_info(uint8_t idx, tuh_cdc_itf_info_t* info)
|
||||||
@ -533,7 +533,7 @@ static void process_cdc_config(tuh_xfer_t* xfer)
|
|||||||
uintptr_t const state = xfer->user_data;
|
uintptr_t const state = xfer->user_data;
|
||||||
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
|
uint8_t const itf_num = (uint8_t) tu_le16toh(xfer->setup->wIndex);
|
||||||
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
|
uint8_t const idx = tuh_cdc_itf_get_index(xfer->daddr, itf_num);
|
||||||
TU_ASSERT(idx != TU_INDEX_INVALID_8, );
|
TU_ASSERT(idx != TUSB_INDEX_INVALID_8, );
|
||||||
|
|
||||||
switch(state)
|
switch(state)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ typedef struct
|
|||||||
} tuh_cdc_itf_info_t;
|
} tuh_cdc_itf_info_t;
|
||||||
|
|
||||||
// Get Interface index from device address + interface number
|
// Get Interface index from device address + interface number
|
||||||
// return TUSB_INDEX_INVALID (0xFF) if not found
|
// return TUSB_INDEX_INVALID_8 (0xFF) if not found
|
||||||
uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num);
|
uint8_t tuh_cdc_itf_get_index(uint8_t daddr, uint8_t itf_num);
|
||||||
|
|
||||||
// Get Interface information
|
// Get Interface information
|
||||||
|
@ -75,12 +75,6 @@
|
|||||||
|
|
||||||
#include "tusb_timeout.h" // TODO remove
|
#include "tusb_timeout.h" // TODO remove
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
TU_INDEX_INVALID_8 = 0xFFu
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Optional API implemented by application if needed
|
// Optional API implemented by application if needed
|
||||||
// TODO move to a more ovious place/file
|
// TODO move to a more ovious place/file
|
||||||
|
@ -273,6 +273,11 @@ enum
|
|||||||
CONTROL_STAGE_ACK
|
CONTROL_STAGE_ACK
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
TUSB_INDEX_INVALID_8 = 0xFFu
|
||||||
|
};
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// USB Descriptors
|
// USB Descriptors
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
@ -195,7 +195,7 @@ enum { CONFIG_NUM = 1 }; // default to use configuration 1
|
|||||||
// sum of end device + hub
|
// sum of end device + hub
|
||||||
#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
|
#define TOTAL_DEVICES (CFG_TUH_DEVICE_MAX + CFG_TUH_HUB)
|
||||||
|
|
||||||
static uint8_t _usbh_controller = TU_INDEX_INVALID_8;
|
static uint8_t _usbh_controller = TUSB_INDEX_INVALID_8;
|
||||||
|
|
||||||
// Device with address = 0 for enumeration
|
// Device with address = 0 for enumeration
|
||||||
static usbh_dev0_t _dev0;
|
static usbh_dev0_t _dev0;
|
||||||
@ -303,13 +303,13 @@ tusb_speed_t tuh_speed_get (uint8_t dev_addr)
|
|||||||
static void clear_device(usbh_device_t* dev)
|
static void clear_device(usbh_device_t* dev)
|
||||||
{
|
{
|
||||||
tu_memclr(dev, sizeof(usbh_device_t));
|
tu_memclr(dev, sizeof(usbh_device_t));
|
||||||
memset(dev->itf2drv, TU_INDEX_INVALID_8, sizeof(dev->itf2drv)); // invalid mapping
|
memset(dev->itf2drv, TUSB_INDEX_INVALID_8, sizeof(dev->itf2drv)); // invalid mapping
|
||||||
memset(dev->ep2drv , TU_INDEX_INVALID_8, sizeof(dev->ep2drv )); // invalid mapping
|
memset(dev->ep2drv , TUSB_INDEX_INVALID_8, sizeof(dev->ep2drv )); // invalid mapping
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_inited(void)
|
bool tuh_inited(void)
|
||||||
{
|
{
|
||||||
return _usbh_controller != TU_INDEX_INVALID_8;
|
return _usbh_controller != TUSB_INDEX_INVALID_8;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool tuh_init(uint8_t controller_id)
|
bool tuh_init(uint8_t controller_id)
|
||||||
@ -1033,6 +1033,38 @@ bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
|||||||
return tuh_control_xfer(&xfer);
|
return tuh_control_xfer(&xfer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool tuh_interface_set(uint8_t daddr, uint8_t itf_num, uint8_t itf_alt,
|
||||||
|
tuh_xfer_cb_t complete_cb, uintptr_t user_data)
|
||||||
|
{
|
||||||
|
TU_LOG_USBH("Set Interface %u Alternate %u\r\n", itf_num, itf_alt);
|
||||||
|
|
||||||
|
tusb_control_request_t const request =
|
||||||
|
{
|
||||||
|
.bmRequestType_bit =
|
||||||
|
{
|
||||||
|
.recipient = TUSB_REQ_RCPT_DEVICE,
|
||||||
|
.type = TUSB_REQ_TYPE_STANDARD,
|
||||||
|
.direction = TUSB_DIR_OUT
|
||||||
|
},
|
||||||
|
.bRequest = TUSB_REQ_SET_INTERFACE,
|
||||||
|
.wValue = tu_htole16(itf_alt),
|
||||||
|
.wIndex = tu_htole16(itf_num),
|
||||||
|
.wLength = 0
|
||||||
|
};
|
||||||
|
|
||||||
|
tuh_xfer_t xfer =
|
||||||
|
{
|
||||||
|
.daddr = daddr,
|
||||||
|
.ep_addr = 0,
|
||||||
|
.setup = &request,
|
||||||
|
.buffer = NULL,
|
||||||
|
.complete_cb = complete_cb,
|
||||||
|
.user_data = user_data
|
||||||
|
};
|
||||||
|
|
||||||
|
return tuh_control_xfer(&xfer);
|
||||||
|
}
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Descriptor Sync
|
// Descriptor Sync
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
@ -1358,11 +1390,11 @@ static void process_enumeration(tuh_xfer_t* xfer)
|
|||||||
|
|
||||||
dev->configured = 1;
|
dev->configured = 1;
|
||||||
|
|
||||||
// Start the Set Configuration process for interfaces (itf = TU_INDEX_INVALID_8)
|
// Start the Set Configuration process for interfaces (itf = TUSB_INDEX_INVALID_8)
|
||||||
// Since driver can perform control transfer within its set_config, this is done asynchronously.
|
// Since driver can perform control transfer within its set_config, this is done asynchronously.
|
||||||
// The process continue with next interface when class driver complete its sequence with usbh_driver_set_config_complete()
|
// The process continue with next interface when class driver complete its sequence with usbh_driver_set_config_complete()
|
||||||
// TODO use separated API instead of using TU_INDEX_INVALID_8
|
// TODO use separated API instead of using TUSB_INDEX_INVALID_8
|
||||||
usbh_driver_set_config_complete(daddr, TU_INDEX_INVALID_8);
|
usbh_driver_set_config_complete(daddr, TUSB_INDEX_INVALID_8);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -1562,7 +1594,7 @@ static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configur
|
|||||||
uint8_t const itf_num = desc_itf->bInterfaceNumber+i;
|
uint8_t const itf_num = desc_itf->bInterfaceNumber+i;
|
||||||
|
|
||||||
// Interface number must not be used already
|
// Interface number must not be used already
|
||||||
TU_ASSERT( TU_INDEX_INVALID_8 == dev->itf2drv[itf_num] );
|
TU_ASSERT( TUSB_INDEX_INVALID_8 == dev->itf2drv[itf_num] );
|
||||||
dev->itf2drv[itf_num] = drv_id;
|
dev->itf2drv[itf_num] = drv_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1596,7 +1628,7 @@ void usbh_driver_set_config_complete(uint8_t dev_addr, uint8_t itf_num)
|
|||||||
// IAD binding interface such as CDCs should return itf_num + 1 when complete
|
// IAD binding interface such as CDCs should return itf_num + 1 when complete
|
||||||
// with usbh_driver_set_config_complete()
|
// with usbh_driver_set_config_complete()
|
||||||
uint8_t const drv_id = dev->itf2drv[itf_num];
|
uint8_t const drv_id = dev->itf2drv[itf_num];
|
||||||
if (drv_id != TU_INDEX_INVALID_8)
|
if (drv_id != TUSB_INDEX_INVALID_8)
|
||||||
{
|
{
|
||||||
usbh_class_driver_t const * driver = &usbh_class_drivers[drv_id];
|
usbh_class_driver_t const * driver = &usbh_class_drivers[drv_id];
|
||||||
TU_LOG_USBH("%s set config: itf = %u\r\n", driver->name, itf_num);
|
TU_LOG_USBH("%s set config: itf = %u\r\n", driver->name, itf_num);
|
||||||
|
@ -171,6 +171,11 @@ bool tuh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
|
|||||||
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
bool tuh_configuration_set(uint8_t daddr, uint8_t config_num,
|
||||||
tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||||
|
|
||||||
|
// Set Interface (control transfer)
|
||||||
|
// true on success, false if there is on-going control transfer or incorrect parameters
|
||||||
|
bool tuh_interface_set(uint8_t daddr, uint8_t itf_num, uint8_t itf_alt,
|
||||||
|
tuh_xfer_cb_t complete_cb, uintptr_t user_data);
|
||||||
|
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
// Descriptors Asynchronous (non-blocking)
|
// Descriptors Asynchronous (non-blocking)
|
||||||
//--------------------------------------------------------------------+
|
//--------------------------------------------------------------------+
|
||||||
|
Loading…
x
Reference in New Issue
Block a user