Skip to content

Commit 9aaa6c9

Browse files
committed
update serial host bridge example
1 parent 29a0342 commit 9aaa6c9

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

examples/DualRole/CDC/serial_host_bridge/serial_host_bridge.ino

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -56,10 +56,8 @@ Adafruit_USBH_CDC SerialHost;
5656
//--------------------------------------------------------------------+
5757

5858
void setup() {
59-
Serial1.begin(115200);
60-
6159
Serial.begin(115200);
62-
while ( !Serial ) delay(10); // wait for native usb
60+
// while ( !Serial ) delay(10); // wait for native usb
6361

6462
Serial.println("TinyUSB Host Serial Echo Example");
6563
}
@@ -89,7 +87,7 @@ void loop()
8987
//--------------------------------------------------------------------+
9088

9189
void setup1() {
92-
while ( !Serial ) delay(10); // wait for native usb
90+
// while ( !Serial ) delay(10); // wait for native usb
9391
Serial.println("Core1 setup to run TinyUSB host with pio-usb");
9492

9593
// Check for CPU frequency, must be multiple of 120Mhz for bit-banging USB
@@ -125,6 +123,8 @@ void setup1() {
125123
// Note: For rp2040 pico-pio-usb, calling USBHost.begin() on core1 will have most of the
126124
// host bit-banging processing works done in core1 to free up core0 for other works
127125
USBHost.begin(1);
126+
127+
SerialHost.begin(115200);
128128
}
129129

130130
void loop1()
@@ -140,23 +140,20 @@ void loop1()
140140
//--------------------------------------------------------------------+
141141
// TinyUSB Host callbacks
142142
//--------------------------------------------------------------------+
143+
extern "C" {
143144

144145
// Invoked when a device with CDC interface is mounted
145146
// idx is index of cdc interface in the internal pool.
146147
void tuh_cdc_mount_cb(uint8_t idx) {
147148
// bind SerialHost object to this interface index
148-
SerialHost.setInterfaceIndex(idx);
149-
SerialHost.begin(115200);
150-
149+
SerialHost.mount(idx);
151150
Serial.println("SerialHost is connected to a new CDC device");
152151
}
153152

154153
// Invoked when a device with CDC interface is unmounted
155154
void tuh_cdc_umount_cb(uint8_t idx) {
156-
if (idx == SerialHost.getInterfaceIndex()) {
157-
// unbind SerialHost if this interface is unmounted
158-
SerialHost.end();
159-
160-
Serial.println("SerialHost is disconnected");
161-
}
155+
SerialHost.umount(idx);
156+
Serial.println("SerialHost is disconnected");
162157
}
158+
159+
}

0 commit comments

Comments
 (0)