- Notifications
You must be signed in to change notification settings - Fork 7.6k
/
Copy pathUSB.h
122 lines (94 loc) · 2.89 KB
/
USB.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
111
112
113
114
115
116
117
118
119
120
121
122
// 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"
#if SOC_USB_OTG_SUPPORTED
#include"sdkconfig.h"
#if CONFIG_TINYUSB_ENABLED
#include"esp_event.h"
#include"USBCDC.h"
#defineARDUINO_USB_ON_BOOT (ARDUINO_USB_CDC_ON_BOOT | ARDUINO_USB_MSC_ON_BOOT | ARDUINO_USB_DFU_ON_BOOT)
ESP_EVENT_DECLARE_BASE(ARDUINO_USB_EVENTS);
typedefenum {
ARDUINO_USB_ANY_EVENT = ESP_EVENT_ANY_ID,
ARDUINO_USB_STARTED_EVENT = 0,
ARDUINO_USB_STOPPED_EVENT,
ARDUINO_USB_SUSPEND_EVENT,
ARDUINO_USB_RESUME_EVENT,
ARDUINO_USB_MAX_EVENT,
} arduino_usb_event_t;
typedefunion {
struct {
bool remote_wakeup_en;
} suspend;
} arduino_usb_event_data_t;
classESPUSB {
public:
ESPUSB(size_t event_task_stack_size = 2048, uint8_t event_task_priority = 5);
~ESPUSB();
voidonEvent(esp_event_handler_t callback);
voidonEvent(arduino_usb_event_t event, esp_event_handler_t callback);
boolVID(uint16_t v);
uint16_tVID(void);
boolPID(uint16_t p);
uint16_tPID(void);
boolfirmwareVersion(uint16_t version);
uint16_tfirmwareVersion(void);
boolusbVersion(uint16_t version);
uint16_tusbVersion(void);
boolusbPower(uint16_tmA);
uint16_tusbPower(void);
boolusbClass(uint8_t _class);
uint8_tusbClass(void);
boolusbSubClass(uint8_t subClass);
uint8_tusbSubClass(void);
boolusbProtocol(uint8_t protocol);
uint8_tusbProtocol(void);
boolusbAttributes(uint8_t attr);
uint8_tusbAttributes(void);
boolwebUSB(bool enabled);
boolwebUSB(void);
boolproductName(constchar *name);
constchar *productName(void);
boolmanufacturerName(constchar *name);
constchar *manufacturerName(void);
boolserialNumber(constchar *name);
constchar *serialNumber(void);
boolwebUSBURL(constchar *name);
constchar *webUSBURL(void);
boolenableDFU();
boolbegin();
operatorbool() const;
private:
uint16_t vid;
uint16_t pid;
String product_name;
String manufacturer_name;
String serial_number;
uint16_t fw_version;
uint16_t usb_version;
uint8_t usb_class;
uint8_t usb_subclass;
uint8_t usb_protocol;
uint8_t usb_attributes;
uint16_t usb_power_ma;
bool webusb_enabled;
String webusb_url;
bool _started;
size_t _task_stack_size;
uint8_t _event_task_priority;
};
extern ESPUSB USB;
#endif/* CONFIG_TINYUSB_ENABLED */
#endif/* SOC_USB_OTG_SUPPORTED */