Skip to content

Commit

Permalink
update dual examples: serial_host_bridge, hid_device_report, msc_file…
Browse files Browse the repository at this point in the history
…_explorer to work with max3421e
  • Loading branch information
hathach committed Sep 14, 2023
1 parent 6829820 commit 1752f57
Show file tree
Hide file tree
Showing 19 changed files with 230 additions and 110 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
/.development
.idea
platformio.ini
.pio/
Empty file.
Empty file.
Empty file.
71 changes: 51 additions & 20 deletions examples/DualRole/CDC/serial_host_bridge/serial_host_bridge.ino
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,10 @@
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
*/

#ifdef ARDUINO_ARCH_RP2040
// pio-usb is required for rp2040 host
#include "pio_usb.h"

// TinyUSB lib
#include "Adafruit_TinyUSB.h"

// Pin D+ for host, D- = D+ + 1
#ifndef PIN_USB_HOST_DP
#define PIN_USB_HOST_DP 16
Expand All @@ -44,26 +42,66 @@
#ifndef PIN_5V_EN_STATE
#define PIN_5V_EN_STATE 1
#endif
#endif

// USB Host object
#include "Adafruit_TinyUSB.h"

#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
#include "SPI.h"
// USB Host using MAX3421E: SPI, CS, INT
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
#else
Adafruit_USBH_Host USBHost;
#endif

// CDC Host object
Adafruit_USBH_CDC SerialHost;


void host_loop()
{
USBHost.task();

// periodically flush SerialHost if connected
if ( SerialHost && SerialHost.connected() ) {
SerialHost.flush();
}

Serial.flush();
}

#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
//--------------------------------------------------------------------+
// Setup and Loop on Core0
// Using Host shield MAX3421E controller
//--------------------------------------------------------------------+
void setup() {
Serial.begin(115200);

// init host stack on controller (rhport) 1
USBHost.begin(1);

// while ( !Serial ) delay(10); // wait for native usb
Serial.println("TinyUSB Host Serial Echo Example");
}

void loop() {
host_loop();
}

#elif defined(ARDUINO_ARCH_RP2040)
//--------------------------------------------------------------------+
// For RP2040 use both core0 for device stack, core1 for host stack
//--------------------------------------------------------------------+

//------------- Core0 -------------//
void setup() {
Serial.begin(115200);
// while ( !Serial ) delay(10); // wait for native usb

Serial.println("TinyUSB Host Serial Echo Example");
}

void loop()
{
void loop() {
uint8_t buf[64];

// Serial -> SerialHost
Expand All @@ -82,10 +120,7 @@ void loop()
}
}

//--------------------------------------------------------------------+
// Setup and Loop on Core1
//--------------------------------------------------------------------+

//------------- Core1 -------------//
void setup1() {
// while ( !Serial ) delay(10); // wait for native usb
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
Expand Down Expand Up @@ -140,16 +175,12 @@ void setup1() {
SerialHost.begin(115200);
}

void loop1()
{
USBHost.task();

// periodically flush SerialHost if connected
if ( SerialHost && SerialHost.connected() ) {
SerialHost.flush();
}
void loop1() {
host_loop();
}

#endif

//--------------------------------------------------------------------+
// TinyUSB Host callbacks
//--------------------------------------------------------------------+
Expand All @@ -169,4 +200,4 @@ void tuh_cdc_umount_cb(uint8_t idx) {
Serial.println("SerialHost is disconnected");
}

}
}
Empty file.
Empty file.
Empty file.
58 changes: 43 additions & 15 deletions examples/DualRole/HID/hid_device_report/hid_device_report.ino
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,12 @@
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
*/

// Language ID: English
#define LANGUAGE_ID 0x0409

#ifdef ARDUINO_ARCH_RP2040
// pio-usb is required for rp2040 host
#include "pio_usb.h"
#include "Adafruit_TinyUSB.h"

// Pin D+ for host, D- = D+ + 1
#ifndef PIN_USB_HOST_DP
Expand All @@ -38,34 +41,58 @@
#ifndef PIN_5V_EN_STATE
#define PIN_5V_EN_STATE 1
#endif
#endif

// Language ID: English
#define LANGUAGE_ID 0x0409
#include "Adafruit_TinyUSB.h"

#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421

// USB Host object
#include "SPI.h"

// USB Host using MAX3421E: SPI, CS, INT
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
#else
Adafruit_USBH_Host USBHost;
#endif

#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421

//--------------------------------------------------------------------+
// Setup and Loop on Core0
// Using Host shield MAX3421E controller
//--------------------------------------------------------------------+

void setup()
{
void setup() {
Serial.begin(115200);
while ( !Serial ) delay(10); // wait for native usb

Serial.println("TinyUSB Dual Device Info Example");
// init host stack on controller (rhport) 1
USBHost.begin(1);

// while ( !Serial ) delay(10); // wait for native usb
Serial.println("TinyUSB Dual: HID Device Report Example");
}

void loop()
{
void loop() {
USBHost.task();
Serial.flush();
}

#elif defined(ARDUINO_ARCH_RP2040)
//--------------------------------------------------------------------+
// Setup and Loop on Core1
// For RP2040 use both core0 for device stack, core1 for host stack
//--------------------------------------------------------------------+

//------------- Core0 -------------//
void setup() {
Serial.begin(115200);
while ( !Serial ) delay(10); // wait for native usb

Serial.println("TinyUSB Dual: HID Device Report Example");
}

void loop() {
Serial.flush();
}

//------------- Core1 -------------//
void setup1() {
//while ( !Serial ) delay(10); // wait for native usb
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
Expand Down Expand Up @@ -107,11 +134,12 @@ void setup1() {
USBHost.begin(1);
}

void loop1()
{
void loop1() {
USBHost.task();
}

#endif

extern "C" {

// Invoked when device with hid interface is mounted
Expand Down
Loading

0 comments on commit 1752f57

Please sign in to comment.