Modified for PS3 Joystick

Dependents:   NiseKabuto

Fork of USBDevice by Samuel Mokrani

Committer:
sankichi
Date:
Sat Jul 27 14:05:26 2013 +0000
Revision:
1:ac5cca60029a
Parent:
0:140cdf8e2d60
First Release

Who changed what in which revision?

UserRevisionLine numberNew contents of line
samux 0:140cdf8e2d60 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
samux 0:140cdf8e2d60 2 *
samux 0:140cdf8e2d60 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
samux 0:140cdf8e2d60 4 * and associated documentation files (the "Software"), to deal in the Software without
samux 0:140cdf8e2d60 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
samux 0:140cdf8e2d60 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
samux 0:140cdf8e2d60 7 * Software is furnished to do so, subject to the following conditions:
samux 0:140cdf8e2d60 8 *
samux 0:140cdf8e2d60 9 * The above copyright notice and this permission notice shall be included in all copies or
samux 0:140cdf8e2d60 10 * substantial portions of the Software.
samux 0:140cdf8e2d60 11 *
samux 0:140cdf8e2d60 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
samux 0:140cdf8e2d60 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
samux 0:140cdf8e2d60 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
samux 0:140cdf8e2d60 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
samux 0:140cdf8e2d60 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
samux 0:140cdf8e2d60 17 */
samux 0:140cdf8e2d60 18
samux 0:140cdf8e2d60 19 #ifndef USB_HID_H
samux 0:140cdf8e2d60 20 #define USB_HID_H
samux 0:140cdf8e2d60 21
samux 0:140cdf8e2d60 22 /* These headers are included for child class. */
samux 0:140cdf8e2d60 23 #include "USBEndpoints.h"
samux 0:140cdf8e2d60 24 #include "USBDescriptor.h"
samux 0:140cdf8e2d60 25 #include "USBDevice_Types.h"
samux 0:140cdf8e2d60 26
samux 0:140cdf8e2d60 27 #include "USBHID_Types.h"
samux 0:140cdf8e2d60 28 #include "USBDevice.h"
samux 0:140cdf8e2d60 29
samux 0:140cdf8e2d60 30
samux 0:140cdf8e2d60 31 /**
samux 0:140cdf8e2d60 32 * USBHID example
samux 0:140cdf8e2d60 33 * @code
samux 0:140cdf8e2d60 34 * #include "mbed.h"
samux 0:140cdf8e2d60 35 * #include "USBHID.h"
samux 0:140cdf8e2d60 36 *
samux 0:140cdf8e2d60 37 * USBHID hid;
samux 0:140cdf8e2d60 38 * HID_REPORT recv;
samux 0:140cdf8e2d60 39 * BusOut leds(LED1,LED2,LED3,LED4);
samux 0:140cdf8e2d60 40 *
samux 0:140cdf8e2d60 41 * int main(void) {
samux 0:140cdf8e2d60 42 * while (1) {
samux 0:140cdf8e2d60 43 * hid.read(&recv);
samux 0:140cdf8e2d60 44 * leds = recv.data[0];
samux 0:140cdf8e2d60 45 * }
samux 0:140cdf8e2d60 46 * }
samux 0:140cdf8e2d60 47 * @endcode
samux 0:140cdf8e2d60 48 */
samux 0:140cdf8e2d60 49
samux 0:140cdf8e2d60 50 class USBHID: public USBDevice {
samux 0:140cdf8e2d60 51 public:
samux 0:140cdf8e2d60 52
samux 0:140cdf8e2d60 53 /**
samux 0:140cdf8e2d60 54 * Constructor
samux 0:140cdf8e2d60 55 *
samux 0:140cdf8e2d60 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
samux 0:140cdf8e2d60 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
samux 0:140cdf8e2d60 58 * @param vendor_id Your vendor_id
samux 0:140cdf8e2d60 59 * @param product_id Your product_id
samux 0:140cdf8e2d60 60 * @param product_release Your preoduct_release
samux 0:140cdf8e2d60 61 * @param connect Connect the device
samux 0:140cdf8e2d60 62 */
samux 0:140cdf8e2d60 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);
samux 0:140cdf8e2d60 64
samux 0:140cdf8e2d60 65
samux 0:140cdf8e2d60 66 /**
samux 0:140cdf8e2d60 67 * Send a Report. warning: blocking
samux 0:140cdf8e2d60 68 *
samux 0:140cdf8e2d60 69 * @param report Report which will be sent (a report is defined by all data and the length)
samux 0:140cdf8e2d60 70 * @returns true if successful
samux 0:140cdf8e2d60 71 */
samux 0:140cdf8e2d60 72 bool send(HID_REPORT *report);
samux 0:140cdf8e2d60 73
samux 0:140cdf8e2d60 74
samux 0:140cdf8e2d60 75 /**
samux 0:140cdf8e2d60 76 * Send a Report. warning: non blocking
samux 0:140cdf8e2d60 77 *
samux 0:140cdf8e2d60 78 * @param report Report which will be sent (a report is defined by all data and the length)
samux 0:140cdf8e2d60 79 * @returns true if successful
samux 0:140cdf8e2d60 80 */
samux 0:140cdf8e2d60 81 bool sendNB(HID_REPORT *report);
samux 0:140cdf8e2d60 82
samux 0:140cdf8e2d60 83 /**
samux 0:140cdf8e2d60 84 * Read a report: blocking
samux 0:140cdf8e2d60 85 *
samux 0:140cdf8e2d60 86 * @param report pointer to the report to fill
samux 0:140cdf8e2d60 87 * @returns true if successful
samux 0:140cdf8e2d60 88 */
samux 0:140cdf8e2d60 89 bool read(HID_REPORT * report);
samux 0:140cdf8e2d60 90
samux 0:140cdf8e2d60 91 /**
samux 0:140cdf8e2d60 92 * Read a report: non blocking
samux 0:140cdf8e2d60 93 *
samux 0:140cdf8e2d60 94 * @param report pointer to the report to fill
samux 0:140cdf8e2d60 95 * @returns true if successful
samux 0:140cdf8e2d60 96 */
samux 0:140cdf8e2d60 97 bool readNB(HID_REPORT * report);
samux 0:140cdf8e2d60 98
samux 0:140cdf8e2d60 99 protected:
samux 0:140cdf8e2d60 100 uint16_t reportLength;
samux 0:140cdf8e2d60 101
samux 0:140cdf8e2d60 102 /*
samux 0:140cdf8e2d60 103 * Get the Report descriptor
samux 0:140cdf8e2d60 104 *
samux 0:140cdf8e2d60 105 * @returns pointer to the report descriptor
samux 0:140cdf8e2d60 106 */
samux 0:140cdf8e2d60 107 virtual uint8_t * reportDesc();
samux 0:140cdf8e2d60 108
samux 0:140cdf8e2d60 109 /*
samux 0:140cdf8e2d60 110 * Get the length of the report descriptor
samux 0:140cdf8e2d60 111 *
samux 0:140cdf8e2d60 112 * @returns the length of the report descriptor
samux 0:140cdf8e2d60 113 */
samux 0:140cdf8e2d60 114 virtual uint16_t reportDescLength();
samux 0:140cdf8e2d60 115
samux 0:140cdf8e2d60 116 /*
samux 0:140cdf8e2d60 117 * Get string product descriptor
samux 0:140cdf8e2d60 118 *
samux 0:140cdf8e2d60 119 * @returns pointer to the string product descriptor
samux 0:140cdf8e2d60 120 */
samux 0:140cdf8e2d60 121 virtual uint8_t * stringIproductDesc();
samux 0:140cdf8e2d60 122
samux 0:140cdf8e2d60 123 /*
samux 0:140cdf8e2d60 124 * Get string interface descriptor
samux 0:140cdf8e2d60 125 *
samux 0:140cdf8e2d60 126 * @returns pointer to the string interface descriptor
samux 0:140cdf8e2d60 127 */
samux 0:140cdf8e2d60 128 virtual uint8_t * stringIinterfaceDesc();
samux 0:140cdf8e2d60 129
samux 0:140cdf8e2d60 130 /*
samux 0:140cdf8e2d60 131 * Get configuration descriptor
samux 0:140cdf8e2d60 132 *
samux 0:140cdf8e2d60 133 * @returns pointer to the configuration descriptor
samux 0:140cdf8e2d60 134 */
samux 0:140cdf8e2d60 135 virtual uint8_t * configurationDesc();
samux 0:140cdf8e2d60 136
samux 0:140cdf8e2d60 137
samux 0:140cdf8e2d60 138 /*
samux 0:140cdf8e2d60 139 * HID Report received by SET_REPORT request. Warning: Called in ISR context
samux 0:140cdf8e2d60 140 * First byte of data will be the report ID
samux 0:140cdf8e2d60 141 *
samux 0:140cdf8e2d60 142 * @param report Data and length received
samux 0:140cdf8e2d60 143 */
samux 0:140cdf8e2d60 144 virtual void HID_callbackSetReport(HID_REPORT *report){};
samux 0:140cdf8e2d60 145
samux 0:140cdf8e2d60 146
samux 0:140cdf8e2d60 147 /*
samux 0:140cdf8e2d60 148 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
samux 0:140cdf8e2d60 149 * This is used to handle extensions to standard requests
samux 0:140cdf8e2d60 150 * and class specific requests
samux 0:140cdf8e2d60 151 *
samux 0:140cdf8e2d60 152 * @returns true if class handles this request
samux 0:140cdf8e2d60 153 */
samux 0:140cdf8e2d60 154 virtual bool USBCallback_request();
samux 0:140cdf8e2d60 155
samux 0:140cdf8e2d60 156
samux 0:140cdf8e2d60 157 /*
samux 0:140cdf8e2d60 158 * Called by USBDevice layer. Set configuration of the device.
samux 0:140cdf8e2d60 159 * For instance, you can add all endpoints that you need on this function.
samux 0:140cdf8e2d60 160 *
samux 0:140cdf8e2d60 161 * @param configuration Number of the configuration
samux 0:140cdf8e2d60 162 * @returns true if class handles this request
samux 0:140cdf8e2d60 163 */
samux 0:140cdf8e2d60 164 virtual bool USBCallback_setConfiguration(uint8_t configuration);
samux 0:140cdf8e2d60 165
samux 0:140cdf8e2d60 166 private:
samux 0:140cdf8e2d60 167 HID_REPORT outputReport;
samux 0:140cdf8e2d60 168 uint8_t output_length;
samux 0:140cdf8e2d60 169 uint8_t input_length;
samux 0:140cdf8e2d60 170 };
samux 0:140cdf8e2d60 171
samux 0:140cdf8e2d60 172 #endif