Fixed version check for AOA 2.0

Fork of AndroidAccessory by Giles Barton-Owen

Committer:
p07gbar
Date:
Tue Aug 02 08:32:26 2011 +0000
Revision:
1:0d5fc52b4dcd
Parent:
0:1151e4446dbc
Child:
2:98fbe1660f0a
Added some major commenting

Who changed what in which revision?

UserRevisionLine numberNew contents of line
p07gbar 1:0d5fc52b4dcd 1 /* mbed AndroidAccessory Library
p07gbar 1:0d5fc52b4dcd 2 * Created by p07gbar from work by Makoto Abe
p07gbar 1:0d5fc52b4dcd 3 *
p07gbar 1:0d5fc52b4dcd 4 */
p07gbar 0:1151e4446dbc 5 #ifndef ADK_H_INCLUDED
p07gbar 0:1151e4446dbc 6 #define ADK_H_INCLUDED
p07gbar 0:1151e4446dbc 7
p07gbar 0:1151e4446dbc 8 #include "mbed.h"
p07gbar 0:1151e4446dbc 9 #include "USBHost.h"
p07gbar 0:1151e4446dbc 10
p07gbar 0:1151e4446dbc 11
p07gbar 0:1151e4446dbc 12 //#define ADKLOG 1
p07gbar 0:1151e4446dbc 13 #if ADKLOG
p07gbar 0:1151e4446dbc 14 #define LOG(...) printf(__VA_ARGS__)
p07gbar 0:1151e4446dbc 15 #define Log(...) printf(__VA_ARGS__)
p07gbar 0:1151e4446dbc 16 #define log(...) printf(__VA_ARGS__)
p07gbar 0:1151e4446dbc 17
p07gbar 0:1151e4446dbc 18 #else
p07gbar 0:1151e4446dbc 19 #define LOG(...) do {} while(0)
p07gbar 0:1151e4446dbc 20 #define Log(...) do {} while(0)
p07gbar 0:1151e4446dbc 21 #define log(...) do {} while(0)
p07gbar 0:1151e4446dbc 22
p07gbar 0:1151e4446dbc 23 #endif
p07gbar 0:1151e4446dbc 24
p07gbar 0:1151e4446dbc 25 #define ACCESSORY_STRING_MANUFACTURER 0
p07gbar 0:1151e4446dbc 26 #define ACCESSORY_STRING_MODEL 1
p07gbar 0:1151e4446dbc 27 #define ACCESSORY_STRING_DESCRIPTION 2
p07gbar 0:1151e4446dbc 28 #define ACCESSORY_STRING_VERSION 3
p07gbar 0:1151e4446dbc 29 #define ACCESSORY_STRING_URI 4
p07gbar 0:1151e4446dbc 30 #define ACCESSORY_STRING_SERIAL 5
p07gbar 0:1151e4446dbc 31
p07gbar 0:1151e4446dbc 32 #define ACCESSORY_GET_PROTOCOL 51
p07gbar 0:1151e4446dbc 33 #define ACCESSORY_SEND_STRING 52
p07gbar 0:1151e4446dbc 34 #define ACCESSORY_START 53
p07gbar 0:1151e4446dbc 35
p07gbar 0:1151e4446dbc 36
p07gbar 1:0d5fc52b4dcd 37
p07gbar 1:0d5fc52b4dcd 38 /** An AndroidAccessory control class
p07gbar 1:0d5fc52b4dcd 39 *
p07gbar 1:0d5fc52b4dcd 40 * It allows easy creation of a mbed android ADK accessory, with minimal low level fussing.
p07gbar 1:0d5fc52b4dcd 41 * Base code should have methods resetDevice(), setupDevice(), callbackRead(u8 *buff, int len) and callBackWrite() functions
p07gbar 1:0d5fc52b4dcd 42 *
p07gbar 1:0d5fc52b4dcd 43 */
p07gbar 0:1151e4446dbc 44
p07gbar 0:1151e4446dbc 45 class AndroidAccessory {
p07gbar 0:1151e4446dbc 46 public:
p07gbar 0:1151e4446dbc 47
p07gbar 1:0d5fc52b4dcd 48
p07gbar 1:0d5fc52b4dcd 49
p07gbar 1:0d5fc52b4dcd 50 /** Create a AndroidAccessory object
p07gbar 1:0d5fc52b4dcd 51 *
p07gbar 1:0d5fc52b4dcd 52 * Create a AndroidAccessoryobject with specified buffer sizes and infomation
p07gbar 1:0d5fc52b4dcd 53 *
p07gbar 1:0d5fc52b4dcd 54 * @param rbuffsize The size of the read buffer
p07gbar 1:0d5fc52b4dcd 55 * @param wbuffsize The size of the write buffer
p07gbar 1:0d5fc52b4dcd 56 * @param manufacturer The manufacturer of the accessory
p07gbar 1:0d5fc52b4dcd 57 * @param model The model of the accessory
p07gbar 1:0d5fc52b4dcd 58 * @param description A short description of the accessory
p07gbar 1:0d5fc52b4dcd 59 * @param version The current version of the accessory
p07gbar 1:0d5fc52b4dcd 60 * @param uri Some data to go with the accessory (URL or more description)
p07gbar 1:0d5fc52b4dcd 61 * @param serial The serial number of the accessory
p07gbar 1:0d5fc52b4dcd 62 */
p07gbar 0:1151e4446dbc 63 AndroidAccessory(int rbuffsize,int wbuffsize,
p07gbar 0:1151e4446dbc 64 const char* manufacturer,
p07gbar 0:1151e4446dbc 65 const char *model,
p07gbar 0:1151e4446dbc 66 const char *description,
p07gbar 0:1151e4446dbc 67 const char *version,
p07gbar 0:1151e4446dbc 68 const char *uri,
p07gbar 0:1151e4446dbc 69 const char *serial
p07gbar 0:1151e4446dbc 70 );
p07gbar 1:0d5fc52b4dcd 71
p07gbar 1:0d5fc52b4dcd 72 /** Init the device
p07gbar 1:0d5fc52b4dcd 73 *
p07gbar 1:0d5fc52b4dcd 74 * @param device Device number
p07gbar 1:0d5fc52b4dcd 75 * @param configuration Configuration
p07gbar 1:0d5fc52b4dcd 76 * @param interfaceNumber Inteface number
p07gbar 1:0d5fc52b4dcd 77 */
p07gbar 0:1151e4446dbc 78 virtual void init(int device, int configuration, int interfaceNumber);
p07gbar 1:0d5fc52b4dcd 79
p07gbar 1:0d5fc52b4dcd 80 /** Reset the device
p07gbar 1:0d5fc52b4dcd 81 * This is meant to be implimented by the user of the class
p07gbar 1:0d5fc52b4dcd 82 *
p07gbar 1:0d5fc52b4dcd 83 */
p07gbar 0:1151e4446dbc 84 virtual void resetDevice()=0;
p07gbar 1:0d5fc52b4dcd 85
p07gbar 1:0d5fc52b4dcd 86 /** Setup the device
p07gbar 1:0d5fc52b4dcd 87 * This is meant to be implimented by the user of the class. Called when the device is first intialised
p07gbar 1:0d5fc52b4dcd 88 *
p07gbar 1:0d5fc52b4dcd 89 */
p07gbar 0:1151e4446dbc 90 virtual void setupDevice()=0;
p07gbar 1:0d5fc52b4dcd 91
p07gbar 1:0d5fc52b4dcd 92 /** Callback on Read
p07gbar 1:0d5fc52b4dcd 93 * This is meant to be implimented by the user of the class. Called when some data has been read in.
p07gbar 1:0d5fc52b4dcd 94 *
p07gbar 1:0d5fc52b4dcd 95 * @param buff The buffered read in data
p07gbar 1:0d5fc52b4dcd 96 * @param len The length of the packet recived
p07gbar 1:0d5fc52b4dcd 97 *
p07gbar 1:0d5fc52b4dcd 98 */
p07gbar 0:1151e4446dbc 99 virtual int callbackRead(u8 *buff, int len)=0;
p07gbar 1:0d5fc52b4dcd 100
p07gbar 1:0d5fc52b4dcd 101 /** Callback after Write
p07gbar 1:0d5fc52b4dcd 102 * This is meant to be implimented by the user of the class. Called when the write has been finished.
p07gbar 1:0d5fc52b4dcd 103 *
p07gbar 1:0d5fc52b4dcd 104 */
p07gbar 0:1151e4446dbc 105 virtual int callbackWrite()=0;
p07gbar 1:0d5fc52b4dcd 106
p07gbar 1:0d5fc52b4dcd 107 /** Write over USB
p07gbar 1:0d5fc52b4dcd 108 * This sends the data in the buffer over USB in a packet
p07gbar 1:0d5fc52b4dcd 109 *
p07gbar 1:0d5fc52b4dcd 110 * @param buff The buffer to write out
p07gbar 1:0d5fc52b4dcd 111 * @param len The length of the packet to send
p07gbar 1:0d5fc52b4dcd 112 *
p07gbar 1:0d5fc52b4dcd 113 */
p07gbar 0:1151e4446dbc 114 int write(u8 *buff, int len);
p07gbar 1:0d5fc52b4dcd 115
p07gbar 1:0d5fc52b4dcd 116 /** Write over USB
p07gbar 1:0d5fc52b4dcd 117 * This sends the data in the buffer over USB in a packet, sends _writebuff and _writebuffsize
p07gbar 1:0d5fc52b4dcd 118 *
p07gbar 1:0d5fc52b4dcd 119 */
p07gbar 0:1151e4446dbc 120 int write() {
p07gbar 0:1151e4446dbc 121 return write(_writebuff,_writebuffsize);
p07gbar 0:1151e4446dbc 122 }
p07gbar 1:0d5fc52b4dcd 123
p07gbar 1:0d5fc52b4dcd 124 /** Write over USB with no callback
p07gbar 1:0d5fc52b4dcd 125 * This sends the data in the buffer over USB in a packet, waits until the packet is sent, rather than doing a callback
p07gbar 1:0d5fc52b4dcd 126 *
p07gbar 1:0d5fc52b4dcd 127 * @param buff The buffer to write out
p07gbar 1:0d5fc52b4dcd 128 * @param len The length of the packet to send
p07gbar 1:0d5fc52b4dcd 129 *
p07gbar 1:0d5fc52b4dcd 130 */
p07gbar 0:1151e4446dbc 131 int writeNC(u8 *buff, int len);
p07gbar 1:0d5fc52b4dcd 132
p07gbar 1:0d5fc52b4dcd 133 /** Write over USB
p07gbar 1:0d5fc52b4dcd 134 * This sends the data in the buffer over USB in a packet, waits until the packet is sent, rather than doing a callback, sends _writebuff and _writebuffsize
p07gbar 1:0d5fc52b4dcd 135 *
p07gbar 1:0d5fc52b4dcd 136 */
p07gbar 0:1151e4446dbc 137 int writeNC() {
p07gbar 0:1151e4446dbc 138 return writeNC(_writebuff,_writebuffsize);
p07gbar 0:1151e4446dbc 139 }
p07gbar 0:1151e4446dbc 140
p07gbar 1:0d5fc52b4dcd 141 /** Read the buffer USB
p07gbar 1:0d5fc52b4dcd 142 * This sends the data in the buffer over USB in a packet, waits until the packet is sent, rather than doing a callback
p07gbar 1:0d5fc52b4dcd 143 *
p07gbar 1:0d5fc52b4dcd 144 * @param buff The buffer to read into
p07gbar 1:0d5fc52b4dcd 145 * @param len The length of the packet to read in
p07gbar 1:0d5fc52b4dcd 146 *
p07gbar 1:0d5fc52b4dcd 147 * @param returns The number of bytes read
p07gbar 1:0d5fc52b4dcd 148 *
p07gbar 1:0d5fc52b4dcd 149 */
p07gbar 0:1151e4446dbc 150 int read(u8 *buff, int len);
p07gbar 0:1151e4446dbc 151
p07gbar 0:1151e4446dbc 152
p07gbar 0:1151e4446dbc 153 void adkEnd() {
p07gbar 0:1151e4446dbc 154 // _initok=false;
p07gbar 0:1151e4446dbc 155 resetDevice();
p07gbar 0:1151e4446dbc 156 }; //if connection close
p07gbar 0:1151e4446dbc 157 bool switchDevice(int device);
p07gbar 0:1151e4446dbc 158
p07gbar 0:1151e4446dbc 159 //buffer
p07gbar 0:1151e4446dbc 160 u8* _readbuff;
p07gbar 0:1151e4446dbc 161 int _readbuffsize;
p07gbar 0:1151e4446dbc 162 u8* _writebuff;
p07gbar 0:1151e4446dbc 163 int _writebuffsize;
p07gbar 0:1151e4446dbc 164 u8* _strbuff;//255bytes;
p07gbar 0:1151e4446dbc 165 void sendString(const char *str);
p07gbar 0:1151e4446dbc 166
p07gbar 0:1151e4446dbc 167 private:
p07gbar 0:1151e4446dbc 168
p07gbar 0:1151e4446dbc 169 void sendString(int device, int index, const char *str);
p07gbar 0:1151e4446dbc 170 int getProtocol(int device);
p07gbar 0:1151e4446dbc 171
p07gbar 0:1151e4446dbc 172 const char *manufacturer;
p07gbar 0:1151e4446dbc 173 const char *model;
p07gbar 0:1151e4446dbc 174 const char *description;
p07gbar 0:1151e4446dbc 175 const char *version;
p07gbar 0:1151e4446dbc 176 const char *uri;
p07gbar 0:1151e4446dbc 177 const char *serial;
p07gbar 0:1151e4446dbc 178
p07gbar 0:1151e4446dbc 179 //endpoints
p07gbar 0:1151e4446dbc 180 int input_ep;
p07gbar 0:1151e4446dbc 181 int output_ep;
p07gbar 0:1151e4446dbc 182
p07gbar 0:1151e4446dbc 183 int _device;
p07gbar 0:1151e4446dbc 184 int _configuration;
p07gbar 0:1151e4446dbc 185 int _interfaceNumber;
p07gbar 0:1151e4446dbc 186
p07gbar 0:1151e4446dbc 187 //bool _initok;
p07gbar 0:1151e4446dbc 188
p07gbar 0:1151e4446dbc 189 };
p07gbar 0:1151e4446dbc 190
p07gbar 0:1151e4446dbc 191 extern AndroidAccessory* _adk;
p07gbar 0:1151e4446dbc 192
p07gbar 0:1151e4446dbc 193
p07gbar 0:1151e4446dbc 194 #endif