USB device stack

Dependents:   blinky_max32630fthr FTHR_USB_serial FTHR_OLED HSP_RPC_GUI_3_0_1 ... more

Fork of USBDevice by mbed official

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers USBKeyboard.cpp Source File

USBKeyboard.cpp

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 #include "stdint.h"
00020 
00021 #include "USBKeyboard.h"
00022 
00023 #define REPORT_ID_KEYBOARD 1
00024 #define REPORT_ID_VOLUME   3
00025 
00026 
00027 typedef struct {
00028     unsigned char usage;
00029     unsigned char modifier;
00030 } KEYMAP;
00031 
00032 #ifdef US_KEYBOARD
00033 /* US keyboard (as HID standard) */
00034 #define KEYMAP_SIZE (152)
00035 const KEYMAP keymap[KEYMAP_SIZE] = {
00036     {0, 0},             /* NUL */
00037     {0, 0},             /* SOH */
00038     {0, 0},             /* STX */
00039     {0, 0},             /* ETX */
00040     {0, 0},             /* EOT */
00041     {0, 0},             /* ENQ */
00042     {0, 0},             /* ACK */
00043     {0, 0},             /* BEL */
00044     {0x2a, 0},          /* BS  */  /* Keyboard Delete (Backspace) */
00045     {0x2b, 0},          /* TAB */  /* Keyboard Tab */
00046     {0x28, 0},          /* LF  */  /* Keyboard Return (Enter) */
00047     {0, 0},             /* VT  */
00048     {0, 0},             /* FF  */
00049     {0, 0},             /* CR  */
00050     {0, 0},             /* SO  */
00051     {0, 0},             /* SI  */
00052     {0, 0},             /* DEL */
00053     {0, 0},             /* DC1 */
00054     {0, 0},             /* DC2 */
00055     {0, 0},             /* DC3 */
00056     {0, 0},             /* DC4 */
00057     {0, 0},             /* NAK */
00058     {0, 0},             /* SYN */
00059     {0, 0},             /* ETB */
00060     {0, 0},             /* CAN */
00061     {0, 0},             /* EM  */
00062     {0, 0},             /* SUB */
00063     {0, 0},             /* ESC */
00064     {0, 0},             /* FS  */
00065     {0, 0},             /* GS  */
00066     {0, 0},             /* RS  */
00067     {0, 0},             /* US  */
00068     {0x2c, 0},          /*   */
00069     {0x1e, KEY_SHIFT},      /* ! */
00070     {0x34, KEY_SHIFT},      /* " */
00071     {0x20, KEY_SHIFT},      /* # */
00072     {0x21, KEY_SHIFT},      /* $ */
00073     {0x22, KEY_SHIFT},      /* % */
00074     {0x24, KEY_SHIFT},      /* & */
00075     {0x34, 0},          /* ' */
00076     {0x26, KEY_SHIFT},      /* ( */
00077     {0x27, KEY_SHIFT},      /* ) */
00078     {0x25, KEY_SHIFT},      /* * */
00079     {0x2e, KEY_SHIFT},      /* + */
00080     {0x36, 0},          /* , */
00081     {0x2d, 0},          /* - */
00082     {0x37, 0},          /* . */
00083     {0x38, 0},          /* / */
00084     {0x27, 0},          /* 0 */
00085     {0x1e, 0},          /* 1 */
00086     {0x1f, 0},          /* 2 */
00087     {0x20, 0},          /* 3 */
00088     {0x21, 0},          /* 4 */
00089     {0x22, 0},          /* 5 */
00090     {0x23, 0},          /* 6 */
00091     {0x24, 0},          /* 7 */
00092     {0x25, 0},          /* 8 */
00093     {0x26, 0},          /* 9 */
00094     {0x33, KEY_SHIFT},      /* : */
00095     {0x33, 0},          /* ; */
00096     {0x36, KEY_SHIFT},      /* < */
00097     {0x2e, 0},          /* = */
00098     {0x37, KEY_SHIFT},      /* > */
00099     {0x38, KEY_SHIFT},      /* ? */
00100     {0x1f, KEY_SHIFT},      /* @ */
00101     {0x04, KEY_SHIFT},      /* A */
00102     {0x05, KEY_SHIFT},      /* B */
00103     {0x06, KEY_SHIFT},      /* C */
00104     {0x07, KEY_SHIFT},      /* D */
00105     {0x08, KEY_SHIFT},      /* E */
00106     {0x09, KEY_SHIFT},      /* F */
00107     {0x0a, KEY_SHIFT},      /* G */
00108     {0x0b, KEY_SHIFT},      /* H */
00109     {0x0c, KEY_SHIFT},      /* I */
00110     {0x0d, KEY_SHIFT},      /* J */
00111     {0x0e, KEY_SHIFT},      /* K */
00112     {0x0f, KEY_SHIFT},      /* L */
00113     {0x10, KEY_SHIFT},      /* M */
00114     {0x11, KEY_SHIFT},      /* N */
00115     {0x12, KEY_SHIFT},      /* O */
00116     {0x13, KEY_SHIFT},      /* P */
00117     {0x14, KEY_SHIFT},      /* Q */
00118     {0x15, KEY_SHIFT},      /* R */
00119     {0x16, KEY_SHIFT},      /* S */
00120     {0x17, KEY_SHIFT},      /* T */
00121     {0x18, KEY_SHIFT},      /* U */
00122     {0x19, KEY_SHIFT},      /* V */
00123     {0x1a, KEY_SHIFT},      /* W */
00124     {0x1b, KEY_SHIFT},      /* X */
00125     {0x1c, KEY_SHIFT},      /* Y */
00126     {0x1d, KEY_SHIFT},      /* Z */
00127     {0x2f, 0},          /* [ */
00128     {0x31, 0},          /* \ */
00129     {0x30, 0},          /* ] */
00130     {0x23, KEY_SHIFT},      /* ^ */
00131     {0x2d, KEY_SHIFT},      /* _ */
00132     {0x35, 0},          /* ` */
00133     {0x04, 0},          /* a */
00134     {0x05, 0},          /* b */
00135     {0x06, 0},          /* c */
00136     {0x07, 0},          /* d */
00137     {0x08, 0},          /* e */
00138     {0x09, 0},          /* f */
00139     {0x0a, 0},          /* g */
00140     {0x0b, 0},          /* h */
00141     {0x0c, 0},          /* i */
00142     {0x0d, 0},          /* j */
00143     {0x0e, 0},          /* k */
00144     {0x0f, 0},          /* l */
00145     {0x10, 0},          /* m */
00146     {0x11, 0},          /* n */
00147     {0x12, 0},          /* o */
00148     {0x13, 0},          /* p */
00149     {0x14, 0},          /* q */
00150     {0x15, 0},          /* r */
00151     {0x16, 0},          /* s */
00152     {0x17, 0},          /* t */
00153     {0x18, 0},          /* u */
00154     {0x19, 0},          /* v */
00155     {0x1a, 0},          /* w */
00156     {0x1b, 0},          /* x */
00157     {0x1c, 0},          /* y */
00158     {0x1d, 0},          /* z */
00159     {0x2f, KEY_SHIFT},      /* { */
00160     {0x31, KEY_SHIFT},      /* | */
00161     {0x30, KEY_SHIFT},      /* } */
00162     {0x35, KEY_SHIFT},      /* ~ */
00163     {0,0},              /* DEL */
00164 
00165     {0x3a, 0},          /* F1 */
00166     {0x3b, 0},          /* F2 */
00167     {0x3c, 0},          /* F3 */
00168     {0x3d, 0},          /* F4 */
00169     {0x3e, 0},          /* F5 */
00170     {0x3f, 0},          /* F6 */
00171     {0x40, 0},          /* F7 */
00172     {0x41, 0},          /* F8 */
00173     {0x42, 0},          /* F9 */
00174     {0x43, 0},          /* F10 */
00175     {0x44, 0},          /* F11 */
00176     {0x45, 0},          /* F12 */
00177 
00178     {0x46, 0},          /* PRINT_SCREEN */
00179     {0x47, 0},          /* SCROLL_LOCK */
00180     {0x39, 0},          /* CAPS_LOCK */
00181     {0x53, 0},          /* NUM_LOCK */
00182     {0x49, 0},          /* INSERT */
00183     {0x4a, 0},          /* HOME */
00184     {0x4b, 0},          /* PAGE_UP */
00185     {0x4e, 0},          /* PAGE_DOWN */
00186 
00187     {0x4f, 0},          /* RIGHT_ARROW */
00188     {0x50, 0},          /* LEFT_ARROW */
00189     {0x51, 0},          /* DOWN_ARROW */
00190     {0x52, 0},          /* UP_ARROW */
00191 };
00192 
00193 #else
00194 /* UK keyboard */
00195 #define KEYMAP_SIZE (152)
00196 const KEYMAP keymap[KEYMAP_SIZE] = {
00197     {0, 0},             /* NUL */
00198     {0, 0},             /* SOH */
00199     {0, 0},             /* STX */
00200     {0, 0},             /* ETX */
00201     {0, 0},             /* EOT */
00202     {0, 0},             /* ENQ */
00203     {0, 0},             /* ACK */
00204     {0, 0},             /* BEL */
00205     {0x2a, 0},          /* BS  */  /* Keyboard Delete (Backspace) */
00206     {0x2b, 0},          /* TAB */  /* Keyboard Tab */
00207     {0x28, 0},          /* LF  */  /* Keyboard Return (Enter) */
00208     {0, 0},             /* VT  */
00209     {0, 0},             /* FF  */
00210     {0, 0},             /* CR  */
00211     {0, 0},             /* SO  */
00212     {0, 0},             /* SI  */
00213     {0, 0},             /* DEL */
00214     {0, 0},             /* DC1 */
00215     {0, 0},             /* DC2 */
00216     {0, 0},             /* DC3 */
00217     {0, 0},             /* DC4 */
00218     {0, 0},             /* NAK */
00219     {0, 0},             /* SYN */
00220     {0, 0},             /* ETB */
00221     {0, 0},             /* CAN */
00222     {0, 0},             /* EM  */
00223     {0, 0},             /* SUB */
00224     {0, 0},             /* ESC */
00225     {0, 0},             /* FS  */
00226     {0, 0},             /* GS  */
00227     {0, 0},             /* RS  */
00228     {0, 0},             /* US  */
00229     {0x2c, 0},          /*   */
00230     {0x1e, KEY_SHIFT},      /* ! */
00231     {0x1f, KEY_SHIFT},      /* " */
00232     {0x32, 0},          /* # */
00233     {0x21, KEY_SHIFT},      /* $ */
00234     {0x22, KEY_SHIFT},      /* % */
00235     {0x24, KEY_SHIFT},      /* & */
00236     {0x34, 0},          /* ' */
00237     {0x26, KEY_SHIFT},      /* ( */
00238     {0x27, KEY_SHIFT},      /* ) */
00239     {0x25, KEY_SHIFT},      /* * */
00240     {0x2e, KEY_SHIFT},      /* + */
00241     {0x36, 0},          /* , */
00242     {0x2d, 0},          /* - */
00243     {0x37, 0},          /* . */
00244     {0x38, 0},          /* / */
00245     {0x27, 0},          /* 0 */
00246     {0x1e, 0},          /* 1 */
00247     {0x1f, 0},          /* 2 */
00248     {0x20, 0},          /* 3 */
00249     {0x21, 0},          /* 4 */
00250     {0x22, 0},          /* 5 */
00251     {0x23, 0},          /* 6 */
00252     {0x24, 0},          /* 7 */
00253     {0x25, 0},          /* 8 */
00254     {0x26, 0},          /* 9 */
00255     {0x33, KEY_SHIFT},      /* : */
00256     {0x33, 0},          /* ; */
00257     {0x36, KEY_SHIFT},      /* < */
00258     {0x2e, 0},          /* = */
00259     {0x37, KEY_SHIFT},      /* > */
00260     {0x38, KEY_SHIFT},      /* ? */
00261     {0x34, KEY_SHIFT},      /* @ */
00262     {0x04, KEY_SHIFT},      /* A */
00263     {0x05, KEY_SHIFT},      /* B */
00264     {0x06, KEY_SHIFT},      /* C */
00265     {0x07, KEY_SHIFT},      /* D */
00266     {0x08, KEY_SHIFT},      /* E */
00267     {0x09, KEY_SHIFT},      /* F */
00268     {0x0a, KEY_SHIFT},      /* G */
00269     {0x0b, KEY_SHIFT},      /* H */
00270     {0x0c, KEY_SHIFT},      /* I */
00271     {0x0d, KEY_SHIFT},      /* J */
00272     {0x0e, KEY_SHIFT},      /* K */
00273     {0x0f, KEY_SHIFT},      /* L */
00274     {0x10, KEY_SHIFT},      /* M */
00275     {0x11, KEY_SHIFT},      /* N */
00276     {0x12, KEY_SHIFT},      /* O */
00277     {0x13, KEY_SHIFT},      /* P */
00278     {0x14, KEY_SHIFT},      /* Q */
00279     {0x15, KEY_SHIFT},      /* R */
00280     {0x16, KEY_SHIFT},      /* S */
00281     {0x17, KEY_SHIFT},      /* T */
00282     {0x18, KEY_SHIFT},      /* U */
00283     {0x19, KEY_SHIFT},      /* V */
00284     {0x1a, KEY_SHIFT},      /* W */
00285     {0x1b, KEY_SHIFT},      /* X */
00286     {0x1c, KEY_SHIFT},      /* Y */
00287     {0x1d, KEY_SHIFT},      /* Z */
00288     {0x2f, 0},          /* [ */
00289     {0x64, 0},          /* \ */
00290     {0x30, 0},          /* ] */
00291     {0x23, KEY_SHIFT},      /* ^ */
00292     {0x2d, KEY_SHIFT},      /* _ */
00293     {0x35, 0},          /* ` */
00294     {0x04, 0},          /* a */
00295     {0x05, 0},          /* b */
00296     {0x06, 0},          /* c */
00297     {0x07, 0},          /* d */
00298     {0x08, 0},          /* e */
00299     {0x09, 0},          /* f */
00300     {0x0a, 0},          /* g */
00301     {0x0b, 0},          /* h */
00302     {0x0c, 0},          /* i */
00303     {0x0d, 0},          /* j */
00304     {0x0e, 0},          /* k */
00305     {0x0f, 0},          /* l */
00306     {0x10, 0},          /* m */
00307     {0x11, 0},          /* n */
00308     {0x12, 0},          /* o */
00309     {0x13, 0},          /* p */
00310     {0x14, 0},          /* q */
00311     {0x15, 0},          /* r */
00312     {0x16, 0},          /* s */
00313     {0x17, 0},          /* t */
00314     {0x18, 0},          /* u */
00315     {0x19, 0},          /* v */
00316     {0x1a, 0},          /* w */
00317     {0x1b, 0},          /* x */
00318     {0x1c, 0},          /* y */
00319     {0x1d, 0},          /* z */
00320     {0x2f, KEY_SHIFT},      /* { */
00321     {0x64, KEY_SHIFT},      /* | */
00322     {0x30, KEY_SHIFT},      /* } */
00323     {0x32, KEY_SHIFT},      /* ~ */
00324     {0,0},             /* DEL */
00325 
00326     {0x3a, 0},          /* F1 */
00327     {0x3b, 0},          /* F2 */
00328     {0x3c, 0},          /* F3 */
00329     {0x3d, 0},          /* F4 */
00330     {0x3e, 0},          /* F5 */
00331     {0x3f, 0},          /* F6 */
00332     {0x40, 0},          /* F7 */
00333     {0x41, 0},          /* F8 */
00334     {0x42, 0},          /* F9 */
00335     {0x43, 0},          /* F10 */
00336     {0x44, 0},          /* F11 */
00337     {0x45, 0},          /* F12 */
00338 
00339     {0x46, 0},          /* PRINT_SCREEN */
00340     {0x47, 0},          /* SCROLL_LOCK */
00341     {0x39, 0},          /* CAPS_LOCK */
00342     {0x53, 0},          /* NUM_LOCK */
00343     {0x49, 0},          /* INSERT */
00344     {0x4a, 0},          /* HOME */
00345     {0x4b, 0},          /* PAGE_UP */
00346     {0x4e, 0},          /* PAGE_DOWN */
00347 
00348     {0x4f, 0},          /* RIGHT_ARROW */
00349     {0x50, 0},          /* LEFT_ARROW */
00350     {0x51, 0},          /* DOWN_ARROW */
00351     {0x52, 0},          /* UP_ARROW */
00352 };
00353 #endif
00354 
00355 uint8_t * USBKeyboard::reportDesc() {
00356     static uint8_t reportDescriptor[] = {
00357         USAGE_PAGE(1), 0x01,                    // Generic Desktop
00358         USAGE(1), 0x06,                         // Keyboard
00359         COLLECTION(1), 0x01,                    // Application
00360         REPORT_ID(1),       REPORT_ID_KEYBOARD,
00361 
00362         USAGE_PAGE(1), 0x07,                    // Key Codes
00363         USAGE_MINIMUM(1), 0xE0,
00364         USAGE_MAXIMUM(1), 0xE7,
00365         LOGICAL_MINIMUM(1), 0x00,
00366         LOGICAL_MAXIMUM(1), 0x01,
00367         REPORT_SIZE(1), 0x01,
00368         REPORT_COUNT(1), 0x08,
00369         INPUT(1), 0x02,                         // Data, Variable, Absolute
00370         REPORT_COUNT(1), 0x01,
00371         REPORT_SIZE(1), 0x08,
00372         INPUT(1), 0x01,                         // Constant
00373 
00374 
00375         REPORT_COUNT(1), 0x05,
00376         REPORT_SIZE(1), 0x01,
00377         USAGE_PAGE(1), 0x08,                    // LEDs
00378         USAGE_MINIMUM(1), 0x01,
00379         USAGE_MAXIMUM(1), 0x05,
00380         OUTPUT(1), 0x02,                        // Data, Variable, Absolute
00381         REPORT_COUNT(1), 0x01,
00382         REPORT_SIZE(1), 0x03,
00383         OUTPUT(1), 0x01,                        // Constant
00384 
00385 
00386         REPORT_COUNT(1), 0x06,
00387         REPORT_SIZE(1), 0x08,
00388         LOGICAL_MINIMUM(1), 0x00,
00389         LOGICAL_MAXIMUM(1), 0x65,
00390         USAGE_PAGE(1), 0x07,                    // Key Codes
00391         USAGE_MINIMUM(1), 0x00,
00392         USAGE_MAXIMUM(1), 0x65,
00393         INPUT(1), 0x00,                         // Data, Array
00394         END_COLLECTION(0),
00395 
00396         // Media Control
00397         USAGE_PAGE(1), 0x0C,
00398         USAGE(1), 0x01,
00399         COLLECTION(1), 0x01,
00400         REPORT_ID(1), REPORT_ID_VOLUME,
00401         USAGE_PAGE(1), 0x0C,
00402         LOGICAL_MINIMUM(1), 0x00,
00403         LOGICAL_MAXIMUM(1), 0x01,
00404         REPORT_SIZE(1), 0x01,
00405         REPORT_COUNT(1), 0x07,
00406         USAGE(1), 0xB5,             // Next Track
00407         USAGE(1), 0xB6,             // Previous Track
00408         USAGE(1), 0xB7,             // Stop
00409         USAGE(1), 0xCD,             // Play / Pause
00410         USAGE(1), 0xE2,             // Mute
00411         USAGE(1), 0xE9,             // Volume Up
00412         USAGE(1), 0xEA,             // Volume Down
00413         INPUT(1), 0x02,             // Input (Data, Variable, Absolute)
00414         REPORT_COUNT(1), 0x01,
00415         INPUT(1), 0x01,
00416         END_COLLECTION(0),
00417     };
00418     reportLength = sizeof(reportDescriptor);
00419     return reportDescriptor;
00420 }
00421 
00422 
00423 bool USBKeyboard::EPINT_OUT_callback() {
00424     uint32_t bytesRead = 0;
00425     uint8_t led[65];
00426     USBDevice::readEP(EPINT_OUT, led, &bytesRead, MAX_HID_REPORT_SIZE);
00427 
00428     // we take led[1] because led[0] is the report ID
00429     lock_status = led[1] & 0x07;
00430 
00431     // We activate the endpoint to be able to recceive data
00432     if (!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
00433         return false;
00434     return true;
00435 }
00436 
00437 uint8_t USBKeyboard::lockStatus() {
00438     return lock_status;
00439 }
00440 
00441 int USBKeyboard::_putc(int c) {
00442     return keyCode(c, keymap[c].modifier);
00443 }
00444 
00445 bool USBKeyboard::keyCode(uint8_t key, uint8_t modifier) {
00446     // Send a simulated keyboard keypress. Returns true if successful.
00447     HID_REPORT report;
00448 
00449     report.data[0] = REPORT_ID_KEYBOARD;
00450     report.data[1] = modifier;
00451     report.data[2] = 0;
00452     report.data[3] = keymap[key].usage;
00453     report.data[4] = 0;
00454     report.data[5] = 0;
00455     report.data[6] = 0;
00456     report.data[7] = 0;
00457     report.data[8] = 0;
00458 
00459     report.length = 9;
00460 
00461     if (!send(&report)) {
00462         return false;
00463     }
00464 
00465     report.data[1] = 0;
00466     report.data[3] = 0;
00467 
00468     if (!send(&report)) {
00469         return false;
00470     }
00471 
00472     return true;
00473 
00474 }
00475 
00476 
00477 bool USBKeyboard::mediaControl(MEDIA_KEY key) {
00478     HID_REPORT report;
00479 
00480     report.data[0] = REPORT_ID_VOLUME;
00481     report.data[1] = (1 << key) & 0x7f;
00482 
00483     report.length = 2;
00484 
00485     if (!send(&report)) {
00486         return false;
00487     }
00488 
00489     report.data[0] = REPORT_ID_VOLUME;
00490     report.data[1] = 0;
00491 
00492     report.length = 2;
00493 
00494     return send(&report);
00495 }
00496 
00497 
00498 #define DEFAULT_CONFIGURATION (1)
00499 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
00500                                + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
00501                                + (1 * HID_DESCRIPTOR_LENGTH) \
00502                                + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
00503 
00504 uint8_t * USBKeyboard::configurationDesc() {
00505     static uint8_t configurationDescriptor[] = {
00506         CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
00507         CONFIGURATION_DESCRIPTOR,       // bDescriptorType
00508         LSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (LSB)
00509         MSB(TOTAL_DESCRIPTOR_LENGTH),   // wTotalLength (MSB)
00510         0x01,                           // bNumInterfaces
00511         DEFAULT_CONFIGURATION,          // bConfigurationValue
00512         0x00,                           // iConfiguration
00513         C_RESERVED | C_SELF_POWERED,    // bmAttributes
00514         C_POWER(0),                     // bMaxPowerHello World from Mbed
00515 
00516         INTERFACE_DESCRIPTOR_LENGTH,    // bLength
00517         INTERFACE_DESCRIPTOR,           // bDescriptorType
00518         0x00,                           // bInterfaceNumber
00519         0x00,                           // bAlternateSetting
00520         0x02,                           // bNumEndpoints
00521         HID_CLASS,                      // bInterfaceClass
00522         1,                              // bInterfaceSubClass
00523         1,                              // bInterfaceProtocol (keyboard)
00524         0x00,                           // iInterface
00525 
00526         HID_DESCRIPTOR_LENGTH,          // bLength
00527         HID_DESCRIPTOR,                 // bDescriptorType
00528         LSB(HID_VERSION_1_11),          // bcdHID (LSB)
00529         MSB(HID_VERSION_1_11),          // bcdHID (MSB)
00530         0x00,                           // bCountryCode
00531         0x01,                           // bNumDescriptors
00532         REPORT_DESCRIPTOR,              // bDescriptorType
00533         (uint8_t)(LSB(reportDescLength())),  // wDescriptorLength (LSB)
00534         (uint8_t)(MSB(reportDescLength())),  // wDescriptorLength (MSB)
00535 
00536         ENDPOINT_DESCRIPTOR_LENGTH,     // bLength
00537         ENDPOINT_DESCRIPTOR,            // bDescriptorType
00538         PHY_TO_DESC(EPINT_IN),          // bEndpointAddress
00539         E_INTERRUPT,                    // bmAttributes
00540         LSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (LSB)
00541         MSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (MSB)
00542         1,                             // bInterval (milliseconds)
00543 
00544         ENDPOINT_DESCRIPTOR_LENGTH,     // bLength
00545         ENDPOINT_DESCRIPTOR,            // bDescriptorType
00546         PHY_TO_DESC(EPINT_OUT),          // bEndpointAddress
00547         E_INTERRUPT,                    // bmAttributes
00548         LSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (LSB)
00549         MSB(MAX_PACKET_SIZE_EPINT),     // wMaxPacketSize (MSB)
00550         1,                             // bInterval (milliseconds)
00551     };
00552     return configurationDescriptor;
00553 }