USB Host Shield 2.0
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
adk.h
Go to the documentation of this file.
1 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved.
2 
3 This software may be distributed and modified under the terms of the GNU
4 General Public License version 2 (GPL2) as published by the Free Software
5 Foundation and appearing in the file GPL2.TXT included in the packaging of
6 this file. Please note that GPL2 Section 2[b] requires that all works based
7 on this software must also be made publicly available under the terms of
8 the GPL2 ("Copyleft").
9 
10 Contact information
11 -------------------
12 
13 Circuits At Home, LTD
14 Web : http://www.circuitsathome.com
15 e-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 /* requests */
30 
31 #define ADK_GETPROTO 51 //check USB accessory protocol version
32 #define ADK_SENDSTR 52 //send identifying string
33 #define ADK_ACCSTART 53 //start device in accessory mode
34 
35 #define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
36 #define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
37 
38 #define ACCESSORY_STRING_MANUFACTURER 0
39 #define ACCESSORY_STRING_MODEL 1
40 #define ACCESSORY_STRING_DESCRIPTION 2
41 #define ACCESSORY_STRING_VERSION 3
42 #define ACCESSORY_STRING_URI 4
43 #define ACCESSORY_STRING_SERIAL 5
44 
45 #define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT
46 
47 class ADK;
48 
49 class ADK : public USBDeviceConfig, public UsbConfigXtracter {
50 private:
51  /* ID strings */
52  const char* manufacturer;
53  const char* model;
54  const char* description;
55  const char* version;
56  const char* uri;
57  const char* serial;
58 
59  /* ADK proprietary requests */
60  uint8_t getProto(uint8_t* adkproto);
61  uint8_t sendStr(uint8_t index, const char* str);
62  uint8_t switchAcc(void);
63 
64 protected:
65  static const uint8_t epDataInIndex; // DataIn endpoint index
66  static const uint8_t epDataOutIndex; // DataOUT endpoint index
67 
68  /* mandatory members */
70  uint8_t bAddress;
71  uint8_t bConfNum; // configuration number
72 
73  uint8_t bNumEP; // total number of EP in the configuration
74  bool ready;
75 
76  /* Endpoint data structure */
78 
80 
81 public:
82  ADK(USB *pUsb, const char* manufacturer,
83  const char* model,
84  const char* description,
85  const char* version,
86  const char* uri,
87  const char* serial);
88 
89  // Methods for receiving and sending data
90  uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr);
91  uint8_t SndData(uint16_t nbytes, uint8_t *dataptr);
92 
93 
94  // USBDeviceConfig implementation
95  virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed);
96  virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
97  virtual uint8_t Release();
98 
99  virtual uint8_t Poll() {
100  return 0;
101  };
102 
103  virtual uint8_t GetAddress() {
104  return bAddress;
105  };
106 
107  virtual bool isReady() {
108  return ready;
109  };
110 
111  virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid) {
112  return (vid == ADK_VID && (pid == ADK_PID || pid == ADB_PID));
113  };
114 
115  //UsbConfigXtracter implementation
116  virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
117 }; //class ADK : public USBDeviceConfig ...
118 
119 /* get ADK protocol version */
120 
121 /* returns 2 bytes in *adkproto */
122 inline uint8_t ADK::getProto(uint8_t* adkproto) {
123  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL));
124 }
125 
126 /* send ADK string */
127 inline uint8_t ADK::sendStr(uint8_t index, const char* str) {
128  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*) str, NULL));
129 }
130 
131 /* switch to accessory mode */
132 inline uint8_t ADK::switchAcc(void) {
133  return( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
134 }
135 
136 #endif // _ADK_H_
#define ADB_PID
Definition: adk.h:27
static const uint8_t epDataInIndex
Definition: adk.h:65
uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr)
Definition: adk.cpp:325
virtual uint8_t Release()
Definition: adk.cpp:315
uint8_t SndData(uint16_t nbytes, uint8_t *dataptr)
Definition: adk.cpp:331
virtual void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep)
Definition: adk.cpp:287
USB * pUsb
Definition: adk.h:69
virtual uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:61
#define ADK_GETPROTO
Definition: adk.h:31
virtual bool isReady()
Definition: adk.h:107
static const uint8_t epDataOutIndex
Definition: adk.h:66
Definition: adk.h:49
#define ADK_ACCSTART
Definition: adk.h:33
#define ADK_PID
Definition: adk.h:26
virtual uint8_t Poll()
Definition: adk.h:99
uint8_t ctrlReq(uint8_t addr, uint8_t ep, uint8_t bmReqType, uint8_t bRequest, uint8_t wValLo, uint8_t wValHi, uint16_t wInd, uint16_t total, uint16_t nbytes, uint8_t *dataptr, USBReadParser *p)
Definition: Usb.cpp:126
#define ADK_SENDSTR
Definition: adk.h:32
#define bmREQ_ADK_GET
Definition: adk.h:35
bool ready
Definition: adk.h:74
virtual uint8_t GetAddress()
Definition: adk.h:103
Definition: address.h:32
virtual boolean VIDPIDOK(uint16_t vid, uint16_t pid)
Definition: adk.h:111
ADK(USB *pUsb, const char *manufacturer, const char *model, const char *description, const char *version, const char *uri, const char *serial)
Definition: adk.cpp:25
EpInfo epInfo[ADK_MAX_ENDPOINTS]
Definition: adk.h:77
#define bmREQ_ADK_SEND
Definition: adk.h:36
#define ADK_MAX_ENDPOINTS
Definition: adk.h:45
void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR *ep_ptr)
Definition: adk.cpp:335
virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed)
Definition: adk.cpp:66
Definition: UsbCore.h:152
uint8_t bNumEP
Definition: adk.h:73
#define ADK_VID
Definition: adk.h:25
uint8_t bConfNum
Definition: adk.h:71
uint8_t bAddress
Definition: adk.h:70