usb: Update USB Host Library
This commit updates the USB Host Library as follows:
- usb_helpers.h
- Removed dependency on USB Host Library API
- Added function to print string descriptors
- usbh
- Fixed bug where an interface/endpoint could be claimed/allocated multiple times
- Removed redundant device ref_count change
- Added unit test for USB Host Library API usage
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* SPDX-FileCopyrightText: 2015-2021 Espressif Systems (Shanghai) CO LTD
|
||||
* SPDX-FileCopyrightText: 2015-2022 Espressif Systems (Shanghai) CO LTD
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
@@ -111,6 +111,44 @@ const usb_ep_desc_t *usb_parse_endpoint_descriptor_by_index(const usb_intf_desc_
|
||||
*/
|
||||
const usb_ep_desc_t *usb_parse_endpoint_descriptor_by_address(const usb_config_desc_t *config_desc, uint8_t bInterfaceNumber, uint8_t bAlternateSetting, uint8_t bEndpointAddress, int *offset);
|
||||
|
||||
// ----------------------------------------------- Descriptor Printing -------------------------------------------------
|
||||
|
||||
/**
|
||||
* @brief Print class specific descriptor callback
|
||||
*
|
||||
* Optional callback to be provided to usb_print_config_descriptor() function.
|
||||
* The callback is called when when a non-standard descriptor is encountered.
|
||||
* The callback should decode the descriptor as print it.
|
||||
*/
|
||||
typedef void (*print_class_descriptor_cb)(const usb_standard_desc_t *);
|
||||
|
||||
/**
|
||||
* @brief Print device descriptor
|
||||
*
|
||||
* @param devc_desc Device descriptor
|
||||
*/
|
||||
void usb_print_device_descriptor(const usb_device_desc_t *devc_desc);
|
||||
|
||||
/**
|
||||
* @brief Print configuration descriptor
|
||||
*
|
||||
* - This function prints the full contents of a configuration descriptor (including interface and endpoint descriptors)
|
||||
* - When a non-standard descriptor is encountered, this function will call the class_specific_cb if it is provided
|
||||
*
|
||||
* @param cfg_desc Configuration descriptor
|
||||
* @param class_specific_cb Class specific descriptor callback. Can be NULL
|
||||
*/
|
||||
void usb_print_config_descriptor(const usb_config_desc_t *cfg_desc, print_class_descriptor_cb class_specific_cb);
|
||||
|
||||
/**
|
||||
* @brief Print a string descriptor
|
||||
*
|
||||
* This funciton will only print ASCII characters of the UTF-16 encoded string
|
||||
*
|
||||
* @param str_desc String descriptor
|
||||
*/
|
||||
void usb_print_string_descriptor(const usb_str_desc_t *str_desc);
|
||||
|
||||
// ------------------------------------------------------ Misc ---------------------------------------------------------
|
||||
|
||||
/**
|
||||
@@ -118,6 +156,8 @@ const usb_ep_desc_t *usb_parse_endpoint_descriptor_by_address(const usb_config_d
|
||||
*
|
||||
* This is a convenience function to round up a size/length to an endpoint's MPS (Maximum packet size). This is useful
|
||||
* when calculating transfer or buffer lengths of IN endpoints.
|
||||
* - If MPS <= 0, this function will return 0
|
||||
* - If num_bytes <= 0, this function will return 0
|
||||
*
|
||||
* @param[in] num_bytes Number of bytes
|
||||
* @param[in] mps MPS
|
||||
@@ -125,31 +165,12 @@ const usb_ep_desc_t *usb_parse_endpoint_descriptor_by_address(const usb_config_d
|
||||
*/
|
||||
static inline int usb_round_up_to_mps(int num_bytes, int mps)
|
||||
{
|
||||
if (num_bytes < 0 || mps < 0) {
|
||||
if (num_bytes <= 0 || mps <= 0) { //MPS can never be zero
|
||||
return 0;
|
||||
}
|
||||
return ((num_bytes + mps - 1) / mps) * mps;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Print class specific descriptor callback
|
||||
*
|
||||
* Optional callback to be provided to usb_print_descriptors() function.
|
||||
* The callback is called when when a non-standard descriptor is encountered.
|
||||
* The callback should decode the descriptor as print it.
|
||||
*/
|
||||
|
||||
typedef void (*print_class_descriptor_cb)(const usb_standard_desc_t *);
|
||||
|
||||
/**
|
||||
* @brief Prints usb descriptors
|
||||
*
|
||||
* @param[in] device Handle to device
|
||||
* @param[in] class_specific_cb Optional callback to print class specific descriptors
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t usb_print_descriptors(usb_device_handle_t device, print_class_descriptor_cb class_specific_cb);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -148,7 +148,7 @@ esp_err_t usb_host_install(const usb_host_config_t *config);
|
||||
* - All devices must have been freed by calling usb_host_device_free_all() and receiving the
|
||||
* USB_HOST_LIB_EVENT_FLAGS_ALL_FREE event flag
|
||||
*
|
||||
* @note If skip_phy_setup was set when the Host Library was installed, the user is responsible for diasbling the
|
||||
* @note If skip_phy_setup was set when the Host Library was installed, the user is responsible for disabling the
|
||||
* underlying Host Controller and USB PHY (internal or external).
|
||||
* @return esp_err_t
|
||||
*/
|
||||
@@ -159,10 +159,11 @@ esp_err_t usb_host_uninstall(void);
|
||||
*
|
||||
* - This function handles all of the USB Host Library's processing and should be called repeatedly in a loop
|
||||
* - Check event_flags_ret to see if an flags are set indicating particular USB Host Library events
|
||||
* - This function should never be called by multiple threads simultaneously
|
||||
*
|
||||
* @note This function can block
|
||||
* @param[in] timeout_ticks Timeout in ticks to wait for an event to occur
|
||||
* @param[out] event_flags_ret Event flags that indicate what USB Host Library event occurred
|
||||
* @param[out] event_flags_ret Event flags that indicate what USB Host Library event occurred.
|
||||
* @return esp_err_t
|
||||
*/
|
||||
esp_err_t usb_host_lib_handle_events(TickType_t timeout_ticks, uint32_t *event_flags_ret);
|
||||
@@ -213,6 +214,7 @@ esp_err_t usb_host_client_deregister(usb_host_client_handle_t client_hdl);
|
||||
* @brief USB Host Library client processing function
|
||||
*
|
||||
* - This function handles all of a client's processing and should be called repeatedly in a loop
|
||||
* - For a particular client, this function should never be called by multiple threads simultaneously
|
||||
*
|
||||
* @note This function can block
|
||||
* @param[in] client_hdl Client handle
|
||||
@@ -283,8 +285,7 @@ esp_err_t usb_host_device_free_all(void);
|
||||
*
|
||||
* - This function fills an empty list with the address of connected devices
|
||||
* - The Device addresses can then used in usb_host_device_open()
|
||||
* - If there are more devices than the list_len, this function will only fill
|
||||
* up to list_len number of devices.
|
||||
* - If there are more devices than the list_len, this function will only fill up to list_len number of devices.
|
||||
*
|
||||
* @param[in] list_len Length of the empty list
|
||||
* @param[inout] dev_addr_list Empty list to be filled
|
||||
|
||||
Reference in New Issue
Block a user