add parse config descriptor to example

move usbh_edpt_open() to public API, remove rhport from its signature
This commit is contained in:
hathach
2022-03-19 00:43:31 +07:00
parent ba1185bf28
commit 4795cca04a
11 changed files with 180 additions and 46 deletions
+3 -1
View File
@@ -183,6 +183,8 @@ void hub_init(void)
bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf_desc, uint16_t max_len)
{
(void) rhport;
TU_VERIFY(TUSB_CLASS_HUB == itf_desc->bInterfaceClass &&
0 == itf_desc->bInterfaceSubClass);
@@ -199,7 +201,7 @@ bool hub_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_interface_t const *itf
TU_ASSERT(TUSB_DESC_ENDPOINT == desc_ep->bDescriptorType &&
TUSB_XFER_INTERRUPT == desc_ep->bmAttributes.xfer, 0);
TU_ASSERT(usbh_edpt_open(rhport, dev_addr, desc_ep));
TU_ASSERT(usbh_edpt_open(dev_addr, desc_ep));
hub_interface_t* p_hub = get_itf(dev_addr);
+6 -5
View File
@@ -806,10 +806,11 @@ static bool usbh_edpt_control_open(uint8_t dev_addr, uint8_t max_packet_size)
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, &ep0_desc);
}
bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
bool usbh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep)
{
TU_ASSERT( tu_edpt_validate(desc_ep, tuh_speed_get(dev_addr)) );
return hcd_edpt_open(rhport, dev_addr, desc_ep);
return hcd_edpt_open(usbh_get_rhport(dev_addr), dev_addr, desc_ep);
}
bool usbh_edpt_busy(uint8_t dev_addr, uint8_t ep_addr)
@@ -1189,7 +1190,7 @@ enum {
};
static bool enum_request_set_addr(void);
static bool parse_configuration_descriptor (uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg);
static bool _parse_configuration_descriptor (uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg);
static void enum_full_complete(void);
// process device enumeration
@@ -1350,7 +1351,7 @@ static void process_enumeration(tuh_xfer_t* xfer)
case ENUM_SET_CONFIG:
// Parse configuration & set up drivers
// Driver open aren't allowed to make any usb transfer yet
TU_ASSERT( parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
TU_ASSERT( _parse_configuration_descriptor(daddr, (tusb_desc_configuration_t*) _usbh_ctrl_buf), );
TU_ASSERT( tuh_configuration_set(daddr, CONFIG_NUM, process_enumeration, ENUM_CONFIG_DRIVER), );
break;
@@ -1496,7 +1497,7 @@ static bool enum_request_set_addr(void)
return true;
}
static bool parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg)
static bool _parse_configuration_descriptor(uint8_t dev_addr, tusb_desc_configuration_t const* desc_cfg)
{
usbh_device_t* dev = get_device(dev_addr);
+10 -4
View File
@@ -44,8 +44,10 @@ typedef struct tuh_xfer_s tuh_xfer_t;
typedef void (*tuh_xfer_cb_t)(tuh_xfer_t* xfer);
// Note: layout and order of this will be changed in near future
// Note1: layout and order of this will be changed in near future
// it is advised to initialize it using member name
// Note2: not all field is available/meaningful in callback, some info is not saved by
// usbh to save SRAM
struct tuh_xfer_s
{
uint8_t daddr;
@@ -124,14 +126,18 @@ static inline bool tuh_ready(uint8_t daddr)
//--------------------------------------------------------------------+
// Submit a control transfer
// Note: blocking if complete callback is NULL, in this case xfer contents will be updated to reflect the result
// - async: complete callback invoked when finished.
// - sync : blocking if complete callback is NULL.
bool tuh_control_xfer(tuh_xfer_t* xfer);
// Submit a bulk/interrupt transfer
// xfer memory must exist until transfer is complete.
// Note: blocking if complete callback is NULL.
// - async: complete callback invoked when finished.
// - sync : blocking if complete callback is NULL.
bool tuh_edpt_xfer(tuh_xfer_t* xfer);
// Open an endpoint
bool usbh_edpt_open(uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
// Set Configuration (control transfer)
// config_num = 0 will un-configure device. Note: config_num = config_descriptor_index + 1
// true on success, false if there is on-going control transfer or incorrect parameters
-3
View File
@@ -63,9 +63,6 @@ void usbh_int_set(bool enabled);
// USBH Endpoint API
//--------------------------------------------------------------------+
// Open an endpoint
bool usbh_edpt_open(uint8_t rhport, uint8_t dev_addr, tusb_desc_endpoint_t const * desc_ep);
// Submit a usb transfer with callback support, require CFG_TUH_API_EDPT_XFER
bool usbh_edpt_xfer_with_callback(uint8_t dev_addr, uint8_t ep_addr, uint8_t * buffer, uint16_t total_bytes,
tuh_xfer_cb_t complete_cb, uintptr_t user_data);