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).
USBHID/USBHID.cpp@4:50ec00aa4515, 2017-03-28 (annotated)
- Committer:
- frq08711@LMECWL0871.LME.ST.COM
- Date:
- Tue Mar 28 11:00:57 2017 +0200
- Branch:
- master
- Revision:
- 4:50ec00aa4515
- Parent:
- 1:2a3ae13b45ef
update for 5.4.2
Who changed what in which revision?
User | Revision | Line number | New 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 | 4:50ec00aa4515 | 202 | USAGE_PAGE(2), LSB(0xFFAB), MSB(0xFFAB), |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 203 | USAGE(2), LSB(0x0200), MSB(0x0200), |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 204 | COLLECTION(1), 0x01, // Collection (Application) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 205 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 206 | REPORT_SIZE(1), 0x08, // 8 bits |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 207 | LOGICAL_MINIMUM(1), 0x00, |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 208 | LOGICAL_MAXIMUM(1), 0xFF, |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 209 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 210 | REPORT_COUNT(1), input_length, |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 211 | USAGE(1), 0x01, |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 212 | INPUT(1), 0x02, // Data, Var, Abs |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 213 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 214 | REPORT_COUNT(1), output_length, |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 215 | USAGE(1), 0x02, |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 216 | OUTPUT(1), 0x02, // Data, Var, Abs |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 217 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 218 | END_COLLECTION(0), |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 219 | }; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 220 | reportLength = sizeof(reportDescriptor); |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 221 | return reportDescriptor; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 222 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 223 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 224 | #define DEFAULT_CONFIGURATION (1) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 225 | #define TOTAL_DESCRIPTOR_LENGTH ((1 * CONFIGURATION_DESCRIPTOR_LENGTH) \ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 226 | + (1 * INTERFACE_DESCRIPTOR_LENGTH) \ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 227 | + (1 * HID_DESCRIPTOR_LENGTH) \ |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 228 | + (2 * ENDPOINT_DESCRIPTOR_LENGTH)) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 229 | |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 230 | uint8_t * USBHID::configurationDesc() { |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 231 | static uint8_t configurationDescriptor[] = { |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 232 | CONFIGURATION_DESCRIPTOR_LENGTH, // bLength |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 233 | CONFIGURATION_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 234 | LSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (LSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 235 | MSB(TOTAL_DESCRIPTOR_LENGTH), // wTotalLength (MSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 236 | 0x01, // bNumInterfaces |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 237 | DEFAULT_CONFIGURATION, // bConfigurationValue |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 238 | 0x00, // iConfiguration |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 239 | C_RESERVED | C_SELF_POWERED, // bmAttributes |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 240 | C_POWER(0), // bMaxPower |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 241 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 242 | INTERFACE_DESCRIPTOR_LENGTH, // bLength |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 243 | INTERFACE_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 244 | 0x00, // bInterfaceNumber |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 245 | 0x00, // bAlternateSetting |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 246 | 0x02, // bNumEndpoints |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 247 | HID_CLASS, // bInterfaceClass |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 248 | HID_SUBCLASS_NONE, // bInterfaceSubClass |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 249 | HID_PROTOCOL_NONE, // bInterfaceProtocol |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 250 | 0x00, // iInterface |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 251 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 252 | HID_DESCRIPTOR_LENGTH, // bLength |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 253 | HID_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 254 | LSB(HID_VERSION_1_11), // bcdHID (LSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 255 | MSB(HID_VERSION_1_11), // bcdHID (MSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 256 | 0x00, // bCountryCode |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 257 | 0x01, // bNumDescriptors |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 258 | REPORT_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 259 | (uint8_t)(LSB(reportDescLength())), // wDescriptorLength (LSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 260 | (uint8_t)(MSB(reportDescLength())), // wDescriptorLength (MSB) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 261 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 262 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 263 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 264 | PHY_TO_DESC(EPINT_IN), // bEndpointAddress |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 265 | E_INTERRUPT, // bmAttributes |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 266 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 267 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 268 | 1, // bInterval (milliseconds) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 269 | |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 270 | ENDPOINT_DESCRIPTOR_LENGTH, // bLength |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 271 | ENDPOINT_DESCRIPTOR, // bDescriptorType |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 272 | PHY_TO_DESC(EPINT_OUT), // bEndpointAddress |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 273 | E_INTERRUPT, // bmAttributes |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 274 | LSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (LSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 275 | MSB(MAX_PACKET_SIZE_EPINT), // wMaxPacketSize (MSB) |
frq08711@LMECWL0871.LME.ST.COM | 4:50ec00aa4515 | 276 | 1, // bInterval (milliseconds) |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 277 | }; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 278 | return configurationDescriptor; |
frq08711@LMECWL0871.LME.ST.COM | 1:2a3ae13b45ef | 279 | } |