You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

adk.h 4.4KB

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