Pinscape Controller version 1 fork. This is a fork to allow for ongoing bug fixes to the original controller version, from before the major changes for the expansion board project.

Dependencies:   FastIO FastPWM SimpleDMA mbed

Fork of Pinscape_Controller by Mike R

Committer:
mjr
Date:
Mon Feb 15 23:03:55 2016 +0000
Revision:
68:edfecf67a931
Parent:
55:e47a4b7ab348
Finalize USB library updates to fix compatibility problems introduced in USBHAL_KL25Z overhaul.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mjr 52:63f0a9b45f0c 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
mjr 52:63f0a9b45f0c 2 *
mjr 52:63f0a9b45f0c 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
mjr 52:63f0a9b45f0c 4 * and associated documentation files (the "Software"), to deal in the Software without
mjr 52:63f0a9b45f0c 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
mjr 52:63f0a9b45f0c 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
mjr 52:63f0a9b45f0c 7 * Software is furnished to do so, subject to the following conditions:
mjr 52:63f0a9b45f0c 8 *
mjr 52:63f0a9b45f0c 9 * The above copyright notice and this permission notice shall be included in all copies or
mjr 52:63f0a9b45f0c 10 * substantial portions of the Software.
mjr 52:63f0a9b45f0c 11 *
mjr 52:63f0a9b45f0c 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
mjr 52:63f0a9b45f0c 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
mjr 52:63f0a9b45f0c 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
mjr 52:63f0a9b45f0c 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
mjr 52:63f0a9b45f0c 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
mjr 52:63f0a9b45f0c 17 */
mjr 52:63f0a9b45f0c 18
mjr 52:63f0a9b45f0c 19 #ifndef USB_HID_H
mjr 52:63f0a9b45f0c 20 #define USB_HID_H
mjr 52:63f0a9b45f0c 21
mjr 52:63f0a9b45f0c 22 /* These headers are included for child class. */
mjr 52:63f0a9b45f0c 23 #include "USBEndpoints.h"
mjr 52:63f0a9b45f0c 24 #include "USBDescriptor.h"
mjr 52:63f0a9b45f0c 25 #include "USBDevice_Types.h"
mjr 52:63f0a9b45f0c 26
mjr 52:63f0a9b45f0c 27 #include "USBHID_Types.h"
mjr 52:63f0a9b45f0c 28 #include "USBDevice.h"
mjr 52:63f0a9b45f0c 29
mjr 52:63f0a9b45f0c 30
mjr 52:63f0a9b45f0c 31 /**
mjr 52:63f0a9b45f0c 32 * USBHID example
mjr 52:63f0a9b45f0c 33 * @code
mjr 52:63f0a9b45f0c 34 * #include "mbed.h"
mjr 52:63f0a9b45f0c 35 * #include "USBHID.h"
mjr 52:63f0a9b45f0c 36 *
mjr 52:63f0a9b45f0c 37 * USBHID hid;
mjr 52:63f0a9b45f0c 38 * HID_REPORT recv;
mjr 52:63f0a9b45f0c 39 * BusOut leds(LED1,LED2,LED3,LED4);
mjr 52:63f0a9b45f0c 40 *
mjr 52:63f0a9b45f0c 41 * int main(void) {
mjr 52:63f0a9b45f0c 42 * while (1) {
mjr 52:63f0a9b45f0c 43 * hid.read(&recv);
mjr 52:63f0a9b45f0c 44 * leds = recv.data[0];
mjr 52:63f0a9b45f0c 45 * }
mjr 52:63f0a9b45f0c 46 * }
mjr 52:63f0a9b45f0c 47 * @endcode
mjr 52:63f0a9b45f0c 48 */
mjr 52:63f0a9b45f0c 49
mjr 52:63f0a9b45f0c 50 class USBHID: public USBDevice {
mjr 52:63f0a9b45f0c 51 public:
mjr 52:63f0a9b45f0c 52
mjr 52:63f0a9b45f0c 53 /**
mjr 52:63f0a9b45f0c 54 * Constructor
mjr 52:63f0a9b45f0c 55 *
mjr 52:63f0a9b45f0c 56 * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
mjr 52:63f0a9b45f0c 57 * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
mjr 52:63f0a9b45f0c 58 * @param vendor_id Your vendor_id
mjr 52:63f0a9b45f0c 59 * @param product_id Your product_id
mjr 52:63f0a9b45f0c 60 * @param product_release Your preoduct_release
mjr 52:63f0a9b45f0c 61 * @param connect Connect the device
mjr 52:63f0a9b45f0c 62 */
mjr 52:63f0a9b45f0c 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);
mjr 52:63f0a9b45f0c 64
mjr 52:63f0a9b45f0c 65
mjr 52:63f0a9b45f0c 66 /**
mjr 52:63f0a9b45f0c 67 * Send a Report. warning: blocking
mjr 52:63f0a9b45f0c 68 *
mjr 52:63f0a9b45f0c 69 * @param report Report which will be sent (a report is defined by all data and the length)
mjr 52:63f0a9b45f0c 70 * @returns true if successful
mjr 52:63f0a9b45f0c 71 */
mjr 52:63f0a9b45f0c 72 bool send(HID_REPORT *report);
mjr 52:63f0a9b45f0c 73
mjr 52:63f0a9b45f0c 74
mjr 52:63f0a9b45f0c 75 /**
mjr 52:63f0a9b45f0c 76 * Send a Report. warning: non blocking
mjr 52:63f0a9b45f0c 77 *
mjr 52:63f0a9b45f0c 78 * @param report Report which will be sent (a report is defined by all data and the length)
mjr 52:63f0a9b45f0c 79 * @returns true if successful
mjr 52:63f0a9b45f0c 80 */
mjr 52:63f0a9b45f0c 81 bool sendNB(HID_REPORT *report);
mjr 52:63f0a9b45f0c 82
mjr 52:63f0a9b45f0c 83 /**
mjr 52:63f0a9b45f0c 84 * Send a Report with timeout. Blocks until the report has been sent or the timeout
mjr 52:63f0a9b45f0c 85 * expires, whichever comes first.
mjr 52:63f0a9b45f0c 86 *
mjr 52:63f0a9b45f0c 87 * @param report Report to be sent
mjr 52:63f0a9b45f0c 88 * @param timeout_ms Timeout in milliseconds
mjr 52:63f0a9b45f0c 89 * @returns true if successful
mjr 52:63f0a9b45f0c 90 */
mjr 52:63f0a9b45f0c 91 bool sendTO(HID_REPORT *report, int timeout_ms);
mjr 52:63f0a9b45f0c 92
mjr 52:63f0a9b45f0c 93 /**
mjr 52:63f0a9b45f0c 94 * Read a report: blocking
mjr 52:63f0a9b45f0c 95 *
mjr 52:63f0a9b45f0c 96 * @param report pointer to the report to fill
mjr 52:63f0a9b45f0c 97 * @returns true if successful
mjr 52:63f0a9b45f0c 98 */
mjr 52:63f0a9b45f0c 99 bool read(HID_REPORT * report);
mjr 52:63f0a9b45f0c 100
mjr 52:63f0a9b45f0c 101 /**
mjr 52:63f0a9b45f0c 102 * Read a report: non blocking
mjr 52:63f0a9b45f0c 103 *
mjr 52:63f0a9b45f0c 104 * @param report pointer to the report to fill
mjr 52:63f0a9b45f0c 105 * @returns true if successful
mjr 52:63f0a9b45f0c 106 */
mjr 52:63f0a9b45f0c 107 bool readNB(HID_REPORT * report);
mjr 52:63f0a9b45f0c 108
mjr 52:63f0a9b45f0c 109 protected:
mjr 52:63f0a9b45f0c 110 uint16_t reportLength;
mjr 52:63f0a9b45f0c 111
mjr 52:63f0a9b45f0c 112 /*
mjr 52:63f0a9b45f0c 113 * Get the Report descriptor
mjr 52:63f0a9b45f0c 114 *
mjr 52:63f0a9b45f0c 115 * @returns pointer to the report descriptor
mjr 52:63f0a9b45f0c 116 */
mjr 52:63f0a9b45f0c 117 virtual uint8_t * reportDesc();
mjr 53:02408ec83097 118 virtual uint8_t * reportDescN(int idx) { return idx == 0 ? reportDesc() : 0; }
mjr 52:63f0a9b45f0c 119
mjr 52:63f0a9b45f0c 120 /*
mjr 52:63f0a9b45f0c 121 * Get the length of the report descriptor
mjr 52:63f0a9b45f0c 122 *
mjr 52:63f0a9b45f0c 123 * @returns the length of the report descriptor
mjr 52:63f0a9b45f0c 124 */
mjr 52:63f0a9b45f0c 125 virtual uint16_t reportDescLength();
mjr 52:63f0a9b45f0c 126 virtual uint16_t reportDescLengthN(int idx)
mjr 52:63f0a9b45f0c 127 {
mjr 52:63f0a9b45f0c 128 reportDescN(idx);
mjr 52:63f0a9b45f0c 129 return reportLength;
mjr 52:63f0a9b45f0c 130 }
mjr 52:63f0a9b45f0c 131
mjr 52:63f0a9b45f0c 132 /*
mjr 52:63f0a9b45f0c 133 * Get string product descriptor
mjr 52:63f0a9b45f0c 134 *
mjr 52:63f0a9b45f0c 135 * @returns pointer to the string product descriptor
mjr 52:63f0a9b45f0c 136 */
mjr 52:63f0a9b45f0c 137 virtual uint8_t * stringIproductDesc();
mjr 52:63f0a9b45f0c 138
mjr 52:63f0a9b45f0c 139 /*
mjr 52:63f0a9b45f0c 140 * Get string interface descriptor
mjr 52:63f0a9b45f0c 141 *
mjr 52:63f0a9b45f0c 142 * @returns pointer to the string interface descriptor
mjr 52:63f0a9b45f0c 143 */
mjr 52:63f0a9b45f0c 144 virtual uint8_t * stringIinterfaceDesc();
mjr 52:63f0a9b45f0c 145
mjr 52:63f0a9b45f0c 146 /*
mjr 52:63f0a9b45f0c 147 * Get configuration descriptor
mjr 52:63f0a9b45f0c 148 *
mjr 52:63f0a9b45f0c 149 * @returns pointer to the configuration descriptor
mjr 52:63f0a9b45f0c 150 */
mjr 52:63f0a9b45f0c 151 virtual uint8_t * configurationDesc();
mjr 55:e47a4b7ab348 152
mjr 55:e47a4b7ab348 153 /*
mjr 55:e47a4b7ab348 154 * Set the idle time on the given interface. The idle time is the time between
mjr 55:e47a4b7ab348 155 * INTERRUPT IN reports sent from the device to the host in the absence of any
mjr 55:e47a4b7ab348 156 * updates in values. E.g., for a keyboard, this is the time between reports
mjr 55:e47a4b7ab348 157 * when there's no new key up/down activity to report. An infinite idle time
mjr 55:e47a4b7ab348 158 * means that reports are sent only when new activity occurs.
mjr 55:e47a4b7ab348 159 *
mjr 55:e47a4b7ab348 160 * @param ifc Interface index (this specifies which interface is affected, in
mjr 55:e47a4b7ab348 161 * cases where the device has multiple interfaces)
mjr 55:e47a4b7ab348 162 *
mjr 55:e47a4b7ab348 163 * @param reportID Report ID (specifies which report type is affected, in cases
mjr 55:e47a4b7ab348 164 * where the device has multiple report types)
mjr 55:e47a4b7ab348 165 *
mjr 55:e47a4b7ab348 166 * @param t Idle time in 4ms units, with the special case that 0 means infinity.
mjr 55:e47a4b7ab348 167 * The maximum value is 255 units (1.02s).
mjr 55:e47a4b7ab348 168 */
mjr 55:e47a4b7ab348 169 virtual void setIdleTime(int ifc, int reportId, int t) { }
mjr 55:e47a4b7ab348 170
mjr 55:e47a4b7ab348 171 /*
mjr 55:e47a4b7ab348 172 * Get the idle time on the given interface. Returns the idle time information
mjr 55:e47a4b7ab348 173 * previously set with setIdleTime().
mjr 55:e47a4b7ab348 174 *
mjr 55:e47a4b7ab348 175 * @param ifc Interface index (specifies which interface is being queried, in
mjr 55:e47a4b7ab348 176 * cases where the device has multiple interfaces)
mjr 55:e47a4b7ab348 177 *
mjr 55:e47a4b7ab348 178 * @param reportID Report ID (specifies which report type is being queried, in
mjr 55:e47a4b7ab348 179 * cases where the device has multiple report types)
mjr 55:e47a4b7ab348 180 *
mjr 55:e47a4b7ab348 181 * @return The idle time currently set on the interface, in 4ms units. 0 means
mjr 55:e47a4b7ab348 182 * infinity (so reports will only be sent when there's new data)
mjr 55:e47a4b7ab348 183 */
mjr 55:e47a4b7ab348 184 virtual uint8_t getIdleTime(int ifc, int reportId) { return 0; }
mjr 52:63f0a9b45f0c 185
mjr 52:63f0a9b45f0c 186 /*
mjr 52:63f0a9b45f0c 187 * HID Report received by SET_REPORT request. Warning: Called in ISR context
mjr 52:63f0a9b45f0c 188 * First byte of data will be the report ID
mjr 52:63f0a9b45f0c 189 *
mjr 52:63f0a9b45f0c 190 * @param report Data and length received
mjr 52:63f0a9b45f0c 191 */
mjr 52:63f0a9b45f0c 192 virtual void HID_callbackSetReport(HID_REPORT *report){};
mjr 52:63f0a9b45f0c 193
mjr 52:63f0a9b45f0c 194
mjr 52:63f0a9b45f0c 195 /*
mjr 52:63f0a9b45f0c 196 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
mjr 52:63f0a9b45f0c 197 * This is used to handle extensions to standard requests
mjr 52:63f0a9b45f0c 198 * and class specific requests
mjr 52:63f0a9b45f0c 199 *
mjr 52:63f0a9b45f0c 200 * @returns true if class handles this request
mjr 52:63f0a9b45f0c 201 */
mjr 52:63f0a9b45f0c 202 virtual bool USBCallback_request();
mjr 52:63f0a9b45f0c 203
mjr 52:63f0a9b45f0c 204
mjr 52:63f0a9b45f0c 205 /*
mjr 52:63f0a9b45f0c 206 * Called by USBDevice layer. Set configuration of the device.
mjr 52:63f0a9b45f0c 207 * For instance, you can add all endpoints that you need on this function.
mjr 52:63f0a9b45f0c 208 *
mjr 52:63f0a9b45f0c 209 * @param configuration Number of the configuration
mjr 52:63f0a9b45f0c 210 * @returns true if class handles this request
mjr 52:63f0a9b45f0c 211 */
mjr 52:63f0a9b45f0c 212 virtual bool USBCallback_setConfiguration(uint8_t configuration);
mjr 52:63f0a9b45f0c 213
mjr 52:63f0a9b45f0c 214 private:
mjr 52:63f0a9b45f0c 215 HID_REPORT outputReport;
mjr 52:63f0a9b45f0c 216 uint8_t output_length;
mjr 52:63f0a9b45f0c 217 uint8_t input_length;
mjr 55:e47a4b7ab348 218 uint8_t idleData;
mjr 52:63f0a9b45f0c 219 };
mjr 52:63f0a9b45f0c 220
mjr 52:63f0a9b45f0c 221 #endif