forked from emfcamp/TiDAL-Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
esp-iot-solution.diff
246 lines (231 loc) · 10.5 KB
/
esp-iot-solution.diff
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
diff --git a/component.cmake b/component.cmake
index 14ee198..7fc09b5 100644
--- a/component.cmake
+++ b/component.cmake
@@ -2,25 +2,6 @@
add_compile_options(-fdiagnostics-color=always)
list(APPEND EXTRA_COMPONENT_DIRS
- "$ENV{IOT_SOLUTION_PATH}/components"
- "$ENV{IOT_SOLUTION_PATH}/components/audio"
- "$ENV{IOT_SOLUTION_PATH}/examples/common_components"
- "$ENV{IOT_SOLUTION_PATH}/components/bus"
- "$ENV{IOT_SOLUTION_PATH}/components/button"
- "$ENV{IOT_SOLUTION_PATH}/components/display"
- "$ENV{IOT_SOLUTION_PATH}/components/display/digital_tube"
- "$ENV{IOT_SOLUTION_PATH}/components/expander/io_expander"
- "$ENV{IOT_SOLUTION_PATH}/components/gui"
- "$ENV{IOT_SOLUTION_PATH}/components/led"
- "$ENV{IOT_SOLUTION_PATH}/components/motor"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors/gesture"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors/humiture"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors/imu"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors/light_sensor"
- "$ENV{IOT_SOLUTION_PATH}/components/sensors/pressure"
- "$ENV{IOT_SOLUTION_PATH}/components/storage"
- "$ENV{IOT_SOLUTION_PATH}/components/storage/eeprom"
- "$ENV{IOT_SOLUTION_PATH}/components/FreeRTOS-Plus-CLI"
+ "$ENV{IOT_SOLUTION_PATH}/components/usb/tinyusb"
)
diff --git a/components/usb/tinyusb/additions/include/tusb_config.h b/components/usb/tinyusb/additions/include/tusb_config.h
index 2b6e48c..c4ca8c5 100644
--- a/components/usb/tinyusb/additions/include/tusb_config.h
+++ b/components/usb/tinyusb/additions/include/tusb_config.h
@@ -109,7 +109,9 @@ extern "C" {
// Enabled device class driver
#define CFG_TUD_CDC CONFIG_TINYUSB_CDC_PORT_NUM
#define CFG_TUD_MSC CONFIG_TINYUSB_MSC_ENABLED
-#define CFG_TUD_HID CONFIG_TINYUSB_HID_ENABLED
+#define CFG_TUD_HID_KBD 1
+#define CFG_TUD_U2FHID false
+#define CFG_TUD_HID 1
#define CFG_TUD_MIDI CONFIG_TINYUSB_MIDI_ENABLED
#define CFG_TUD_CUSTOM_CLASS CONFIG_TINYUSB_CUSTOM_CLASS_ENABLED
#define CFG_TUD_NET CONFIG_TINYUSB_NET_ENABLED
diff --git a/components/usb/tinyusb/additions/include_private/descriptors_control.h b/components/usb/tinyusb/additions/include_private/descriptors_control.h
index 743653c..e77569a 100644
--- a/components/usb/tinyusb/additions/include_private/descriptors_control.h
+++ b/components/usb/tinyusb/additions/include_private/descriptors_control.h
@@ -51,12 +51,16 @@ enum {
EPNUM_MSC_DATA,
# endif
-# if CFG_TUD_HID
+# if CFG_TUD_HID_KBD
EPNUM_HID_DATA,
# endif
+
+# if CFG_TUD_U2FHID
+ EPNUM_HID_DATA_2,
+# endif
};
-#if ((CFG_TUD_BTH * 2) + (CFG_TUD_NET * 2) + (CFG_TUD_CDC * 2) + CFG_TUD_MSC + CFG_TUD_HID) > 4
+#if ((CFG_TUD_BTH * 2) + (CFG_TUD_NET * 2) + (CFG_TUD_CDC * 2) + CFG_TUD_MSC + CFG_TUD_HID + CFG_TUD_U2FHID) > 4
#error "USB endpoint number not be more than 5"
#endif
@@ -89,10 +93,14 @@ enum {
ITF_NUM_MSC,
# endif
-# if CFG_TUD_HID
+# if CFG_TUD_HID_KBD
ITF_NUM_HID,
# endif
+# if CFG_TUD_U2FHID
+ ITF_NUM_HID_2,
+# endif
+
# if CFG_TUD_DFU
ITF_NUM_DFU,
# endif
@@ -115,9 +123,12 @@ enum {
#if CFG_TUD_MSC
STRID_MSC_INTERFACE,
#endif
-#if CFG_TUD_HID
+#if CFG_TUD_HID_KBD
STRID_HID_INTERFACE,
#endif
+#if CFG_TUD_U2FHID
+ STRID_HID_INTERFACE_2,
+#endif
#if CFG_TUD_BTH
STRID_BTH_INTERFACE,
#endif
@@ -134,14 +145,16 @@ enum {
TUD_CDC_DESC_LEN * CFG_TUD_CDC +
TUD_RNDIS_DESC_LEN * CFG_TUD_NET +
TUD_MSC_DESC_LEN * CFG_TUD_MSC +
- TUD_HID_DESC_LEN * CFG_TUD_HID +
+ TUD_HID_DESC_LEN * CFG_TUD_HID_KBD +
+ TUD_HID_DESC_LEN * CFG_TUD_U2FHID +
TUD_BTH_DESC_LEN * CFG_TUD_BTH,
ALT_CONFIG_TOTAL_LEN = TUD_CONFIG_DESC_LEN +
TUD_CDC_ECM_DESC_LEN * CFG_TUD_NET +
TUD_CDC_DESC_LEN * CFG_TUD_CDC +
TUD_MSC_DESC_LEN * CFG_TUD_MSC +
- TUD_HID_DESC_LEN * CFG_TUD_HID +
+ TUD_HID_DESC_LEN * CFG_TUD_HID_KBD +
+ TUD_HID_DESC_LEN * CFG_TUD_U2FHID +
TUD_BTH_DESC_LEN * CFG_TUD_BTH +
TUD_DFU_DESC_LEN(DFU_ALT_COUNT) * CFG_TUD_DFU
};
diff --git a/components/usb/tinyusb/additions/src/descriptors_control.c b/components/usb/tinyusb/additions/src/descriptors_control.c
index c868fd4..949c931 100644
--- a/components/usb/tinyusb/additions/src/descriptors_control.c
+++ b/components/usb/tinyusb/additions/src/descriptors_control.c
@@ -15,6 +15,29 @@
#include "esp_log.h"
#include "descriptors_control.h"
#include "dfu_device.h"
+#include "../../../../../../drivers/tidal_usb/u2f_hid.h"
+
+
+#define TILDA_REPORT_DESC_U2F(...) \
+ HID_USAGE_PAGE_N ( FIDO_USAGE_PAGE, 2 ) ,\
+ HID_USAGE ( FIDO_USAGE_U2FHID ) ,\
+ HID_COLLECTION ( HID_COLLECTION_APPLICATION ) ,\
+ /* Report ID if any */\
+ __VA_ARGS__ \
+ HID_USAGE ( FIDO_USAGE_DATA_IN ) ,\
+ HID_LOGICAL_MIN ( 0 ) ,\
+ HID_LOGICAL_MAX_N ( 0xff, 2 ) ,\
+ HID_REPORT_COUNT ( 64 ) ,\
+ HID_REPORT_SIZE ( 8 ) ,\
+ HID_INPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
+ HID_USAGE ( FIDO_USAGE_DATA_OUT ) ,\
+ HID_LOGICAL_MIN ( 0 ) ,\
+ HID_LOGICAL_MAX_N ( 0xff, 2 ) ,\
+ HID_REPORT_COUNT ( 64 ) ,\
+ HID_REPORT_SIZE ( 8 ) ,\
+ HID_OUTPUT ( HID_DATA | HID_VARIABLE | HID_ABSOLUTE ) ,\
+ HID_COLLECTION_END \
+
static const char *TAG = "tusb_desc";
static tusb_desc_device_t s_descriptor;
@@ -22,6 +45,11 @@ static char *s_str_descriptor[USB_STRING_DESCRIPTOR_ARRAY_SIZE];
static uint8_t *s_config_descriptor = NULL;
#define MAX_DESC_BUF_SIZE 32
+#if CFG_TUD_U2FHID //HID Report Descriptor
+uint8_t const desc_hid_report_2[] = {
+ TILDA_REPORT_DESC_U2F()
+};
+#endif
#if CFG_TUD_HID //HID Report Descriptor
uint8_t const desc_hid_report[] = {
TUD_HID_REPORT_DESC_KEYBOARD(HID_REPORT_ID(REPORT_ID_KEYBOARD)),
@@ -37,7 +65,7 @@ uint8_t const desc_configuration[] = {
TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, ALT_CONFIG_TOTAL_LEN, 0, 100),
#else
// Config number, interface count, string index, total length, attribute, power in mA
- TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, TUSB_DESC_TOTAL_LEN, 0, 100),
+ TUD_CONFIG_DESCRIPTOR(1, ITF_NUM_TOTAL, 0, TUSB_DESC_TOTAL_LEN, 0, 500),
#endif
#if CFG_TUD_BTH
// BT Primary controller descriptor
@@ -61,9 +89,12 @@ uint8_t const desc_configuration[] = {
// Interface number, string index, EP Out & EP In address, EP size
TUD_MSC_DESCRIPTOR(ITF_NUM_MSC, STRID_MSC_INTERFACE, EPNUM_MSC_DATA, (0x80 | EPNUM_MSC_DATA), 64), // highspeed 512
#endif
-#if CFG_TUD_HID
+#if CFG_TUD_HID_KBD
// Interface number, string index, protocol, report descriptor len, EP In address, size & polling interval
- TUD_HID_DESCRIPTOR(ITF_NUM_HID, STRID_HID_INTERFACE, HID_PROTOCOL_NONE, sizeof(desc_hid_report), (0x80 | EPNUM_HID_DATA), 16, 10)
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID, STRID_HID_INTERFACE, HID_PROTOCOL_KEYBOARD, sizeof(desc_hid_report), (0x80 | EPNUM_HID_DATA), 8, 10),
+#endif
+#if CFG_TUD_U2FHID
+ TUD_HID_DESCRIPTOR(ITF_NUM_HID_2, STRID_HID_INTERFACE_2, HID_PROTOCOL_NONE, sizeof(desc_hid_report_2), (0x80 | EPNUM_HID_DATA_2), 8, 10),
#endif
#if CFG_TUD_DFU
@@ -164,8 +195,19 @@ uint16_t const *tud_descriptor_string_cb(uint8_t index, uint16_t langid)
#if CFG_TUD_HID
uint8_t const *tud_hid_descriptor_report_cb(uint8_t itf)
{
- (void)itf;
- return desc_hid_report;
+ ESP_LOGW(TAG, "Getting descriptor for interface %d", itf);
+ #if CFG_TUD_HID_KBD
+ if (itf == 0) {
+ return desc_hid_report;
+ }
+ #endif
+ #if CFG_TUD_U2FHID
+ if (itf == 1) {
+ return desc_hid_report_2;
+ }
+ #endif
+ ESP_LOGE(TAG, "Unknown descriptor %d", itf);
+ return NULL;
}
#endif
diff --git a/components/usb/tinyusb/additions/src/tusb_hid.c b/components/usb/tinyusb/additions/src/tusb_hid.c
index a274622..368c8a4 100644
--- a/components/usb/tinyusb/additions/src/tusb_hid.c
+++ b/components/usb/tinyusb/additions/src/tusb_hid.c
@@ -130,6 +130,7 @@ uint16_t tud_hid_get_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t
// Invoked when received SET_REPORT control request or
// received data on OUT endpoint ( Report ID = 0, Type = 0 )
+/*
void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t report_type, uint8_t const *buffer, uint16_t bufsize)
{
// TODO set LED based on CAPLOCK, NUMLOCK etc...
@@ -139,3 +140,4 @@ void tud_hid_set_report_cb(uint8_t itf, uint8_t report_id, hid_report_type_t rep
(void) buffer;
(void) bufsize;
}
+*/
\ No newline at end of file
diff --git a/components/usb/tinyusb/additions/src/usb_descriptors.c b/components/usb/tinyusb/additions/src/usb_descriptors.c
index ebcd5b3..af0de20 100644
--- a/components/usb/tinyusb/additions/src/usb_descriptors.c
+++ b/components/usb/tinyusb/additions/src/usb_descriptors.c
@@ -133,8 +133,11 @@ tusb_desc_strarray_device_t descriptor_str_kconfig = {
CONFIG_TINYUSB_DESC_MSC_STRING, // MSC Interface
#endif
-#if CFG_TUD_HID
- CONFIG_TINYUSB_DESC_HID_STRING // HIDs
+#if CFG_TUD_HID_KBD
+ CONFIG_TINYUSB_DESC_HID_STRING, // HIDs
+#endif
+#if CFG_TUD_U2FHID
+ "TiDAL U2F", // U2FHID
#endif
#if CFG_TUD_BTH