USB device stack - Added support for the logo/windows key to USB keyboard.

Dependents:   randomSearch

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBHID.h Source File

USBHID.h

00001 /* Copyright (c) 2010-2011 mbed.org, MIT License
00002 *
00003 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
00004 * and associated documentation files (the "Software"), to deal in the Software without
00005 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
00006 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
00007 * Software is furnished to do so, subject to the following conditions:
00008 *
00009 * The above copyright notice and this permission notice shall be included in all copies or
00010 * substantial portions of the Software.
00011 *
00012 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
00013 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
00014 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
00015 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
00016 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00017 */
00018 
00019 #ifndef USB_HID_H
00020 #define USB_HID_H
00021 
00022 /* These headers are included for child class. */
00023 #include "USBEndpoints.h"
00024 #include "USBDescriptor.h"
00025 #include "USBDevice_Types.h"
00026 
00027 #include "USBHID_Types.h"
00028 #include "USBDevice.h"
00029 
00030 
00031 /**
00032  * USBHID example
00033  * @code
00034  * #include "mbed.h"
00035  * #include "USBHID.h"
00036  *
00037  * USBHID hid;
00038  * HID_REPORT recv;
00039  * BusOut leds(LED1,LED2,LED3,LED4);
00040  *
00041  * int main(void) {
00042  *    while (1) {
00043  *        hid.read(&recv);
00044  *        leds = recv.data[0];
00045  *    }
00046  * }
00047  * @endcode
00048  */
00049 
00050 class USBHID: public USBDevice {
00051 public:
00052 
00053     /**
00054     * Constructor
00055     *
00056     * @param output_report_length Maximum length of a sent report (up to 64 bytes) (default: 64 bytes)
00057     * @param input_report_length Maximum length of a received report (up to 64 bytes) (default: 64 bytes)
00058     * @param vendor_id Your vendor_id
00059     * @param product_id Your product_id
00060     * @param product_release Your preoduct_release
00061     * @param connect Connect the device
00062     */
00063     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);
00064 
00065 
00066     /**
00067     * Send a Report. warning: blocking
00068     *
00069     * @param report Report which will be sent (a report is defined by all data and the length)
00070     * @returns true if successful
00071     */
00072     bool send(HID_REPORT *report);
00073 
00074 
00075     /**
00076     * Send a Report. warning: non blocking
00077     *
00078     * @param report Report which will be sent (a report is defined by all data and the length)
00079     * @returns true if successful
00080     */
00081     bool sendNB(HID_REPORT *report);
00082 
00083     /**
00084     * Read a report: blocking
00085     *
00086     * @param report pointer to the report to fill
00087     * @returns true if successful
00088     */
00089     bool read(HID_REPORT * report);
00090 
00091     /**
00092     * Read a report: non blocking
00093     *
00094     * @param report pointer to the report to fill
00095     * @returns true if successful
00096     */
00097     bool readNB(HID_REPORT * report);
00098 
00099 protected:
00100     uint16_t reportLength;
00101 
00102     /*
00103     * Get the Report descriptor
00104     *
00105     * @returns pointer to the report descriptor
00106     */
00107     virtual uint8_t * reportDesc();
00108 
00109     /*
00110     * Get the length of the report descriptor
00111     *
00112     * @returns the length of the report descriptor
00113     */
00114     virtual uint16_t reportDescLength();
00115 
00116     /*
00117     * Get string product descriptor
00118     *
00119     * @returns pointer to the string product descriptor
00120     */
00121     virtual uint8_t * stringIproductDesc();
00122 
00123     /*
00124     * Get string interface descriptor
00125     *
00126     * @returns pointer to the string interface descriptor
00127     */
00128     virtual uint8_t * stringIinterfaceDesc();
00129 
00130     /*
00131     * Get configuration descriptor
00132     *
00133     * @returns pointer to the configuration descriptor
00134     */
00135     virtual uint8_t * configurationDesc();
00136 
00137 
00138     /*
00139     * HID Report received by SET_REPORT request. Warning: Called in ISR context
00140     * First byte of data will be the report ID
00141     *
00142     * @param report Data and length received
00143     */
00144     virtual void HID_callbackSetReport(HID_REPORT *report){};
00145 
00146 
00147     /*
00148     * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
00149     * This is used to handle extensions to standard requests
00150     * and class specific requests
00151     *
00152     * @returns true if class handles this request
00153     */
00154     virtual bool USBCallback_request();
00155 
00156 
00157     /*
00158     * Called by USBDevice layer. Set configuration of the device.
00159     * For instance, you can add all endpoints that you need on this function.
00160     *
00161     * @param configuration Number of the configuration
00162     * @returns true if class handles this request
00163     */
00164     virtual bool USBCallback_setConfiguration(uint8_t configuration);
00165 
00166 private:
00167     HID_REPORT outputReport;
00168     uint8_t output_length;
00169     uint8_t input_length;
00170 };
00171 
00172 #endif