Emulation of LocalFileSystem with virtual COM.
Dependents: KL46Z-lpc81isp lpcterm2
#include "USBLocalFileSystem.h" int main() { USBLocalFileSystem* usb_local = new USBLocalFileSystem(); // RamDisk(64KB) while(1) { usb_local->lock(true); usb_local->remount(); char filename[32]; if (usb_local->find(filename, sizeof(filename), "*.TXT")) { FILE* fp = fopen(filename, "r"); if (fp) { int c; while((c = fgetc(fp)) != EOF) { usb_local->putc(c); } fclose(fp); } } usb_local->lock(false); wait_ms(1000*5); } }
Sample application:
Import programKL46Z-lpc81isp
ISP example program.
Import programlpcterm2
semihost server example program
USBMSD2/USBMSD2.cpp@6:528036abfb02, 2014-06-21 (annotated)
- Committer:
- va009039
- Date:
- Sat Jun 21 22:39:59 2014 +0000
- Revision:
- 6:528036abfb02
- Parent:
- 4:8f6857784854
add LPC11U68
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
va009039 | 0:39eb4d5b97df | 1 | /* Copyright (c) 2010-2011 mbed.org, MIT License |
va009039 | 0:39eb4d5b97df | 2 | * |
va009039 | 0:39eb4d5b97df | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
va009039 | 0:39eb4d5b97df | 4 | * and associated documentation files (the "Software"), to deal in the Software without |
va009039 | 0:39eb4d5b97df | 5 | * restriction, including without limitation the rights to use, copy, modify, merge, publish, |
va009039 | 0:39eb4d5b97df | 6 | * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the |
va009039 | 0:39eb4d5b97df | 7 | * Software is furnished to do so, subject to the following conditions: |
va009039 | 0:39eb4d5b97df | 8 | * |
va009039 | 0:39eb4d5b97df | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
va009039 | 0:39eb4d5b97df | 10 | * substantial portions of the Software. |
va009039 | 0:39eb4d5b97df | 11 | * |
va009039 | 0:39eb4d5b97df | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
va009039 | 0:39eb4d5b97df | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
va009039 | 0:39eb4d5b97df | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
va009039 | 0:39eb4d5b97df | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
va009039 | 0:39eb4d5b97df | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
va009039 | 0:39eb4d5b97df | 17 | */ |
va009039 | 0:39eb4d5b97df | 18 | |
va009039 | 0:39eb4d5b97df | 19 | #include "stdint.h" |
va009039 | 0:39eb4d5b97df | 20 | #include "USBMSD2.h" |
va009039 | 0:39eb4d5b97df | 21 | #include "USB_MSD.h" |
va009039 | 0:39eb4d5b97df | 22 | #include "USB_CDC.h" |
va009039 | 0:39eb4d5b97df | 23 | #include "USB_HID.h" |
va009039 | 0:39eb4d5b97df | 24 | |
va009039 | 0:39eb4d5b97df | 25 | #if (DEBUG2 > 3) |
va009039 | 0:39eb4d5b97df | 26 | #define USB_DBG(...) do{fprintf(stderr,"[%s@%d] ",__PRETTY_FUNCTION__,__LINE__);fprintf(stderr,__VA_ARGS__);fprintf(stderr,"\r\n");} while(0); |
va009039 | 0:39eb4d5b97df | 27 | #else |
va009039 | 0:39eb4d5b97df | 28 | #define USB_DBG(...) while(0) |
va009039 | 0:39eb4d5b97df | 29 | #endif |
va009039 | 0:39eb4d5b97df | 30 | |
va009039 | 0:39eb4d5b97df | 31 | #define DEFAULT_CONFIGURATION (1) |
va009039 | 0:39eb4d5b97df | 32 | |
va009039 | 0:39eb4d5b97df | 33 | USBMSD2::USBMSD2(uint16_t vendor_id, uint16_t product_id, uint16_t product_release) |
va009039 | 0:39eb4d5b97df | 34 | : USBDevice(vendor_id, product_id, product_release) |
va009039 | 0:39eb4d5b97df | 35 | { |
va009039 | 0:39eb4d5b97df | 36 | USB_DBG("%p vid=%04x pid=%04x", this, vendor_id, product_id); |
va009039 | 0:39eb4d5b97df | 37 | |
va009039 | 0:39eb4d5b97df | 38 | _msd = new USB_MSD(this, this); |
va009039 | 0:39eb4d5b97df | 39 | _cdc = new USB_CDC(this); |
va009039 | 0:39eb4d5b97df | 40 | _hid = new USB_HID(this); |
va009039 | 0:39eb4d5b97df | 41 | } |
va009039 | 0:39eb4d5b97df | 42 | |
va009039 | 0:39eb4d5b97df | 43 | USBMSD2::~USBMSD2() { |
va009039 | 0:39eb4d5b97df | 44 | _msd->disconnect(); |
va009039 | 0:39eb4d5b97df | 45 | USBDevice::disconnect(); |
va009039 | 0:39eb4d5b97df | 46 | } |
va009039 | 0:39eb4d5b97df | 47 | |
va009039 | 0:39eb4d5b97df | 48 | void USBMSD2::putc(int c) |
va009039 | 0:39eb4d5b97df | 49 | { |
va009039 | 0:39eb4d5b97df | 50 | _cdc->putc(c); |
va009039 | 0:39eb4d5b97df | 51 | } |
va009039 | 0:39eb4d5b97df | 52 | |
va009039 | 0:39eb4d5b97df | 53 | int USBMSD2::getc() |
va009039 | 0:39eb4d5b97df | 54 | { |
va009039 | 0:39eb4d5b97df | 55 | return _cdc->getc(); |
va009039 | 0:39eb4d5b97df | 56 | } |
va009039 | 0:39eb4d5b97df | 57 | |
va009039 | 0:39eb4d5b97df | 58 | int USBMSD2::readable() |
va009039 | 0:39eb4d5b97df | 59 | { |
va009039 | 0:39eb4d5b97df | 60 | return _cdc->readable(); |
va009039 | 0:39eb4d5b97df | 61 | } |
va009039 | 0:39eb4d5b97df | 62 | |
va009039 | 0:39eb4d5b97df | 63 | int USBMSD2::writeable() |
va009039 | 0:39eb4d5b97df | 64 | { |
va009039 | 0:39eb4d5b97df | 65 | return _cdc->writeable(); |
va009039 | 0:39eb4d5b97df | 66 | } |
va009039 | 0:39eb4d5b97df | 67 | |
va009039 | 0:39eb4d5b97df | 68 | bool USBMSD2::readNB(HID_REPORT* report) |
va009039 | 0:39eb4d5b97df | 69 | { |
va009039 | 0:39eb4d5b97df | 70 | return _hid->readNB(report); |
va009039 | 0:39eb4d5b97df | 71 | } |
va009039 | 0:39eb4d5b97df | 72 | |
va009039 | 0:39eb4d5b97df | 73 | bool USBMSD2::send(HID_REPORT* report) |
va009039 | 0:39eb4d5b97df | 74 | { |
va009039 | 0:39eb4d5b97df | 75 | return _hid->send(report); |
va009039 | 0:39eb4d5b97df | 76 | } |
va009039 | 0:39eb4d5b97df | 77 | |
va009039 |
4:8f6857784854 | 78 | USB_MSD* USBMSD2::getMSD() |
va009039 |
4:8f6857784854 | 79 | { |
va009039 |
4:8f6857784854 | 80 | return _msd; |
va009039 |
4:8f6857784854 | 81 | } |
va009039 |
4:8f6857784854 | 82 | |
va009039 |
4:8f6857784854 | 83 | USB_CDC* USBMSD2::getCDC() |
va009039 |
4:8f6857784854 | 84 | { |
va009039 |
4:8f6857784854 | 85 | return _cdc; |
va009039 |
4:8f6857784854 | 86 | } |
va009039 |
4:8f6857784854 | 87 | |
va009039 |
4:8f6857784854 | 88 | USB_HID* USBMSD2::getHID() |
va009039 |
4:8f6857784854 | 89 | { |
va009039 |
4:8f6857784854 | 90 | return _hid; |
va009039 |
4:8f6857784854 | 91 | } |
va009039 |
4:8f6857784854 | 92 | |
va009039 | 0:39eb4d5b97df | 93 | bool USBMSD2::connect() |
va009039 | 0:39eb4d5b97df | 94 | { |
va009039 | 0:39eb4d5b97df | 95 | if (_msd->connect()) { |
va009039 | 0:39eb4d5b97df | 96 | USBDevice::connect(); |
va009039 | 0:39eb4d5b97df | 97 | return true; |
va009039 | 0:39eb4d5b97df | 98 | } |
va009039 | 0:39eb4d5b97df | 99 | return false; |
va009039 | 0:39eb4d5b97df | 100 | } |
va009039 | 0:39eb4d5b97df | 101 | |
va009039 | 0:39eb4d5b97df | 102 | // Called in ISR context to process a class specific request |
va009039 | 0:39eb4d5b97df | 103 | bool USBMSD2::USBCallback_request(void) { |
va009039 | 0:39eb4d5b97df | 104 | CONTROL_TRANSFER* transfer = getTransferPtr(); |
va009039 | 0:39eb4d5b97df | 105 | if (_msd->Request_callback(transfer)) { |
va009039 | 0:39eb4d5b97df | 106 | return true; |
va009039 | 0:39eb4d5b97df | 107 | } |
va009039 | 0:39eb4d5b97df | 108 | if (_cdc->Request_callback(transfer)) { |
va009039 | 0:39eb4d5b97df | 109 | return true; |
va009039 | 0:39eb4d5b97df | 110 | } |
va009039 | 0:39eb4d5b97df | 111 | // Find the HID descriptor, after the configuration descriptor |
va009039 | 0:39eb4d5b97df | 112 | uint8_t* hidDescriptor = findDescriptor(HID_DESCRIPTOR); |
va009039 | 0:39eb4d5b97df | 113 | if (_hid->Request_callback(transfer, hidDescriptor)) { |
va009039 | 0:39eb4d5b97df | 114 | return true; |
va009039 | 0:39eb4d5b97df | 115 | } |
va009039 | 0:39eb4d5b97df | 116 | return false; |
va009039 | 0:39eb4d5b97df | 117 | } |
va009039 | 0:39eb4d5b97df | 118 | |
va009039 | 0:39eb4d5b97df | 119 | /* virtual */ void USBMSD2::USBCallback_requestCompleted(uint8_t* buf, uint32_t length) |
va009039 | 0:39eb4d5b97df | 120 | { |
va009039 | 0:39eb4d5b97df | 121 | CONTROL_TRANSFER* transfer = getTransferPtr(); |
va009039 | 0:39eb4d5b97df | 122 | if (_cdc->RequestCompleted_callback(transfer, buf, length)) { |
va009039 | 0:39eb4d5b97df | 123 | return; |
va009039 | 0:39eb4d5b97df | 124 | } |
va009039 | 0:39eb4d5b97df | 125 | } |
va009039 | 0:39eb4d5b97df | 126 | |
va009039 | 0:39eb4d5b97df | 127 | // Called in ISR context |
va009039 | 0:39eb4d5b97df | 128 | // Set configuration. Return false if the |
va009039 | 0:39eb4d5b97df | 129 | // configuration is not supported. |
va009039 | 0:39eb4d5b97df | 130 | bool USBMSD2::USBCallback_setConfiguration(uint8_t configuration) { |
va009039 | 0:39eb4d5b97df | 131 | if (configuration != DEFAULT_CONFIGURATION) { |
va009039 | 0:39eb4d5b97df | 132 | return false; |
va009039 | 0:39eb4d5b97df | 133 | } |
va009039 | 0:39eb4d5b97df | 134 | |
va009039 | 0:39eb4d5b97df | 135 | // Configure endpoints > 0 |
va009039 | 0:39eb4d5b97df | 136 | addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 137 | addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 138 | |
va009039 | 0:39eb4d5b97df | 139 | addEndpoint(CDC_EPINT_IN, MAX_PACKET_SIZE_EPINT); |
va009039 | 0:39eb4d5b97df | 140 | addEndpoint(CDC_EPBULK_IN, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 141 | addEndpoint(CDC_EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 142 | addEndpoint(HID_EPINT_IN, MAX_PACKET_SIZE_EPINT); |
va009039 | 0:39eb4d5b97df | 143 | addEndpoint(HID_EPINT_OUT, MAX_PACKET_SIZE_EPINT); |
va009039 | 0:39eb4d5b97df | 144 | |
va009039 | 0:39eb4d5b97df | 145 | //activate readings |
va009039 | 0:39eb4d5b97df | 146 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 147 | readStart(CDC_EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
va009039 | 0:39eb4d5b97df | 148 | readStart(HID_EPINT_OUT, MAX_PACKET_SIZE_EPINT); |
va009039 | 0:39eb4d5b97df | 149 | |
va009039 | 0:39eb4d5b97df | 150 | return true; |
va009039 | 0:39eb4d5b97df | 151 | } |
va009039 | 0:39eb4d5b97df | 152 | |
va009039 | 0:39eb4d5b97df | 153 | /* virtual */ bool USBMSD2::EP2_OUT_callback() |
va009039 | 0:39eb4d5b97df | 154 | { |
va009039 | 0:39eb4d5b97df | 155 | return _msd->EPBULK_OUT_callback(); |
va009039 | 0:39eb4d5b97df | 156 | } |
va009039 | 0:39eb4d5b97df | 157 | |
va009039 | 0:39eb4d5b97df | 158 | /* virtual */ bool USBMSD2::EP2_IN_callback() { |
va009039 | 0:39eb4d5b97df | 159 | return _msd->EPBULK_IN_callback(); |
va009039 | 0:39eb4d5b97df | 160 | } |
va009039 | 0:39eb4d5b97df | 161 | |
va009039 | 0:39eb4d5b97df | 162 | /* virtual */ bool USBMSD2::EP3_OUT_callback() |
va009039 | 0:39eb4d5b97df | 163 | { |
va009039 | 0:39eb4d5b97df | 164 | return _cdc->EPBULK_OUT_callback(); |
va009039 | 0:39eb4d5b97df | 165 | } |
va009039 | 0:39eb4d5b97df | 166 | |
va009039 | 0:39eb4d5b97df | 167 | /* virtual */ bool USBMSD2::EP5_OUT_callback() |
va009039 | 0:39eb4d5b97df | 168 | { |
va009039 | 0:39eb4d5b97df | 169 | return _cdc->EPBULK_OUT_callback(); |
va009039 | 0:39eb4d5b97df | 170 | } |
va009039 | 0:39eb4d5b97df | 171 | |
va009039 | 0:39eb4d5b97df | 172 | uint8_t * USBMSD2::deviceDesc() { |
va009039 | 0:39eb4d5b97df | 173 | static uint8_t deviceDescriptor[] = { |
va009039 | 0:39eb4d5b97df | 174 | 18, // bLength |
va009039 | 0:39eb4d5b97df | 175 | 1, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 176 | 0x10, 0x01, // bcdUSB |
va009039 | 0:39eb4d5b97df | 177 | 2, // bDeviceClass |
va009039 | 0:39eb4d5b97df | 178 | 0, // bDeviceSubClass |
va009039 | 0:39eb4d5b97df | 179 | 0, // bDeviceProtocol |
va009039 | 0:39eb4d5b97df | 180 | MAX_PACKET_SIZE_EP0, // bMaxPacketSize0 |
va009039 | 0:39eb4d5b97df | 181 | (uint8_t)(LSB(VENDOR_ID)), (uint8_t)(MSB(VENDOR_ID)), // idVendor |
va009039 | 0:39eb4d5b97df | 182 | (uint8_t)(LSB(PRODUCT_ID)), (uint8_t)(MSB(PRODUCT_ID)),// idProduct |
va009039 | 0:39eb4d5b97df | 183 | 0x00, 0x01, // bcdDevice |
va009039 | 0:39eb4d5b97df | 184 | 1, // iManufacturer |
va009039 | 0:39eb4d5b97df | 185 | 2, // iProduct |
va009039 | 0:39eb4d5b97df | 186 | 3, // iSerialNumber |
va009039 | 0:39eb4d5b97df | 187 | 1 // bNumConfigurations |
va009039 | 0:39eb4d5b97df | 188 | }; |
va009039 | 0:39eb4d5b97df | 189 | return deviceDescriptor; |
va009039 | 0:39eb4d5b97df | 190 | } |
va009039 | 0:39eb4d5b97df | 191 | |
va009039 | 0:39eb4d5b97df | 192 | uint8_t * USBMSD2::stringIinterfaceDesc() { |
va009039 | 0:39eb4d5b97df | 193 | static uint8_t stringIinterfaceDescriptor[] = { |
va009039 | 0:39eb4d5b97df | 194 | 0x08, //bLength |
va009039 | 0:39eb4d5b97df | 195 | STRING_DESCRIPTOR, //bDescriptorType 0x03 |
va009039 | 0:39eb4d5b97df | 196 | 'H',0,'I',0,'D',0, //bString iInterface - HID |
va009039 | 0:39eb4d5b97df | 197 | }; |
va009039 | 0:39eb4d5b97df | 198 | return stringIinterfaceDescriptor; |
va009039 | 0:39eb4d5b97df | 199 | } |
va009039 | 0:39eb4d5b97df | 200 | |
va009039 | 0:39eb4d5b97df | 201 | uint8_t * USBMSD2::stringIproductDesc() { |
va009039 | 0:39eb4d5b97df | 202 | static uint8_t stringIproductDescriptor[] = { |
va009039 | 0:39eb4d5b97df | 203 | 32, //bLength |
va009039 | 0:39eb4d5b97df | 204 | STRING_DESCRIPTOR, //bDescriptorType 0x03 |
va009039 | 0:39eb4d5b97df | 205 | 'K',0,'L',0,'2',0,'5',0,'Z',0,' ',0,'C',0,'M',0,'S',0,'I',0,'S',0,'-',0,'D',0,'A',0,'P',0 // KL25Z CMSIS-DAP |
va009039 | 0:39eb4d5b97df | 206 | }; |
va009039 | 0:39eb4d5b97df | 207 | return stringIproductDescriptor; |
va009039 | 0:39eb4d5b97df | 208 | } |
va009039 | 0:39eb4d5b97df | 209 | |
va009039 | 0:39eb4d5b97df | 210 | uint8_t * USBMSD2::configurationDesc() { |
va009039 | 0:39eb4d5b97df | 211 | static uint8_t configDescriptor[] = { |
va009039 | 0:39eb4d5b97df | 212 | // Configuration 1 |
va009039 | 0:39eb4d5b97df | 213 | 9, // bLength |
va009039 | 0:39eb4d5b97df | 214 | 2, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 215 | LSB(122), // wTotalLength |
va009039 | 0:39eb4d5b97df | 216 | MSB(122), |
va009039 | 0:39eb4d5b97df | 217 | 4, // bNumInterfaces |
va009039 | 0:39eb4d5b97df | 218 | 1, // bConfigurationValue: 0x01 is used to select this configuration |
va009039 | 0:39eb4d5b97df | 219 | 0x00, // iConfiguration: no string to describe this configuration |
va009039 | 0:39eb4d5b97df | 220 | 0x80, // bmAttributes |
va009039 | 0:39eb4d5b97df | 221 | 250, // bMaxPower, device power consumption is 100 mA |
va009039 | 0:39eb4d5b97df | 222 | |
va009039 | 0:39eb4d5b97df | 223 | // Interface 0, Alternate Setting 0, MSC Class |
va009039 | 0:39eb4d5b97df | 224 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 225 | INTERFACE_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 226 | 0, // bInterfaceNumber |
va009039 | 0:39eb4d5b97df | 227 | 0, // bAlternateSetting |
va009039 | 0:39eb4d5b97df | 228 | 2, // bNumEndpoints |
va009039 | 0:39eb4d5b97df | 229 | 0x08, // bInterfaceClass |
va009039 | 0:39eb4d5b97df | 230 | 0x06, // bInterfaceSubClass |
va009039 | 0:39eb4d5b97df | 231 | 0x50, // bInterfaceProtocol |
va009039 | 0:39eb4d5b97df | 232 | 0x04, // iInterface |
va009039 | 0:39eb4d5b97df | 233 | |
va009039 | 0:39eb4d5b97df | 234 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
va009039 | 0:39eb4d5b97df | 235 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 236 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 237 | PHY_TO_DESC(EPBULK_IN), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 238 | E_BULK, // bmAttributes (0x02=bulk) |
va009039 | 0:39eb4d5b97df | 239 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 240 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 241 | 0, // bInterval |
va009039 | 0:39eb4d5b97df | 242 | |
va009039 | 0:39eb4d5b97df | 243 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
va009039 | 0:39eb4d5b97df | 244 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 245 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 246 | PHY_TO_DESC(EPBULK_OUT), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 247 | E_BULK, // bmAttributes (0x02=bulk) |
va009039 | 0:39eb4d5b97df | 248 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 249 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 250 | 0, // bInterval |
va009039 | 0:39eb4d5b97df | 251 | |
va009039 | 0:39eb4d5b97df | 252 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 |
va009039 | 0:39eb4d5b97df | 253 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 254 | INTERFACE_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 255 | 1, // bInterfaceNumber |
va009039 | 0:39eb4d5b97df | 256 | 0, // bAlternateSetting |
va009039 | 0:39eb4d5b97df | 257 | 1, // bNumEndpoints |
va009039 | 0:39eb4d5b97df | 258 | 0x02, // bInterfaceClass |
va009039 | 0:39eb4d5b97df | 259 | 0x02, // bInterfaceSubClass |
va009039 | 0:39eb4d5b97df | 260 | 0x01, // bInterfaceProtocol |
va009039 | 0:39eb4d5b97df | 261 | 0, // iInterface |
va009039 | 0:39eb4d5b97df | 262 | |
va009039 | 0:39eb4d5b97df | 263 | // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26 |
va009039 | 0:39eb4d5b97df | 264 | 5, // bFunctionLength |
va009039 | 0:39eb4d5b97df | 265 | 0x24, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 266 | 0x00, // bDescriptorSubtype |
va009039 | 0:39eb4d5b97df | 267 | 0x10, 0x01, // bcdCDC |
va009039 | 0:39eb4d5b97df | 268 | |
va009039 | 0:39eb4d5b97df | 269 | // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27 |
va009039 | 0:39eb4d5b97df | 270 | 5, // bFunctionLength |
va009039 | 0:39eb4d5b97df | 271 | 0x24, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 272 | 0x01, // bDescriptorSubtype |
va009039 | 0:39eb4d5b97df | 273 | 0x03, // bmCapabilities |
va009039 | 0:39eb4d5b97df | 274 | 2, // bDataInterface |
va009039 | 0:39eb4d5b97df | 275 | |
va009039 | 0:39eb4d5b97df | 276 | // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28 |
va009039 | 0:39eb4d5b97df | 277 | 4, // bFunctionLength |
va009039 | 0:39eb4d5b97df | 278 | 0x24, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 279 | 0x02, // bDescriptorSubtype |
va009039 | 0:39eb4d5b97df | 280 | 0x06, // bmCapabilities |
va009039 | 0:39eb4d5b97df | 281 | |
va009039 | 0:39eb4d5b97df | 282 | // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33 |
va009039 | 0:39eb4d5b97df | 283 | 5, // bFunctionLength |
va009039 | 0:39eb4d5b97df | 284 | 0x24, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 285 | 0x06, // bDescriptorSubtype |
va009039 | 0:39eb4d5b97df | 286 | 1, // bMasterInterface |
va009039 | 0:39eb4d5b97df | 287 | 2, // bSlaveInterface0 |
va009039 | 0:39eb4d5b97df | 288 | |
va009039 | 0:39eb4d5b97df | 289 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
va009039 | 0:39eb4d5b97df | 290 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 291 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 292 | PHY_TO_DESC(CDC_EPINT_IN), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 293 | E_INTERRUPT, // bmAttributes (0x03=intr) |
va009039 | 0:39eb4d5b97df | 294 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 295 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 296 | 2, // bInterval |
va009039 | 0:39eb4d5b97df | 297 | |
va009039 | 0:39eb4d5b97df | 298 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 |
va009039 | 0:39eb4d5b97df | 299 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 300 | INTERFACE_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 301 | 2, // bInterfaceNumber |
va009039 | 0:39eb4d5b97df | 302 | 0, // bAlternateSetting |
va009039 | 0:39eb4d5b97df | 303 | 2, // bNumEndpoints |
va009039 | 0:39eb4d5b97df | 304 | 0x0A, // bInterfaceClass |
va009039 | 0:39eb4d5b97df | 305 | 0x00, // bInterfaceSubClass |
va009039 | 0:39eb4d5b97df | 306 | 0x00, // bInterfaceProtocol |
va009039 | 0:39eb4d5b97df | 307 | 0, // iInterface |
va009039 | 0:39eb4d5b97df | 308 | |
va009039 | 0:39eb4d5b97df | 309 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
va009039 | 0:39eb4d5b97df | 310 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 311 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 312 | PHY_TO_DESC(CDC_EPBULK_IN), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 313 | E_BULK, // bmAttributes (0x02=bulk) |
va009039 | 0:39eb4d5b97df | 314 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 315 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 316 | 0, // bInterval |
va009039 | 0:39eb4d5b97df | 317 | |
va009039 | 0:39eb4d5b97df | 318 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
va009039 | 0:39eb4d5b97df | 319 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 320 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 321 | PHY_TO_DESC(CDC_EPBULK_OUT),// bEndpointAddress |
va009039 | 0:39eb4d5b97df | 322 | E_BULK, // bmAttributes (0x02=bulk) |
va009039 | 0:39eb4d5b97df | 323 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 324 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 325 | 0, // bInterval |
va009039 | 0:39eb4d5b97df | 326 | |
va009039 | 0:39eb4d5b97df | 327 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 328 | INTERFACE_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 329 | 3, // bInterfaceNumber |
va009039 | 0:39eb4d5b97df | 330 | 0, // bAlternateSetting |
va009039 | 0:39eb4d5b97df | 331 | 2, // bNumEndpoints |
va009039 | 0:39eb4d5b97df | 332 | HID_CLASS, // bInterfaceClass |
va009039 | 0:39eb4d5b97df | 333 | HID_SUBCLASS_NONE, // bInterfaceSubClass |
va009039 | 0:39eb4d5b97df | 334 | HID_PROTOCOL_NONE, // bInterfaceProtocol |
va009039 | 0:39eb4d5b97df | 335 | 0, // iInterface |
va009039 | 0:39eb4d5b97df | 336 | |
va009039 | 0:39eb4d5b97df | 337 | HID_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 338 | HID_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 339 | LSB(HID_VERSION_1_11), // bcdHID (LSB) |
va009039 | 0:39eb4d5b97df | 340 | MSB(HID_VERSION_1_11), // bcdHID (MSB) |
va009039 | 0:39eb4d5b97df | 341 | 0x00, // bCountryCode |
va009039 | 0:39eb4d5b97df | 342 | 1, // bNumDescriptors |
va009039 | 0:39eb4d5b97df | 343 | REPORT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 344 | LSB(_hid->reportDescLength()), // wDescriptorLength (LSB) |
va009039 | 0:39eb4d5b97df | 345 | MSB(_hid->reportDescLength()), // wDescriptorLength (MSB) |
va009039 | 0:39eb4d5b97df | 346 | |
va009039 | 0:39eb4d5b97df | 347 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 348 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 349 | PHY_TO_DESC(HID_EPINT_IN), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 350 | E_INTERRUPT, // bmAttributes |
va009039 | 0:39eb4d5b97df | 351 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 352 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 353 | 1, // bInterval (milliseconds) |
va009039 | 0:39eb4d5b97df | 354 | |
va009039 | 0:39eb4d5b97df | 355 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
va009039 | 0:39eb4d5b97df | 356 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
va009039 | 0:39eb4d5b97df | 357 | PHY_TO_DESC(HID_EPINT_OUT), // bEndpointAddress |
va009039 | 0:39eb4d5b97df | 358 | E_INTERRUPT, // bmAttributes |
va009039 | 0:39eb4d5b97df | 359 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
va009039 | 0:39eb4d5b97df | 360 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
va009039 | 0:39eb4d5b97df | 361 | 1, // bInterval (milliseconds) |
va009039 | 0:39eb4d5b97df | 362 | }; |
va009039 | 0:39eb4d5b97df | 363 | return configDescriptor; |
va009039 | 0:39eb4d5b97df | 364 | } |