Control the wondrous spinning-frog game of Zuma's Revenge with a rotating chair and an Airzooka. Maps compass rotation, flex sensor and push button input to USB actions to control Zuma's Revenge (http://www.popcap.com/games/zumas-revenge/online)

Dependencies:   LSM303DLHC mbed

Note that content for USB HID and USB Device is actually from the USBDevice mbed library. However, we made a couple of small changes to this library (allowing USB clicks at a particular location) that required us to break it off from the main project if we wanted to publish without pushing upstream.

Committer:
andrewhead
Date:
Mon Sep 29 01:12:20 2014 +0000
Revision:
0:4df415dde990
Initial Commit.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andrewhead 0:4df415dde990 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
andrewhead 0:4df415dde990 2 *
andrewhead 0:4df415dde990 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
andrewhead 0:4df415dde990 4 * and associated documentation files (the "Software"), to deal in the Software without
andrewhead 0:4df415dde990 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
andrewhead 0:4df415dde990 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
andrewhead 0:4df415dde990 7 * Software is furnished to do so, subject to the following conditions:
andrewhead 0:4df415dde990 8 *
andrewhead 0:4df415dde990 9 * The above copyright notice and this permission notice shall be included in all copies or
andrewhead 0:4df415dde990 10 * substantial portions of the Software.
andrewhead 0:4df415dde990 11 *
andrewhead 0:4df415dde990 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
andrewhead 0:4df415dde990 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
andrewhead 0:4df415dde990 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
andrewhead 0:4df415dde990 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
andrewhead 0:4df415dde990 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
andrewhead 0:4df415dde990 17 */
andrewhead 0:4df415dde990 18
andrewhead 0:4df415dde990 19 #ifndef USBDEVICE_H
andrewhead 0:4df415dde990 20 #define USBDEVICE_H
andrewhead 0:4df415dde990 21
andrewhead 0:4df415dde990 22 #include "mbed.h"
andrewhead 0:4df415dde990 23 #include "USBDevice_Types.h"
andrewhead 0:4df415dde990 24 #include "USBHAL.h"
andrewhead 0:4df415dde990 25
andrewhead 0:4df415dde990 26 class USBDevice: public USBHAL
andrewhead 0:4df415dde990 27 {
andrewhead 0:4df415dde990 28 public:
andrewhead 0:4df415dde990 29 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
andrewhead 0:4df415dde990 30
andrewhead 0:4df415dde990 31 /*
andrewhead 0:4df415dde990 32 * Check if the device is configured
andrewhead 0:4df415dde990 33 *
andrewhead 0:4df415dde990 34 * @returns true if configured, false otherwise
andrewhead 0:4df415dde990 35 */
andrewhead 0:4df415dde990 36 bool configured(void);
andrewhead 0:4df415dde990 37
andrewhead 0:4df415dde990 38 /*
andrewhead 0:4df415dde990 39 * Connect a device
andrewhead 0:4df415dde990 40 */
andrewhead 0:4df415dde990 41 void connect(void);
andrewhead 0:4df415dde990 42
andrewhead 0:4df415dde990 43 /*
andrewhead 0:4df415dde990 44 * Disconnect a device
andrewhead 0:4df415dde990 45 */
andrewhead 0:4df415dde990 46 void disconnect(void);
andrewhead 0:4df415dde990 47
andrewhead 0:4df415dde990 48 /*
andrewhead 0:4df415dde990 49 * Add an endpoint
andrewhead 0:4df415dde990 50 *
andrewhead 0:4df415dde990 51 * @param endpoint endpoint which will be added
andrewhead 0:4df415dde990 52 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
andrewhead 0:4df415dde990 53 * @returns true if successful, false otherwise
andrewhead 0:4df415dde990 54 */
andrewhead 0:4df415dde990 55 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
andrewhead 0:4df415dde990 56
andrewhead 0:4df415dde990 57 /*
andrewhead 0:4df415dde990 58 * Start a reading on a certain endpoint.
andrewhead 0:4df415dde990 59 * You can access the result of the reading by USBDevice_read
andrewhead 0:4df415dde990 60 *
andrewhead 0:4df415dde990 61 * @param endpoint endpoint which will be read
andrewhead 0:4df415dde990 62 * @param maxSize the maximum length that can be read
andrewhead 0:4df415dde990 63 * @return true if successful
andrewhead 0:4df415dde990 64 */
andrewhead 0:4df415dde990 65 bool readStart(uint8_t endpoint, uint32_t maxSize);
andrewhead 0:4df415dde990 66
andrewhead 0:4df415dde990 67 /*
andrewhead 0:4df415dde990 68 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
andrewhead 0:4df415dde990 69 * must be called.
andrewhead 0:4df415dde990 70 *
andrewhead 0:4df415dde990 71 * Warning: blocking
andrewhead 0:4df415dde990 72 *
andrewhead 0:4df415dde990 73 * @param endpoint endpoint which will be read
andrewhead 0:4df415dde990 74 * @param buffer buffer will be filled with the data received
andrewhead 0:4df415dde990 75 * @param size the number of bytes read will be stored in *size
andrewhead 0:4df415dde990 76 * @param maxSize the maximum length that can be read
andrewhead 0:4df415dde990 77 * @returns true if successful
andrewhead 0:4df415dde990 78 */
andrewhead 0:4df415dde990 79 bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
andrewhead 0:4df415dde990 80
andrewhead 0:4df415dde990 81 /*
andrewhead 0:4df415dde990 82 * Read a certain endpoint.
andrewhead 0:4df415dde990 83 *
andrewhead 0:4df415dde990 84 * Warning: non blocking
andrewhead 0:4df415dde990 85 *
andrewhead 0:4df415dde990 86 * @param endpoint endpoint which will be read
andrewhead 0:4df415dde990 87 * @param buffer buffer will be filled with the data received (if data are available)
andrewhead 0:4df415dde990 88 * @param size the number of bytes read will be stored in *size
andrewhead 0:4df415dde990 89 * @param maxSize the maximum length that can be read
andrewhead 0:4df415dde990 90 * @returns true if successful
andrewhead 0:4df415dde990 91 */
andrewhead 0:4df415dde990 92 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
andrewhead 0:4df415dde990 93
andrewhead 0:4df415dde990 94 /*
andrewhead 0:4df415dde990 95 * Write a certain endpoint.
andrewhead 0:4df415dde990 96 *
andrewhead 0:4df415dde990 97 * Warning: blocking
andrewhead 0:4df415dde990 98 *
andrewhead 0:4df415dde990 99 * @param endpoint endpoint to write
andrewhead 0:4df415dde990 100 * @param buffer data contained in buffer will be write
andrewhead 0:4df415dde990 101 * @param size the number of bytes to write
andrewhead 0:4df415dde990 102 * @param maxSize the maximum length that can be written on this endpoint
andrewhead 0:4df415dde990 103 */
andrewhead 0:4df415dde990 104 bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
andrewhead 0:4df415dde990 105
andrewhead 0:4df415dde990 106
andrewhead 0:4df415dde990 107 /*
andrewhead 0:4df415dde990 108 * Write a certain endpoint.
andrewhead 0:4df415dde990 109 *
andrewhead 0:4df415dde990 110 * Warning: non blocking
andrewhead 0:4df415dde990 111 *
andrewhead 0:4df415dde990 112 * @param endpoint endpoint to write
andrewhead 0:4df415dde990 113 * @param buffer data contained in buffer will be write
andrewhead 0:4df415dde990 114 * @param size the number of bytes to write
andrewhead 0:4df415dde990 115 * @param maxSize the maximum length that can be written on this endpoint
andrewhead 0:4df415dde990 116 */
andrewhead 0:4df415dde990 117 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
andrewhead 0:4df415dde990 118
andrewhead 0:4df415dde990 119
andrewhead 0:4df415dde990 120 /*
andrewhead 0:4df415dde990 121 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
andrewhead 0:4df415dde990 122 *
andrewhead 0:4df415dde990 123 * May be used to reset state
andrewhead 0:4df415dde990 124 */
andrewhead 0:4df415dde990 125 virtual void USBCallback_busReset(void) {};
andrewhead 0:4df415dde990 126
andrewhead 0:4df415dde990 127 /*
andrewhead 0:4df415dde990 128 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
andrewhead 0:4df415dde990 129 * This is used to handle extensions to standard requests
andrewhead 0:4df415dde990 130 * and class specific requests
andrewhead 0:4df415dde990 131 *
andrewhead 0:4df415dde990 132 * @returns true if class handles this request
andrewhead 0:4df415dde990 133 */
andrewhead 0:4df415dde990 134 virtual bool USBCallback_request() { return false; };
andrewhead 0:4df415dde990 135
andrewhead 0:4df415dde990 136 /*
andrewhead 0:4df415dde990 137 * Called by USBDevice on Endpoint0 request completion
andrewhead 0:4df415dde990 138 * if the 'notify' flag has been set to true. Warning: Called in ISR context
andrewhead 0:4df415dde990 139 *
andrewhead 0:4df415dde990 140 * In this case it is used to indicate that a HID report has
andrewhead 0:4df415dde990 141 * been received from the host on endpoint 0
andrewhead 0:4df415dde990 142 *
andrewhead 0:4df415dde990 143 * @param buf buffer received on endpoint 0
andrewhead 0:4df415dde990 144 * @param length length of this buffer
andrewhead 0:4df415dde990 145 */
andrewhead 0:4df415dde990 146 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
andrewhead 0:4df415dde990 147
andrewhead 0:4df415dde990 148 /*
andrewhead 0:4df415dde990 149 * Called by USBDevice layer. Set configuration of the device.
andrewhead 0:4df415dde990 150 * For instance, you can add all endpoints that you need on this function.
andrewhead 0:4df415dde990 151 *
andrewhead 0:4df415dde990 152 * @param configuration Number of the configuration
andrewhead 0:4df415dde990 153 */
andrewhead 0:4df415dde990 154 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
andrewhead 0:4df415dde990 155
andrewhead 0:4df415dde990 156 /*
andrewhead 0:4df415dde990 157 * Called by USBDevice layer. Set interface/alternate of the device.
andrewhead 0:4df415dde990 158 *
andrewhead 0:4df415dde990 159 * @param interface Number of the interface to be configured
andrewhead 0:4df415dde990 160 * @param alternate Number of the alternate to be configured
andrewhead 0:4df415dde990 161 * @returns true if class handles this request
andrewhead 0:4df415dde990 162 */
andrewhead 0:4df415dde990 163 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
andrewhead 0:4df415dde990 164
andrewhead 0:4df415dde990 165 /*
andrewhead 0:4df415dde990 166 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
andrewhead 0:4df415dde990 167 *
andrewhead 0:4df415dde990 168 * @returns pointer to the device descriptor
andrewhead 0:4df415dde990 169 */
andrewhead 0:4df415dde990 170 virtual uint8_t * deviceDesc();
andrewhead 0:4df415dde990 171
andrewhead 0:4df415dde990 172 /*
andrewhead 0:4df415dde990 173 * Get configuration descriptor
andrewhead 0:4df415dde990 174 *
andrewhead 0:4df415dde990 175 * @returns pointer to the configuration descriptor
andrewhead 0:4df415dde990 176 */
andrewhead 0:4df415dde990 177 virtual uint8_t * configurationDesc(){return NULL;};
andrewhead 0:4df415dde990 178
andrewhead 0:4df415dde990 179 /*
andrewhead 0:4df415dde990 180 * Get string lang id descriptor
andrewhead 0:4df415dde990 181 *
andrewhead 0:4df415dde990 182 * @return pointer to the string lang id descriptor
andrewhead 0:4df415dde990 183 */
andrewhead 0:4df415dde990 184 virtual uint8_t * stringLangidDesc();
andrewhead 0:4df415dde990 185
andrewhead 0:4df415dde990 186 /*
andrewhead 0:4df415dde990 187 * Get string manufacturer descriptor
andrewhead 0:4df415dde990 188 *
andrewhead 0:4df415dde990 189 * @returns pointer to the string manufacturer descriptor
andrewhead 0:4df415dde990 190 */
andrewhead 0:4df415dde990 191 virtual uint8_t * stringImanufacturerDesc();
andrewhead 0:4df415dde990 192
andrewhead 0:4df415dde990 193 /*
andrewhead 0:4df415dde990 194 * Get string product descriptor
andrewhead 0:4df415dde990 195 *
andrewhead 0:4df415dde990 196 * @returns pointer to the string product descriptor
andrewhead 0:4df415dde990 197 */
andrewhead 0:4df415dde990 198 virtual uint8_t * stringIproductDesc();
andrewhead 0:4df415dde990 199
andrewhead 0:4df415dde990 200 /*
andrewhead 0:4df415dde990 201 * Get string serial descriptor
andrewhead 0:4df415dde990 202 *
andrewhead 0:4df415dde990 203 * @returns pointer to the string serial descriptor
andrewhead 0:4df415dde990 204 */
andrewhead 0:4df415dde990 205 virtual uint8_t * stringIserialDesc();
andrewhead 0:4df415dde990 206
andrewhead 0:4df415dde990 207 /*
andrewhead 0:4df415dde990 208 * Get string configuration descriptor
andrewhead 0:4df415dde990 209 *
andrewhead 0:4df415dde990 210 * @returns pointer to the string configuration descriptor
andrewhead 0:4df415dde990 211 */
andrewhead 0:4df415dde990 212 virtual uint8_t * stringIConfigurationDesc();
andrewhead 0:4df415dde990 213
andrewhead 0:4df415dde990 214 /*
andrewhead 0:4df415dde990 215 * Get string interface descriptor
andrewhead 0:4df415dde990 216 *
andrewhead 0:4df415dde990 217 * @returns pointer to the string interface descriptor
andrewhead 0:4df415dde990 218 */
andrewhead 0:4df415dde990 219 virtual uint8_t * stringIinterfaceDesc();
andrewhead 0:4df415dde990 220
andrewhead 0:4df415dde990 221 /*
andrewhead 0:4df415dde990 222 * Get the length of the report descriptor
andrewhead 0:4df415dde990 223 *
andrewhead 0:4df415dde990 224 * @returns length of the report descriptor
andrewhead 0:4df415dde990 225 */
andrewhead 0:4df415dde990 226 virtual uint16_t reportDescLength() { return 0; };
andrewhead 0:4df415dde990 227
andrewhead 0:4df415dde990 228
andrewhead 0:4df415dde990 229
andrewhead 0:4df415dde990 230 protected:
andrewhead 0:4df415dde990 231 virtual void busReset(void);
andrewhead 0:4df415dde990 232 virtual void EP0setupCallback(void);
andrewhead 0:4df415dde990 233 virtual void EP0out(void);
andrewhead 0:4df415dde990 234 virtual void EP0in(void);
andrewhead 0:4df415dde990 235 virtual void connectStateChanged(unsigned int connected);
andrewhead 0:4df415dde990 236 virtual void suspendStateChanged(unsigned int suspended);
andrewhead 0:4df415dde990 237 uint8_t * findDescriptor(uint8_t descriptorType);
andrewhead 0:4df415dde990 238 CONTROL_TRANSFER * getTransferPtr(void);
andrewhead 0:4df415dde990 239
andrewhead 0:4df415dde990 240 uint16_t VENDOR_ID;
andrewhead 0:4df415dde990 241 uint16_t PRODUCT_ID;
andrewhead 0:4df415dde990 242 uint16_t PRODUCT_RELEASE;
andrewhead 0:4df415dde990 243
andrewhead 0:4df415dde990 244 private:
andrewhead 0:4df415dde990 245 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
andrewhead 0:4df415dde990 246 bool requestGetDescriptor(void);
andrewhead 0:4df415dde990 247 bool controlOut(void);
andrewhead 0:4df415dde990 248 bool controlIn(void);
andrewhead 0:4df415dde990 249 bool requestSetAddress(void);
andrewhead 0:4df415dde990 250 bool requestSetConfiguration(void);
andrewhead 0:4df415dde990 251 bool requestSetFeature(void);
andrewhead 0:4df415dde990 252 bool requestClearFeature(void);
andrewhead 0:4df415dde990 253 bool requestGetStatus(void);
andrewhead 0:4df415dde990 254 bool requestSetup(void);
andrewhead 0:4df415dde990 255 bool controlSetup(void);
andrewhead 0:4df415dde990 256 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
andrewhead 0:4df415dde990 257 bool requestGetConfiguration(void);
andrewhead 0:4df415dde990 258 bool requestGetInterface(void);
andrewhead 0:4df415dde990 259 bool requestSetInterface(void);
andrewhead 0:4df415dde990 260
andrewhead 0:4df415dde990 261 CONTROL_TRANSFER transfer;
andrewhead 0:4df415dde990 262 USB_DEVICE device;
andrewhead 0:4df415dde990 263
andrewhead 0:4df415dde990 264 uint16_t currentInterface;
andrewhead 0:4df415dde990 265 uint8_t currentAlternate;
andrewhead 0:4df415dde990 266 };
andrewhead 0:4df415dde990 267
andrewhead 0:4df415dde990 268
andrewhead 0:4df415dde990 269 #endif