Il y avait des problèmes dans la libraire...

Fork of USBDEVICE by ST

Committer:
qroche
Date:
Sun Sep 03 23:19:21 2017 +0000
Branch:
master
Revision:
5:3329e56e51d7
Parent:
1:2a3ae13b45ef
fin;

Who changed what in which revision?

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