From d0a29092b6f273e8f70eaddf1120718994c845ef Mon Sep 17 00:00:00 2001 From: Jeff Epler Date: Fri, 14 Mar 2025 14:19:15 -0500 Subject: [PATCH] WIP switching to pico-pio-usb --- CMakeLists.txt | 7 +++++++ include/tusb_config.h | 2 ++ src/main.c | 9 ++++++++- 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 8878289..6a2c61e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,10 @@ set(HSTX_D2P 19 CACHE STRING "HSTX D2+ PIN") option(USE_VGA_RES "Video uses VGA (640x480) resolution" OFF) set(VIDEO_PIN 18 CACHE STRING "VGA Video GPIO base pin (followed by VS, CLK, HS)") +# Pins for PIO-based USB host +set(PIN_USB_HOST_DP CACHE STRING "1") +set(PIN_USB_HOST_DM CACHE STRING "2") + # See below, -DMEMSIZE= will configure umac's memory size, # overriding defaults. @@ -122,6 +126,9 @@ else() endif() +add_compile_definitions(PIN_USB_HOST_DP=${PIN_USB_HOST_DP}) +add_compile_definitions(PIN_USB_HOST_DM=${PIN_USB_HOST_DM}) + if (TARGET tinyusb_device) add_executable(firmware src/main.c diff --git a/include/tusb_config.h b/include/tusb_config.h index ba1b92f..cbe8523 100644 --- a/include/tusb_config.h +++ b/include/tusb_config.h @@ -83,6 +83,8 @@ // max device support (excluding hub device) #define CFG_TUH_DEVICE_MAX (CFG_TUH_HUB ? 4 : 1) // hub typically has 4 ports +#define CFG_TUH_RPI_PIO_USB 1 + //------------- HID -------------// #define CFG_TUH_HID_EPIN_BUFSIZE 64 #define CFG_TUH_HID_EPOUT_BUFSIZE 64 diff --git a/src/main.c b/src/main.c index e347cc3..42c18f6 100644 --- a/src/main.c +++ b/src/main.c @@ -273,7 +273,14 @@ int main() multicore_launch_core1(core1_main); printf("Starting, init usb\n"); - tusb_init(); + + pio_usb_configuration_t pio_cfg = PIO_USB_DEFAULT_CONFIG; + _Static_assert(PIN_USB_HOST_DP + 1 == PIN_USB_HOST_DM || PIN_USB_HOST_DP - 1 == PIN_USB_HOST_DM, "Permitted USB D+/D- configuration"); + pio_cfg.pinout = PIN_USB_HOST_DP + 1 == PIN_USB_HOST_DM ? PIO_USB_PINOUT_DPDM : PIO_USB_PINOUT_DMDP; + pio_cfg.pin_dp = PIN_USB_HOST_DP; + tuh_configure(BOARD_TUH_RHPORT, TUH_CFGID_RPI_PIO_USB_CONFIGURATION, &pio_cfg); + + tuh_init(BOARD_TUH_RHPORT); /* This happens on core 0: */ while (true) {