aboutsummaryrefslogtreecommitdiff
path: root/lib/usbhost/USB_Host_Shield_2.0/adk.h
diff options
context:
space:
mode:
Diffstat (limited to 'lib/usbhost/USB_Host_Shield_2.0/adk.h')
-rw-r--r--lib/usbhost/USB_Host_Shield_2.0/adk.h140
1 files changed, 140 insertions, 0 deletions
diff --git a/lib/usbhost/USB_Host_Shield_2.0/adk.h b/lib/usbhost/USB_Host_Shield_2.0/adk.h
new file mode 100644
index 000000000..4a2920b88
--- /dev/null
+++ b/lib/usbhost/USB_Host_Shield_2.0/adk.h
@@ -0,0 +1,140 @@
1/* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2
3This software may be distributed and modified under the terms of the GNU
4General Public License version 2 (GPL2) as published by the Free Software
5Foundation and appearing in the file GPL2.TXT included in the packaging of
6this file. Please note that GPL2 Section 2[b] requires that all works based
7on this software must also be made publicly available under the terms of
8the GPL2 ("Copyleft").
9
10Contact information
11-------------------
12
13Circuits At Home, LTD
14Web : http://www.circuitsathome.com
15e-mail : support@circuitsathome.com
16 */
17
18/* Google ADK interface support header */
19
20#if !defined(_ADK_H_)
21#define _ADK_H_
22
23#include "Usb.h"
24
25#define ADK_VID 0x18D1
26#define ADK_PID 0x2D00
27#define ADB_PID 0x2D01
28
29#define XOOM //enables repeating getProto() and getConf() attempts
30//necessary for slow devices such as Motorola XOOM
31//defined by default, can be commented out to save memory
32
33/* requests */
34
35#define ADK_GETPROTO 51 //check USB accessory protocol version
36#define ADK_SENDSTR 52 //send identifying string
37#define ADK_ACCSTART 53 //start device in accessory mode
38
39#define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
40#define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
41
42#define ACCESSORY_STRING_MANUFACTURER 0
43#define ACCESSORY_STRING_MODEL 1
44#define ACCESSORY_STRING_DESCRIPTION 2
45#define ACCESSORY_STRING_VERSION 3
46#define ACCESSORY_STRING_URI 4
47#define ACCESSORY_STRING_SERIAL 5
48
49#define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT
50
51class ADK;
52
53class ADK : public USBDeviceConfig, public UsbConfigXtracter {
54private:
55 /* ID strings */
56 const char* manufacturer;
57 const char* model;
58 const char* description;
59 const char* version;
60 const char* uri;
61 const char* serial;
62
63 /* ADK proprietary requests */
64 uint8_t getProto(uint8_t* adkproto);
65 uint8_t sendStr(uint8_t index, const char* str);
66 uint8_t switchAcc(void);
67
68protected:
69 static const uint8_t epDataInIndex; // DataIn endpoint index
70 static const uint8_t epDataOutIndex; // DataOUT endpoint index
71
72 /* mandatory members */
73 USB *pUsb;
74 uint8_t bAddress;
75 uint8_t bConfNum; // configuration number
76
77 uint8_t bNumEP; // total number of EP in the configuration
78 bool ready;
79
80 /* Endpoint data structure */
81 EpInfo epInfo[ADK_MAX_ENDPOINTS];
82
83 void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr);
84
85public:
86 ADK(USB *pUsb, const char* manufacturer,
87 const char* model,
88 const char* description,
89 const char* version,
90 const char* uri,
91 const char* serial);
92
93 // Methods for receiving and sending data
94 uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
95 uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
96
97
98 // USBDeviceConfig implementation
99 uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
100 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
101 uint8_t Release();
102
103 virtual uint8_t Poll() {
104 return 0;
105 };
106
107 virtual uint8_t GetAddress() {
108 return bAddress;
109 };
110
111 virtual bool isReady() {
112 return ready;
113 };
114
115 virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) {
116 return (vid == ADK_VID && (pid == ADK_PID || pid == ADB_PID));
117 };
118
119 //UsbConfigXtracter implementation
120 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
121}; //class ADK : public USBDeviceConfig ...
122
123/* get ADK protocol version */
124
125/* returns 2 bytes in *adkproto */
126inline uint8_t ADK::getProto(uint8_t* adkproto) {
127 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL));
128}
129
130/* send ADK string */
131inline uint8_t ADK::sendStr(uint8_t index, const char* str) {
132 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL));
133}
134
135/* switch to accessory mode */
136inline uint8_t ADK::switchAcc(void) {
137 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
138}
139
140#endif // _ADK_H_