]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/pl2303/pl2303_gps/pl2303_gps.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_gps / pl2303_gps.ino
1 /* USB Host to PL2303-based USB GPS unit interface */
2 /* Navibee GM720 receiver - Sirf Star III */
3 /* USB support */
4 #include <usbhub.h>
5 /* CDC support */
6 #include <cdcacm.h>
7 #include <cdcprolific.h>
8
9 // Satisfy the IDE, which needs to see the include statment in the ino too.
10 #ifdef dobogusinclude
11 #include <spi4teensy3.h>
12 #include <SPI.h>
13 #endif
14
15 class PLAsyncOper : public CDCAsyncOper {
16 public:
17         uint8_t OnInit(ACM *pacm);
18 };
19
20 uint8_t PLAsyncOper::OnInit(ACM *pacm) {
21         uint8_t rcode;
22
23         // Set DTR = 1
24         rcode = pacm->SetControlLineState(1);
25
26         if(rcode) {
27                 ErrorMessage<uint8_t>(PSTR("SetControlLineState"), rcode);
28                 return rcode;
29         }
30
31         LINE_CODING lc;
32         lc.dwDTERate = 4800; //default serial speed of GPS unit
33         lc.bCharFormat = 0;
34         lc.bParityType = 0;
35         lc.bDataBits = 8;
36
37         rcode = pacm->SetLineCoding(&lc);
38
39         if(rcode)
40                 ErrorMessage<uint8_t>(PSTR("SetLineCoding"), rcode);
41
42         return rcode;
43 }
44
45 USB Usb;
46 USBHub Hub(&Usb);
47 PLAsyncOper AsyncOper;
48 PL2303 Pl(&Usb, &AsyncOper);
49 uint32_t read_delay;
50 #define READ_DELAY 100
51
52 void setup() {
53         Serial.begin(115200);
54 #if !defined(__MIPSEL__)
55         while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
56 #endif
57         Serial.println("Start");
58
59         if(Usb.Init() == -1)
60                 Serial.println("OSCOKIRQ failed to assert");
61
62         delay(200);
63 }
64
65 void loop() {
66         uint8_t rcode;
67         uint8_t buf[64]; //serial buffer equals Max.packet size of bulk-IN endpoint
68         uint16_t rcvd = 64;
69
70         Usb.Task();
71
72         if(Pl.isReady()) {
73                 /* reading the GPS */
74                 if((long)(millis() - read_delay) >= 0L) {
75                         read_delay += READ_DELAY;
76                         rcode = Pl.RcvData(&rcvd, buf);
77                         if(rcode && rcode != hrNAK)
78                                 ErrorMessage<uint8_t>(PSTR("Ret"), rcode);
79                         if(rcvd) { //more than zero bytes received
80                                 for(uint16_t i = 0; i < rcvd; i++) {
81                                         Serial.print((char)buf[i]); //printing on the screen
82                                 }//for( uint16_t i=0; i < rcvd; i++...
83                         }//if( rcvd
84                 }//if( read_delay > millis()...
85         }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING..
86 }
87
88