I am working on a macropad project and I want to use usb otg mode. When I compile/upload the code in arduino, it runs as expected, I can see the serial logs and I can detect the usb device. However when I try to set the usb-mode in platformIO it does not work. Here is a minimum working example:
#include <Adafruit_TinyUSB.h>
uint8_t const desc_hid_report[] = {
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
0x09, 0x05, // USAGE (Game Pad)
0xA1, 0x01, // COLLECTION (Application)
// 16 Buttons
0x05, 0x09, // USAGE_PAGE (Button)
0x19, 0x01, // USAGE_MINIMUM (Button 1)
0x29, 0x10, // USAGE_MAXIMUM (Button 16)
0x15, 0x00, // LOGICAL_MINIMUM (0)
0x25, 0x01, // LOGICAL_MAXIMUM (1)
0x95, 0x10, // REPORT_COUNT (16)
0x75, 0x01, // REPORT_SIZE (1)
0x81, 0x02, // INPUT (Data,Var,Abs)
0xC0 // END_COLLECTION
};
// Create USB HID instance
Adafruit_USBD_HID usb_hid(desc_hid_report, sizeof(desc_hid_report),
HID_ITF_PROTOCOL_NONE, 2, false);
typedef struct {
uint16_t buttons; // 16 buttons
} __attribute__((packed)) gamepad_report_t;
gamepad_report_t gp = {0};
void setup() {
Serial.begin(115200);
TinyUSBDevice.setManufacturerDescriptor("Des");
TinyUSBDevice.setProductDescriptor("ESP32-S3 Macropad");
TinyUSBDevice.setID(0xCafe, 0x4001);
if (!TinyUSBDevice.isInitialized()) {
TinyUSBDevice.begin(0);
}
usb_hid.begin();
// Force re-enumeration
if (TinyUSBDevice.mounted()) {
TinyUSBDevice.detach();
delay(10);
TinyUSBDevice.attach();
}
Serial.println("Button-only Gamepad ready!");
}
void loop() {
// Press button 1
gp.buttons = 0x0001;
usb_hid.sendReport(0, &gp, sizeof(gp));
delay(5000);
// Release all buttons
gp.buttons = 0x0000;
usb_hid.sendReport(0, &gp, sizeof(gp));
delay(5000);
}
The platform.ini file as follows:
[env:seeed_xiao_esp32s3]
platform = espressif32
board = seeed_xiao_esp32s3
framework = arduino
lib_deps:
mathertel/RotaryEncoder@^1.5.3
adafruit/Adafruit TinyUSB Library@^3.7.2
I tried to set build_flags for usb mode, but that did not change anything.
Any help would be appriciated!

