[136] | 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 | #ifndef ADK_H_INCLUDED
|
---|
| 21 | #define ADK_H_INCLUDED
|
---|
| 22 |
|
---|
| 23 | #include <stdint.h>
|
---|
| 24 | #include "usb_ch9.h"
|
---|
| 25 | #include "Usb.h"
|
---|
| 26 | #include "hid.h"
|
---|
| 27 | #include "Arduino.h"
|
---|
| 28 | #include "confdescparser.h"
|
---|
| 29 |
|
---|
| 30 | #define ADK_VID 0x18D1
|
---|
| 31 | #define ADK_PID 0x2D00
|
---|
| 32 | #define ADB_PID 0x2D01
|
---|
| 33 |
|
---|
| 34 | #define XOOM //enables repeating getProto() and getConf() attempts
|
---|
| 35 | //necessary for slow devices such as Motorola XOOM
|
---|
| 36 | //defined by default, can be commented out to save memory
|
---|
| 37 |
|
---|
| 38 | /* Requests */
|
---|
| 39 |
|
---|
| 40 | #define ADK_GETPROTO 51 //check USB accessory protocol version
|
---|
| 41 | #define ADK_SENDSTR 52 //send identifying string
|
---|
| 42 | #define ADK_ACCSTART 53 //start device in accessory mode
|
---|
| 43 |
|
---|
| 44 | #define bmREQ_ADK_GET USB_SETUP_DEVICE_TO_HOST|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
|
---|
| 45 | #define bmREQ_ADK_SEND USB_SETUP_HOST_TO_DEVICE|USB_SETUP_TYPE_VENDOR|USB_SETUP_RECIPIENT_DEVICE
|
---|
| 46 |
|
---|
| 47 | #define ACCESSORY_STRING_MANUFACTURER 0
|
---|
| 48 | #define ACCESSORY_STRING_MODEL 1
|
---|
| 49 | #define ACCESSORY_STRING_DESCRIPTION 2
|
---|
| 50 | #define ACCESSORY_STRING_VERSION 3
|
---|
| 51 | #define ACCESSORY_STRING_URI 4
|
---|
| 52 | #define ACCESSORY_STRING_SERIAL 5
|
---|
| 53 |
|
---|
| 54 | #define ADK_MAX_ENDPOINTS 3 //endpoint 0, bulk_IN, bulk_OUT
|
---|
| 55 |
|
---|
| 56 | /**
|
---|
| 57 | * \class ADK definition.
|
---|
| 58 | */
|
---|
| 59 | class ADK : public USBDeviceConfig, public UsbConfigXtracter
|
---|
| 60 | {
|
---|
| 61 | private:
|
---|
| 62 | /* ID strings */
|
---|
| 63 | const char* manufacturer;
|
---|
| 64 | const char* model;
|
---|
| 65 | const char* description;
|
---|
| 66 | const char* version;
|
---|
| 67 | const char* uri;
|
---|
| 68 | const char* serial;
|
---|
| 69 |
|
---|
| 70 | /* ADK proprietary requests */
|
---|
| 71 | uint32_t getProto(uint8_t* adkproto);
|
---|
| 72 | uint32_t sendStr(uint32_t index, const char* str);
|
---|
| 73 | uint32_t switchAcc(void);
|
---|
| 74 |
|
---|
| 75 | protected:
|
---|
| 76 | static const uint32_t epDataInIndex; // DataIn endpoint index
|
---|
| 77 | static const uint32_t epDataOutIndex; // DataOUT endpoint index
|
---|
| 78 |
|
---|
| 79 | /* Mandatory members */
|
---|
| 80 | USBHost *pUsb;
|
---|
| 81 | uint32_t bAddress; // Device USB address
|
---|
| 82 | uint32_t bConfNum; // configuration number
|
---|
| 83 |
|
---|
| 84 | uint32_t bNumEP; // total number of EP in the configuration
|
---|
| 85 | bool ready;
|
---|
| 86 |
|
---|
| 87 | /* Endpoint data structure describing the device EP */
|
---|
| 88 | EpInfo epInfo[ADK_MAX_ENDPOINTS];
|
---|
| 89 |
|
---|
| 90 | public:
|
---|
| 91 | ADK(USBHost *pUsb, const char* pmanufacturer,
|
---|
| 92 | const char* pmodel,
|
---|
| 93 | const char* pdescription,
|
---|
| 94 | const char* pversion,
|
---|
| 95 | const char* puri,
|
---|
| 96 | const char* pserial);
|
---|
| 97 |
|
---|
| 98 | // Methods for receiving and sending data
|
---|
| 99 | uint32_t read(uint32_t *nreadbytes, uint32_t datalen, uint8_t *dataptr);
|
---|
| 100 | uint32_t write(uint32_t datalen, uint8_t *dataptr);
|
---|
| 101 |
|
---|
| 102 |
|
---|
| 103 | // USBDeviceConfig implementation
|
---|
| 104 | virtual uint32_t Init(uint32_t parent, uint32_t port, uint32_t lowspeed);
|
---|
| 105 | virtual uint32_t Release();
|
---|
| 106 | virtual uint32_t Poll() { return 0; }; // not implemented
|
---|
| 107 | virtual uint32_t GetAddress() { return bAddress; };
|
---|
| 108 | virtual bool isReady() { return ready; };
|
---|
| 109 |
|
---|
| 110 | // UsbConfigXtracter implementation
|
---|
| 111 | virtual void EndpointXtract(uint32_t conf, uint32_t iface, uint32_t alt, uint32_t proto, const USB_ENDPOINT_DESCRIPTOR *ep);
|
---|
| 112 | };
|
---|
| 113 |
|
---|
| 114 | /**
|
---|
| 115 | * \brief Get ADK protocol version.
|
---|
| 116 | *
|
---|
| 117 | * \param adkproto Empty buffer to be filled by getProto (2 bytes) with the ADK
|
---|
| 118 | * protocol version value.
|
---|
| 119 | *
|
---|
| 120 | * \return 0 on success, error code otherwise.
|
---|
| 121 | */
|
---|
| 122 | inline uint32_t ADK::getProto(uint8_t* adkproto)
|
---|
| 123 | {
|
---|
| 124 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_GET, ADK_GETPROTO, 0, 0, 0, 2, 2, adkproto, NULL));
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | /**
|
---|
| 128 | * \brief Send ADK string.
|
---|
| 129 | *
|
---|
| 130 | * \param index String index.
|
---|
| 131 | * \param str String to send.
|
---|
| 132 | *
|
---|
| 133 | * \return 0 on success, error code otherwise.
|
---|
| 134 | */
|
---|
| 135 | inline uint32_t ADK::sendStr(uint32_t index, const char* str)
|
---|
| 136 | {
|
---|
| 137 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_SENDSTR, 0, 0, index, strlen(str) + 1, strlen(str) + 1, (uint8_t*)str, NULL));
|
---|
| 138 | }
|
---|
| 139 |
|
---|
| 140 | /**
|
---|
| 141 | * \brief Send a switch to accessory mode request.
|
---|
| 142 | *
|
---|
| 143 | * \return 0 on success, error code otherwise.
|
---|
| 144 | */
|
---|
| 145 | inline uint32_t ADK::switchAcc(void)
|
---|
| 146 | {
|
---|
| 147 | return (pUsb->ctrlReq(bAddress, 0, bmREQ_ADK_SEND, ADK_ACCSTART, 0, 0, 0, 0, 0, NULL, NULL));
|
---|
| 148 | }
|
---|
| 149 |
|
---|
| 150 | #endif /* ADK_H_INCLUDED */
|
---|