USB Composite support

Dependents:   mbed_cdc_hid_composite

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBComposite.h Source File

USBComposite.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 USBCOMPOSITE_H
00020 #define USBCOMPOSITE_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 "USBDevice.h"
00028 
00029 class USBComposite: public USBDevice{
00030 public:
00031 
00032     /*
00033     * Constructor
00034     *
00035     * @param vendor_id Your vendor_id
00036     * @param product_id Your product_id
00037     * @param product_release Your preoduct_release
00038     * @param connect_blocking define if the connection must be blocked if USB not plugged in
00039     */
00040     USBComposite(bool connect_blocking = true, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001);
00041 
00042     virtual bool bind(USBComposite *intf) {
00043         uint8_t i;
00044         for (i = 0; i < sizeof(_intfs)/sizeof(_intfs[0]); ++i) {
00045             if (_intfs[i] == NULL){
00046                 _intfs[i] = intf;
00047                 return true;
00048             }
00049         }
00050         return false;
00051     }
00052 
00053 protected:
00054 
00055     /*
00056     * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
00057     *
00058     * @returns pointer to the device descriptor
00059     */
00060     virtual uint8_t * deviceDesc();
00061 
00062     /*
00063     * Get string product descriptor
00064     *
00065     * @returns pointer to the string product descriptor
00066     */
00067     virtual uint8_t * stringIproductDesc();
00068 
00069     /*
00070     * Get string interface descriptor
00071     *
00072     * @returns pointer to the string interface descriptor
00073     */
00074     virtual uint8_t * stringIinterfaceDesc();
00075 
00076     /*
00077     * Get configuration descriptor
00078     *
00079     * @returns pointer to the configuration descriptor
00080     */
00081     virtual uint8_t * configurationDesc();
00082 
00083 
00084 protected:
00085     virtual bool USBCallback_request();
00086     virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length);
00087     virtual bool USBCallback_setConfiguration(uint8_t configuration);
00088     volatile bool terminal_connected;
00089 
00090     USBComposite* _intfs[4];
00091 };
00092 
00093 #endif