Skip to content

Commit 1752f57

Browse files
committed
update dual examples: serial_host_bridge, hid_device_report, msc_file_explorer to work with max3421e
1 parent 6829820 commit 1752f57

19 files changed

+230
-110
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
/.development
33
.idea
44
platformio.ini
5+
.pio/

examples/DualRole/CDC/serial_host_bridge/.metro_m0_tinyusb.only

Whitespace-only changes.

examples/DualRole/CDC/serial_host_bridge/.metro_m4_tinyusb.only

Whitespace-only changes.

examples/DualRole/CDC/serial_host_bridge/.nrf52840.only

Whitespace-only changes.

examples/DualRole/CDC/serial_host_bridge/serial_host_bridge.ino

Lines changed: 51 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,10 @@
2525
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2626
*/
2727

28+
#ifdef ARDUINO_ARCH_RP2040
2829
// pio-usb is required for rp2040 host
2930
#include "pio_usb.h"
3031

31-
// TinyUSB lib
32-
#include "Adafruit_TinyUSB.h"
33-
3432
// Pin D+ for host, D- = D+ + 1
3533
#ifndef PIN_USB_HOST_DP
3634
#define PIN_USB_HOST_DP 16
@@ -44,26 +42,66 @@
4442
#ifndef PIN_5V_EN_STATE
4543
#define PIN_5V_EN_STATE 1
4644
#endif
45+
#endif
4746

48-
// USB Host object
47+
#include "Adafruit_TinyUSB.h"
48+
49+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
50+
#include "SPI.h"
51+
// USB Host using MAX3421E: SPI, CS, INT
52+
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
53+
#else
4954
Adafruit_USBH_Host USBHost;
55+
#endif
5056

5157
// CDC Host object
5258
Adafruit_USBH_CDC SerialHost;
5359

60+
61+
void host_loop()
62+
{
63+
USBHost.task();
64+
65+
// periodically flush SerialHost if connected
66+
if ( SerialHost && SerialHost.connected() ) {
67+
SerialHost.flush();
68+
}
69+
70+
Serial.flush();
71+
}
72+
73+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
5474
//--------------------------------------------------------------------+
55-
// Setup and Loop on Core0
75+
// Using Host shield MAX3421E controller
5676
//--------------------------------------------------------------------+
77+
void setup() {
78+
Serial.begin(115200);
5779

80+
// init host stack on controller (rhport) 1
81+
USBHost.begin(1);
82+
83+
// while ( !Serial ) delay(10); // wait for native usb
84+
Serial.println("TinyUSB Host Serial Echo Example");
85+
}
86+
87+
void loop() {
88+
host_loop();
89+
}
90+
91+
#elif defined(ARDUINO_ARCH_RP2040)
92+
//--------------------------------------------------------------------+
93+
// For RP2040 use both core0 for device stack, core1 for host stack
94+
//--------------------------------------------------------------------+
95+
96+
//------------- Core0 -------------//
5897
void setup() {
5998
Serial.begin(115200);
6099
// while ( !Serial ) delay(10); // wait for native usb
61100

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

65-
void loop()
66-
{
104+
void loop() {
67105
uint8_t buf[64];
68106

69107
// Serial -> SerialHost
@@ -82,10 +120,7 @@ void loop()
82120
}
83121
}
84122

85-
//--------------------------------------------------------------------+
86-
// Setup and Loop on Core1
87-
//--------------------------------------------------------------------+
88-
123+
//------------- Core1 -------------//
89124
void setup1() {
90125
// while ( !Serial ) delay(10); // wait for native usb
91126
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -140,16 +175,12 @@ void setup1() {
140175
SerialHost.begin(115200);
141176
}
142177

143-
void loop1()
144-
{
145-
USBHost.task();
146-
147-
// periodically flush SerialHost if connected
148-
if ( SerialHost && SerialHost.connected() ) {
149-
SerialHost.flush();
150-
}
178+
void loop1() {
179+
host_loop();
151180
}
152181

182+
#endif
183+
153184
//--------------------------------------------------------------------+
154185
// TinyUSB Host callbacks
155186
//--------------------------------------------------------------------+
@@ -169,4 +200,4 @@ void tuh_cdc_umount_cb(uint8_t idx) {
169200
Serial.println("SerialHost is disconnected");
170201
}
171202

172-
}
203+
}

examples/DualRole/HID/hid_device_report/.metro_m0_tinyusb.only

Whitespace-only changes.

examples/DualRole/HID/hid_device_report/.metro_m4_tinyusb.only

Whitespace-only changes.

examples/DualRole/HID/hid_device_report/.nrf52840.only

Whitespace-only changes.

examples/DualRole/HID/hid_device_report/hid_device_report.ino

Lines changed: 43 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,12 @@
2121
* - CPU Speed must be either 120 or 240 Mhz. Selected via "Menu -> CPU Speed"
2222
*/
2323

24+
// Language ID: English
25+
#define LANGUAGE_ID 0x0409
26+
27+
#ifdef ARDUINO_ARCH_RP2040
2428
// pio-usb is required for rp2040 host
2529
#include "pio_usb.h"
26-
#include "Adafruit_TinyUSB.h"
2730

2831
// Pin D+ for host, D- = D+ + 1
2932
#ifndef PIN_USB_HOST_DP
@@ -38,34 +41,58 @@
3841
#ifndef PIN_5V_EN_STATE
3942
#define PIN_5V_EN_STATE 1
4043
#endif
44+
#endif
4145

42-
// Language ID: English
43-
#define LANGUAGE_ID 0x0409
46+
#include "Adafruit_TinyUSB.h"
47+
48+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
4449

45-
// USB Host object
50+
#include "SPI.h"
51+
52+
// USB Host using MAX3421E: SPI, CS, INT
53+
Adafruit_USBH_Host USBHost(&SPI, 10, 9);
54+
#else
4655
Adafruit_USBH_Host USBHost;
56+
#endif
57+
58+
#if defined(CFG_TUH_MAX3421) && CFG_TUH_MAX3421
4759

4860
//--------------------------------------------------------------------+
49-
// Setup and Loop on Core0
61+
// Using Host shield MAX3421E controller
5062
//--------------------------------------------------------------------+
51-
52-
void setup()
53-
{
63+
void setup() {
5464
Serial.begin(115200);
55-
while ( !Serial ) delay(10); // wait for native usb
5665

57-
Serial.println("TinyUSB Dual Device Info Example");
66+
// init host stack on controller (rhport) 1
67+
USBHost.begin(1);
68+
69+
// while ( !Serial ) delay(10); // wait for native usb
70+
Serial.println("TinyUSB Dual: HID Device Report Example");
5871
}
5972

60-
void loop()
61-
{
73+
void loop() {
74+
USBHost.task();
6275
Serial.flush();
6376
}
6477

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

83+
//------------- Core0 -------------//
84+
void setup() {
85+
Serial.begin(115200);
86+
while ( !Serial ) delay(10); // wait for native usb
87+
88+
Serial.println("TinyUSB Dual: HID Device Report Example");
89+
}
90+
91+
void loop() {
92+
Serial.flush();
93+
}
94+
95+
//------------- Core1 -------------//
6996
void setup1() {
7097
//while ( !Serial ) delay(10); // wait for native usb
7198
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
@@ -107,11 +134,12 @@ void setup1() {
107134
USBHost.begin(1);
108135
}
109136

110-
void loop1()
111-
{
137+
void loop1() {
112138
USBHost.task();
113139
}
114140

141+
#endif
142+
115143
extern "C" {
116144

117145
// Invoked when device with hid interface is mounted

0 commit comments

Comments
 (0)