USB Composite support
Dependents: mbed_cdc_hid_composite
Fork of USBDevice by
USBDevice/USBComposite.h@55:7c559fcb1d17, 2015-05-31 (annotated)
- Committer:
- steeven
- Date:
- Sun May 31 15:36:50 2015 +0000
- Revision:
- 55:7c559fcb1d17
Make USBDevice support Composite
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
steeven | 55:7c559fcb1d17 | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
steeven | 55:7c559fcb1d17 | 2 | * |
steeven | 55:7c559fcb1d17 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
steeven | 55:7c559fcb1d17 | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
steeven | 55:7c559fcb1d17 | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
steeven | 55:7c559fcb1d17 | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
steeven | 55:7c559fcb1d17 | 7 | * Software is furnished to do so, subject to the following conditions: |
steeven | 55:7c559fcb1d17 | 8 | * |
steeven | 55:7c559fcb1d17 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
steeven | 55:7c559fcb1d17 | 10 | * substantial portions of the Software. |
steeven | 55:7c559fcb1d17 | 11 | * |
steeven | 55:7c559fcb1d17 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
steeven | 55:7c559fcb1d17 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
steeven | 55:7c559fcb1d17 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
steeven | 55:7c559fcb1d17 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
steeven | 55:7c559fcb1d17 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
steeven | 55:7c559fcb1d17 | 17 | */ |
steeven | 55:7c559fcb1d17 | 18 | |
steeven | 55:7c559fcb1d17 | 19 | #ifndef USBCOMPOSITE_H |
steeven | 55:7c559fcb1d17 | 20 | #define USBCOMPOSITE_H |
steeven | 55:7c559fcb1d17 | 21 | |
steeven | 55:7c559fcb1d17 | 22 | /* These headers are included for child class. */ |
steeven | 55:7c559fcb1d17 | 23 | #include "USBEndpoints.h" |
steeven | 55:7c559fcb1d17 | 24 | #include "USBDescriptor.h" |
steeven | 55:7c559fcb1d17 | 25 | #include "USBDevice_Types.h" |
steeven | 55:7c559fcb1d17 | 26 | |
steeven | 55:7c559fcb1d17 | 27 | #include "USBDevice.h" |
steeven | 55:7c559fcb1d17 | 28 | |
steeven | 55:7c559fcb1d17 | 29 | class USBComposite: public USBDevice{ |
steeven | 55:7c559fcb1d17 | 30 | public: |
steeven | 55:7c559fcb1d17 | 31 | |
steeven | 55:7c559fcb1d17 | 32 | /* |
steeven | 55:7c559fcb1d17 | 33 | * Constructor |
steeven | 55:7c559fcb1d17 | 34 | * |
steeven | 55:7c559fcb1d17 | 35 | * @param vendor_id Your vendor_id |
steeven | 55:7c559fcb1d17 | 36 | * @param product_id Your product_id |
steeven | 55:7c559fcb1d17 | 37 | * @param product_release Your preoduct_release |
steeven | 55:7c559fcb1d17 | 38 | * @param connect_blocking define if the connection must be blocked if USB not plugged in |
steeven | 55:7c559fcb1d17 | 39 | */ |
steeven | 55:7c559fcb1d17 | 40 | USBComposite(bool connect_blocking = true, uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, uint16_t product_release = 0x0001); |
steeven | 55:7c559fcb1d17 | 41 | |
steeven | 55:7c559fcb1d17 | 42 | virtual bool bind(USBComposite *intf) { |
steeven | 55:7c559fcb1d17 | 43 | uint8_t i; |
steeven | 55:7c559fcb1d17 | 44 | for (i = 0; i < sizeof(_intfs)/sizeof(_intfs[0]); ++i) { |
steeven | 55:7c559fcb1d17 | 45 | if (_intfs[i] == NULL){ |
steeven | 55:7c559fcb1d17 | 46 | _intfs[i] = intf; |
steeven | 55:7c559fcb1d17 | 47 | return true; |
steeven | 55:7c559fcb1d17 | 48 | } |
steeven | 55:7c559fcb1d17 | 49 | } |
steeven | 55:7c559fcb1d17 | 50 | return false; |
steeven | 55:7c559fcb1d17 | 51 | } |
steeven | 55:7c559fcb1d17 | 52 | |
steeven | 55:7c559fcb1d17 | 53 | protected: |
steeven | 55:7c559fcb1d17 | 54 | |
steeven | 55:7c559fcb1d17 | 55 | /* |
steeven | 55:7c559fcb1d17 | 56 | * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength. |
steeven | 55:7c559fcb1d17 | 57 | * |
steeven | 55:7c559fcb1d17 | 58 | * @returns pointer to the device descriptor |
steeven | 55:7c559fcb1d17 | 59 | */ |
steeven | 55:7c559fcb1d17 | 60 | virtual uint8_t * deviceDesc(); |
steeven | 55:7c559fcb1d17 | 61 | |
steeven | 55:7c559fcb1d17 | 62 | /* |
steeven | 55:7c559fcb1d17 | 63 | * Get string product descriptor |
steeven | 55:7c559fcb1d17 | 64 | * |
steeven | 55:7c559fcb1d17 | 65 | * @returns pointer to the string product descriptor |
steeven | 55:7c559fcb1d17 | 66 | */ |
steeven | 55:7c559fcb1d17 | 67 | virtual uint8_t * stringIproductDesc(); |
steeven | 55:7c559fcb1d17 | 68 | |
steeven | 55:7c559fcb1d17 | 69 | /* |
steeven | 55:7c559fcb1d17 | 70 | * Get string interface descriptor |
steeven | 55:7c559fcb1d17 | 71 | * |
steeven | 55:7c559fcb1d17 | 72 | * @returns pointer to the string interface descriptor |
steeven | 55:7c559fcb1d17 | 73 | */ |
steeven | 55:7c559fcb1d17 | 74 | virtual uint8_t * stringIinterfaceDesc(); |
steeven | 55:7c559fcb1d17 | 75 | |
steeven | 55:7c559fcb1d17 | 76 | /* |
steeven | 55:7c559fcb1d17 | 77 | * Get configuration descriptor |
steeven | 55:7c559fcb1d17 | 78 | * |
steeven | 55:7c559fcb1d17 | 79 | * @returns pointer to the configuration descriptor |
steeven | 55:7c559fcb1d17 | 80 | */ |
steeven | 55:7c559fcb1d17 | 81 | virtual uint8_t * configurationDesc(); |
steeven | 55:7c559fcb1d17 | 82 | |
steeven | 55:7c559fcb1d17 | 83 | |
steeven | 55:7c559fcb1d17 | 84 | protected: |
steeven | 55:7c559fcb1d17 | 85 | virtual bool USBCallback_request(); |
steeven | 55:7c559fcb1d17 | 86 | virtual void USBCallback_requestCompleted(uint8_t *buf, uint32_t length); |
steeven | 55:7c559fcb1d17 | 87 | virtual bool USBCallback_setConfiguration(uint8_t configuration); |
steeven | 55:7c559fcb1d17 | 88 | volatile bool terminal_connected; |
steeven | 55:7c559fcb1d17 | 89 | |
steeven | 55:7c559fcb1d17 | 90 | USBComposite* _intfs[4]; |
steeven | 55:7c559fcb1d17 | 91 | }; |
steeven | 55:7c559fcb1d17 | 92 | |
steeven | 55:7c559fcb1d17 | 93 | #endif |