USB HID device for CMSIS-DAP

Dependents:   lpcterm2 Simple-CMSIS-DAP

Committer:
va009039
Date:
Sat Sep 14 11:19:17 2013 +0000
Revision:
0:6b9154ed73c6
Child:
2:7dee016756ce
first commit

Who changed what in which revision?

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