blablabla

Dependencies:   MAG3110 MMA8451Q SLCD- TSI USBDevice mbed

Committer:
Osator
Date:
Wed Apr 16 12:20:00 2014 +0000
Revision:
0:339b7abfa147
blablabla

Who changed what in which revision?

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