Skip to content

Commit 5e40ffd

Browse files
committed
update hid examples to work esp32s2
1 parent 4a3013d commit 5e40ffd

File tree

6 files changed

+64
-22
lines changed

6 files changed

+64
-22
lines changed

examples/Composite/mouse_external_flash/mouse_external_flash.ino

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@
1919
#include "Adafruit_SPIFlash.h"
2020
#include "Adafruit_TinyUSB.h"
2121

22+
//--------------------------------------------------------------------+
23+
// MSC External Flash
24+
//--------------------------------------------------------------------+
25+
2226
// Uncomment to run example with FRAM
2327
// #define FRAM_CS A5
2428
// #define FRAM_SPI SPI
@@ -51,26 +55,39 @@ Adafruit_SPIFlash flash(&flashTransport);
5155

5256
Adafruit_USBD_MSC usb_msc;
5357

58+
//--------------------------------------------------------------------+
59+
// HID
60+
//--------------------------------------------------------------------+
61+
5462
// HID report descriptor using TinyUSB's template
5563
// Single Report (no ID) descriptor
5664
uint8_t const desc_hid_report[] =
5765
{
5866
TUD_HID_REPORT_DESC_MOUSE()
5967
};
6068

61-
Adafruit_USBD_HID usb_hid;
69+
// USB HID object. For ESP32 these values cannot be changed after this declaration
70+
// desc report, desc len, protocol, interval, use out endpoint
71+
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, false);
6272

63-
#if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS
73+
#if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
6474
const int pin = 4; // Left Button
6575
bool activeState = true;
66-
#elif defined ARDUINO_NRF52840_FEATHER
67-
const int pin = 7; // UserSw
76+
77+
#elif defined(ARDUINO_FUNHOUSE_ESP32S2)
78+
const int pin = BUTTON_DOWN;
79+
bool activeState = true;
80+
81+
#elif defined PIN_BUTTON1
82+
const int pin = PIN_BUTTON1;
6883
bool activeState = false;
84+
6985
#else
7086
const int pin = 12;
7187
bool activeState = false;
7288
#endif
7389

90+
7491
// the setup function runs once when you press reset or power the board
7592
void setup()
7693
{
@@ -92,11 +109,12 @@ void setup()
92109

93110
usb_msc.begin();
94111

95-
96112
// Set up button
97113
pinMode(pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
98114

99-
usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
115+
// Notes: following commented-out functions has no affect on ESP32
116+
// usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
117+
100118
usb_hid.begin();
101119

102120
Serial.begin(115200);

examples/Composite/mouse_ramdisk/mouse_ramdisk.ino

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,25 +16,40 @@
1616

1717
#include "Adafruit_TinyUSB.h"
1818

19+
//--------------------------------------------------------------------+
20+
// MSC RAM Disk Config
21+
//--------------------------------------------------------------------+
22+
1923
// 8KB is the smallest size that windows allow to mount
2024
#define DISK_BLOCK_NUM 16
2125
#define DISK_BLOCK_SIZE 512
2226
#include "ramdisk.h"
2327

28+
Adafruit_USBD_MSC usb_msc;
29+
30+
//--------------------------------------------------------------------+
31+
// HID Config
32+
//--------------------------------------------------------------------+
33+
2434
// HID report descriptor using TinyUSB's template
2535
// Single Report (no ID) descriptor
2636
uint8_t const desc_hid_report[] =
2737
{
2838
TUD_HID_REPORT_DESC_MOUSE()
2939
};
3040

31-
Adafruit_USBD_HID usb_hid;
32-
Adafruit_USBD_MSC usb_msc;
41+
// USB HID object. For ESP32 these values cannot be changed after this declaration
42+
// desc report, desc len, protocol, interval, use out endpoint
43+
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, false);
3344

34-
#if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS || defined ARDUINO_NRF52840_CIRCUITPLAY
45+
#if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
3546
const int pin = 4; // Left Button
3647
bool activeState = true;
3748

49+
#elif defined(ARDUINO_FUNHOUSE_ESP32S2)
50+
const int pin = BUTTON_DOWN;
51+
bool activeState = true;
52+
3853
#elif defined PIN_BUTTON1
3954
const int pin = PIN_BUTTON1;
4055
bool activeState = false;
@@ -69,7 +84,9 @@ void setup()
6984
// Set up button
7085
pinMode(pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
7186

72-
usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
87+
// Notes: following commented-out functions has no affect on ESP32
88+
// usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
89+
7390
usb_hid.begin();
7491

7592
Serial.begin(115200);

examples/HID/hid_boot_keyboard/hid_boot_keyboard.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ uint8_t const desc_hid_report[] =
2525
TUD_HID_REPORT_DESC_KEYBOARD()
2626
};
2727

28-
// USB HID object
29-
// Note: For ESP32 these values cannot be changed after this declaration
28+
// USB HID object. For ESP32 these values cannot be changed after this declaration
3029
// desc report, desc len, protocol, interval, use out endpoint
3130
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_KEYBOARD, 2, false);
3231

