]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/pl2303/pl2303_gprs_terminal/pl2303_gprs_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 / pl2303 / pl2303_gprs_terminal / pl2303_gprs_terminal.ino
1 /* Arduino terminal for PL2303 USB to serial converter and DealeXtreme GPRS modem. */
2 /* USB support */
3 #include <usbhub.h>
4 /* CDC support */
5 #include <cdcacm.h>
6 #include <cdcprolific.h>
7
8 // Satisfy the IDE, which needs to see the include statment in the ino too.
9 #ifdef dobogusinclude
10 #include <spi4teensy3.h>
11 #include <SPI.h>
12 #endif
13
14 class PLAsyncOper : public CDCAsyncOper
15 {
16 public:
17     uint8_t OnInit(ACM *pacm);
18 };
19
20 uint8_t PLAsyncOper::OnInit(ACM *pacm)
21 {
22     uint8_t rcode;
23
24     // Set DTR = 1
25     rcode = pacm->SetControlLineState(1);
26
27     if (rcode)
28     {
29         ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
30         return rcode;
31     }
32
33     LINE_CODING lc;
34     //lc.dwDTERate      = 9600;
35     lc.dwDTERate = 115200;
36     lc.bCharFormat      = 0;
37     lc.bParityType      = 0;
38     lc.bDataBits        = 8;
39
40     rcode = pacm->SetLineCoding(&lc);
41
42     if (rcode)
43         ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
44
45     return rcode;
46 }
47 USB     Usb;
48 //USBHub     Hub(&Usb);
49 PLAsyncOper  AsyncOper;
50 PL2303       Pl(&Usb, &AsyncOper);
51
52 void setup()
53 {
54   Serial.begin( 115200 );
55 #if !defined(__MIPSEL__)
56   while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
57 #endif
58   Serial.println("Start");
59
60   if (Usb.Init() == -1)
61       Serial.println("OSCOKIRQ failed to assert");
62
63   delay( 200 );
64 }
65
66 void loop()
67 {
68     Usb.Task();
69
70     if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
71     {
72        uint8_t rcode;
73
74        /* reading the keyboard */
75        if(Serial.available()) {
76          uint8_t data= Serial.read();
77
78          /* sending to the phone */
79          rcode = Pl.SndData(1, &data);
80          if (rcode)
81             ErrorMessage<uint8_t>(PSTR("SndData"), rcode);
82        }//if(Serial.available()...
83
84         /* reading the converter */
85         /* buffer size must be greater or equal to max.packet size */
86         /* it it set to 64 (largest possible max.packet size) here, can be tuned down
87         for particular endpoint */
88         uint8_t  buf[64];
89         uint16_t rcvd = 64;
90         rcode = Pl.RcvData(&rcvd, buf);
91          if (rcode && rcode != hrNAK)
92            ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
93
94            if( rcvd ) { //more than zero bytes received
95              for(uint16_t i=0; i < rcvd; i++ ) {
96                Serial.print((char)buf[i]); //printing on the screen
97              }
98            }//if( rcvd ...
99     }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
100 }
101