USBDevice for STM support

Dependents:   Nucleo_Usb_JoyMouse Nucleo_usbmouse ELEC350_1-referral-2018-usb-hid USBJoystick_HelloWorld2_wip ... more

This library contains all mbed usb device library (mbed-os\features\unsupported\USBDevice).

Committer:
frq08711@LMECWL0871.LME.ST.COM
Date:
Thu Dec 15 17:40:59 2016 +0100
Revision:
1:2a3ae13b45ef
Child:
4:50ec00aa4515
copy of git hub directory unsupported/USBDevice

Who changed what in which revision?

UserRevisionLine numberNew contents of line
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 2 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 4 * and associated documentation files (the "Software"), to deal in the Software without
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 7 * Software is furnished to do so, subject to the following conditions:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 8 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 9 * The above copyright notice and this permission notice shall be included in all copies or
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 10 * substantial portions of the Software.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 11 *
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 17 */
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 18
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 19 #include "stdint.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 20 #include "USBHAL.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 21 #include "USBHID.h"
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 22
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 23
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 24 USBHID::USBHID(uint8_t output_report_length, uint8_t input_report_length, uint16_t vendor_id, uint16_t product_id, uint16_t product_release, bool connect): USBDevice(vendor_id, product_id, product_release)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 25 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 26 output_length = output_report_length;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 27 input_length = input_report_length;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 28 if(connect) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 29 USBDevice::connect();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 30 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 31 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 32
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 33
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 34 bool USBHID::send(HID_REPORT *report)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 35 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 36 return write(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 37 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 38
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 39 bool USBHID::sendNB(HID_REPORT *report)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 40 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 41 return writeNB(EPINT_IN, report->data, report->length, MAX_HID_REPORT_SIZE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 42 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 43
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 44
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 45 bool USBHID::read(HID_REPORT *report)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 46 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 47 uint32_t bytesRead = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 48 bool result;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 49 result = USBDevice::readEP(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 50 if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 51 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 52 report->length = bytesRead;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 53 return result;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 54 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 55
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 56
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 57 bool USBHID::readNB(HID_REPORT *report)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 58 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 59 uint32_t bytesRead = 0;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 60 bool result;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 61 result = USBDevice::readEP_NB(EPINT_OUT, report->data, &bytesRead, MAX_HID_REPORT_SIZE);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 62 // if readEP_NB did not succeed, does not issue a readStart
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 63 if (!result)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 64 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 65 report->length = bytesRead;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 66 if(!readStart(EPINT_OUT, MAX_HID_REPORT_SIZE))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 67 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 68 return result;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 69 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 70
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 71
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 72 uint16_t USBHID::reportDescLength() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 73 reportDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 74 return reportLength;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 75 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 76
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 77
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 78
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 79 //
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 80 // Route callbacks from lower layers to class(es)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 81 //
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 82
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 83
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 84 // Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 85 // Called by USBDevice on Endpoint0 request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 86 // This is used to handle extensions to standard requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 87 // and class specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 88 // Return true if class handles this request
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 89 bool USBHID::USBCallback_request() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 90 bool success = false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 91 CONTROL_TRANSFER * transfer = getTransferPtr();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 92 uint8_t *hidDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 93
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 94 // Process additional standard requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 95
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 96 if ((transfer->setup.bmRequestType.Type == STANDARD_TYPE))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 97 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 98 switch (transfer->setup.bRequest)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 99 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 100 case GET_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 101 switch (DESCRIPTOR_TYPE(transfer->setup.wValue))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 102 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 103 case REPORT_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 104 if ((reportDesc() != NULL) \
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 105 && (reportDescLength() != 0))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 106 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 107 transfer->remaining = reportDescLength();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 108 transfer->ptr = reportDesc();
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 109 transfer->direction = DEVICE_TO_HOST;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 110 success = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 111 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 112 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 113 case HID_DESCRIPTOR:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 114 // Find the HID descriptor, after the configuration descriptor
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 115 hidDescriptor = findDescriptor(HID_DESCRIPTOR);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 116 if (hidDescriptor != NULL)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 117 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 118 transfer->remaining = HID_DESCRIPTOR_LENGTH;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 119 transfer->ptr = hidDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 120 transfer->direction = DEVICE_TO_HOST;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 121 success = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 122 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 123 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 124
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 125 default:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 126 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 127 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 128 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 129 default:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 130 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 131 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 132 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 133
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 134 // Process class-specific requests
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 135
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 136 if (transfer->setup.bmRequestType.Type == CLASS_TYPE)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 137 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 138 switch (transfer->setup.bRequest)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 139 {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 140 case SET_REPORT:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 141 // First byte will be used for report ID
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 142 outputReport.data[0] = transfer->setup.wValue & 0xff;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 143 outputReport.length = transfer->setup.wLength + 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 144
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 145 transfer->remaining = sizeof(outputReport.data) - 1;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 146 transfer->ptr = &outputReport.data[1];
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 147 transfer->direction = HOST_TO_DEVICE;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 148 transfer->notify = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 149 success = true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 150 default:
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 151 break;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 152 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 153 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 154
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 155 return success;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 156 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 157
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 158
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 159 #define DEFAULT_CONFIGURATION (1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 160
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 161
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 162 // Called in ISR context
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 163 // Set configuration. Return false if the
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 164 // configuration is not supported
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 165 bool USBHID::USBCallback_setConfiguration(uint8_t configuration) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 166 if (configuration != DEFAULT_CONFIGURATION) {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 167 return false;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 168 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 169
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 170 // Configure endpoints > 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 171 addEndpoint(EPINT_IN, MAX_PACKET_SIZE_EPINT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 172 addEndpoint(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 173
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 174 // We activate the endpoint to be able to recceive data
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 175 readStart(EPINT_OUT, MAX_PACKET_SIZE_EPINT);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 176 return true;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 177 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 178
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 179
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 180 uint8_t * USBHID::stringIinterfaceDesc() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 181 static uint8_t stringIinterfaceDescriptor[] = {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 182 0x08, //bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 183 STRING_DESCRIPTOR, //bDescriptorType 0x03
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 184 'H',0,'I',0,'D',0, //bString iInterface - HID
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 185 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 186 return stringIinterfaceDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 187 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 188
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 189 uint8_t * USBHID::stringIproductDesc() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 190 static uint8_t stringIproductDescriptor[] = {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 191 0x16, //bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 192 STRING_DESCRIPTOR, //bDescriptorType 0x03
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 193 'H',0,'I',0,'D',0,' ',0,'D',0,'E',0,'V',0,'I',0,'C',0,'E',0 //bString iProduct - HID device
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 194 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 195 return stringIproductDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 196 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 197
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 198
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 199
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 200 uint8_t * USBHID::reportDesc() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 201 static uint8_t reportDescriptor[] = {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 202 0x06, LSB(0xFFAB), MSB(0xFFAB),
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 203 0x0A, LSB(0x0200), MSB(0x0200),
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 204 0xA1, 0x01, // Collection 0x01
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 205 0x75, 0x08, // report size = 8 bits
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 206 0x15, 0x00, // logical minimum = 0
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 207 0x26, 0xFF, 0x00, // logical maximum = 255
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 208 0x95, input_length, // report count
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 209 0x09, 0x01, // usage
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 210 0x81, 0x02, // Input (array)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 211 0x95, output_length,// report count
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 212 0x09, 0x02, // usage
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 213 0x91, 0x02, // Output (array)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 214 0xC0 // end collection
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 215
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 216 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 217 reportLength = sizeof(reportDescriptor);
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 218 return reportDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 219 }
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 220
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 221 #define DEFAULT_CONFIGURATION (1)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 222 #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 223 + (1 * INTERFACE_DESCRIPTOR_LENGTH) \
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 224 + (1 * HID_DESCRIPTOR_LENGTH) \
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 225 + (2 * ENDPOINT_DESCRIPTOR_LENGTH))
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 226
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 227 uint8_t * USBHID::configurationDesc() {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 228 static uint8_t configurationDescriptor[] = {
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 229 CONFIGURATION_DESCRIPTOR_LENGTH,// bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 230 CONFIGURATION_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 231 LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 232 MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 233 0x01, // bNumInterfaces
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 234 DEFAULT_CONFIGURATION, // bConfigurationValue
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 235 0x00, // iConfiguration
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 236 C_RESERVED | C_SELF_POWERED, // bmAttributes
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 237 C_POWER(0), // bMaxPower
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 238
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 239 INTERFACE_DESCRIPTOR_LENGTH, // bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 240 INTERFACE_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 241 0x00, // bInterfaceNumber
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 242 0x00, // bAlternateSetting
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 243 0x02, // bNumEndpoints
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 244 HID_CLASS, // bInterfaceClass
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 245 HID_SUBCLASS_NONE, // bInterfaceSubClass
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 246 HID_PROTOCOL_NONE, // bInterfaceProtocol
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 247 0x00, // iInterface
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 248
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 249 HID_DESCRIPTOR_LENGTH, // bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 250 HID_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 251 LSB(HID_VERSION_1_11), // bcdHID (LSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 252 MSB(HID_VERSION_1_11), // bcdHID (MSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 253 0x00, // bCountryCode
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 254 0x01, // bNumDescriptors
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 255 REPORT_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 256 (uint8_t)(LSB(this->reportDescLength())), // wDescriptorLength (LSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 257 (uint8_t)(MSB(this->reportDescLength())), // wDescriptorLength (MSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 258
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 259 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 260 ENDPOINT_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 261 PHY_TO_DESC(EPINT_IN), // bEndpointAddress
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 262 E_INTERRUPT, // bmAttributes
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 263 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 264 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 265 1, // bInterval (milliseconds)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 266
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 267 ENDPOINT_DESCRIPTOR_LENGTH, // bLength
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 268 ENDPOINT_DESCRIPTOR, // bDescriptorType
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 269 PHY_TO_DESC(EPINT_OUT), // bEndpointAddress
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 270 E_INTERRUPT, // bmAttributes
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 271 LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 272 MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 273 1, // bInterval (milliseconds)
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 274 };
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 275 return configurationDescriptor;
frq08711@LMECWL0871.LME.ST.COM 1:2a3ae13b45ef 276 }