2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/*
 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  SPDX - FileCopyrightText :  2015 - 2024  Espressif  Systems  ( Shanghai )  CO  LTD 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  SPDX - License - Identifier :  Apache - 2.0 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# pragma once 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  <stdint.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  <sys/queue.h> 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "freertos/FreeRTOS.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "freertos/task.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "hcd.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "usb/usb_types_ch9.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# include  "usb/usb_types_stack.h" 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# ifdef __cplusplus 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								extern  " C "  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# endif 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// ------------------------------------------------------ Types --------------------------------------------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ----------------------- Handles -------------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Handle  of  a  allocated  endpoint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:53:27 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								typedef  struct  usbh_ep_handle_s  * usbh_ep_handle_t ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// ----------------------- Events --------------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Enumerator  for  various  USBH  events 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								typedef  enum  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:44:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EVENT_CTRL_XFER ,            /**< A control transfer has completed */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EVENT_NEW_DEV ,              /**< A new device has been enumerated and added to the device pool */ 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 18:28:04 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EVENT_DEV_GONE ,             /**< A device is gone. Clients should close the device */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 20:57:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EVENT_DEV_FREE ,             /**< A device has been freed. Its upstream port can now be recycled */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EVENT_ALL_FREE ,             /**< All devices have been freed */ 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_event_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Event  data  object  for  USBH  events 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    usbh_event_t  event ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    union  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:44:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            usb_device_handle_t  dev_hdl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            urb_t  * urb ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  ctrl_xfer_data ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            uint8_t  dev_addr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  new_dev_data ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            uint8_t  dev_addr ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            usb_device_handle_t  dev_hdl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								        }  dev_gone_data ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 20:57:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            unsigned  int  dev_uid ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								            usb_device_handle_t  parent_dev_hdl ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								            uint8_t  port_num ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-21 20:57:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								        }  dev_free_data ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    } ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_event_data_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 18:28:04 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Endpoint  events 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 18:28:04 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Optimization :  Keep  this  identical  to  hcd_pipe_event_t 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 18:28:04 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  enum  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_NONE ,                      /**< The EP has no events (used to indicate no events when polling) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_URB_DONE ,                  /**< The EP has completed a URB. The URB can be dequeued */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_ERROR_XFER ,                /**< The EP encountered excessive errors when transferring a URB i.e., three three consecutive transaction errors (e.g., no ACK, bad CRC etc) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_ERROR_URB_NOT_AVAIL ,       /**< The EP tried to execute a transfer but no URB was available */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_ERROR_OVERFLOW ,            /**< The EP received more data than requested. Usually a Packet babble error (i.e., an IN packet has exceeded the EP's MPS) */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_EVENT_ERROR_STALL ,               /**< EP received a STALL response */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_ep_event_t ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-14 18:28:04 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ------------------ Requests/Commands --------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Endpoint  commands 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ note  Optimization :  Keep  this  identical  to  hcd_pipe_cmd_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  enum  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_CMD_HALT ,            /**< Halt an active endpoint. Any currently executing URB will be canceled. Enqueued URBs are left untouched */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_CMD_FLUSH ,           /**< Can only be called when halted. Will cause all enqueued URBs to be canceled */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    USBH_EP_CMD_CLEAR ,           /**< Causes a halted endpoint to become active again. Any enqueued URBs will being executing.*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_ep_cmd_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// ---------------------- Callbacks ------------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Callback  used  to  indicate  that  the  USBH  has  an  event 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ note  This  callback  is  called  from  within  usbh_process ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-02-23 04:25:10 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								typedef  void  ( * usbh_event_cb_t ) ( usbh_event_data_t  * event_data ,  void  * arg ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Callback  used  to  indicate  an  event  on  an  endpoint 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Return  whether  to  yield  or  not  if  called  from  an  ISR .  Always  return  false  if  not  called  from  an  ISR 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  bool  ( * usbh_ep_cb_t ) ( usbh_ep_handle_t  ep_hdl ,  usbh_ep_event_t  ep_event ,  void  * arg ,  bool  in_isr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								// ----------------------- Objects -------------------------
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Configuration  for  an  endpoint  being  allocated  using  usbh_ep_alloc ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    uint8_t  bInterfaceNumber ;        /**< Interface number */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  bAlternateSetting ;       /**< Alternate setting number of the interface */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  bEndpointAddress ;        /**< Endpoint address */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    usbh_ep_cb_t  ep_cb ;              /**< Endpoint event callback */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    void  * ep_cb_arg ;                 /**< Endpoint callback argument */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    void  * context ;                   /**< Endpoint context */ 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_ep_config_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  USBH  configuration  used  in  usbh_install ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  struct  { 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								    usb_proc_req_cb_t  proc_req_cb ;           /**< Processing request callback */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    void  * proc_req_cb_arg ;                   /**< Processing request callback argument */ 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								    usbh_event_cb_t  event_cb ;                /**< USBH event callback */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    void  * event_cb_arg ;                      /**< USBH event callback argument */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_config_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  USBH  device  parameters  used  in  usbh_devs_add ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								*/ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								typedef  struct  { 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    unsigned  int  uid ;                        /**< Unique ID assigned to the device */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    usb_speed_t  speed ;                       /**< Device's speed */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    hcd_port_handle_t  root_port_hdl ;         /**< Handle of the port that the device is connected to */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    usb_device_handle_t  parent_dev_hdl ;      /**< Parent's device handle */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								    uint8_t  parent_port_num ;                 /**< Parent's port number */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								}  usbh_dev_params_t ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// ---------------------- USBH Processing Functions ----------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Installs  the  USBH  driver 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  This  function  will  internally  install  the  HCD 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  This  must  be  called  before  calling  any  Hub  driver  functions 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-18 02:07:53 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Before  calling  this  function ,  the  Host  Controller  must  already  be  un - clock  gated  and  reset .  The  USB  PHY 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *        ( internal  or  external ,  and  associated  GPIOs )  must  already  be  configured . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  usbh_config  USBH  driver  configuration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_install ( const  usbh_config_t  * usbh_config ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Uninstall  the  USBH  driver 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  This  function  will  uninstall  the  HCD 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  The  Hub  driver  must  be  uninstalled  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-11-18 02:07:53 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  will  simply  free  the  resources  used  by  the  USBH .  The  underlying  Host  Controller  and  USB  PHY  will 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *        not  be  disabled . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_uninstall ( void ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  USBH  processing  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  USBH  processing  function  that  must  be  called  repeatedly  to  process  USBH  events 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  If  blocking ,  the  caller  can  block  until  the  proc_req_cb ( )  is  called  with  USB_PROC_REQ_SOURCE_USBH  as  the  request 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *    source .  The  USB_PROC_REQ_SOURCE_USBH  source  indicates  that  this  function  should  be  called . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-27 21:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  can  block 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_process ( void ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ---------------------- Device Pool Functions --------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:46:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  the  current  number  of  devices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  can  block 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  num_devs_ret  Current  number  of  devices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_num ( int  * num_devs_ret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-12-08 19:46:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-10-28 00:54:27 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Fill  list  with  address  of  currently  connected  devices 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  This  function  fills  the  provided  list  with  the  address  of  current  connected  devices 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  Device  address  can  then  be  used  in  usbh_devs_open ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-28 00:54:27 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  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  empty  list 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ inout ]  dev_addr_list  Empty  list  to  be  filled 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  num_dev_ret  Number  of  devices  filled  into  list 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_addr_list_fill ( int  list_len ,  uint8_t  * dev_addr_list ,  int  * num_dev_ret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-28 00:54:27 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Create  a  device  and  add  it  to  the  device  pool 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  created  device  will  not  be  enumerated  where  the  device ' s  address  is  0 , 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  device  and  config  descriptor  are  NULL .  The  device  will  still  have  a  default 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  pipe ,  thus  allowing  control  transfers  to  be  submitted . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  Call  usbh_devs_open ( )  before  communicating  with  the  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  Call  usbh_dev_enum_lock ( )  before  enumerating  the  device  via  the  various 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  usbh_dev_set_ . . . ( )  functions . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  params    Device  parameters ,  using  for  device  creation 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_add ( usbh_dev_params_t  * params ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Indicates  to  the  USBH  that  a  device  is  gone 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  uid  Unique  ID  assigned  to  the  device  on  creation  ( see  ' usbh_devs_add ( ) ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_remove ( unsigned  int  uid ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  a  device ' s  connection  information 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ note  Can  be  called  without  opening  the  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  uid                Unique  ID  assigned  to  the  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  parent_info       Parent  device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  port_num          Parent  port  number 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_get_parent_info ( unsigned  int  uid ,  usb_parent_dev_info_t  * parent_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Mark  that  all  devices  should  be  freed  at  the  next  possible  opportunity 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  A  device  marked  as  free  will  not  be  freed  until  the  last  client  using  the  device  has  called  usbh_devs_close ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *   -  ESP_OK :  There  were  no  devices  to  free  to  begin  with .  Current  state  is  all  free 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *   -  ESP_ERR_NOT_FINISHED :  One  or  more  devices  still  need  to  be  freed  ( but  have  been  marked  " to be freed " ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_mark_all_free ( void ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Open  a  device  by  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  A  device  must  be  opened  before  it  can  be  used 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_addr  Device  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_open ( uint8_t  dev_addr ,  usb_device_handle_t  * dev_hdl ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Trigger  a  USBH_EVENT_NEW_DEV  event  for  the  device 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  This  is  typically  called  after  a  device  has  been  fully  enumerated . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_devs_new_dev_event ( usb_device_handle_t  dev_hdl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								// ------------------------ Device Functions -----------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Close  a  device 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_close ( usb_device_handle_t  dev_hdl ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ------------------------------ Getters --------------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  a  device ' s  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  dev_addr  Device ' s  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_get_addr ( usb_device_handle_t  dev_hdl ,  uint8_t  * dev_addr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  a  device ' s  information 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  It  is  possible  that  the  device  has  not  been  enumerated  yet ,  thus  some 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  fields  may  be  NULL . 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  dev_info  Device  information 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_get_info ( usb_device_handle_t  dev_hdl ,  usb_device_info_t  * dev_info ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  a  device ' s  device  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  The  device  descriptor  is  cached  when  the  device  is  created  by  the  Hub  driver 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  It  is  possible  that  the  device  has  not  been  enumerated  yet ,  thus  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  device  descriptor  could  be  NULL . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  dev_desc_ret  Device  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_get_desc ( usb_device_handle_t  dev_hdl ,  const  usb_device_desc_t  * * dev_desc_ret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  a  device ' s  active  configuration  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  Simply  returns  a  reference  to  the  internally  cached  configuration  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  It  is  possible  that  the  device  has  not  been  enumerated  yet ,  thus  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  configuration  descriptor  could  be  NULL . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param  config_desc_ret 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_get_config_desc ( usb_device_handle_t  dev_hdl ,  const  usb_config_desc_t  * * config_desc_ret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ------------------------------- Setters -------------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Lock  a  device  for  enumeration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  A  device ' s  enumeration  lock  must  be  set  before  any  of  its  enumeration  fields 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( e . g . ,  address ,  device / config  descriptors )  can  be  set / updated . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  The  caller  must  be  the  sole  opener  of  the  device  ( see  ' usbh_devs_open ( ) ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  when  locking  the  device  for  enumeration . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_enum_lock ( usb_device_handle_t  dev_hdl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Release  a  device ' s  enumeration  lock 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_enum_unlock ( usb_device_handle_t  dev_hdl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Set  the  maximum  packet  size  of  EP0  for  a  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Typically  called  during  enumeration  after  obtaining  the  first  8  bytes  of  the 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  device ' s  descriptor . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  The  device ' s  enumeration  lock  must  be  set  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( see  ' usbh_dev_enum_lock ( ) ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  wMaxPacketSize  Maximum  packet  size 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_set_ep0_mps ( usb_device_handle_t  dev_hdl ,  uint16_t  wMaxPacketSize ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Set  a  device ' s  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Typically  called  during  enumeration  after  a  SET_ADDRESS  request  has  been 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  sent  to  the  device . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  The  device ' s  enumeration  lock  must  be  set  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( see  ' usbh_dev_enum_lock ( ) ' ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_addr  Device  address  to  set 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_set_addr ( usb_device_handle_t  dev_hdl ,  uint8_t  dev_addr ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Set  a  device ' s  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Typically  called  during  enumeration  after  obtaining  the  device ' s  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  via  a  GET_DESCRIPTOR  request . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  The  device ' s  enumeration  lock  must  be  set  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( see  ' usbh_dev_enum_lock ( ) ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  device_desc  Device  descriptor  to  copy 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_set_desc ( usb_device_handle_t  dev_hdl ,  const  usb_device_desc_t  * device_desc ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Set  a  device ' s  configuration  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Typically  called  during  enumeration  after  obtaining  the  device ' s  configuration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  descriptor  via  a  GET_DESCRIPTOR  request . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  The  device ' s  enumeration  lock  must  be  set  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( see  ' usbh_dev_enum_lock ( ) ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  config_desc_full  Configuration  descriptor  to  copy 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_set_config_desc ( usb_device_handle_t  dev_hdl ,  const  usb_config_desc_t  * config_desc_full ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Set  a  device ' s  string  descriptor 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Typically  called  during  enumeration  after  obtaining  one  of  the  device ' s  string 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  descriptor  via  a  GET_DESCRIPTOR  request . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Callers  of  this  function  must  have  opened  the  device  via  usbh_devs_open ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  The  device ' s  enumeration  lock  must  be  set  before  calling  this  function 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  ( see  ' usbh_dev_enum_lock ( ) ' ) 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-10 05:06:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  str_desc  String  descriptor  to  copy 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  select  Select  string  descriptor .  0 / 1 / 2  for  Manufacturer / Product / Serial 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  Number  string  descriptors  respectively 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_set_str_desc ( usb_device_handle_t  dev_hdl ,  const  usb_str_desc_t  * str_desc ,  int  select ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ----------------------- Endpoint Functions ----------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Allocate  an  endpoint  on  a  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  This  function  allows  clients  to  allocate  a  non - default  endpoint  ( i . e . ,  not  EP0 )  on  a  connected  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-04-03 11:24:03 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  A  client  must  have  opened  the  device  using  usbh_devs_open ( )  before  attempting  to  allocate  an  endpoint  on  the  device 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  -  A  client  should  call  this  function  to  allocate  all  endpoints  in  an  interface  that  the  client  has  claimed . 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  A  client  must  allocate  an  endpoint  using  this  function  before  attempting  to  communicate  with  it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  Once  the  client  allocates  an  endpoint ,  the  client  is  now  owns / manages  the  endpoint .  No  other  client  should  use  or 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-08 23:12:25 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  deallocate  the  endpoint . 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-27 21:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  can  block 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  Default  endpoints  ( EP0 )  are  owned  by  the  USBH .  For  control  transfers ,  use  usbh_dev_submit_ctrl_urb ( )  instead 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_config  Endpoint  configuration 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  ep_hdl_ret  Endpoint  handle 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_alloc ( usb_device_handle_t  dev_hdl ,  usbh_ep_config_t  * ep_config ,  usbh_ep_handle_t  * ep_hdl_ret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Free  and  endpoint  on  a  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  This  function  frees  an  endpoint  previously  allocated  by  the  client  using  usbh_ep_alloc ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  Only  the  client  that  allocated  the  endpoint  should  free  it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  The  client  must  have  halted  and  flushed  the  endpoint  using  usbh_ep_command ( )  before  attempting  to  free  it 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  -  The  client  must  ensure  that  there  are  no  more  function  calls  to  the  endpoint  before  freeing  it 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-10-27 21:15:46 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  can  block 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_hdl  Endpoint  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_free ( usbh_ep_handle_t  ep_hdl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  the  handle  of  an  endpoint  using  its  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  The  endpoint  must  have  been  previously  allocated  using  usbh_ep_alloc ( ) 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  bEndpointAddress  Endpoint  address 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  ep_hdl_ret  Endpoint  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_get_handle ( usb_device_handle_t  dev_hdl ,  uint8_t  bEndpointAddress ,  usbh_ep_handle_t  * ep_hdl_ret ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Execute  a  command  on  a  particular  endpoint 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Endpoint  commands  allows  executing  a  certain  action  on  an  endpoint  ( e . g . ,  halting ,  flushing ,  clearing  etc ) 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_hdl  Endpoint  handle 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  command  Endpoint  command 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_command ( usbh_ep_handle_t  ep_hdl ,  usbh_ep_cmd_t  command ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Get  the  context  of  an  endpoint 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Get  the  context  variable  assigned  to  and  endpoint  on  allocation . 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ note  This  function  can  block 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_hdl  Endpoint  handle 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  Endpoint  context 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								void  * usbh_ep_get_context ( usbh_ep_handle_t  ep_hdl ) ; 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-03-28 11:07:34 +01:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								// ------------------------- Transfer Functions --------------------------------
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ brief  Submit  a  control  transfer  ( URB )  to  a  device 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  dev_hdl  Device  handle 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  urb  URB 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_dev_submit_ctrl_urb ( usb_device_handle_t  dev_hdl ,  urb_t  * urb ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Enqueue  a  URB  to  an  endpoint 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  The  URB  will  remain  enqueued  until  it  completes  ( successfully  or  errors  out ) .  Use  usbh_ep_dequeue_urb ( )  to  dequeue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  a  completed  URB . 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_hdl  Endpoint  handle 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  urb  URB  to  enqueue 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_enqueue_urb ( usbh_ep_handle_t  ep_hdl ,  urb_t  * urb ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								/**
 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ brief  Dequeue  a  URB  from  an  endpoint 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  Dequeue  a  completed  URB  from  an  endpoint .  The  USBH_EP_EVENT_URB_DONE  indicates  that  URBs  can  be  dequeued 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 * 
							 
						 
					
						
							
								
									
										
										
										
											2023-05-09 00:43:32 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ in ]  ep_hdl  Endpoint  handle 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								 *  @ param [ out ]  urb_ret  Dequeued  URB ,  or  NULL  if  no  more  URBs  to  dequeue 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								 *  @ return  esp_err_t 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								 */ 
							 
						 
					
						
							
								
									
										
										
										
											2024-03-29 21:29:01 +08:00 
										
									 
								 
							 
							
								
									
										 
									 
								
							 
							
								 
							 
							
							
								esp_err_t  usbh_ep_dequeue_urb ( usbh_ep_handle_t  ep_hdl ,  urb_t  * * urb_ret ) ; 
							 
						 
					
						
							
								
									
										
										
										
											2021-08-24 23:20:50 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# ifdef __cplusplus 
 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								} 
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							 
							
							
								# endif