@@ -122,32 +122,41 @@ int __USBGetMouseReportID() {
122
122
}
123
123
124
124
static uint8_t *GetDescHIDReport (int *len) {
125
+ static uint8_t *report = nullptr ;
126
+ int report_len = 0 ;
127
+
128
+ if (report) {
129
+ free (report);
130
+ }
131
+
125
132
if (__USBInstallKeyboard && __USBInstallMouse) {
126
- static uint8_t desc_hid_report[] = {
133
+ uint8_t desc_hid_report[] = {
127
134
TUD_HID_REPORT_DESC_KEYBOARD (HID_REPORT_ID (1 )),
128
135
TUD_HID_REPORT_DESC_MOUSE (HID_REPORT_ID (2 ))
129
136
};
130
- if (len) {
131
- *len = sizeof (desc_hid_report);
132
- }
133
- return desc_hid_report;
137
+ report_len = sizeof (desc_hid_report);
138
+ report = (uint8_t *)malloc (report_len);
139
+ memcpy (report, desc_hid_report, report_len);
134
140
} else if (__USBInstallKeyboard && ! __USBInstallMouse) {
135
- static uint8_t desc_hid_report[] = {
141
+ uint8_t desc_hid_report[] = {
136
142
TUD_HID_REPORT_DESC_KEYBOARD (HID_REPORT_ID (1 ))
137
143
};
138
- if (len) {
139
- *len = sizeof (desc_hid_report);
140
- }
141
- return desc_hid_report;
144
+ report_len = sizeof (desc_hid_report);
145
+ report = (uint8_t *)malloc (report_len);
146
+ memcpy (report, desc_hid_report, report_len);
142
147
} else { // if (!__USBInstallKeyboard && __USBInstallMouse) {
143
- static uint8_t desc_hid_report[] = {
148
+ uint8_t desc_hid_report[] = {
144
149
TUD_HID_REPORT_DESC_MOUSE (HID_REPORT_ID (1 ))
145
150
};
146
- if (len) {
147
- *len = sizeof (desc_hid_report);
148
- }
149
- return desc_hid_report;
151
+ report_len = sizeof (desc_hid_report);
152
+ report = (uint8_t *)malloc (report_len);
153
+ memcpy (report, desc_hid_report, report_len);
154
+ }
155
+
156
+ if (len) {
157
+ *len = report_len;
150
158
}
159
+ return report;
151
160
}
152
161
153
162
// Invoked when received GET HID REPORT DESCRIPTOR
@@ -161,35 +170,35 @@ uint8_t const * tud_hid_descriptor_report_cb(uint8_t instance) {
161
170
162
171
const uint8_t *tud_descriptor_configuration_cb (uint8_t index) {
163
172
(void )index;
164
- static uint8_t *usbd_desc_cfg = NULL ;
173
+ static uint8_t *usbd_desc_cfg = nullptr ;
165
174
166
175
if (!usbd_desc_cfg) {
167
176
bool hasHID = __USBInstallKeyboard || __USBInstallMouse;
168
177
169
178
uint8_t interface_count = (__USBInstallSerial ? 2 : 0 ) + (hasHID ? 1 : 0 ) + (__USBInstallMIDI ? 2 : 0 );
170
179
171
- static uint8_t cdc_desc[TUD_CDC_DESC_LEN] = {
180
+ uint8_t cdc_desc[TUD_CDC_DESC_LEN] = {
172
181
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
173
182
TUD_CDC_DESCRIPTOR (USBD_ITF_CDC, USBD_STR_CDC, USBD_CDC_EP_CMD, USBD_CDC_CMD_MAX_SIZE, USBD_CDC_EP_OUT, USBD_CDC_EP_IN, USBD_CDC_IN_OUT_MAX_SIZE)
174
183
};
175
184
176
185
int hid_report_len;
177
186
GetDescHIDReport (&hid_report_len);
178
187
uint8_t hid_itf = __USBInstallSerial ? 2 : 0 ;
179
- static uint8_t hid_desc[TUD_HID_DESC_LEN] = {
188
+ uint8_t hid_desc[TUD_HID_DESC_LEN] = {
180
189
// Interface number, string index, protocol, report descriptor len, EP In & Out address, size & polling interval
181
190
TUD_HID_DESCRIPTOR (hid_itf, 0 , HID_ITF_PROTOCOL_NONE, hid_report_len, EPNUM_HID, CFG_TUD_HID_EP_BUFSIZE, 10 )
182
191
};
183
192
184
193
uint8_t midi_itf = hid_itf + (hasHID ? 1 : 0 );
185
- static uint8_t midi_desc[TUD_MIDI_DESC_LEN] = {
194
+ uint8_t midi_desc[TUD_MIDI_DESC_LEN] = {
186
195
// Interface number, string index, EP Out & EP In address, EP size
187
196
TUD_MIDI_DESCRIPTOR (midi_itf, 0 , EPNUM_MIDI, 0x80 | EPNUM_MIDI, 64 )
188
197
};
189
198
190
199
int usbd_desc_len = TUD_CONFIG_DESC_LEN + (__USBInstallSerial ? sizeof (cdc_desc) : 0 ) + (hasHID ? sizeof (hid_desc) : 0 ) + (__USBInstallMIDI ? sizeof (midi_desc) : 0 );
191
200
192
- static uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
201
+ uint8_t tud_cfg_desc[TUD_CONFIG_DESC_LEN] = {
193
202
// Config number, interface count, string index, total length, attribute, power in mA
194
203
TUD_CONFIG_DESCRIPTOR (1 , interface_count, USBD_STR_0, usbd_desc_len, TUSB_DESC_CONFIG_ATT_REMOTE_WAKEUP, USBD_MAX_POWER_MA)
195
204
};
@@ -277,6 +286,7 @@ void __USBStart() {
277
286
}
278
287
279
288
mutex_init (&__usb_mutex);
289
+
280
290
tusb_init ();
281
291
282
292
irq_set_exclusive_handler (USB_TASK_IRQ, usb_irq);
0 commit comments