diff --git a/examples/DualRole/Simple/device_info/device_info.ino b/examples/DualRole/Simple/device_info/device_info.ino index 909aa567..5d10cc1a 100644 --- a/examples/DualRole/Simple/device_info/device_info.ino +++ b/examples/DualRole/Simple/device_info/device_info.ino @@ -62,10 +62,8 @@ #include "Adafruit_TinyUSB.h" #if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421 - #include "SPI.h" - -// USB Host object using MAX3421E: SPI, CS, INT +// USB Host using MAX3421E: SPI, CS, INT Adafruit_USBH_Host USBHost(&SPI, 10, 9); #else Adafruit_USBH_Host USBHost; @@ -93,7 +91,7 @@ void setup() { // init host stack on controller (rhport) 1 USBHost.begin(1); - while ( !Serial ) delay(10); // wait for native usb +// while ( !Serial ) delay(10); // wait for native usb Serial.println("TinyUSB Dual Device Info Example"); } diff --git a/src/arduino/Adafruit_USBH_Host.cpp b/src/arduino/Adafruit_USBH_Host.cpp index 2e304925..fc600eb5 100644 --- a/src/arduino/Adafruit_USBH_Host.cpp +++ b/src/arduino/Adafruit_USBH_Host.cpp @@ -199,6 +199,14 @@ void tuh_max3421_int_api(uint8_t rhport, bool enabled) { NVIC_DisableIRQ(EIC_IRQn); } #endif + +#elif defined(ARDUINO_NRF52_ADAFRUIT) + if (enabled) { + NVIC_EnableIRQ(GPIOTE_IRQn); + } else { + NVIC_DisableIRQ(GPIOTE_IRQn); + } + #endif } } diff --git a/src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp b/src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp index 46069e5e..cd56ff82 100644 --- a/src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp +++ b/src/arduino/ports/nrf/Adafruit_TinyUSB_nrf.cpp @@ -68,7 +68,8 @@ static void usb_device_task(void *param) { // 2 is highest for application NVIC_SetPriority(USBD_IRQn, 2); - tusb_init(); + // init device on rhport0 + tud_init(0); usb_hardware_init(); diff --git a/src/arduino/ports/nrf/tusb_config_nrf.h b/src/arduino/ports/nrf/tusb_config_nrf.h index 7b9e5711..eef1c31a 100644 --- a/src/arduino/ports/nrf/tusb_config_nrf.h +++ b/src/arduino/ports/nrf/tusb_config_nrf.h @@ -34,12 +34,6 @@ extern "C" { //-------------------------------------------------------------------- #define CFG_TUSB_MCU OPT_MCU_NRF5X -#ifdef USE_TINYUSB -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_DEVICE -#else -#define CFG_TUSB_RHPORT0_MODE OPT_MODE_NONE -#endif - #define CFG_TUSB_OS OPT_OS_FREERTOS #define CFG_TUSB_MEM_SECTION #define CFG_TUSB_MEM_ALIGN __attribute__((aligned(4))) @@ -48,6 +42,19 @@ extern "C" { #define CFG_TUSB_DEBUG 0 #endif +#ifdef USE_TINYUSB +// Enable device stack +#define CFG_TUD_ENABLED 1 + +// Enable host stack with MAX3421E (host shield) +#define CFG_TUH_ENABLED 1 +#define CFG_TUH_MAX3421 1 + +#else +#define CFG_TUD_ENABLED 0 +#define CFG_TUH_ENABLED 0 +#endif + //-------------------------------------------------------------------- // DEVICE CONFIGURATION //-------------------------------------------------------------------- @@ -79,10 +86,54 @@ extern "C" { #ifndef CFG_TUD_VENDOR_RX_BUFSIZE #define CFG_TUD_VENDOR_RX_BUFSIZE 64 #endif + #ifndef CFG_TUD_VENDOR_TX_BUFSIZE #define CFG_TUD_VENDOR_TX_BUFSIZE 64 #endif +//-------------------------------------------------------------------- +// Host Configuration +//-------------------------------------------------------------------- + +// Size of buffer to hold descriptors and other data used for enumeration +#define CFG_TUH_ENUMERATION_BUFSIZE 256 + +// Number of hub devices +#define CFG_TUH_HUB 1 + +// max device support (excluding hub device): 1 hub typically has 4 ports +#define CFG_TUH_DEVICE_MAX (3 * CFG_TUH_HUB + 1) + +// Enable tuh_edpt_xfer() API +// #define CFG_TUH_API_EDPT_XFER 1 + +// Number of mass storage +#define CFG_TUH_MSC 1 + +// Number of HIDs +// typical keyboard + mouse device can have 3,4 HID interfaces +#define CFG_TUH_HID (3 * CFG_TUH_DEVICE_MAX) + +// Number of CDC interfaces +// FTDI and CP210x are not part of CDC class, only to re-use CDC driver API +#define CFG_TUH_CDC 1 +#define CFG_TUH_CDC_FTDI 1 +#define CFG_TUH_CDC_CP210X 1 + +// RX & TX fifo size +#define CFG_TUH_CDC_RX_BUFSIZE 64 +#define CFG_TUH_CDC_TX_BUFSIZE 64 + +// Set Line Control state on enumeration/mounted: +// DTR ( bit 0), RTS (bit 1) +#define CFG_TUH_CDC_LINE_CONTROL_ON_ENUM 0x03 + +// Set Line Coding on enumeration/mounted, value for cdc_line_coding_t +// bit rate = 115200, 1 stop bit, no parity, 8 bit data width +// This need Pico-PIO-USB at least 0.5.1 +#define CFG_TUH_CDC_LINE_CODING_ON_ENUM \ + { 115200, CDC_LINE_CONDING_STOP_BITS_1, CDC_LINE_CODING_PARITY_NONE, 8 } + #ifdef __cplusplus } #endif diff --git a/src/portable/analog/max3421/hcd_max3421.c b/src/portable/analog/max3421/hcd_max3421.c index 866e9e1c..b879ab56 100644 --- a/src/portable/analog/max3421/hcd_max3421.c +++ b/src/portable/analog/max3421/hcd_max3421.c @@ -428,8 +428,8 @@ bool hcd_init(uint8_t rhport) { reg_write(rhport, PINCTL_ADDR, PINCTL_FDUPSPI, false); // V1 is 0x01, V2 is 0x12, V3 is 0x13 - // uint8_t const revision = reg_read(rhport, REVISION_ADDR, false); - // TU_LOG2_HEX(revision); +// uint8_t const revision = reg_read(rhport, REVISION_ADDR, false); +// TU_LOG2_HEX(revision); // reset reg_write(rhport, USBCTL_ADDR, USBCTL_CHIPRES, false);