Skip to content

Commit 69576fb

Browse files
committed
Simplify the example, use MIT license for compatibility/clarity.
1 parent fc84b31 commit 69576fb

File tree

3 files changed

+28
-376
lines changed

3 files changed

+28
-376
lines changed

examples/CDC/multiCDC/multiCDC.ino

Lines changed: 28 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11
/*
2-
This example demonstrates the use of multiple USB CDC/ACM "Virtual Serial" ports,
3-
using Ha Thach's tinyUSB library, and the port of that library to the Arduino environment
2+
This example demonstrates the use of multiple USB CDC/ACM "Virtual
3+
Serial" ports, using Ha Thach's tinyUSB library, and the port of
4+
that library to the Arduino environment
5+
46
https://github.com/hathach/tinyusb
57
https://github.com/adafruit/Adafruit_TinyUSB_Arduino
68
79
Written by Bill Westfield (aka WestfW), June 2021.
8-
This code is released to the public domain (note that this is a different
9-
license than the rest of the TinyUSB library and examples.)
10+
Copyright 2021 by Bill Westfield
11+
MIT license, check LICENSE for more information
1012
11-
The example creates three virtual serial ports, runs a non-blocking parser on
12-
each one, and allows them to send messages to each other. This is pretty useless,
13-
and is relatively complex for an example, but it exercises a bunch of the CDC features.
13+
The example creates three virtual serial ports. Text entered on
14+
any of the ports will be echoed to the other two ports.
1415
15-
The max number of CDC ports (CFG_TUD_CDC) has to be changed to at least 3, changed in
16-
the core tusb_config.h file.
16+
The max number of CDC ports (CFG_TUD_CDC) has to be changed to at
17+
least 3, changed in the core tusb_config.h file.
1718
*/
1819

1920
#include <Adafruit_TinyUSB.h>
20-
#include "simpleParser.h"
2121

2222
#define LED LED_BUILTIN
2323

@@ -47,74 +47,31 @@ void setup() {
4747
}
4848
delay(1000);
4949
}
50-
Serial.print("You are TTY0\n\r\n0> ");
51-
USBSer2.print("You are TTY1\n\r\n1> ");
52-
USBSer3.print("You are TTY2\n\r\n2> ");
50+
Serial.print("You are port 0\n\r\n0> ");
51+
USBSer2.print("You are port 1\n\r\n1> ");
52+
USBSer3.print("You are port 2\n\r\n2> ");
5353
}
5454

55-
56-
// We need a parser for each Virtual Serial port
57-
simpleParser<80> line0(Serial);
58-
simpleParser<80> line1(USBSer2);
59-
simpleParser<80> line2(USBSer3);
60-
6155
int LEDstate = 0;
6256

63-
// Given an input port and an output port and a message, send it off.
64-
65-
void sendmsg(Adafruit_USBD_CDC &out, Adafruit_USBD_CDC &in, char *msg) {
66-
out.print("\r\nTTY");
67-
out.print(in.getInstance());
68-
out.print(": ");
69-
out.println(msg);
70-
out.flush();
71-
}
72-
73-
// we've received a line on some port. Check if it's a valid comand,
74-
// parse the arguments, and take appropriate action
75-
void parseMsg(Adafruit_USBD_CDC &in, parserCore &parser) {
76-
int target;
77-
enum { CMD_SEND, CMD_HELP, CMD_HELP2 };
78-
int cmd = parser.keyword("send help ? ");
79-
switch (cmd) {
80-
case CMD_SEND:
81-
target = parser.number();
82-
if (target < 0 || target >= CFG_TUD_CDC || ports[target] == NULL) {
83-
in.println("Bad target line");
84-
return;
85-
}
86-
sendmsg(*ports[target], in, parser.restOfLine());
87-
break;
88-
89-
case CMD_HELP:
90-
case CMD_HELP2:
91-
in.println("Available commands:\r\n SEND N msg");
92-
break;
93-
default:
94-
in.println("invalid command");
95-
break;
96-
}
97-
}
98-
9957
void loop() {
100-
if (line0.getLine()) {
101-
parseMsg(Serial, line0);
102-
line0.reset();
103-
Serial.print("0> ");
104-
58+
int ch;
59+
ch = Serial.read();
60+
if (ch > 0) {
61+
USBSer2.write(ch);
62+
USBSer3.write(ch);
10563
}
106-
if (line1.getLine()) {
107-
parseMsg(USBSer2, line1);
108-
line1.reset();
109-
USBSer2.print("1> ");
64+
ch = USBSer2.read();
65+
if (ch > 0) {
66+
Serial.write(ch);
67+
USBSer3.write(ch);
11068
}
111-
if (line2.getLine()) {
112-
parseMsg(USBSer3, line2);
113-
line2.reset();
114-
USBSer3.print("2> ");
69+
ch = USBSer3.read();
70+
if (ch > 0) {
71+
Serial.write(ch);
72+
USBSer2.write(ch);
11573
}
11674
if (delay_without_delaying(500)) {
117-
// blink LED to show we're still alive
11875
LEDstate = !LEDstate;
11976
digitalWrite(LED, LEDstate);
12077
}
@@ -132,3 +89,5 @@ boolean delay_without_delaying(unsigned long time) {
13289
}
13390
return false;
13491
}
92+
93+
// Helper: non-blocking line-at-a-time read.

examples/CDC/multiCDC/simpleParser.cpp

Lines changed: 0 additions & 246 deletions
This file was deleted.

0 commit comments

Comments
 (0)