Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: 11u35_usbLocalFilesystem
Fork of USBLocalFileSystem by
USBMSD2/USBMSD2.cpp@0:39eb4d5b97df, 2014-05-03 (annotated)
- Committer:
- va009039
- Date:
- Sat May 03 11:21:37 2014 +0000
- Revision:
- 0:39eb4d5b97df
- Child:
- 4:8f6857784854
first commit
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 | 0:39eb4d5b97df | 78 | bool USBMSD2::connect() |
| va009039 | 0:39eb4d5b97df | 79 | { |
| va009039 | 0:39eb4d5b97df | 80 | if (_msd->connect()) { |
| va009039 | 0:39eb4d5b97df | 81 | USBDevice::connect(); |
| va009039 | 0:39eb4d5b97df | 82 | return true; |
| va009039 | 0:39eb4d5b97df | 83 | } |
| va009039 | 0:39eb4d5b97df | 84 | return false; |
| va009039 | 0:39eb4d5b97df | 85 | } |
| va009039 | 0:39eb4d5b97df | 86 | |
| va009039 | 0:39eb4d5b97df | 87 | // Called in ISR context to process a class specific request |
| va009039 | 0:39eb4d5b97df | 88 | bool USBMSD2::USBCallback_request(void) { |
| va009039 | 0:39eb4d5b97df | 89 | CONTROL_TRANSFER* transfer = getTransferPtr(); |
| va009039 | 0:39eb4d5b97df | 90 | if (_msd->Request_callback(transfer)) { |
| va009039 | 0:39eb4d5b97df | 91 | return true; |
| va009039 | 0:39eb4d5b97df | 92 | } |
| va009039 | 0:39eb4d5b97df | 93 | if (_cdc->Request_callback(transfer)) { |
| va009039 | 0:39eb4d5b97df | 94 | return true; |
| va009039 | 0:39eb4d5b97df | 95 | } |
| va009039 | 0:39eb4d5b97df | 96 | // Find the HID descriptor, after the configuration descriptor |
| va009039 | 0:39eb4d5b97df | 97 | uint8_t* hidDescriptor = findDescriptor(HID_DESCRIPTOR); |
| va009039 | 0:39eb4d5b97df | 98 | if (_hid->Request_callback(transfer, hidDescriptor)) { |
| va009039 | 0:39eb4d5b97df | 99 | return true; |
| va009039 | 0:39eb4d5b97df | 100 | } |
| va009039 | 0:39eb4d5b97df | 101 | return false; |
| va009039 | 0:39eb4d5b97df | 102 | } |
| va009039 | 0:39eb4d5b97df | 103 | |
| va009039 | 0:39eb4d5b97df | 104 | /* virtual */ void USBMSD2::USBCallback_requestCompleted(uint8_t* buf, uint32_t length) |
| va009039 | 0:39eb4d5b97df | 105 | { |
| va009039 | 0:39eb4d5b97df | 106 | CONTROL_TRANSFER* transfer = getTransferPtr(); |
| va009039 | 0:39eb4d5b97df | 107 | if (_cdc->RequestCompleted_callback(transfer, buf, length)) { |
| va009039 | 0:39eb4d5b97df | 108 | return; |
| va009039 | 0:39eb4d5b97df | 109 | } |
| va009039 | 0:39eb4d5b97df | 110 | } |
| va009039 | 0:39eb4d5b97df | 111 | |
| va009039 | 0:39eb4d5b97df | 112 | // Called in ISR context |
| va009039 | 0:39eb4d5b97df | 113 | // Set configuration. Return false if the |
| va009039 | 0:39eb4d5b97df | 114 | // configuration is not supported. |
| va009039 | 0:39eb4d5b97df | 115 | bool USBMSD2::USBCallback_setConfiguration(uint8_t configuration) { |
| va009039 | 0:39eb4d5b97df | 116 | if (configuration != DEFAULT_CONFIGURATION) { |
| va009039 | 0:39eb4d5b97df | 117 | return false; |
| va009039 | 0:39eb4d5b97df | 118 | } |
| va009039 | 0:39eb4d5b97df | 119 | |
| va009039 | 0:39eb4d5b97df | 120 | // Configure endpoints > 0 |
| va009039 | 0:39eb4d5b97df | 121 | addEndpoint(EPBULK_IN, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 122 | addEndpoint(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 123 | |
| va009039 | 0:39eb4d5b97df | 124 | addEndpoint(CDC_EPINT_IN, MAX_PACKET_SIZE_EPINT); |
| va009039 | 0:39eb4d5b97df | 125 | addEndpoint(CDC_EPBULK_IN, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 126 | addEndpoint(CDC_EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 127 | addEndpoint(HID_EPINT_IN, MAX_PACKET_SIZE_EPINT); |
| va009039 | 0:39eb4d5b97df | 128 | addEndpoint(HID_EPINT_OUT, MAX_PACKET_SIZE_EPINT); |
| va009039 | 0:39eb4d5b97df | 129 | |
| va009039 | 0:39eb4d5b97df | 130 | //activate readings |
| va009039 | 0:39eb4d5b97df | 131 | readStart(EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 132 | readStart(CDC_EPBULK_OUT, MAX_PACKET_SIZE_EPBULK); |
| va009039 | 0:39eb4d5b97df | 133 | readStart(HID_EPINT_OUT, MAX_PACKET_SIZE_EPINT); |
| va009039 | 0:39eb4d5b97df | 134 | |
| va009039 | 0:39eb4d5b97df | 135 | return true; |
| va009039 | 0:39eb4d5b97df | 136 | } |
| va009039 | 0:39eb4d5b97df | 137 | |
| va009039 | 0:39eb4d5b97df | 138 | /* virtual */ bool USBMSD2::EP2_OUT_callback() |
| va009039 | 0:39eb4d5b97df | 139 | { |
| va009039 | 0:39eb4d5b97df | 140 | return _msd->EPBULK_OUT_callback(); |
| va009039 | 0:39eb4d5b97df | 141 | } |
| va009039 | 0:39eb4d5b97df | 142 | |
| va009039 | 0:39eb4d5b97df | 143 | /* virtual */ bool USBMSD2::EP2_IN_callback() { |
| va009039 | 0:39eb4d5b97df | 144 | return _msd->EPBULK_IN_callback(); |
| va009039 | 0:39eb4d5b97df | 145 | } |
| va009039 | 0:39eb4d5b97df | 146 | |
| va009039 | 0:39eb4d5b97df | 147 | /* virtual */ bool USBMSD2::EP3_OUT_callback() |
| va009039 | 0:39eb4d5b97df | 148 | { |
| va009039 | 0:39eb4d5b97df | 149 | return _cdc->EPBULK_OUT_callback(); |
| va009039 | 0:39eb4d5b97df | 150 | } |
| va009039 | 0:39eb4d5b97df | 151 | |
| va009039 | 0:39eb4d5b97df | 152 | /* virtual */ bool USBMSD2::EP5_OUT_callback() |
| va009039 | 0:39eb4d5b97df | 153 | { |
| va009039 | 0:39eb4d5b97df | 154 | return _cdc->EPBULK_OUT_callback(); |
| va009039 | 0:39eb4d5b97df | 155 | } |
| va009039 | 0:39eb4d5b97df | 156 | |
| va009039 | 0:39eb4d5b97df | 157 | uint8_t * USBMSD2::deviceDesc() { |
| va009039 | 0:39eb4d5b97df | 158 | static uint8_t deviceDescriptor[] = { |
| va009039 | 0:39eb4d5b97df | 159 | 18, // bLength |
| va009039 | 0:39eb4d5b97df | 160 | 1, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 161 | 0x10, 0x01, // bcdUSB |
| va009039 | 0:39eb4d5b97df | 162 | 2, // bDeviceClass |
| va009039 | 0:39eb4d5b97df | 163 | 0, // bDeviceSubClass |
| va009039 | 0:39eb4d5b97df | 164 | 0, // bDeviceProtocol |
| va009039 | 0:39eb4d5b97df | 165 | MAX_PACKET_SIZE_EP0, // bMaxPacketSize0 |
| va009039 | 0:39eb4d5b97df | 166 | (uint8_t)(LSB(VENDOR_ID)), (uint8_t)(MSB(VENDOR_ID)), // idVendor |
| va009039 | 0:39eb4d5b97df | 167 | (uint8_t)(LSB(PRODUCT_ID)), (uint8_t)(MSB(PRODUCT_ID)),// idProduct |
| va009039 | 0:39eb4d5b97df | 168 | 0x00, 0x01, // bcdDevice |
| va009039 | 0:39eb4d5b97df | 169 | 1, // iManufacturer |
| va009039 | 0:39eb4d5b97df | 170 | 2, // iProduct |
| va009039 | 0:39eb4d5b97df | 171 | 3, // iSerialNumber |
| va009039 | 0:39eb4d5b97df | 172 | 1 // bNumConfigurations |
| va009039 | 0:39eb4d5b97df | 173 | }; |
| va009039 | 0:39eb4d5b97df | 174 | return deviceDescriptor; |
| va009039 | 0:39eb4d5b97df | 175 | } |
| va009039 | 0:39eb4d5b97df | 176 | |
| va009039 | 0:39eb4d5b97df | 177 | uint8_t * USBMSD2::stringIinterfaceDesc() { |
| va009039 | 0:39eb4d5b97df | 178 | static uint8_t stringIinterfaceDescriptor[] = { |
| va009039 | 0:39eb4d5b97df | 179 | 0x08, //bLength |
| va009039 | 0:39eb4d5b97df | 180 | STRING_DESCRIPTOR, //bDescriptorType 0x03 |
| va009039 | 0:39eb4d5b97df | 181 | 'H',0,'I',0,'D',0, //bString iInterface - HID |
| va009039 | 0:39eb4d5b97df | 182 | }; |
| va009039 | 0:39eb4d5b97df | 183 | return stringIinterfaceDescriptor; |
| va009039 | 0:39eb4d5b97df | 184 | } |
| va009039 | 0:39eb4d5b97df | 185 | |
| va009039 | 0:39eb4d5b97df | 186 | uint8_t * USBMSD2::stringIproductDesc() { |
| va009039 | 0:39eb4d5b97df | 187 | static uint8_t stringIproductDescriptor[] = { |
| va009039 | 0:39eb4d5b97df | 188 | 32, //bLength |
| va009039 | 0:39eb4d5b97df | 189 | STRING_DESCRIPTOR, //bDescriptorType 0x03 |
| va009039 | 0:39eb4d5b97df | 190 | '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 | 191 | }; |
| va009039 | 0:39eb4d5b97df | 192 | return stringIproductDescriptor; |
| va009039 | 0:39eb4d5b97df | 193 | } |
| va009039 | 0:39eb4d5b97df | 194 | |
| va009039 | 0:39eb4d5b97df | 195 | uint8_t * USBMSD2::configurationDesc() { |
| va009039 | 0:39eb4d5b97df | 196 | static uint8_t configDescriptor[] = { |
| va009039 | 0:39eb4d5b97df | 197 | // Configuration 1 |
| va009039 | 0:39eb4d5b97df | 198 | 9, // bLength |
| va009039 | 0:39eb4d5b97df | 199 | 2, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 200 | LSB(122), // wTotalLength |
| va009039 | 0:39eb4d5b97df | 201 | MSB(122), |
| va009039 | 0:39eb4d5b97df | 202 | 4, // bNumInterfaces |
| va009039 | 0:39eb4d5b97df | 203 | 1, // bConfigurationValue: 0x01 is used to select this configuration |
| va009039 | 0:39eb4d5b97df | 204 | 0x00, // iConfiguration: no string to describe this configuration |
| va009039 | 0:39eb4d5b97df | 205 | 0x80, // bmAttributes |
| va009039 | 0:39eb4d5b97df | 206 | 250, // bMaxPower, device power consumption is 100 mA |
| va009039 | 0:39eb4d5b97df | 207 | |
| va009039 | 0:39eb4d5b97df | 208 | // Interface 0, Alternate Setting 0, MSC Class |
| va009039 | 0:39eb4d5b97df | 209 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 210 | INTERFACE_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 211 | 0, // bInterfaceNumber |
| va009039 | 0:39eb4d5b97df | 212 | 0, // bAlternateSetting |
| va009039 | 0:39eb4d5b97df | 213 | 2, // bNumEndpoints |
| va009039 | 0:39eb4d5b97df | 214 | 0x08, // bInterfaceClass |
| va009039 | 0:39eb4d5b97df | 215 | 0x06, // bInterfaceSubClass |
| va009039 | 0:39eb4d5b97df | 216 | 0x50, // bInterfaceProtocol |
| va009039 | 0:39eb4d5b97df | 217 | 0x04, // iInterface |
| va009039 | 0:39eb4d5b97df | 218 | |
| va009039 | 0:39eb4d5b97df | 219 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
| va009039 | 0:39eb4d5b97df | 220 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 221 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 222 | PHY_TO_DESC(EPBULK_IN), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 223 | E_BULK, // bmAttributes (0x02=bulk) |
| va009039 | 0:39eb4d5b97df | 224 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 225 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 226 | 0, // bInterval |
| va009039 | 0:39eb4d5b97df | 227 | |
| va009039 | 0:39eb4d5b97df | 228 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
| va009039 | 0:39eb4d5b97df | 229 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 230 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 231 | PHY_TO_DESC(EPBULK_OUT), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 232 | E_BULK, // bmAttributes (0x02=bulk) |
| va009039 | 0:39eb4d5b97df | 233 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 234 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 235 | 0, // bInterval |
| va009039 | 0:39eb4d5b97df | 236 | |
| va009039 | 0:39eb4d5b97df | 237 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 |
| va009039 | 0:39eb4d5b97df | 238 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 239 | INTERFACE_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 240 | 1, // bInterfaceNumber |
| va009039 | 0:39eb4d5b97df | 241 | 0, // bAlternateSetting |
| va009039 | 0:39eb4d5b97df | 242 | 1, // bNumEndpoints |
| va009039 | 0:39eb4d5b97df | 243 | 0x02, // bInterfaceClass |
| va009039 | 0:39eb4d5b97df | 244 | 0x02, // bInterfaceSubClass |
| va009039 | 0:39eb4d5b97df | 245 | 0x01, // bInterfaceProtocol |
| va009039 | 0:39eb4d5b97df | 246 | 0, // iInterface |
| va009039 | 0:39eb4d5b97df | 247 | |
| va009039 | 0:39eb4d5b97df | 248 | // CDC Header Functional Descriptor, CDC Spec 5.2.3.1, Table 26 |
| va009039 | 0:39eb4d5b97df | 249 | 5, // bFunctionLength |
| va009039 | 0:39eb4d5b97df | 250 | 0x24, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 251 | 0x00, // bDescriptorSubtype |
| va009039 | 0:39eb4d5b97df | 252 | 0x10, 0x01, // bcdCDC |
| va009039 | 0:39eb4d5b97df | 253 | |
| va009039 | 0:39eb4d5b97df | 254 | // Call Management Functional Descriptor, CDC Spec 5.2.3.2, Table 27 |
| va009039 | 0:39eb4d5b97df | 255 | 5, // bFunctionLength |
| va009039 | 0:39eb4d5b97df | 256 | 0x24, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 257 | 0x01, // bDescriptorSubtype |
| va009039 | 0:39eb4d5b97df | 258 | 0x03, // bmCapabilities |
| va009039 | 0:39eb4d5b97df | 259 | 2, // bDataInterface |
| va009039 | 0:39eb4d5b97df | 260 | |
| va009039 | 0:39eb4d5b97df | 261 | // Abstract Control Management Functional Descriptor, CDC Spec 5.2.3.3, Table 28 |
| va009039 | 0:39eb4d5b97df | 262 | 4, // bFunctionLength |
| va009039 | 0:39eb4d5b97df | 263 | 0x24, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 264 | 0x02, // bDescriptorSubtype |
| va009039 | 0:39eb4d5b97df | 265 | 0x06, // bmCapabilities |
| va009039 | 0:39eb4d5b97df | 266 | |
| va009039 | 0:39eb4d5b97df | 267 | // Union Functional Descriptor, CDC Spec 5.2.3.8, Table 33 |
| va009039 | 0:39eb4d5b97df | 268 | 5, // bFunctionLength |
| va009039 | 0:39eb4d5b97df | 269 | 0x24, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 270 | 0x06, // bDescriptorSubtype |
| va009039 | 0:39eb4d5b97df | 271 | 1, // bMasterInterface |
| va009039 | 0:39eb4d5b97df | 272 | 2, // bSlaveInterface0 |
| va009039 | 0:39eb4d5b97df | 273 | |
| va009039 | 0:39eb4d5b97df | 274 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
| va009039 | 0:39eb4d5b97df | 275 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 276 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 277 | PHY_TO_DESC(CDC_EPINT_IN), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 278 | E_INTERRUPT, // bmAttributes (0x03=intr) |
| va009039 | 0:39eb4d5b97df | 279 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 280 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 281 | 2, // bInterval |
| va009039 | 0:39eb4d5b97df | 282 | |
| va009039 | 0:39eb4d5b97df | 283 | // interface descriptor, USB spec 9.6.5, page 267-269, Table 9-12 |
| va009039 | 0:39eb4d5b97df | 284 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 285 | INTERFACE_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 286 | 2, // bInterfaceNumber |
| va009039 | 0:39eb4d5b97df | 287 | 0, // bAlternateSetting |
| va009039 | 0:39eb4d5b97df | 288 | 2, // bNumEndpoints |
| va009039 | 0:39eb4d5b97df | 289 | 0x0A, // bInterfaceClass |
| va009039 | 0:39eb4d5b97df | 290 | 0x00, // bInterfaceSubClass |
| va009039 | 0:39eb4d5b97df | 291 | 0x00, // bInterfaceProtocol |
| va009039 | 0:39eb4d5b97df | 292 | 0, // iInterface |
| va009039 | 0:39eb4d5b97df | 293 | |
| va009039 | 0:39eb4d5b97df | 294 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
| va009039 | 0:39eb4d5b97df | 295 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 296 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 297 | PHY_TO_DESC(CDC_EPBULK_IN), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 298 | E_BULK, // bmAttributes (0x02=bulk) |
| va009039 | 0:39eb4d5b97df | 299 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 300 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 301 | 0, // bInterval |
| va009039 | 0:39eb4d5b97df | 302 | |
| va009039 | 0:39eb4d5b97df | 303 | // endpoint descriptor, USB spec 9.6.6, page 269-271, Table 9-13 |
| va009039 | 0:39eb4d5b97df | 304 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 305 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 306 | PHY_TO_DESC(CDC_EPBULK_OUT),// bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 307 | E_BULK, // bmAttributes (0x02=bulk) |
| va009039 | 0:39eb4d5b97df | 308 | LSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 309 | MSB(MAX_PACKET_SIZE_EPBULK),// wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 310 | 0, // bInterval |
| va009039 | 0:39eb4d5b97df | 311 | |
| va009039 | 0:39eb4d5b97df | 312 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 313 | INTERFACE_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 314 | 3, // bInterfaceNumber |
| va009039 | 0:39eb4d5b97df | 315 | 0, // bAlternateSetting |
| va009039 | 0:39eb4d5b97df | 316 | 2, // bNumEndpoints |
| va009039 | 0:39eb4d5b97df | 317 | HID_CLASS, // bInterfaceClass |
| va009039 | 0:39eb4d5b97df | 318 | HID_SUBCLASS_NONE, // bInterfaceSubClass |
| va009039 | 0:39eb4d5b97df | 319 | HID_PROTOCOL_NONE, // bInterfaceProtocol |
| va009039 | 0:39eb4d5b97df | 320 | 0, // iInterface |
| va009039 | 0:39eb4d5b97df | 321 | |
| va009039 | 0:39eb4d5b97df | 322 | HID_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 323 | HID_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 324 | LSB(HID_VERSION_1_11), // bcdHID (LSB) |
| va009039 | 0:39eb4d5b97df | 325 | MSB(HID_VERSION_1_11), // bcdHID (MSB) |
| va009039 | 0:39eb4d5b97df | 326 | 0x00, // bCountryCode |
| va009039 | 0:39eb4d5b97df | 327 | 1, // bNumDescriptors |
| va009039 | 0:39eb4d5b97df | 328 | REPORT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 329 | LSB(_hid->reportDescLength()), // wDescriptorLength (LSB) |
| va009039 | 0:39eb4d5b97df | 330 | MSB(_hid->reportDescLength()), // wDescriptorLength (MSB) |
| va009039 | 0:39eb4d5b97df | 331 | |
| va009039 | 0:39eb4d5b97df | 332 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 333 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 334 | PHY_TO_DESC(HID_EPINT_IN), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 335 | E_INTERRUPT, // bmAttributes |
| va009039 | 0:39eb4d5b97df | 336 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 337 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 338 | 1, // bInterval (milliseconds) |
| va009039 | 0:39eb4d5b97df | 339 | |
| va009039 | 0:39eb4d5b97df | 340 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
| va009039 | 0:39eb4d5b97df | 341 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
| va009039 | 0:39eb4d5b97df | 342 | PHY_TO_DESC(HID_EPINT_OUT), // bEndpointAddress |
| va009039 | 0:39eb4d5b97df | 343 | E_INTERRUPT, // bmAttributes |
| va009039 | 0:39eb4d5b97df | 344 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
| va009039 | 0:39eb4d5b97df | 345 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
| va009039 | 0:39eb4d5b97df | 346 | 1, // bInterval (milliseconds) |
| va009039 | 0:39eb4d5b97df | 347 | }; |
| va009039 | 0:39eb4d5b97df | 348 | return configDescriptor; |
| va009039 | 0:39eb4d5b97df | 349 | } |
