]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/cdc_XR21B1411/XR_terminal/XR_terminal.ino
lufa: usb-usb: Use LUFA startup instead of cusotom
[max/tmk_keyboard.git] / tmk_core / protocol / usb_hid / USB_Host_Shield_2.0 / examples / cdc_XR21B1411 / XR_terminal / XR_terminal.ino
1 #include <cdc_XR21B1411.h>
2
3 // Satisfy IDE, which only needs to see the include statment in the ino.
4 #ifdef dobogusinclude
5 #include <spi4teensy3.h>
6 #include <SPI.h>
7 #endif
8
9 class ACMAsyncOper : public CDCAsyncOper
10 {
11 public:
12     uint8_t OnInit(ACM *pacm);
13 };
14
15 uint8_t ACMAsyncOper::OnInit(ACM *pacm)
16 {
17     uint8_t rcode;
18     // Set DTR = 1 RTS=1
19     rcode = pacm->SetControlLineState(3);
20
21     if (rcode)
22     {
23         ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
24         return rcode;
25     }
26
27     LINE_CODING lc;
28     lc.dwDTERate        = 115200;
29     lc.bCharFormat      = 0;
30     lc.bParityType      = 0;
31     lc.bDataBits        = 8;
32
33     rcode = pacm->SetLineCoding(&lc);
34
35     if (rcode)
36         ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
37
38     return rcode;
39 }
40
41 USB     Usb;
42 ACMAsyncOper  AsyncOper;
43 XR21B1411     Acm(&Usb, &AsyncOper);
44
45 void setup() {
46         Serial.begin( 115200 );
47 #if !defined(__MIPSEL__)
48         while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
49 #endif
50         Serial.println("\r\n\r\nStart");
51
52         if (Usb.Init() == -1) Serial.println("OSCOKIRQ failed to assert");
53 }
54
55 void loop() {
56         Usb.Task();
57         if( Acm.isReady()) {
58                 uint8_t rcode;
59                 uint8_t  buf[1];
60                 uint16_t rcvd = 1;
61
62                 /* read keyboard */
63                 if(Serial.available()) {
64                          uint8_t data = Serial.read();
65                          /* send */
66                          rcode = Acm.SndData(1, &data);
67                          if (rcode)
68                                  ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
69                  }
70                 
71                 /* read XR serial */
72                 rcode = Acm.RcvData(&rcvd, buf);
73                 if (rcode && rcode != hrNAK)
74                         ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
75
76                 if( rcvd ) { //more than zero bytes received
77                         for(uint16_t i=0; i < rcvd; i++ ) {
78                                 Serial.print((char)buf[i]);
79                         }
80                 }
81         }
82 }
83