summaryrefslogtreecommitdiff
path: root/lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411
diff options
context:
space:
mode:
authorRyan <fauxpark@gmail.com>2021-08-18 18:20:25 +1000
committerGitHub <noreply@github.com>2021-08-18 18:20:25 +1000
commitb16091659cc9a724a8800f77e631643b4ab089ad (patch)
treee44933472c6d100bd4fc5d8a693d9d21e3c32f6f /lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411
parentcf5e40c25139ff64ff246f1c6280e983ef75551c (diff)
Move USB Host Shield and Arduino core to `lib/` (#13973)
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino83
1 files changed, 83 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino b/lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino
new file mode 100644
index 0000000000..0173a08b50
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino
@@ -0,0 +1,83 @@
+#include <cdc_XR21B1411.h>
+
+// Satisfy IDE, which only needs to see the include statment in the ino.
+#ifdef dobogusinclude
+#include <spi4teensy3.h>
+#include <SPI.h>
+#endif
+
+class ACMAsyncOper : public CDCAsyncOper
+{
+public:
+ uint8_t OnInit(ACM *pacm);
+};
+
+uint8_t ACMAsyncOper::OnInit(ACM *pacm)
+{
+ uint8_t rcode;
+ // Set DTR = 1 RTS=1
+ rcode = pacm->SetControlLineState(3);
+
+ if (rcode)
+ {
+ ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
+ return rcode;
+ }
+
+ LINE_CODING lc;
+ lc.dwDTERate = 115200;
+ lc.bCharFormat = 0;
+ lc.bParityType = 0;
+ lc.bDataBits = 8;
+
+ rcode = pacm->SetLineCoding(&lc);
+
+ if (rcode)
+ ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
+
+ return rcode;
+}
+
+USB Usb;
+ACMAsyncOper AsyncOper;
+XR21B1411 Acm(&Usb, &AsyncOper);
+
+void setup() {
+ Serial.begin( 115200 );
+#if !defined(__MIPSEL__)
+ while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
+#endif
+ Serial.println("\r\n\r\nStart");
+
+ if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert");
+}
+
+void loop() {
+ Usb.Task();
+ if( Acm.isReady()) {
+ uint8_t rcode;
+ uint8_t buf[1];
+ uint16_t rcvd = 1;
+
+ /* read keyboard */
+ if(Serial.available()) {
+ uint8_t data = Serial.read();
+ /* send */
+ rcode = Acm.SndData(1, &data);
+ if (rcode)
+ ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
+ }
+
+ /* read XR serial */
+ rcode = Acm.RcvData(&rcvd, buf);
+ if (rcode && rcode != hrNAK)
+ ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
+
+ if( rcvd ) { //more than zero bytes received
+ for(uint16_t i=0; i < rcvd; i++ ) {
+ Serial.print((char)buf[i]);
+ }
+ }
+ }
+}
+