USB device stack - modified

Dependents:   shaun_larada

Fork of USBDevice by mbed official

Committer:
setcom_001
Date:
Mon Jul 22 21:16:27 2013 +0000
Revision:
12:a9671b78d24e
docs update

Who changed what in which revision?

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