From 74b401d622d68ead67a136ee2d76e545128a75e7 Mon Sep 17 00:00:00 2001 From: foamyguy Date: Thu, 17 Apr 2025 14:53:51 -0500 Subject: [PATCH] add support for Metro rp2350, remove unused usb hid device handling, remove device name from folder. --- .../.feather_rp2040_usbhost_tinyusb.test.only | 0 .../.metro_rp2350_usbhost_tinyusb.test.only | 0 .../snes_gamepad_simpletest/gamepad_reports.h | 0 .../snes_gamepad_simpletest.ino | 39 ++++--------------- .../snes_gamepad_simpletest/usbh_helper.h | 20 ++++++++++ 5 files changed, 28 insertions(+), 31 deletions(-) rename USB_SNES_Gamepad/{Arduino_Feather_RP2040_USB_Host => Arduino_USB_Host}/snes_gamepad_simpletest/.feather_rp2040_usbhost_tinyusb.test.only (100%) create mode 100644 USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/.metro_rp2350_usbhost_tinyusb.test.only rename USB_SNES_Gamepad/{Arduino_Feather_RP2040_USB_Host => Arduino_USB_Host}/snes_gamepad_simpletest/gamepad_reports.h (100%) rename USB_SNES_Gamepad/{Arduino_Feather_RP2040_USB_Host => Arduino_USB_Host}/snes_gamepad_simpletest/snes_gamepad_simpletest.ino (85%) rename USB_SNES_Gamepad/{Arduino_Feather_RP2040_USB_Host => Arduino_USB_Host}/snes_gamepad_simpletest/usbh_helper.h (86%) diff --git a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/.feather_rp2040_usbhost_tinyusb.test.only b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/.feather_rp2040_usbhost_tinyusb.test.only similarity index 100% rename from USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/.feather_rp2040_usbhost_tinyusb.test.only rename to USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/.feather_rp2040_usbhost_tinyusb.test.only diff --git a/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/.metro_rp2350_usbhost_tinyusb.test.only b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/.metro_rp2350_usbhost_tinyusb.test.only new file mode 100644 index 000000000..e69de29bb diff --git a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/gamepad_reports.h b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/gamepad_reports.h similarity index 100% rename from USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/gamepad_reports.h rename to USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/gamepad_reports.h diff --git a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino similarity index 85% rename from USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino rename to USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino index 3ba0ab41a..853e4c02f 100644 --- a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino +++ b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/snes_gamepad_simpletest.ino @@ -48,34 +48,8 @@ hid_gamepad_report_t gp; bool printed_blank = false; void setup() { - if (!TinyUSBDevice.isInitialized()) { - TinyUSBDevice.begin(0); - } Serial.begin(115200); - // Setup HID - usb_hid.setPollInterval(2); - usb_hid.setReportDescriptor(desc_hid_report, sizeof(desc_hid_report)); - usb_hid.begin(); - // If already enumerated, additional class driver begin() e.g msc, hid, midi won't take effect until re-enumeration - if (TinyUSBDevice.mounted()) { - TinyUSBDevice.detach(); - delay(10); - TinyUSBDevice.attach(); - } -} - -#if defined(ARDUINO_ARCH_RP2040) -//--------------------------------------------------------------------+ -// For RP2040 use both core0 for device stack, core1 for host stack -//--------------------------------------------------------------------// - -//------------- Core0 -------------// -void loop() { -} - -//------------- Core1 -------------// -void setup1() { // configure pio-usb: defined in usbh_helper.h rp2040_configure_pio_usb(); @@ -83,14 +57,18 @@ void setup1() { // Note: For rp2040 pico-pio-usb, calling USBHost.begin() on core1 will have most of the // host bit-banging processing works done in core1 to free up core0 for other works USBHost.begin(1); + delay(3000); + Serial.print("USB D+ Pin:"); + Serial.println(PIN_USB_HOST_DP); + Serial.print("USB 5V Pin:"); + Serial.println(PIN_5V_EN); } -void loop1() { +void loop() { USBHost.task(); Serial.flush(); } -#endif //--------------------------------------------------------------------+ // HID Host Callback Functions @@ -112,16 +90,15 @@ void tuh_hid_umount_cb(uint8_t dev_addr, uint8_t instance) Serial.printf("HID device unmounted (address %d, instance %d)\n", dev_addr, instance); } - void tuh_hid_report_received_cb(uint8_t dev_addr, uint8_t instance, uint8_t const* report, uint16_t len) { if (report[BYTE_DPAD_LEFT_RIGHT] != DPAD_NEUTRAL || report[BYTE_DPAD_UP_DOWN] != DPAD_NEUTRAL || report[BYTE_ABXY_BUTTONS] != BUTTON_NEUTRAL || report[BYTE_OTHER_BUTTONS] != BUTTON_MISC_NEUTRAL){ - + printed_blank = false; - + //debug print report data // Serial.print("Report data: "); // for (int i = 0; i < len; i++) { diff --git a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/usbh_helper.h b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/usbh_helper.h similarity index 86% rename from USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/usbh_helper.h rename to USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/usbh_helper.h index 6a2dd366a..4a7a099c4 100644 --- a/USB_SNES_Gamepad/Arduino_Feather_RP2040_USB_Host/snes_gamepad_simpletest/usbh_helper.h +++ b/USB_SNES_Gamepad/Arduino_USB_Host/snes_gamepad_simpletest/usbh_helper.h @@ -35,6 +35,26 @@ #endif #endif // ARDUINO_ARCH_RP2040 +#ifdef ARDUINO_ARCH_RP2350 + + // pio-usb is required for rp2040 host + #include "pio_usb.h" + + // Pin D+ for host, D- = D+ + 1 + #ifndef PIN_USB_HOST_DP + #define PIN_USB_HOST_DP 32 + #endif + + // Pin for enabling Host VBUS. comment out if not used + #ifndef PIN_5V_EN + #define PIN_5V_EN 29 + #endif + + #ifndef PIN_5V_EN_STATE + #define PIN_5V_EN_STATE 1 + #endif +#endif // ARDUINO_ARCH_RP2350 + #include "Adafruit_TinyUSB.h" #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421