dhgdh

Dependencies:   MAX44000 PWM_Tone_Library nexpaq_mdk

Fork of LED_Demo by joey shelton

Committer:
cyberjoey
Date:
Sat Oct 22 01:31:58 2016 +0000
Revision:
9:6bb35cef007d
Parent:
1:55a6170b404f
WORKING

Who changed what in which revision?

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