partly working USB Device lib for STM32F746NG Discovery both Interface are working

Dependents:   DISCO-F746NG-USB_Device McLighTT project_Keyboard_to_the_Keyboard MIDIInstrumentPADProject ... more

Committer:
DieterGraef
Date:
Sun Jul 31 17:47:35 2016 +0000
Revision:
0:0a2eaa300982
partly working USB Device library - serial and MIDI is working

Who changed what in which revision?

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