examples/HID/hid_boot_mouse/hid_boot_mouse.ino

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,14 @@
1818
* Depending on the board, the button pin
1919
* and its active state (when pressed) are different
2020
*/
21-
#if defined ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS || defined ARDUINO_NRF52840_CIRCUITPLAY
21+
#if defined(ARDUINO_SAMD_CIRCUITPLAYGROUND_EXPRESS) || defined(ARDUINO_NRF52840_CIRCUITPLAY)
2222
const int pin = 4; // Left Button
2323
bool activeState = true;
2424

25+
#elif defined(ARDUINO_FUNHOUSE_ESP32S2)
26+
const int pin = BUTTON_DOWN;
27+
bool activeState = true;
28+
2529
#elif defined PIN_BUTTON1
2630
const int pin = PIN_BUTTON1;
2731
bool activeState = false;
@@ -39,8 +43,9 @@ uint8_t const desc_hid_report[] =
3943
TUD_HID_REPORT_DESC_MOUSE()
4044
};
4145

42-
// USB HID object
43-
Adafruit_USBD_HID usb_hid;
46+
// USB HID object. For ESP32 these values cannot be changed after this declaration
47+
// desc report, desc len, protocol, interval, use out endpoint
48+
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_MOUSE, 2, false);
4449

4550
// the setup function runs once when you press reset or power the board
4651
void setup()
@@ -53,10 +58,11 @@ void setup()
5358
// Set up button, pullup opposite to active state
5459
pinMode(pin, activeState ? INPUT_PULLDOWN : INPUT_PULLUP);
5560

56-
usb_hid.setBootProtocol(HID_ITF_PROTOCOL_MOUSE);
57-
usb_hid.setPollInterval(2);
58-
usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
59-
//usb_hid.setStringDescriptor("TinyUSB Mouse");
61+
// Notes: following commented-out functions has no affect on ESP32
62+
// usb_hid.setBootProtocol(HID_ITF_PROTOCOL_MOUSE);
63+
// usb_hid.setPollInterval(2);
64+
// usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report));
65+
// usb_hid.setStringDescriptor("TinyUSB Mouse");
6066

6167
usb_hid.begin();
6268

examples/HID/hid_composite/hid_composite.ino

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ uint8_t const desc_hid_report[] =
5353
TUD_HID_REPORT_DESC_CONSUMER( HID_REPORT_ID(RID_CONSUMER_CONTROL) )
5454
};
5555

56-
// USB HID object
57-
// Note: For ESP32 these values cannot be changed after this declaration
56+
// USB HID object. For ESP32 these values cannot be changed after this declaration
5857
// desc report, desc len, protocol, interval, use out endpoint
5958
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report), HID_ITF_PROTOCOL_NONE, 2, false);
6059

src/arduino/ports/esp32/Adafruit_TinyUSB_esp32.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ void TinyUSB_Port_EnterDFU(void) {}
3535

3636
void TinyUSB_Port_InitDevice(uint8_t rhport) { (void)rhport; }
3737

38-
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]) { (void)serial_id; }
38+
uint8_t TinyUSB_Port_GetSerialNumber(uint8_t serial_id[16]) {
39+
(void)serial_id;
40+
return 0;
41+
}
3942

4043
#if 0
4144

0 commit comments

Comments
 (0)