Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: UsbHostMAX3421E_Hello
adk.h
00001 /* Copyright (C) 2011 Circuits At Home, LTD. All rights reserved. 00002 00003 This software may be distributed and modified under the terms of the GNU 00004 General Public License version 2 (GPL2) as published by the Free Software 00005 Foundation and appearing in the file GPL2.TXT included in the packaging of 00006 this file. Please note that GPL2 Section 2[b] requires that all works based 00007 on this software must also be made publicly available under the terms of 00008 the GPL2 ("Copyleft"). 00009 00010 Contact information 00011 ------------------- 00012 00013 Circuits At Home, LTD 00014 Web : http://www.circuitsathome.com 00015 e-mail : support@circuitsathome.com 00016 */ 00017 00018 /* Google ADK interface support header */ 00019 00020 #if !defined(_ADK_H_) 00021 #define _ADK_H_ 00022 00023 #include "Usb.h" 00024 00025 #define ADK_VID 0x18D1 00026 #define ADK_PID 0x2D00 00027 #define ADB_PID 0x2D01 00028 00029 #define XOOM //enables repeating getProto() and getConf() attempts 00030 //necessary for slow devices such as Motorola XOOM 00031 //defined by default, can be commented out to save memory 00032 00033 /* requests */ 00034 00035 #define ADK_GETPROTO 51 //check USB accessory protocol version 00036 #define ADK_SENDSTR 52 //send identifying string 00037 #define ADK_ACCSTART 53 //start device in accessory mode 00038 00039 #define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE 00040 #define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE 00041 00042 #define ACCESSORY_STRING_MANUFACTURER 0 00043 #define ACCESSORY_STRING_MODEL 1 00044 #define ACCESSORY_STRING_DESCRIPTION 2 00045 #define ACCESSORY_STRING_VERSION 3 00046 #define ACCESSORY_STRING_URI 4 00047 #define ACCESSORY_STRING_SERIAL 5 00048 00049 #define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT 00050 00051 class ADK; 00052 00053 class ADK : public USBDeviceConfig, public UsbConfigXtracter { 00054 private: 00055 /* ID strings */ 00056 const char* manufacturer; 00057 const char* model; 00058 const char* description; 00059 const char* version; 00060 const char* uri; 00061 const char* serial; 00062 00063 /* ADK proprietary requests */ 00064 uint8_t getProto(uint8_t* adkproto); 00065 uint8_t sendStr(uint8_t index, const char* str); 00066 uint8_t switchAcc(void); 00067 00068 protected: 00069 static const uint8_t epDataInIndex; // DataIn endpoint index 00070 static const uint8_t epDataOutIndex; // DataOUT endpoint index 00071 00072 /* mandatory members */ 00073 Usb *pUsb; 00074 uint8_t bAddress; 00075 uint8_t bConfNum; // configuration number 00076 00077 uint8_t bNumEP; // total number of EP in the configuration 00078 bool ready; 00079 00080 /* Endpoint data structure */ 00081 EpInfo epInfo[ADK_MAX_ENDPOINTS]; 00082 00083 void PrintEndpointDescriptor(const USB_ENDPOINT_DESCRIPTOR* ep_ptr); 00084 00085 public: 00086 ADK(Usb *pUsb, const char* manufacturer, 00087 const char* model, 00088 const char* description, 00089 const char* version, 00090 const char* uri, 00091 const char* serial); 00092 00093 // Methods for receiving and sending data 00094 uint8_t RcvData(uint16_t *nbytesptr, uint8_t *dataptr); 00095 uint8_t SndData(uint16_t nbytes, uint8_t *dataptr); 00096 00097 00098 // USBDeviceConfig implementation 00099 uint8_t ConfigureDevice(uint8_t parent, uint8_t port, bool lowspeed); 00100 uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed); 00101 uint8_t Release(); 00102 00103 virtual uint8_t Poll() { 00104 return 0; 00105 }; 00106 00107 virtual uint8_t GetAddress() { 00108 return bAddress; 00109 }; 00110 00111 virtual bool isReady() { 00112 return ready; 00113 }; 00114 00115 virtual bool VIDPIDOK(uint16_t vid, uint16_t pid) { 00116 return (vid == ADK_VID && (pid == ADK_PID || pid == ADB_PID)); 00117 }; 00118 00119 //UsbConfigXtracter implementation 00120 void EndpointXtract(uint8_t conf, uint8_t iface, uint8_t alt, uint8_t proto, const USB_ENDPOINT_DESCRIPTOR *ep); 00121 }; //class ADK : public USBDeviceConfig ... 00122 00123 /* get ADK protocol version */ 00124 00125 /* returns 2 bytes in *adkproto */ 00126 inline uint8_t ADK::getProto(uint8_t* adkproto) { 00127 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL)); 00128 } 00129 00130 /* send ADK string */ 00131 inline uint8_t ADK::sendStr(uint8_t index, const char* str) { 00132 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL)); 00133 } 00134 00135 /* switch to accessory mode */ 00136 inline uint8_t ADK::switchAcc(void) { 00137 return ( pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL)); 00138 } 00139 00140 #endif // _ADK_H_
Generated on Tue Jul 12 2022 18:12:04 by
1.7.2