VSF Documented
usb_host.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2026 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18/*
19 * Clean-room re-implementation of ESP-IDF public API "usb/usb_host.h".
20 *
21 * Authored from ESP-IDF v5.x public API reference only. No code copied from
22 * the ESP-IDF source tree.
23 *
24 * Standard USB descriptor types (usb_device_desc_t etc.) are obtained from
25 * VSF's usb_common.h via a conditional include so that types never duplicate
26 * regardless of which headers the application pulls in first.
27 */
28
29#ifndef __VSF_ESPIDF_USB_HOST_H__
30#define __VSF_ESPIDF_USB_HOST_H__
31
32/*============================ INCLUDES ======================================*/
33
34#include <stdint.h>
35#include <stdbool.h>
36#include <stddef.h>
37
38#include "esp_err.h"
39
40#include "FreeRTOS.h"
41#include "task.h"
42
44
46
47/* usb_str_desc_t is not in VSF's usb_common.h -- define it here. */
48#ifndef __vsf_espidf_usb_str_desc_t
49# define __vsf_espidf_usb_str_desc_t
50 typedef struct {
53 uint8_t bString[];
54 } VSF_CAL_PACKED usb_str_desc_t;
55#endif
56
57#ifdef __cplusplus
58extern "C" {
59#endif
60
61/*============================ TYPES =========================================*/
62
63/* Opaque handles */
65typedef void * usb_device_handle_t;
66
67/* USB Host Library configuration (ESP-IDF v5.x layout) */
68typedef struct {
71 bool (*enum_filter_cb)(const usb_device_desc_t *dev_desc,
72 uint8_t *bConfigurationValue);
75
76/* Client event types */
77typedef enum {
81
82/* Client event message */
85 union {
86 struct {
89 struct {
92 };
94
95/* Client event callback type */
97 const usb_host_client_event_msg_t *event_msg, void *arg);
98
99/* USB Host Client configuration */
100typedef struct {
103 union {
104 struct {
107 } async;
108 };
110
111/* Device information */
112typedef struct {
115 int speed;
116 struct {
119 } parent;
120 const usb_str_desc_t *str_desc_manufacturer;
121 const usb_str_desc_t *str_desc_product;
122 const usb_str_desc_t *str_desc_serial_number;
124
125/* USB transfer status codes */
126typedef enum {
136
137/* USB transfer type */
138typedef enum {
144
145/* ISO packet descriptor */
146typedef struct {
152
153/* Forward declaration */
154struct usb_transfer_s;
155
156/* Transfer completion callback */
157typedef void (*usb_transfer_cb_t)(struct usb_transfer_s *transfer);
158
159/* USB Transfer structure */
160typedef struct usb_transfer_s {
172 void *context;
177 void *reserved[4];
179
180/* Library info */
181typedef struct {
185
186/* Library event flags */
187#define USB_HOST_LIB_EVENT_FLAGS_NO_CLIENTS (1 << 0)
188#define USB_HOST_LIB_EVENT_FLAGS_ALL_FREE (1 << 1)
189
190/* Transfer flags */
191#define USB_TRANSFER_FLAG_ZERO_PACK (1 << 0)
192
193/* USB setup packet (8 bytes, USB 2.0 standard) */
194typedef struct {
200} VSF_CAL_PACKED usb_setup_packet_t;
201
202/*============================ PROTOTYPES ====================================*/
203
207 uint32_t *event_flags_ret);
211 usb_host_client_handle_t *client_hdl_ret);
214 TickType_t timeout_ticks);
217 uint8_t dev_addr,
218 usb_device_handle_t *dev_hdl_ret);
220 usb_device_handle_t dev_hdl);
224 const usb_device_desc_t **dev_desc_ret);
226 const usb_config_desc_t **config_desc_ret);
228void usb_print_config_descriptor(const usb_config_desc_t *config_desc,
229 const usb_interface_desc_t *ifc_desc);
230void usb_print_string_descriptor(const usb_str_desc_t *str_desc);
231esp_err_t usb_host_transfer_alloc(size_t data_buffer_size,
232 int num_isoc_packets,
233 usb_transfer_t **transfer_ret);
237 usb_device_handle_t dev_hdl,
238 const usb_setup_packet_t *setup_packet,
239 usb_transfer_t *transfer);
241 usb_device_handle_t dev_hdl,
242 uint8_t bInterfaceNumber,
243 uint8_t bAlternateSetting);
245 usb_device_handle_t dev_hdl,
246 uint8_t bInterfaceNumber);
248 uint8_t bEndpointAddress);
250 uint8_t bEndpointAddress);
251
252#ifdef __cplusplus
253}
254#endif
255
256#endif // __VSF_ESPIDF_USB_HOST_H__
bool
Definition type.h:60
int esp_err_t
Definition esp_err.h:41
uint32_t TickType_t
Definition rtos_al.h:59
#define dev_info(__dev, __fmt,...)
Definition device.h:78
unsigned short uint16_t
Definition stdint.h:7
unsigned uint32_t
Definition stdint.h:9
unsigned char uint8_t
Definition stdint.h:5
Definition usb_host.h:50
uint8_t bDescriptorType
Definition usb_host.h:52
uint8_t bLength
Definition usb_host.h:51
uint8_t bRequest
Definition usb_host.h:196
uint8_t bmRequestType
Definition usb_host.h:195
uint16_t wIndex
Definition usb_host.h:198
uint16_t wValue
Definition usb_host.h:197
uint16_t wLength
Definition usb_host.h:199
Definition usb_common.h:253
Definition usb_common.h:235
Definition usb_host.h:112
const usb_str_desc_t * str_desc_serial_number
Definition usb_host.h:122
uint8_t port_num
Definition usb_host.h:118
const usb_str_desc_t * str_desc_manufacturer
Definition usb_host.h:120
uint8_t dev_addr
Definition usb_host.h:113
usb_device_handle_t dev_hdl
Definition usb_host.h:117
const usb_str_desc_t * str_desc_product
Definition usb_host.h:121
int speed
Definition usb_host.h:115
uint8_t bConfigurationValue
Definition usb_host.h:114
Definition usb_host.h:100
void * callback_arg
Definition usb_host.h:106
usb_host_client_event_cb_t client_event_callback
Definition usb_host.h:105
bool is_synchronous
Definition usb_host.h:101
int max_num_event_msg
Definition usb_host.h:102
Definition usb_host.h:83
usb_host_client_event_t event
Definition usb_host.h:84
uint8_t address
Definition usb_host.h:87
struct usb_host_client_event_msg::@1107::@1110 dev_gone
usb_device_handle_t dev_hdl
Definition usb_host.h:90
struct usb_host_client_event_msg::@1107::@1109 new_dev
Definition usb_host.h:68
int intr_flags
Definition usb_host.h:70
bool skip_phy_setup
Definition usb_host.h:69
uint32_t peripheral_map
Definition usb_host.h:73
Definition usb_host.h:181
int num_clients
Definition usb_host.h:183
int num_devices
Definition usb_host.h:182
Definition usb_common.h:281
Definition usb_host.h:146
usb_transfer_status_t status
Definition usb_host.h:150
uint32_t actual_length
Definition usb_host.h:149
uint32_t offset
Definition usb_host.h:147
uint32_t length
Definition usb_host.h:148
Definition usb_host.h:160
usb_transfer_cb_t callback
Definition usb_host.h:171
uint8_t bEndpointAddress
Definition usb_host.h:162
int num_bytes
Definition usb_host.h:166
uint32_t timeout_ms
Definition usb_host.h:169
usb_transfer_type_t type
Definition usb_host.h:163
int actual_num_bytes
Definition usb_host.h:167
uint32_t flags
Definition usb_host.h:168
uint8_t * data_buffer
Definition usb_host.h:175
usb_transfer_status_t status
Definition usb_host.h:170
usb_isoc_packet_desc_t * isoc_packet_desc
Definition usb_host.h:174
void * context
Definition usb_host.h:172
uint16_t wMaxPacketSize
Definition usb_host.h:165
uint8_t bmAttributes
Definition usb_host.h:164
void * reserved[4]
Definition usb_host.h:177
usb_device_handle_t device_handle
Definition usb_host.h:161
int num_isoc_packets
Definition usb_host.h:173
uint32_t data_buffer_size
Definition usb_host.h:176
esp_err_t usb_host_get_active_config_descriptor(usb_device_handle_t dev_hdl, const usb_config_desc_t **config_desc_ret)
Definition usb_host_port.c:573
esp_err_t usb_host_get_device_descriptor(usb_device_handle_t dev_hdl, const usb_device_desc_t **dev_desc_ret)
Definition usb_host_port.c:558
void(* usb_transfer_cb_t)(struct usb_transfer_s *transfer)
Definition usb_host.h:157
esp_err_t usb_host_client_deregister(usb_host_client_handle_t client_hdl)
Definition usb_host_port.c:437
void * usb_device_handle_t
Definition usb_host.h:65
esp_err_t usb_host_lib_info(usb_host_lib_info_t *lib_info_ret)
Definition usb_host_port.c:382
void usb_print_config_descriptor(const usb_config_desc_t *config_desc, const usb_interface_desc_t *ifc_desc)
Definition usb_host_port.c:597
esp_err_t usb_host_endpoint_flush(usb_device_handle_t dev_hdl, uint8_t bEndpointAddress)
Definition usb_host_port.c:758
usb_host_client_event_t
Definition usb_host.h:77
@ USB_HOST_CLIENT_EVENT_NEW_DEV
Definition usb_host.h:78
@ USB_HOST_CLIENT_EVENT_DEV_GONE
Definition usb_host.h:79
void usb_print_device_descriptor(const usb_device_desc_t *dev_desc)
Definition usb_host_port.c:588
esp_err_t usb_host_client_handle_events(usb_host_client_handle_t client_hdl, TickType_t timeout_ticks)
Definition usb_host_port.c:464
esp_err_t usb_host_client_unblock(usb_host_client_handle_t client_hdl)
Definition usb_host_port.c:483
void(* usb_host_client_event_cb_t)(const usb_host_client_event_msg_t *event_msg, void *arg)
Definition usb_host.h:96
esp_err_t usb_host_lib_handle_events(TickType_t timeout_ticks, uint32_t *event_flags_ret)
Definition usb_host_port.c:368
esp_err_t usb_host_device_free_all(void)
Definition usb_host_port.c:394
void usb_print_string_descriptor(const usb_str_desc_t *str_desc)
Definition usb_host_port.c:607
usb_transfer_type_t
Definition usb_host.h:138
@ USB_TRANSFER_TYPE_BULK
Definition usb_host.h:141
@ USB_TRANSFER_TYPE_ISOCHRONOUS
Definition usb_host.h:140
@ USB_TRANSFER_TYPE_INTR
Definition usb_host.h:142
@ USB_TRANSFER_TYPE_CTRL
Definition usb_host.h:139
esp_err_t usb_host_endpoint_halt(usb_device_handle_t dev_hdl, uint8_t bEndpointAddress)
Definition usb_host_port.c:748
esp_err_t usb_host_uninstall(void)
Definition usb_host_port.c:331
esp_err_t usb_host_device_info(usb_device_handle_t dev_hdl, usb_device_info_t *dev_info)
Definition usb_host_port.c:526
esp_err_t usb_host_device_open(usb_host_client_handle_t client_hdl, uint8_t dev_addr, usb_device_handle_t *dev_hdl_ret)
Definition usb_host_port.c:493
esp_err_t usb_host_client_register(const usb_host_client_config_t *client_config, usb_host_client_handle_t *client_hdl_ret)
Definition usb_host_port.c:407
usb_transfer_status_t
Definition usb_host.h:126
@ USB_TRANSFER_STATUS_SKIPPED
Definition usb_host.h:134
@ USB_TRANSFER_STATUS_OVERFLOW
Definition usb_host.h:132
@ USB_TRANSFER_STATUS_NO_DEVICE
Definition usb_host.h:133
@ USB_TRANSFER_STATUS_ERROR
Definition usb_host.h:128
@ USB_TRANSFER_STATUS_STALL
Definition usb_host.h:131
@ USB_TRANSFER_STATUS_COMPLETED
Definition usb_host.h:127
@ USB_TRANSFER_STATUS_TIMED_OUT
Definition usb_host.h:129
@ USB_TRANSFER_STATUS_CANCELED
Definition usb_host.h:130
esp_err_t usb_host_install(const usb_host_config_t *config)
Definition usb_host_port.c:283
esp_err_t usb_host_interface_release(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl, uint8_t bInterfaceNumber)
Definition usb_host_port.c:744
esp_err_t usb_host_transfer_alloc(size_t data_buffer_size, int num_isoc_packets, usb_transfer_t **transfer_ret)
Definition usb_host_port.c:613
void * usb_host_client_handle_t
Definition usb_host.h:64
struct usb_host_client_event_msg usb_host_client_event_msg_t
esp_err_t usb_host_device_close(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl)
Definition usb_host_port.c:510
esp_err_t usb_host_interface_claim(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl, uint8_t bInterfaceNumber, uint8_t bAlternateSetting)
Definition usb_host_port.c:739
esp_err_t usb_host_transfer_submit(usb_transfer_t *transfer)
Definition usb_host_port.c:647
esp_err_t usb_host_transfer_submit_control(usb_host_client_handle_t client_hdl, usb_device_handle_t dev_hdl, const usb_setup_packet_t *setup_packet, usb_transfer_t *transfer)
Definition usb_host_port.c:684
esp_err_t usb_host_transfer_free(usb_transfer_t *transfer)
Definition usb_host_port.c:633
struct usb_transfer_s usb_transfer_t
Generated from commit: vsfteam/vsf@699cdec