@@ -72,14 +72,12 @@ Adafruit_USBD_MSC usb_msc;
72
72
73
73
// HID report descriptor using TinyUSB's template
74
74
// Single Report (no ID) descriptor
75
- uint8_t const desc_hid_report[] =
76
- {
77
- TUD_HID_REPORT_DESC_MOUSE ()
75
+ uint8_t const desc_hid_report[] = {
76
+ TUD_HID_REPORT_DESC_MOUSE ()
78
77
};
79
78
80
- // USB HID object. For ESP32 these values cannot be changed after this declaration
81
- // desc report, desc len, protocol, interval, use out endpoint
82
- Adafruit_USBD_HID usb_hid (desc_hid_report, sizeof (desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, false);
79
+ // USB HID object
80
+ Adafruit_USBD_HID usb_hid;
83
81
84
82
#if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
85
83
const int pin = 4 ; // Left Button
@@ -93,6 +91,10 @@ Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROT
93
91
const int pin = PIN_BUTTON1;
94
92
bool activeState = false ;
95
93
94
+ #elif defined(ARDUINO_ARCH_ESP32)
95
+ const int pin = 0 ;
96
+ bool activeState = false ;
97
+
96
98
#else
97
99
const int pin = 12 ;
98
100
bool activeState = false ;
@@ -102,6 +104,11 @@ Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROT
102
104
// the setup function runs once when you press reset or power the board
103
105
void setup ()
104
106
{
107
+ #if defined(ARDUINO_ARCH_MBED) && defined(ARDUINO_ARCH_RP2040)
108
+ // Manual begin() is required on core without built-in support for TinyUSB such as mbed rp2040
109
+ TinyUSB_Device_Init (0 );
110
+ #endif
111
+
105
112
flash.begin ();
106
113
107
114
pinMode (LED_BUILTIN, OUTPUT);
@@ -123,9 +130,10 @@ void setup()
123
130
// Set up button
124
131
pinMode (pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
125
132
126
- // Notes: following commented-out functions has no affect on ESP32
127
- // usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
128
-
133
+ // Set up HID
134
+ usb_hid.setReportDescriptor (desc_hid_report, sizeof (desc_hid_report));
135
+ usb_hid.setBootProtocol (HID_ITF_PROTOCOL_NONE);
136
+ usb_hid.setPollInterval (2 );
129
137
usb_hid.begin ();
130
138
131
139
Serial.begin (115200 );
0 commit comments