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 USB_HID_H
andrewhead 0:4df415dde990 20 #define USB_HID_H
andrewhead 0:4df415dde990 21
andrewhead 0:4df415dde990 22 /* These headers are included for child class. */
andrewhead 0:4df415dde990 23 #include "USBEndpoints.h"
andrewhead 0:4df415dde990 24 #include "USBDescriptor.h"
andrewhead 0:4df415dde990 25 #include "USBDevice_Types.h"
andrewhead 0:4df415dde990 26
andrewhead 0:4df415dde990 27 #include "USBHID_Types.h"
andrewhead 0:4df415dde990 28 #include "USBDevice.h"
andrewhead 0:4df415dde990 29
andrewhead 0:4df415dde990 30
andrewhead 0:4df415dde990 31 /**
andrewhead 0:4df415dde990 32 * USBHID example
andrewhead 0:4df415dde990 33 * @code
andrewhead 0:4df415dde990 34 * #include "mbed.h"
andrewhead 0:4df415dde990 35 * #include "USBHID.h"
andrewhead 0:4df415dde990 36 *
andrewhead 0:4df415dde990 37 * USBHID hid;
andrewhead 0:4df415dde990 38 * HID_REPORT recv;
andrewhead 0:4df415dde990 39 * BusOut leds(LED1,LED2,LED3,LED4);
andrewhead 0:4df415dde990 40 *
andrewhead 0:4df415dde990 41 * int main(void) {
andrewhead 0:4df415dde990 42 * while (1) {
andrewhead 0:4df415dde990 43 * hid.read(&recv);
andrewhead 0:4df415dde990 44 * leds = recv.data[0];
andrewhead 0:4df415dde990 45 * }
andrewhead 0:4df415dde990 46 * }
andrewhead 0:4df415dde990 47 * @endcode
andrewhead 0:4df415dde990 48 */
andrewhead 0:4df415dde990 49
andrewhead 0:4df415dde990 50 class USBHID: public USBDevice {
andrewhead 0:4df415dde990 51 public:
andrewhead 0:4df415dde990 52
andrewhead 0:4df415dde990 53 /**
andrewhead 0:4df415dde990 54 * Constructor
andrewhead 0:4df415dde990 55 *
andrewhead 0:4df415dde990 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
andrewhead 0:4df415dde990 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
andrewhead 0:4df415dde990 58 * @param vendor_id Your vendor_id
andrewhead 0:4df415dde990 59 * @param product_id Your product_id
andrewhead 0:4df415dde990 60 * @param product_release Your preoduct_release
andrewhead 0:4df415dde990 61 * @param connect Connect the device
andrewhead 0:4df415dde990 62 */
andrewhead 0:4df415dde990 63 USBHID(uint8_t output_report_length = 64, uint8_t input_report_length = 64, uint16_t vendor_id = 0x1234, uint16_t product_id = 0x0006, uint16_t product_release = 0x0001, bool connect = true);
andrewhead 0:4df415dde990 64
andrewhead 0:4df415dde990 65
andrewhead 0:4df415dde990 66 /**
andrewhead 0:4df415dde990 67 * Send a Report. warning: blocking
andrewhead 0:4df415dde990 68 *
andrewhead 0:4df415dde990 69 * @param report Report which will be sent (a report is defined by all data and the length)
andrewhead 0:4df415dde990 70 * @returns true if successful
andrewhead 0:4df415dde990 71 */
andrewhead 0:4df415dde990 72 bool send(HID_REPORT *report);
andrewhead 0:4df415dde990 73
andrewhead 0:4df415dde990 74
andrewhead 0:4df415dde990 75 /**
andrewhead 0:4df415dde990 76 * Send a Report. warning: non blocking
andrewhead 0:4df415dde990 77 *
andrewhead 0:4df415dde990 78 * @param report Report which will be sent (a report is defined by all data and the length)
andrewhead 0:4df415dde990 79 * @returns true if successful
andrewhead 0:4df415dde990 80 */
andrewhead 0:4df415dde990 81 bool sendNB(HID_REPORT *report);
andrewhead 0:4df415dde990 82
andrewhead 0:4df415dde990 83 /**
andrewhead 0:4df415dde990 84 * Read a report: blocking
andrewhead 0:4df415dde990 85 *
andrewhead 0:4df415dde990 86 * @param report pointer to the report to fill
andrewhead 0:4df415dde990 87 * @returns true if successful
andrewhead 0:4df415dde990 88 */
andrewhead 0:4df415dde990 89 bool read(HID_REPORT * report);
andrewhead 0:4df415dde990 90
andrewhead 0:4df415dde990 91 /**
andrewhead 0:4df415dde990 92 * Read a report: non blocking
andrewhead 0:4df415dde990 93 *
andrewhead 0:4df415dde990 94 * @param report pointer to the report to fill
andrewhead 0:4df415dde990 95 * @returns true if successful
andrewhead 0:4df415dde990 96 */
andrewhead 0:4df415dde990 97 bool readNB(HID_REPORT * report);
andrewhead 0:4df415dde990 98
andrewhead 0:4df415dde990 99 protected:
andrewhead 0:4df415dde990 100 uint16_t reportLength;
andrewhead 0:4df415dde990 101
andrewhead 0:4df415dde990 102 /*
andrewhead 0:4df415dde990 103 * Get the Report descriptor
andrewhead 0:4df415dde990 104 *
andrewhead 0:4df415dde990 105 * @returns pointer to the report descriptor
andrewhead 0:4df415dde990 106 */
andrewhead 0:4df415dde990 107 virtual uint8_t * reportDesc();
andrewhead 0:4df415dde990 108
andrewhead 0:4df415dde990 109 /*
andrewhead 0:4df415dde990 110 * Get the length of the report descriptor
andrewhead 0:4df415dde990 111 *
andrewhead 0:4df415dde990 112 * @returns the length of the report descriptor
andrewhead 0:4df415dde990 113 */
andrewhead 0:4df415dde990 114 virtual uint16_t reportDescLength();
andrewhead 0:4df415dde990 115
andrewhead 0:4df415dde990 116 /*
andrewhead 0:4df415dde990 117 * Get string product descriptor
andrewhead 0:4df415dde990 118 *
andrewhead 0:4df415dde990 119 * @returns pointer to the string product descriptor
andrewhead 0:4df415dde990 120 */
andrewhead 0:4df415dde990 121 virtual uint8_t * stringIproductDesc();
andrewhead 0:4df415dde990 122
andrewhead 0:4df415dde990 123 /*
andrewhead 0:4df415dde990 124 * Get string interface descriptor
andrewhead 0:4df415dde990 125 *
andrewhead 0:4df415dde990 126 * @returns pointer to the string interface descriptor
andrewhead 0:4df415dde990 127 */
andrewhead 0:4df415dde990 128 virtual uint8_t * stringIinterfaceDesc();
andrewhead 0:4df415dde990 129
andrewhead 0:4df415dde990 130 /*
andrewhead 0:4df415dde990 131 * Get configuration descriptor
andrewhead 0:4df415dde990 132 *
andrewhead 0:4df415dde990 133 * @returns pointer to the configuration descriptor
andrewhead 0:4df415dde990 134 */
andrewhead 0:4df415dde990 135 virtual uint8_t * configurationDesc();
andrewhead 0:4df415dde990 136
andrewhead 0:4df415dde990 137
andrewhead 0:4df415dde990 138 /*
andrewhead 0:4df415dde990 139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
andrewhead 0:4df415dde990 140 * First byte of data will be the report ID
andrewhead 0:4df415dde990 141 *
andrewhead 0:4df415dde990 142 * @param report Data and length received
andrewhead 0:4df415dde990 143 */
andrewhead 0:4df415dde990 144 virtual void HID_callbackSetReport(HID_REPORT *report){};
andrewhead 0:4df415dde990 145
andrewhead 0:4df415dde990 146
andrewhead 0:4df415dde990 147 /*
andrewhead 0:4df415dde990 148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
andrewhead 0:4df415dde990 149 * This is used to handle extensions to standard requests
andrewhead 0:4df415dde990 150 * and class specific requests
andrewhead 0:4df415dde990 151 *
andrewhead 0:4df415dde990 152 * @returns true if class handles this request
andrewhead 0:4df415dde990 153 */
andrewhead 0:4df415dde990 154 virtual bool USBCallback_request();
andrewhead 0:4df415dde990 155
andrewhead 0:4df415dde990 156
andrewhead 0:4df415dde990 157 /*
andrewhead 0:4df415dde990 158 * Called by USBDevice layer. Set configuration of the device.
andrewhead 0:4df415dde990 159 * For instance, you can add all endpoints that you need on this function.
andrewhead 0:4df415dde990 160 *
andrewhead 0:4df415dde990 161 * @param configuration Number of the configuration
andrewhead 0:4df415dde990 162 * @returns true if class handles this request
andrewhead 0:4df415dde990 163 */
andrewhead 0:4df415dde990 164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
andrewhead 0:4df415dde990 165
andrewhead 0:4df415dde990 166 private:
andrewhead 0:4df415dde990 167 HID_REPORT outputReport;
andrewhead 0:4df415dde990 168 uint8_t output_length;
andrewhead 0:4df415dde990 169 uint8_t input_length;
andrewhead 0:4df415dde990 170 };
andrewhead 0:4df415dde990 171
andrewhead 0:4df415dde990 172 #endif