]> git.friedersdorff.com Git - max/tmk_keyboard.git/blob - tmk_core/protocol/usb_hid/USB_Host_Shield_2.0/examples/adk/demokit_20/demokit_20.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 / adk / demokit_20 / demokit_20.ino
1 #include <adk.h>
2 #include <usbhub.h>
3
4 // Satisfy IDE, which only needs to see the include statment in the ino.
5 #ifdef dobogusinclude
6 #include <spi4teensy3.h>
7 #include <SPI.h>
8 #endif
9
10 USB Usb;
11 USBHub hub0(&Usb);
12 USBHub hub1(&Usb);
13 ADK adk(&Usb,"Google, Inc.",
14             "DemoKit",
15             "DemoKit Arduino Board",
16             "1.0",
17             "http://www.android.com",
18             "0000000012345678");
19 uint8_t  b, b1;
20
21
22 #define  LED1_RED       3
23 #define  BUTTON1        2
24
25 void init_buttons()
26 {
27         pinMode(BUTTON1, INPUT);
28
29         // enable the internal pullups
30         digitalWrite(BUTTON1, HIGH);
31 }
32
33 void init_leds()
34 {
35         digitalWrite(LED1_RED, 0);
36
37         pinMode(LED1_RED, OUTPUT);
38 }
39
40 void setup()
41 {
42         Serial.begin(115200);
43 #if !defined(__MIPSEL__)
44   while (!Serial); // Wait for serial port to connect - used on Leonardo, Teensy and other boards with built-in USB CDC serial connection
45 #endif
46         Serial.println("\r\nADK demo start");
47
48         if (Usb.Init() == -1) {
49           Serial.println("OSCOKIRQ failed to assert");
50         while(1); //halt
51         }//if (Usb.Init() == -1...
52
53
54         init_leds();
55         init_buttons();
56         b1 = digitalRead(BUTTON1);
57 }
58
59 void loop()
60 {
61   uint8_t rcode;
62   uint8_t msg[3] = { 0x00 };
63    Usb.Task();
64
65    if( adk.isReady() == false ) {
66      analogWrite(LED1_RED, 255);
67      return;
68    }
69    uint16_t len = sizeof(msg);
70
71    rcode = adk.RcvData(&len, msg);
72    if( rcode ) {
73      USBTRACE2("Data rcv. :", rcode );
74    }
75    if(len > 0) {
76      USBTRACE("\r\nData Packet.");
77     // assumes only one command per packet
78     if (msg[0] == 0x2) {
79       switch( msg[1] ) {
80         case 0:
81           analogWrite(LED1_RED, 255 - msg[2]);
82           break;
83       }//switch( msg[1]...
84     }//if (msg[0] == 0x2...
85    }//if( len > 0...
86
87    msg[0] = 0x1;
88
89    b = digitalRead(BUTTON1);
90    if (b != b1) {
91      USBTRACE("\r\nButton state changed");
92      msg[1] = 0;
93      msg[2] = b ? 0 : 1;
94      rcode = adk.SndData( 3, msg );
95      if( rcode ) {
96        USBTRACE2("Button send: ", rcode );
97      }
98      b1 = b;
99     }//if (b != b1...
100
101
102       delay( 10 );
103 }