- Notifications
You must be signed in to change notification settings - Fork 7.6k
/
Copy pathesp32-hal-tinyusb.h
110 lines (91 loc) · 3.56 KB
/
esp32-hal-tinyusb.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2015-2020 Espressif Systems (Shanghai) PTE LTD
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#pragma once
#include"soc/soc_caps.h"
#ifSOC_USB_OTG_SUPPORTED
#include"esp32-hal.h"
#ifCONFIG_TINYUSB_ENABLED
#ifdef__cplusplus
extern"C" {
#endif
#include"tusb.h"
#include"tusb_option.h"
#include"tusb_config.h"
#defineUSB_ESPRESSIF_VID 0x303A
#defineUSB_STRING_DESCRIPTOR_ARRAY_SIZE 10
#ifndefCFG_TUD_ENDOINT_SIZE
#ifCONFIG_IDF_TARGET_ESP32P4
#defineCFG_TUD_ENDOINT_SIZE 512
#else
#defineCFG_TUD_ENDOINT_SIZE 64
#endif
#endif
typedefstruct {
uint16_tvid;
uint16_tpid;
constchar*product_name;
constchar*manufacturer_name;
constchar*serial_number;
uint16_tfw_version;
uint16_tusb_version;
uint8_tusb_class;
uint8_tusb_subclass;
uint8_tusb_protocol;
uint8_tusb_attributes;
uint16_tusb_power_ma;
boolwebusb_enabled;
constchar*webusb_url;
} tinyusb_device_config_t;
#defineTINYUSB_CONFIG_DEFAULT() \
{ \
.vid = USB_ESPRESSIF_VID, .pid = 0x0002, .product_name = CONFIG_TINYUSB_DESC_PRODUCT_STRING, .manufacturer_name = CONFIG_TINYUSB_DESC_MANUFACTURER_STRING, \
.serial_number = CONFIG_TINYUSB_DESC_SERIAL_STRING, .fw_version = CONFIG_TINYUSB_DESC_BCDDEVICE, .usb_version = 0x0200, .usb_class = TUSB_CLASS_MISC, \
.usb_subclass = MISC_SUBCLASS_COMMON, .usb_protocol = MISC_PROTOCOL_IAD, .usb_attributes = TUSB_DESC_CONFIG_ATT_SELF_POWERED, .usb_power_ma = 500, \
.webusb_enabled = false, .webusb_url = "espressif.github.io/arduino-esp32/webusb.html" \
}
esp_err_ttinyusb_init(tinyusb_device_config_t*config);
/*
* USB Persistence API
* */
typedefenum {
RESTART_NO_PERSIST,
RESTART_PERSIST,
RESTART_BOOTLOADER,
RESTART_BOOTLOADER_DFU,
RESTART_TYPE_MAX
} restart_type_t;
voidusb_persist_restart(restart_type_tmode);
// The following definitions and functions are to be used only by the drivers
typedefenum {
USB_INTERFACE_MSC,
USB_INTERFACE_DFU,
USB_INTERFACE_HID,
USB_INTERFACE_VENDOR,
USB_INTERFACE_CDC,
USB_INTERFACE_MIDI,
USB_INTERFACE_CUSTOM,
USB_INTERFACE_MAX
} tinyusb_interface_t;
typedefuint16_t (*tinyusb_descriptor_cb_t)(uint8_t*dst, uint8_t*itf);
esp_err_ttinyusb_enable_interface(tinyusb_interface_tinterface, uint16_tdescriptor_len, tinyusb_descriptor_cb_tcb);
esp_err_ttinyusb_enable_interface2(tinyusb_interface_tinterface, uint16_tdescriptor_len, tinyusb_descriptor_cb_tcb, boolreserve_endpoints);
uint8_ttinyusb_add_string_descriptor(constchar*str);
uint8_ttinyusb_get_free_duplex_endpoint(void);
uint8_ttinyusb_get_free_in_endpoint(void);
uint8_ttinyusb_get_free_out_endpoint(void);
#ifdef__cplusplus
}
#endif
#endif/* CONFIG_TINYUSB_ENABLED */
#endif/* SOC_USB_OTG_SUPPORTED */