|
27 | 27 |
|
28 | 28 | #include <tusb.h> |
29 | 29 | #include <class/hid/hid_device.h> |
30 | | -#include <class/audio/audio.h> |
31 | 30 | #include <pico/time.h> |
32 | 31 | #include <hardware/irq.h> |
33 | 32 | #include <pico/mutex.h> |
34 | 33 | #include <pico/unique_id.h> |
35 | 34 | #include <pico/usb_reset_interface.h> |
36 | 35 | #include <hardware/watchdog.h> |
37 | | -#include <pico/bootrom.h> |
38 | | -#include "sdkoverride/tusb_gamepad16.h" |
39 | | -#include <device/usbd_pvt.h> |
40 | 36 |
|
41 | 37 | // Big, global USB mutex, shared with all USB devices to make sure we don't |
42 | 38 | // have multiple cores updating the TUSB state in parallel |
@@ -76,17 +72,21 @@ typedef struct Entry { |
76 | 72 | static Entry *_hids = nullptr; |
77 | 73 | static Entry *_interfaces = nullptr; |
78 | 74 |
|
79 | | -// USB strings kept in a list of pointers |
| 75 | +// USB strings kept in a list of pointers. Can't use std::vector again because of |
| 76 | +// CRT init non-ordering. |
80 | 77 | static const char **usbd_desc_str; |
81 | 78 | static uint8_t usbd_desc_str_cnt = 0; |
82 | 79 | static uint8_t usbd_desc_str_alloc = 0; |
| 80 | + |
| 81 | +// HID report |
83 | 82 | static int __hid_report_len = 0; |
84 | 83 | static uint8_t *__hid_report = nullptr; |
| 84 | + |
| 85 | +// Global USB descriptor |
85 | 86 | static uint8_t *usbd_desc_cfg = nullptr; |
86 | 87 | #ifdef ENABLE_PICOTOOL_USB |
87 | 88 | static uint8_t _picotool_itf_num; |
88 | 89 | #endif |
89 | | - |
90 | 90 | int usb_hid_poll_interval __attribute__((weak)) = 10; |
91 | 91 |
|
92 | 92 |
|
@@ -133,7 +133,7 @@ static uint8_t AddEntry(Entry **head, int interfaces, const uint8_t *descriptor, |
133 | 133 | } |
134 | 134 |
|
135 | 135 | // Find the index (HID report ID or USB interface) of a given localid |
136 | | -unsigned int usbFindID(Entry *head, unsigned int localid) { |
| 136 | +static unsigned int usbFindID(Entry *head, unsigned int localid) { |
137 | 137 | unsigned int x = 0; |
138 | 138 | while (head && head->localid != localid) { |
139 | 139 | head = head->next; |
@@ -276,6 +276,10 @@ const uint8_t *tud_descriptor_configuration_cb(uint8_t index) { |
276 | 276 | return usbd_desc_cfg; |
277 | 277 | } |
278 | 278 |
|
| 279 | +// Build the binary image of the complete USB descriptor |
| 280 | +// Note that we can add stack-allocated descriptors here because we know |
| 281 | +// we're going to use them before the function exits and they'll not be |
| 282 | +// needed ever again |
279 | 283 | void __SetupUSBDescriptor() { |
280 | 284 | uint8_t interface_count = 0; |
281 | 285 | int usbd_desc_len; |
|
0 commit comments