Added TARGET_DISCO_F469NI in USBHOST\USBHost\TARGET_STM\USBHALHost_STM_TARGET.h
Dependents: DISCO-F469NI_USB_Disk STM32F4xx_USB_Memory
Fork of USBHOST by
USBHost/USBHost.cpp@8:3e7a33f81048, 2020-01-04 (annotated)
- Committer:
- kenjiArai
- Date:
- Sat Jan 04 23:30:59 2020 +0000
- Revision:
- 8:3e7a33f81048
- Parent:
- 5:fc157e6bd5a5
updated for STM32F4xx
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1 | /* mbed USBHost Library |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 2 | * Copyright (c) 2006-2013 ARM Limited |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 3 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 5 | * you may not use this file except in compliance with the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 6 | * You may obtain a copy of the License at |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 7 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 9 | * |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 10 | * Unless required by applicable law or agreed to in writing, software |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 13 | * See the License for the specific language governing permissions and |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 14 | * limitations under the License. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 15 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 16 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 17 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 18 | #include "USBHost.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 19 | #include "USBHostHub.h" |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 20 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 21 | USBHost * USBHost::instHost = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 22 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 23 | #define DEVICE_CONNECTED_EVENT (1 << 0) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 24 | #define DEVICE_DISCONNECTED_EVENT (1 << 1) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 25 | #define TD_PROCESSED_EVENT (1 << 2) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 26 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 27 | #define MAX_TRY_ENUMERATE_HUB 3 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 28 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 29 | #define MIN(a, b) ((a > b) ? b : a) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 30 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 31 | /** |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 32 | * How interrupts are processed: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 33 | * - new device connected: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 34 | * - a message is queued in queue_usb_event with the id DEVICE_CONNECTED_EVENT |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 35 | * - when the usb_thread receives the event, it: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 36 | * - resets the device |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 37 | * - reads the device descriptor |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 38 | * - sets the address of the device |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 39 | * - if it is a hub, enumerates it |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 40 | * - device disconnected: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 41 | * - a message is queued in queue_usb_event with the id DEVICE_DISCONNECTED_EVENT |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 42 | * - when the usb_thread receives the event, it: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 43 | * - free the device and all its children (hub) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 44 | * - td processed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 45 | * - a message is queued in queue_usb_event with the id TD_PROCESSED_EVENT |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 46 | * - when the usb_thread receives the event, it: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 47 | * - call the callback attached to the endpoint where the td is attached |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 48 | */ |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 49 | void USBHost::usb_process() |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 50 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 51 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 52 | bool controlListState; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 53 | bool bulkListState; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 54 | bool interruptListState; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 55 | USBEndpoint * ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 56 | uint8_t i, j, res, timeout_set_addr = 10; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 57 | uint8_t buf[8]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 58 | bool too_many_hub; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 59 | int idx; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 60 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 61 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 62 | uint8_t * buf_transfer; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 63 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 64 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 65 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 66 | uint8_t k; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 67 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 68 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 69 | while(1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 70 | osEvent evt = mail_usb_event.get(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 71 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 72 | if (evt.status == osEventMail) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 73 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 74 | message_t * usb_msg = (message_t*)evt.value.p; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 75 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 76 | switch (usb_msg->event_id) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 77 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 78 | // a new device has been connected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 79 | case DEVICE_CONNECTED_EVENT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 80 | too_many_hub = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 81 | buf[4] = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 82 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 83 | do { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 84 | Lock lock(this); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 85 | bool hub_unplugged = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 86 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 87 | int idx = findDevice(usb_msg->hub, usb_msg->port, (USBHostHub *)(usb_msg->hub_parent)); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 88 | /* check that hub is connected to root port */ |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 89 | if (usb_msg->hub_parent) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 90 | /* a hub device must be present */ |
kenjiArai | 8:3e7a33f81048 | 91 | #if MAX_HUB_NB |
kenjiArai | 8:3e7a33f81048 | 92 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 93 | for (k = 0; k < MAX_HUB_NB; k++) { |
kenjiArai | 8:3e7a33f81048 | 94 | if ((&hubs[k] == usb_msg->hub_parent) && (hub_in_use[k])) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 95 | hub_unplugged=false; |
kenjiArai | 8:3e7a33f81048 | 96 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 97 | } |
kenjiArai | 8:3e7a33f81048 | 98 | #endif |
kenjiArai | 8:3e7a33f81048 | 99 | } else { |
kenjiArai | 8:3e7a33f81048 | 100 | hub_unplugged = false; |
kenjiArai | 8:3e7a33f81048 | 101 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 102 | |
kenjiArai | 8:3e7a33f81048 | 103 | if (((idx!=-1) && deviceInUse[idx] ) || ((idx == -1) && hub_unplugged)) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 104 | break; |
kenjiArai | 8:3e7a33f81048 | 105 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 106 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 107 | for (i =0 ; i < MAX_DEVICE_CONNECTED; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 108 | if (!deviceInUse[i]) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 109 | USB_DBG_EVENT("new device connected: %p\r\n", &devices[i]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 110 | devices[i].init(usb_msg->hub, usb_msg->port, usb_msg->lowSpeed); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 111 | deviceReset[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 112 | deviceInited[i] = true; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 113 | break; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 114 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 115 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 116 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 117 | if (i == MAX_DEVICE_CONNECTED) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 118 | USB_ERR("Too many device connected!!\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 119 | continue; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 120 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 121 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 122 | if (!controlEndpointAllocated) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 123 | control = newEndpoint(CONTROL_ENDPOINT, OUT, 0x08, 0x00); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 124 | addEndpoint(NULL, 0, (USBEndpoint*)control); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 125 | controlEndpointAllocated = true; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 126 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 127 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 128 | #if MAX_HUB_NB |
kenjiArai | 8:3e7a33f81048 | 129 | if (usb_msg->hub_parent) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 130 | devices[i].setHubParent((USBHostHub *)(usb_msg->hub_parent)); |
kenjiArai | 8:3e7a33f81048 | 131 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 132 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 133 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 134 | for (j = 0; j < timeout_set_addr; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 135 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 136 | resetDevice(&devices[i]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 137 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 138 | // set size of control endpoint |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 139 | devices[i].setSizeControlEndpoint(8); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 140 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 141 | devices[i].activeAddress(false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 142 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 143 | // get first 8 bit of device descriptor |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 144 | // and check if we deal with a hub |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 145 | USB_DBG("usb_thread read device descriptor on dev: %p\r\n", &devices[i]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 146 | res = getDeviceDescriptor(&devices[i], buf, 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 147 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 148 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 149 | USB_ERR("usb_thread could not read dev descr"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 150 | continue; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 151 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 152 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 153 | // set size of control endpoint |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 154 | devices[i].setSizeControlEndpoint(buf[7]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 155 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 156 | // second step: set an address to the device |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 157 | res = setAddress(&devices[i], devices[i].getAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 158 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 159 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 160 | USB_ERR("SET ADDR FAILED"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 161 | continue; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 162 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 163 | devices[i].activeAddress(true); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 164 | USB_DBG("Address of %p: %d", &devices[i], devices[i].getAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 165 | |
kenjiArai | 8:3e7a33f81048 | 166 | // Wait for the device to actually set the address. The Status stage |
kenjiArai | 8:3e7a33f81048 | 167 | // of SET ADDRESS happens before the device implements the request. |
kenjiArai | 8:3e7a33f81048 | 168 | // According to Universal Serial Bus Specification Revision 2.0 chapter |
kenjiArai | 8:3e7a33f81048 | 169 | // 9.2.6.3 Set Address Processing, the device is allowed SetAddress() |
kenjiArai | 8:3e7a33f81048 | 170 | // recovery interval of 2 ms. |
kenjiArai | 8:3e7a33f81048 | 171 | ThisThread::sleep_for(2); |
kenjiArai | 8:3e7a33f81048 | 172 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 173 | // try to read again the device descriptor to check if the device |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 174 | // answers to its new address |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 175 | res = getDeviceDescriptor(&devices[i], buf, 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 176 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 177 | if (res == USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 178 | break; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 179 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 180 | |
kenjiArai | 8:3e7a33f81048 | 181 | ThisThread::sleep_for(100); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 182 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 183 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 184 | USB_INFO("New device connected: %p [hub: %d - port: %d]", &devices[i], usb_msg->hub, usb_msg->port); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 185 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 186 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 187 | if (buf[4] == HUB_CLASS) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 188 | for (k = 0; k < MAX_HUB_NB; k++) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 189 | if (hub_in_use[k] == false) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 190 | for (uint8_t j = 0; j < MAX_TRY_ENUMERATE_HUB; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 191 | if (hubs[k].connect(&devices[i])) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 192 | devices[i].hub = &hubs[k]; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 193 | hub_in_use[k] = true; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 194 | break; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 195 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 196 | } |
kenjiArai | 8:3e7a33f81048 | 197 | if (hub_in_use[k] == true) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 198 | break; |
kenjiArai | 8:3e7a33f81048 | 199 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 200 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 201 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 202 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 203 | if (k == MAX_HUB_NB) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 204 | USB_ERR("Too many hubs connected!!\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 205 | too_many_hub = true; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 206 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 207 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 208 | |
kenjiArai | 8:3e7a33f81048 | 209 | if (usb_msg->hub_parent) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 210 | ((USBHostHub *)(usb_msg->hub_parent))->deviceConnected(&devices[i]); |
kenjiArai | 8:3e7a33f81048 | 211 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 212 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 213 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 214 | if ((i < MAX_DEVICE_CONNECTED) && !too_many_hub) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 215 | deviceInUse[i] = true; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 216 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 217 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 218 | } while(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 219 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 220 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 221 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 222 | // a device has been disconnected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 223 | case DEVICE_DISCONNECTED_EVENT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 224 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 225 | do { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 226 | Lock lock(this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 227 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 228 | controlListState = disableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 229 | bulkListState = disableList(BULK_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 230 | interruptListState = disableList(INTERRUPT_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 231 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 232 | idx = findDevice(usb_msg->hub, usb_msg->port, (USBHostHub *)(usb_msg->hub_parent)); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 233 | if (idx != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 234 | freeDevice((USBDeviceConnected*)&devices[idx]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 235 | deviceInited[idx]=false; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 236 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 237 | |
kenjiArai | 8:3e7a33f81048 | 238 | if (controlListState) { |
kenjiArai | 8:3e7a33f81048 | 239 | enableList(CONTROL_ENDPOINT); |
kenjiArai | 8:3e7a33f81048 | 240 | } |
kenjiArai | 8:3e7a33f81048 | 241 | if (bulkListState) { |
kenjiArai | 8:3e7a33f81048 | 242 | enableList(BULK_ENDPOINT); |
kenjiArai | 8:3e7a33f81048 | 243 | } |
kenjiArai | 8:3e7a33f81048 | 244 | if (interruptListState) { |
kenjiArai | 8:3e7a33f81048 | 245 | enableList(INTERRUPT_ENDPOINT); |
kenjiArai | 8:3e7a33f81048 | 246 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 247 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 248 | } while(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 249 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 250 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 251 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 252 | // a td has been processed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 253 | // call callback on the ed associated to the td |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 254 | // we are not in ISR -> users can use printf in their callback method |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 255 | case TD_PROCESSED_EVENT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 256 | ep = (USBEndpoint *) ((HCTD *)usb_msg->td_addr)->ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 257 | if (usb_msg->td_state == USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 258 | USB_DBG_EVENT("call callback on td %p [ep: %p state: %s - dev: %p - %s]", usb_msg->td_addr, ep, ep->getStateString(), ep->dev, ep->dev->getName(ep->getIntfNb())); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 259 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 260 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 261 | if (ep->getDir() == IN) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 262 | buf_transfer = ep->getBufStart(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 263 | printf("READ SUCCESS [%d bytes transferred - td: 0x%08X] on ep: [%p - addr: %02X]: ", ep->getLengthTransferred(), usb_msg->td_addr, ep, ep->getAddress()); |
kenjiArai | 8:3e7a33f81048 | 264 | for (int i = 0; i < ep->getLengthTransferred(); i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 265 | printf("%02X ", buf_transfer[i]); |
kenjiArai | 8:3e7a33f81048 | 266 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 267 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 268 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 269 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 270 | ep->call(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 271 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 272 | idx = findDevice(ep->dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 273 | if (idx != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 274 | if (deviceInUse[idx]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 275 | USB_WARN("td %p processed but not in idle state: %s [ep: %p - dev: %p - %s]", usb_msg->td_addr, ep->getStateString(), ep, ep->dev, ep->dev->getName(ep->getIntfNb())); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 276 | ep->setState(USB_TYPE_IDLE); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 277 | /* as error, on interrupt endpoint can be |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 278 | * reported, call the call back registered , |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 279 | * if device still in use, this call back |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 280 | * shall ask again an interrupt request. |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 281 | */ |
kenjiArai | 8:3e7a33f81048 | 282 | ep->call(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 283 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 284 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 285 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 286 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 287 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 288 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 289 | mail_usb_event.free(usb_msg); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 290 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 291 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 292 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 293 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 294 | USBHost::USBHost() : usbThread(osPriorityNormal, USB_THREAD_STACK) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 295 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 296 | #ifndef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 297 | headControlEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 298 | headBulkEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 299 | headInterruptEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 300 | tailControlEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 301 | tailBulkEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 302 | tailInterruptEndpoint = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 303 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 304 | lenReportDescr = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 305 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 306 | controlEndpointAllocated = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 307 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 308 | for (uint8_t i = 0; i < MAX_DEVICE_CONNECTED; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 309 | deviceInUse[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 310 | devices[i].setAddress(i + 1); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 311 | deviceReset[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 312 | deviceInited[i] = false; |
kenjiArai | 8:3e7a33f81048 | 313 | for (uint8_t j = 0; j < MAX_INTF; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 314 | deviceAttachedDriver[i][j] = false; |
kenjiArai | 8:3e7a33f81048 | 315 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 316 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 317 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 318 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 319 | for (uint8_t i = 0; i < MAX_HUB_NB; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 320 | hubs[i].setHost(this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 321 | hub_in_use[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 322 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 323 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 324 | |
kenjiArai | 8:3e7a33f81048 | 325 | usbThread.start(callback(this, &USBHost::usb_process)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 326 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 327 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 328 | USBHost::Lock::Lock(USBHost* pHost) : m_pHost(pHost) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 329 | { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 330 | m_pHost->usb_mutex.lock(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 331 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 332 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 333 | USBHost::Lock::~Lock() |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 334 | { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 335 | m_pHost->usb_mutex.unlock(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 336 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 337 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 338 | void USBHost::transferCompleted(volatile uint32_t addr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 339 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 340 | uint8_t state; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 341 | |
kenjiArai | 8:3e7a33f81048 | 342 | if(addr == 0) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 343 | return; |
kenjiArai | 8:3e7a33f81048 | 344 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 345 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 346 | volatile HCTD* tdList = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 347 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 348 | //First we must reverse the list order and dequeue each TD |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 349 | do { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 350 | volatile HCTD* td = (volatile HCTD*)addr; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 351 | addr = (uint32_t)td->nextTD; //Dequeue from physical list |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 352 | td->nextTD = (hcTd*)tdList; //Enqueue into reversed list |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 353 | tdList = td; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 354 | } while(addr); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 355 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 356 | while(tdList != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 357 | volatile HCTD* td = tdList; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 358 | tdList = (volatile HCTD*)td->nextTD; //Dequeue element now as it could be modified below |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 359 | if (td->ep != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 360 | USBEndpoint * ep = (USBEndpoint *)(td->ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 361 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 362 | #ifdef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 363 | state = ((HCTD *)td)->state; |
kenjiArai | 8:3e7a33f81048 | 364 | if (state == USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 365 | ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); |
kenjiArai | 8:3e7a33f81048 | 366 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 367 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 368 | #else |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 369 | if (((HCTD *)td)->control >> 28) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 370 | state = ((HCTD *)td)->control >> 28; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 371 | } else { |
kenjiArai | 8:3e7a33f81048 | 372 | if (td->currBufPtr) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 373 | ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); |
kenjiArai | 8:3e7a33f81048 | 374 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 375 | state = 16 /*USB_TYPE_IDLE*/; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 376 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 377 | #endif |
kenjiArai | 8:3e7a33f81048 | 378 | if (state == USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 379 | ep->setLengthTransferred((uint32_t)td->currBufPtr - (uint32_t)ep->getBufStart()); |
kenjiArai | 8:3e7a33f81048 | 380 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 381 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 382 | ep->unqueueTransfer(td); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 383 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 384 | if (ep->getType() != CONTROL_ENDPOINT) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 385 | // callback on the processed td will be called from the usb_thread (not in ISR) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 386 | message_t * usb_msg = mail_usb_event.alloc(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 387 | usb_msg->event_id = TD_PROCESSED_EVENT; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 388 | usb_msg->td_addr = (void *)td; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 389 | usb_msg->td_state = state; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 390 | mail_usb_event.put(usb_msg); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 391 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 392 | ep->setState((USB_TYPE)state); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 393 | ep->ep_queue.put((uint8_t*)1); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 394 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 395 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 396 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 397 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 398 | USBHost * USBHost::getHostInst() |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 399 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 400 | if (instHost == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 401 | instHost = new USBHost(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 402 | instHost->init(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 403 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 404 | return instHost; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 405 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 406 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 407 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 408 | /* |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 409 | * Called when a device has been connected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 410 | * Called in ISR!!!! (no printf) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 411 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 412 | /* virtual */ void USBHost::deviceConnected(int hub, int port, bool lowSpeed, USBHostHub * hub_parent) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 413 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 414 | // be sure that the new device connected is not already connected... |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 415 | int idx = findDevice(hub, port, hub_parent); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 416 | if (idx != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 417 | if (deviceInited[idx]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 418 | return; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 419 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 420 | } |
kenjiArai | 8:3e7a33f81048 | 421 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 422 | message_t * usb_msg = mail_usb_event.alloc(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 423 | usb_msg->event_id = DEVICE_CONNECTED_EVENT; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 424 | usb_msg->hub = hub; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 425 | usb_msg->port = port; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 426 | usb_msg->lowSpeed = lowSpeed; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 427 | usb_msg->hub_parent = hub_parent; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 428 | mail_usb_event.put(usb_msg); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 429 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 430 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 431 | /* |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 432 | * Called when a device has been disconnected |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 433 | * Called in ISR!!!! (no printf) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 434 | */ |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 435 | /* virtual */ void USBHost::deviceDisconnected(int hub, int port, USBHostHub * hub_parent, volatile uint32_t addr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 436 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 437 | // be sure that the device disconnected is connected... |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 438 | int idx = findDevice(hub, port, hub_parent); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 439 | if (idx != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 440 | if (!deviceInUse[idx]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 441 | return; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 442 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 443 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 444 | return; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 445 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 446 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 447 | message_t * usb_msg = mail_usb_event.alloc(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 448 | usb_msg->event_id = DEVICE_DISCONNECTED_EVENT; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 449 | usb_msg->hub = hub; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 450 | usb_msg->port = port; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 451 | usb_msg->hub_parent = hub_parent; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 452 | mail_usb_event.put(usb_msg); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 453 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 454 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 455 | void USBHost::freeDevice(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 456 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 457 | USBEndpoint * ep = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 458 | HCED * ed = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 459 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 460 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 461 | if (dev->getClass() == HUB_CLASS) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 462 | if (dev->hub == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 463 | USB_ERR("HUB NULL!!!!!\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 464 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 465 | dev->hub->hubDisconnected(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 466 | for (uint8_t i = 0; i < MAX_HUB_NB; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 467 | if (dev->hub == &hubs[i]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 468 | hub_in_use[i] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 469 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 470 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 471 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 472 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 473 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 474 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 475 | // notify hub parent that this device has been disconnected |
kenjiArai | 8:3e7a33f81048 | 476 | if (dev->getHubParent()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 477 | dev->getHubParent()->deviceDisconnected(dev); |
kenjiArai | 8:3e7a33f81048 | 478 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 479 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 480 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 481 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 482 | int idx = findDevice(dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 483 | if (idx != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 484 | deviceInUse[idx] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 485 | deviceReset[idx] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 486 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 487 | for (uint8_t j = 0; j < MAX_INTF; j++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 488 | deviceAttachedDriver[idx][j] = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 489 | if (dev->getInterface(j) != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 490 | USB_DBG("FREE INTF %d on dev: %p, %p, nb_endpot: %d, %s", j, (void *)dev->getInterface(j), dev, dev->getInterface(j)->nb_endpoint, dev->getName(j)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 491 | for (int i = 0; i < dev->getInterface(j)->nb_endpoint; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 492 | if ((ep = dev->getEndpoint(j, i)) != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 493 | #ifndef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 494 | ed = (HCED *)ep->getHCED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 495 | ed->control |= (1 << 14); //sKip bit |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 496 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 497 | unqueueEndpoint(ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 498 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 499 | freeTD((volatile uint8_t*)ep->getTDList()[0]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 500 | freeTD((volatile uint8_t*)ep->getTDList()[1]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 501 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 502 | freeED((uint8_t *)ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 503 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 504 | printList(BULK_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 505 | printList(INTERRUPT_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 506 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 507 | USB_INFO("Device disconnected [%p - %s - hub: %d - port: %d]", dev, dev->getName(j), dev->getHub(), dev->getPort()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 508 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 509 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 510 | dev->disconnect(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 511 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 512 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 513 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 514 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 515 | void USBHost::unqueueEndpoint(USBEndpoint * ep) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 516 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 517 | #ifdef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 518 | ep->setState(USB_TYPE_FREE); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 519 | #else |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 520 | USBEndpoint * prec = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 521 | USBEndpoint * current = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 522 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 523 | for (int i = 0; i < 2; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 524 | current = (i == 0) ? (USBEndpoint*)headBulkEndpoint : (USBEndpoint*)headInterruptEndpoint; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 525 | prec = current; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 526 | while (current != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 527 | if (current == ep) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 528 | if (current->nextEndpoint() != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 529 | prec->queueEndpoint(current->nextEndpoint()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 530 | if (current == headBulkEndpoint) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 531 | updateBulkHeadED((uint32_t)current->nextEndpoint()->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 532 | headBulkEndpoint = current->nextEndpoint(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 533 | } else if (current == headInterruptEndpoint) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 534 | updateInterruptHeadED((uint32_t)current->nextEndpoint()->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 535 | headInterruptEndpoint = current->nextEndpoint(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 536 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 537 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 538 | // here we are dequeuing the queue of ed |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 539 | // we need to update the tail pointer |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 540 | else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 541 | prec->queueEndpoint(NULL); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 542 | if (current == headBulkEndpoint) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 543 | updateBulkHeadED(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 544 | headBulkEndpoint = current->nextEndpoint(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 545 | } else if (current == headInterruptEndpoint) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 546 | updateInterruptHeadED(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 547 | headInterruptEndpoint = current->nextEndpoint(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 548 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 549 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 550 | // modify tail |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 551 | switch (current->getType()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 552 | case BULK_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 553 | tailBulkEndpoint = prec; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 554 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 555 | case INTERRUPT_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 556 | tailInterruptEndpoint = prec; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 557 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 558 | default: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 559 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 560 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 561 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 562 | current->setState(USB_TYPE_FREE); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 563 | return; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 564 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 565 | prec = current; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 566 | current = current->nextEndpoint(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 567 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 568 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 569 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 570 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 571 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 572 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 573 | USBDeviceConnected * USBHost::getDevice(uint8_t index) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 574 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 575 | if ((index >= MAX_DEVICE_CONNECTED) || (!deviceInUse[index])) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 576 | return NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 577 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 578 | return (USBDeviceConnected*)&devices[index]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 579 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 580 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 581 | // create an USBEndpoint descriptor. the USBEndpoint is not linked |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 582 | USBEndpoint * USBHost::newEndpoint(ENDPOINT_TYPE type, ENDPOINT_DIRECTION dir, uint32_t size, uint8_t addr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 583 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 584 | int i = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 585 | HCED * ed = (HCED *)getED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 586 | HCTD* td_list[2] = { (HCTD*)getTD(), (HCTD*)getTD() }; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 587 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 588 | memset((void *)td_list[0], 0x00, sizeof(HCTD)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 589 | memset((void *)td_list[1], 0x00, sizeof(HCTD)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 590 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 591 | // search a free USBEndpoint |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 592 | for (i = 0; i < MAX_ENDPOINT; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 593 | if (endpoints[i].getState() == USB_TYPE_FREE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 594 | endpoints[i].init(ed, type, dir, size, addr, td_list); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 595 | USB_DBG("USBEndpoint created (%p): type: %d, dir: %d, size: %d, addr: %d, state: %s", &endpoints[i], type, dir, size, addr, endpoints[i].getStateString()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 596 | return &endpoints[i]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 597 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 598 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 599 | USB_ERR("could not allocate more endpoints!!!!"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 600 | return NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 601 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 602 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 603 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 604 | USB_TYPE USBHost::resetDevice(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 605 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 606 | int index = findDevice(dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 607 | if (index != -1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 608 | USB_DBG("Resetting hub %d, port %d\n", dev->getHub(), dev->getPort()); |
kenjiArai | 8:3e7a33f81048 | 609 | ThisThread::sleep_for(100); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 610 | if (dev->getHub() == 0) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 611 | resetRootHub(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 612 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 613 | #if MAX_HUB_NB |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 614 | else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 615 | dev->getHubParent()->portReset(dev->getPort()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 616 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 617 | #endif |
kenjiArai | 8:3e7a33f81048 | 618 | ThisThread::sleep_for(100); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 619 | deviceReset[index] = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 620 | return USB_TYPE_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 621 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 622 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 623 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 624 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 625 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 626 | // link the USBEndpoint to the linked list and attach an USBEndpoint to a device |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 627 | bool USBHost::addEndpoint(USBDeviceConnected * dev, uint8_t intf_nb, USBEndpoint * ep) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 628 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 629 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 630 | if (ep == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 631 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 632 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 633 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 634 | #ifndef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 635 | HCED * prevEd; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 636 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 637 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 638 | // set device address in the USBEndpoint descriptor |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 639 | if (dev == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 640 | ep->setDeviceAddress(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 641 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 642 | ep->setDeviceAddress(dev->getAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 643 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 644 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 645 | if ((dev != NULL) && dev->getSpeed()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 646 | ep->setSpeed(dev->getSpeed()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 647 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 648 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 649 | ep->setIntfNb(intf_nb); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 650 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 651 | #ifndef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 652 | // queue the new USBEndpoint on the ED list |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 653 | switch (ep->getType()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 654 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 655 | case CONTROL_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 656 | prevEd = ( HCED*) controlHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 657 | if (!prevEd) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 658 | updateControlHeadED((uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 659 | USB_DBG_TRANSFER("First control USBEndpoint: %08X", (uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 660 | headControlEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 661 | tailControlEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 662 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 663 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 664 | tailControlEndpoint->queueEndpoint(ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 665 | tailControlEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 666 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 667 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 668 | case BULK_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 669 | prevEd = ( HCED*) bulkHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 670 | if (!prevEd) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 671 | updateBulkHeadED((uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 672 | USB_DBG_TRANSFER("First bulk USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 673 | headBulkEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 674 | tailBulkEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 675 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 676 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 677 | USB_DBG_TRANSFER("Queue BULK Ed %p after %p\r\n",ep->getHCED(), prevEd); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 678 | tailBulkEndpoint->queueEndpoint(ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 679 | tailBulkEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 680 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 681 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 682 | case INTERRUPT_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 683 | prevEd = ( HCED*) interruptHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 684 | if (!prevEd) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 685 | updateInterruptHeadED((uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 686 | USB_DBG_TRANSFER("First interrupt USBEndpoint: %08X\r\n", (uint32_t) ep->getHCED()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 687 | headInterruptEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 688 | tailInterruptEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 689 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 690 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 691 | USB_DBG_TRANSFER("Queue INTERRUPT Ed %p after %p\r\n",ep->getHCED(), prevEd); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 692 | tailInterruptEndpoint->queueEndpoint(ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 693 | tailInterruptEndpoint = ep; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 694 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 695 | default: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 696 | return false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 697 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 698 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 699 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 700 | ep->dev = dev; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 701 | dev->addEndpoint(intf_nb, ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 702 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 703 | return true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 704 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 705 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 706 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 707 | int USBHost::findDevice(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 708 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 709 | for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 710 | if (dev == &devices[i]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 711 | return i; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 712 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 713 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 714 | return -1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 715 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 716 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 717 | int USBHost::findDevice(uint8_t hub, uint8_t port, USBHostHub * hub_parent) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 718 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 719 | for (int i = 0; i < MAX_DEVICE_CONNECTED; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 720 | if (devices[i].getHub() == hub && devices[i].getPort() == port) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 721 | if (hub_parent != NULL) { |
kenjiArai | 8:3e7a33f81048 | 722 | if (hub_parent == devices[i].getHubParent()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 723 | return i; |
kenjiArai | 8:3e7a33f81048 | 724 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 725 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 726 | return i; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 727 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 728 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 729 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 730 | return -1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 731 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 732 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 733 | void USBHost::printList(ENDPOINT_TYPE type) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 734 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 735 | #if defined(DEBUG_EP_STATE) && !defined(USBHOST_OTHER) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 736 | volatile HCED * hced; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 737 | switch(type) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 738 | case CONTROL_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 739 | hced = (HCED *)controlHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 740 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 741 | case BULK_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 742 | hced = (HCED *)bulkHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 743 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 744 | case INTERRUPT_ENDPOINT: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 745 | hced = (HCED *)interruptHeadED(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 746 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 747 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 748 | volatile HCTD * hctd = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 749 | const char * type_str = (type == BULK_ENDPOINT) ? "BULK" : |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 750 | ((type == INTERRUPT_ENDPOINT) ? "INTERRUPT" : |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 751 | ((type == CONTROL_ENDPOINT) ? "CONTROL" : "ISOCHRONOUS")); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 752 | printf("State of %s:\r\n", type_str); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 753 | while (hced != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 754 | uint8_t dir = ((hced->control & (3 << 11)) >> 11); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 755 | printf("hced: %p [ADDR: %d, DIR: %s, EP_NB: 0x%X]\r\n", hced, |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 756 | hced->control & 0x7f, |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 757 | (dir == 1) ? "OUT" : ((dir == 0) ? "FROM_TD":"IN"), |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 758 | (hced->control & (0xf << 7)) >> 7); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 759 | hctd = (HCTD *)((uint32_t)(hced->headTD) & ~(0xf)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 760 | while (hctd != hced->tailTD) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 761 | printf("\thctd: %p [DIR: %s]\r\n", hctd, ((hctd->control & (3 << 19)) >> 19) == 1 ? "OUT" : "IN"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 762 | hctd = hctd->nextTD; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 763 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 764 | printf("\thctd: %p\r\n", hctd); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 765 | hced = hced->nextED; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 766 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 767 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 768 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 769 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 770 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 771 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 772 | // add a transfer on the TD linked list |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 773 | USB_TYPE USBHost::addTransfer(USBEndpoint * ed, uint8_t * buf, uint32_t len) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 774 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 775 | USB_TYPE ret=USB_TYPE_PROCESSING; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 776 | td_mutex.lock(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 777 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 778 | // allocate a TD which will be freed in TDcompletion |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 779 | volatile HCTD * td = ed->getNextTD(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 780 | if (td == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 781 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 782 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 783 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 784 | #ifndef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 785 | uint32_t token = (ed->isSetup() ? TD_SETUP : ( (ed->getDir() == IN) ? TD_IN : TD_OUT )); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 786 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 787 | uint32_t td_toggle; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 788 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 789 | if (ed->getType() == CONTROL_ENDPOINT) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 790 | if (ed->isSetup()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 791 | td_toggle = TD_TOGGLE_0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 792 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 793 | td_toggle = TD_TOGGLE_1; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 794 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 795 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 796 | td_toggle = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 797 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 798 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 799 | td->control = (TD_ROUNDING | token | TD_DELAY_INT(0) | td_toggle | TD_CC); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 800 | td->currBufPtr = buf; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 801 | td->bufEnd = (buf + (len - 1)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 802 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 803 | ENDPOINT_TYPE type = ed->getType(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 804 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 805 | disableList(type); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 806 | ed->queueTransfer(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 807 | printList(type); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 808 | enableList(type); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 809 | #else |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 810 | /* call method specific for endpoint */ |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 811 | td->currBufPtr = buf; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 812 | td->size = len; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 813 | ret = ed->queueTransfer(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 814 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 815 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 816 | td_mutex.unlock(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 817 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 818 | return ret; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 819 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 820 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 821 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 822 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 823 | USB_TYPE USBHost::getDeviceDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_dev_descr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 824 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 825 | USB_TYPE t = controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 826 | USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 827 | GET_DESCRIPTOR, |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 828 | (DEVICE_DESCRIPTOR << 8) | (0), |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 829 | 0, buf, MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf)); |
kenjiArai | 8:3e7a33f81048 | 830 | if (len_dev_descr) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 831 | *len_dev_descr = MIN(DEVICE_DESCRIPTOR_LENGTH, max_len_buf); |
kenjiArai | 8:3e7a33f81048 | 832 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 833 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 834 | return t; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 835 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 836 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 837 | USB_TYPE USBHost::getConfigurationDescriptor(USBDeviceConnected * dev, uint8_t * buf, uint16_t max_len_buf, uint16_t * len_conf_descr) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 838 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 839 | USB_TYPE res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 840 | uint16_t total_conf_descr_length = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 841 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 842 | // fourth step: get the beginning of the configuration descriptor to have the total length of the conf descr |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 843 | res = controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 844 | USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 845 | GET_DESCRIPTOR, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 846 | (CONFIGURATION_DESCRIPTOR << 8) | (0), |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 847 | 0, buf, CONFIGURATION_DESCRIPTOR_LENGTH); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 848 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 849 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 850 | USB_ERR("GET CONF 1 DESCR FAILED"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 851 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 852 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 853 | total_conf_descr_length = buf[2] | (buf[3] << 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 854 | total_conf_descr_length = MIN(max_len_buf, total_conf_descr_length); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 855 | |
kenjiArai | 8:3e7a33f81048 | 856 | if (len_conf_descr) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 857 | *len_conf_descr = total_conf_descr_length; |
kenjiArai | 8:3e7a33f81048 | 858 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 859 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 860 | USB_DBG("TOTAL_LENGTH: %d \t NUM_INTERF: %d", total_conf_descr_length, buf[4]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 861 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 862 | return controlRead( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 863 | USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 864 | GET_DESCRIPTOR, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 865 | (CONFIGURATION_DESCRIPTOR << 8) | (0), |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 866 | 0, buf, total_conf_descr_length); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 867 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 868 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 869 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 870 | USB_TYPE USBHost::setAddress(USBDeviceConnected * dev, uint8_t address) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 871 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 872 | return controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 873 | USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 874 | SET_ADDRESS, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 875 | address, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 876 | 0, NULL, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 877 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 878 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 879 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 880 | USB_TYPE USBHost::setConfiguration(USBDeviceConnected * dev, uint8_t conf) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 881 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 882 | return controlWrite( dev, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 883 | USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 884 | SET_CONFIGURATION, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 885 | conf, |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 886 | 0, NULL, 0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 887 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 888 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 889 | uint8_t USBHost::numberDriverAttached(USBDeviceConnected * dev) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 890 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 891 | int index = findDevice(dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 892 | uint8_t cnt = 0; |
kenjiArai | 8:3e7a33f81048 | 893 | if (index == -1) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 894 | return 0; |
kenjiArai | 8:3e7a33f81048 | 895 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 896 | for (uint8_t i = 0; i < MAX_INTF; i++) { |
kenjiArai | 8:3e7a33f81048 | 897 | if (deviceAttachedDriver[index][i]) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 898 | cnt++; |
kenjiArai | 8:3e7a33f81048 | 899 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 900 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 901 | return cnt; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 902 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 903 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 904 | // enumerate a device with the control USBEndpoint |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 905 | USB_TYPE USBHost::enumerate(USBDeviceConnected * dev, IUSBEnumerator* pEnumerator) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 906 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 907 | uint16_t total_conf_descr_length = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 908 | USB_TYPE res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 909 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 910 | do { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 911 | Lock lock(this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 912 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 913 | // don't enumerate a device which all interfaces are registered to a specific driver |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 914 | int index = findDevice(dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 915 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 916 | if (index == -1) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 917 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 918 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 919 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 920 | uint8_t nb_intf_attached = numberDriverAttached(dev); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 921 | USB_DBG("dev: %p nb_intf: %d", dev, dev->getNbIntf()); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 922 | USB_DBG("dev: %p nb_intf_attached: %d", dev, nb_intf_attached); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 923 | if ((nb_intf_attached != 0) && (dev->getNbIntf() == nb_intf_attached)) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 924 | USB_DBG("Don't enumerate dev: %p because all intf are registered with a driver", dev); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 925 | return USB_TYPE_OK; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 926 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 927 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 928 | USB_DBG("Enumerate dev: %p", dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 929 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 930 | // third step: get the whole device descriptor to see vid, pid |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 931 | res = getDeviceDescriptor(dev, data, DEVICE_DESCRIPTOR_LENGTH); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 932 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 933 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 934 | USB_DBG("GET DEV DESCR FAILED"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 935 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 936 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 937 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 938 | dev->setClass(data[4]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 939 | dev->setSubClass(data[5]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 940 | dev->setProtocol(data[6]); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 941 | dev->setVid(data[8] | (data[9] << 8)); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 942 | dev->setPid(data[10] | (data[11] << 8)); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 943 | USB_DBG("CLASS: %02X \t VID: %04X \t PID: %04X", data[4], data[8] | (data[9] << 8), data[10] | (data[11] << 8)); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 944 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 945 | pEnumerator->setVidPid( data[8] | (data[9] << 8), data[10] | (data[11] << 8) ); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 946 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 947 | res = getConfigurationDescriptor(dev, data, sizeof(data), &total_conf_descr_length); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 948 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 949 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 950 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 951 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 952 | #if (DEBUG > 3) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 953 | USB_DBG("CONFIGURATION DESCRIPTOR:\r\n"); |
kenjiArai | 8:3e7a33f81048 | 954 | for (int i = 0; i < total_conf_descr_length; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 955 | printf("%02X ", data[i]); |
kenjiArai | 8:3e7a33f81048 | 956 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 957 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 958 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 959 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 960 | // Parse the configuration descriptor |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 961 | parseConfDescr(dev, data, total_conf_descr_length, pEnumerator); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 962 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 963 | // only set configuration if not enumerated before |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 964 | if (!dev->isEnumerated()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 965 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 966 | USB_DBG("Set configuration 1 on dev: %p", dev); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 967 | // sixth step: set configuration (only 1 supported) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 968 | res = setConfiguration(dev, 1); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 969 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 970 | if (res != USB_TYPE_OK) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 971 | USB_DBG("SET CONF FAILED"); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 972 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 973 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 974 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 975 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 976 | dev->setEnumerated(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 977 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 978 | // Now the device is enumerated! |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 979 | USB_DBG("dev %p is enumerated\r\n", dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 980 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 981 | } while(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 982 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 983 | // Some devices may require this delay |
kenjiArai | 8:3e7a33f81048 | 984 | ThisThread::sleep_for(100); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 985 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 986 | return USB_TYPE_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 987 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 988 | // this method fills the USBDeviceConnected object: class,.... . It also add endpoints found in the descriptor. |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 989 | void USBHost::parseConfDescr(USBDeviceConnected * dev, uint8_t * conf_descr, uint32_t len, IUSBEnumerator* pEnumerator) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 990 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 991 | uint32_t index = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 992 | uint32_t len_desc = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 993 | uint8_t id = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 994 | int nb_endpoints_used = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 995 | USBEndpoint * ep = NULL; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 996 | uint8_t intf_nb = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 997 | bool parsing_intf = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 998 | uint8_t current_intf = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 999 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1000 | while (index < len) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1001 | len_desc = conf_descr[index]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1002 | id = conf_descr[index+1]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1003 | switch (id) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1004 | case CONFIGURATION_DESCRIPTOR: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1005 | USB_DBG("dev: %p has %d intf", dev, conf_descr[4]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1006 | dev->setNbIntf(conf_descr[4]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1007 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1008 | case INTERFACE_DESCRIPTOR: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1009 | if(pEnumerator->parseInterface(conf_descr[index + 2], conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7])) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1010 | if (intf_nb++ <= MAX_INTF) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1011 | current_intf = conf_descr[index + 2]; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1012 | dev->addInterface(current_intf, conf_descr[index + 5], conf_descr[index + 6], conf_descr[index + 7]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1013 | nb_endpoints_used = 0; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1014 | USB_DBG("ADD INTF %d on device %p: class: %d, subclass: %d, proto: %d", current_intf, dev, conf_descr[index + 5],conf_descr[index + 6],conf_descr[index + 7]); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1015 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1016 | USB_DBG("Drop intf..."); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1017 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1018 | parsing_intf = true; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1019 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1020 | parsing_intf = false; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1021 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1022 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1023 | case ENDPOINT_DESCRIPTOR: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1024 | if (parsing_intf && (intf_nb <= MAX_INTF) ) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1025 | if (nb_endpoints_used < MAX_ENDPOINT_PER_INTERFACE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1026 | if( pEnumerator->useEndpoint(current_intf, (ENDPOINT_TYPE)(conf_descr[index + 3] & 0x03), (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1)) ) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1027 | // if the USBEndpoint is isochronous -> skip it (TODO: fix this) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1028 | if ((conf_descr[index + 3] & 0x03) != ISOCHRONOUS_ENDPOINT) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1029 | ep = newEndpoint((ENDPOINT_TYPE)(conf_descr[index+3] & 0x03), |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1030 | (ENDPOINT_DIRECTION)((conf_descr[index + 2] >> 7) + 1), |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1031 | conf_descr[index + 4] | (conf_descr[index + 5] << 8), |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1032 | conf_descr[index + 2] & 0x0f); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1033 | USB_DBG("ADD USBEndpoint %p, on interf %d on device %p", ep, current_intf, dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1034 | if (ep != NULL && dev != NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1035 | addEndpoint(dev, current_intf, ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1036 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1037 | USB_DBG("EP NULL"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1038 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1039 | nb_endpoints_used++; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1040 | } else { |
kenjiArai | 8:3e7a33f81048 | 1041 | #if 0 |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1042 | USB_DBG("ISO USBEndpoint NOT SUPPORTED"); |
kenjiArai | 8:3e7a33f81048 | 1043 | #else |
kenjiArai | 8:3e7a33f81048 | 1044 | USB_DBG("???????????????????????????????????????????????????"); |
kenjiArai | 8:3e7a33f81048 | 1045 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1046 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1047 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1048 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1049 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1050 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1051 | case HID_DESCRIPTOR: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1052 | lenReportDescr = conf_descr[index + 7] | (conf_descr[index + 8] << 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1053 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1054 | default: |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1055 | break; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1056 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1057 | index += len_desc; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1058 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1059 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1060 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1061 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1062 | USB_TYPE USBHost::bulkWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1063 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1064 | return generalTransfer(dev, ep, buf, len, blocking, BULK_ENDPOINT, true); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1065 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1066 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1067 | USB_TYPE USBHost::bulkRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1068 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1069 | return generalTransfer(dev, ep, buf, len, blocking, BULK_ENDPOINT, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1070 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1071 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1072 | USB_TYPE USBHost::interruptWrite(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1073 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1074 | return generalTransfer(dev, ep, buf, len, blocking, INTERRUPT_ENDPOINT, true); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1075 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1076 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1077 | USB_TYPE USBHost::interruptRead(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1078 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1079 | return generalTransfer(dev, ep, buf, len, blocking, INTERRUPT_ENDPOINT, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1080 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1081 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1082 | USB_TYPE USBHost::generalTransfer(USBDeviceConnected * dev, USBEndpoint * ep, uint8_t * buf, uint32_t len, bool blocking, ENDPOINT_TYPE type, bool write) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1083 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1084 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1085 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1086 | const char * type_str = (type == BULK_ENDPOINT) ? "BULK" : ((type == INTERRUPT_ENDPOINT) ? "INTERRUPT" : "ISOCHRONOUS"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1087 | USB_DBG_TRANSFER("----- %s %s [dev: %p - %s - hub: %d - port: %d - addr: %d - ep: %02X]------", type_str, (write) ? "WRITE" : "READ", dev, dev->getName(ep->getIntfNb()), dev->getHub(), dev->getPort(), dev->getAddress(), ep->getAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1088 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1089 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1090 | Lock lock(this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1091 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1092 | USB_TYPE res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1093 | ENDPOINT_DIRECTION dir = (write) ? OUT : IN; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1094 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1095 | if (dev == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1096 | USB_ERR("dev NULL"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1097 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1098 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1099 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1100 | if (ep == NULL) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1101 | USB_ERR("ep NULL"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1102 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1103 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1104 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1105 | if (ep->getState() != USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1106 | USB_WARN("[ep: %p - dev: %p - %s] NOT IDLE: %s", ep, ep->dev, ep->dev->getName(ep->getIntfNb()), ep->getStateString()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1107 | return ep->getState(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1108 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1109 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1110 | if ((ep->getDir() != dir) || (ep->getType() != type)) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1111 | USB_ERR("[ep: %p - dev: %p] wrong dir or bad USBEndpoint type", ep, ep->dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1112 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1113 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1114 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1115 | if (dev->getAddress() != ep->getDeviceAddress()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1116 | USB_ERR("[ep: %p - dev: %p] USBEndpoint addr and device addr don't match", ep, ep->dev); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1117 | return USB_TYPE_ERROR; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1118 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1119 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1120 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1121 | if (write) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1122 | USB_DBG_TRANSFER("%s WRITE buffer", type_str); |
kenjiArai | 8:3e7a33f81048 | 1123 | for (int i = 0; i < ep->getLengthTransferred(); i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1124 | printf("%02X ", buf[i]); |
kenjiArai | 8:3e7a33f81048 | 1125 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1126 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1127 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1128 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1129 | res = addTransfer(ep, buf, len); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1130 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1131 | if ((blocking)&& (res == USB_TYPE_PROCESSING)) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1132 | #ifdef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1133 | osEvent event = ep->ep_queue.get(TD_TIMEOUT); |
kenjiArai | 8:3e7a33f81048 | 1134 | if (event.status == osEventTimeout) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1135 | /* control endpoint is confusing for merge on b */ |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1136 | disableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1137 | ep->setState(USB_TYPE_ERROR); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1138 | ep->ep_queue.get(0); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1139 | ep->unqueueTransfer(ep->getProcessedTD()); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1140 | enableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1141 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1142 | #else |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1143 | ep->ep_queue.get(); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1144 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1145 | res = ep->getState(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1146 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1147 | USB_DBG_TRANSFER("%s TRANSFER res: %s on ep: %p\r\n", type_str, ep->getStateString(), ep); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1148 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1149 | if (res != USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1150 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1151 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1152 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1153 | return USB_TYPE_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1154 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1155 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1156 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1157 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1158 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1159 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1160 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1161 | USB_TYPE USBHost::controlRead(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1162 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1163 | return controlTransfer(dev, requestType, request, value, index, buf, len, false); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1164 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1165 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1166 | USB_TYPE USBHost::controlWrite(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1167 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1168 | return controlTransfer(dev, requestType, request, value, index, buf, len, true); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1169 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1170 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1171 | USB_TYPE USBHost::controlTransfer(USBDeviceConnected * dev, uint8_t requestType, uint8_t request, uint32_t value, uint32_t index, uint8_t * buf, uint32_t len, bool write) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1172 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1173 | Lock lock(this); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1174 | USB_DBG_TRANSFER("----- CONTROL %s [dev: %p - hub: %d - port: %d] ------", (write) ? "WRITE" : "READ", dev, dev->getHub(), dev->getPort()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1175 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1176 | int length_transfer = len; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1177 | USB_TYPE res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1178 | uint32_t token; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1179 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1180 | control->setSpeed(dev->getSpeed()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1181 | control->setSize(dev->getSizeControlEndpoint()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1182 | if (dev->isActiveAddress()) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1183 | control->setDeviceAddress(dev->getAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1184 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1185 | control->setDeviceAddress(0); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1186 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1187 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1188 | USB_DBG_TRANSFER("Control transfer on device: %d\r\n", control->getDeviceAddress()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1189 | fillControlBuf(requestType, request, value, index, len); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1190 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1191 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1192 | USB_DBG_TRANSFER("SETUP PACKET: "); |
kenjiArai | 8:3e7a33f81048 | 1193 | for (int i = 0; i < 8; i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1194 | printf("%01X ", setupPacket[i]); |
kenjiArai | 8:3e7a33f81048 | 1195 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1196 | printf("\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1197 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1198 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1199 | control->setNextToken(TD_SETUP); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1200 | res = addTransfer(control, (uint8_t*)setupPacket, 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1201 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1202 | if (res == USB_TYPE_PROCESSING) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1203 | #ifdef USBHOST_OTHER |
kenjiArai | 8:3e7a33f81048 | 1204 | { |
kenjiArai | 8:3e7a33f81048 | 1205 | osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1206 | if (event.status == osEventTimeout) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1207 | disableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1208 | control->setState(USB_TYPE_ERROR); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1209 | control->ep_queue.get(0); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1210 | control->unqueueTransfer(control->getProcessedTD()); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1211 | enableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1212 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1213 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1214 | #else |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1215 | control->ep_queue.get(); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1216 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1217 | res = control->getState(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1218 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1219 | USB_DBG_TRANSFER("CONTROL setup stage %s", control->getStateString()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1220 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1221 | if (res != USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1222 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1223 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1224 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1225 | if (length_transfer) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1226 | token = (write) ? TD_OUT : TD_IN; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1227 | control->setNextToken(token); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1228 | res = addTransfer(control, (uint8_t *)buf, length_transfer); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1229 | |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1230 | if (res == USB_TYPE_PROCESSING) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1231 | #ifdef USBHOST_OTHER |
kenjiArai | 8:3e7a33f81048 | 1232 | { |
kenjiArai | 8:3e7a33f81048 | 1233 | osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL); |
kenjiArai | 8:3e7a33f81048 | 1234 | if (event.status == osEventTimeout) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1235 | disableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1236 | control->setState(USB_TYPE_ERROR); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1237 | control->ep_queue.get(0); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1238 | control->unqueueTransfer(control->getProcessedTD()); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1239 | enableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1240 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1241 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1242 | #else |
kenjiArai | 8:3e7a33f81048 | 1243 | control->ep_queue.get(); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1244 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1245 | res = control->getState(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1246 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1247 | #if DEBUG_TRANSFER |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1248 | USB_DBG_TRANSFER("CONTROL %s stage %s", (write) ? "WRITE" : "READ", control->getStateString()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1249 | if (write) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1250 | USB_DBG_TRANSFER("CONTROL WRITE buffer"); |
kenjiArai | 8:3e7a33f81048 | 1251 | for (int i = 0; i < control->getLengthTransferred(); i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1252 | printf("%02X ", buf[i]); |
kenjiArai | 8:3e7a33f81048 | 1253 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1254 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1255 | } else { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1256 | USB_DBG_TRANSFER("CONTROL READ SUCCESS [%d bytes transferred]", control->getLengthTransferred()); |
kenjiArai | 8:3e7a33f81048 | 1257 | for (int i = 0; i < control->getLengthTransferred(); i++) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1258 | printf("%02X ", buf[i]); |
kenjiArai | 8:3e7a33f81048 | 1259 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1260 | printf("\r\n\r\n"); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1261 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1262 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1263 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1264 | if (res != USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1265 | return res; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1266 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1267 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1268 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1269 | token = (write) ? TD_IN : TD_OUT; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1270 | control->setNextToken(token); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1271 | res = addTransfer(control, NULL, 0); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1272 | if (res == USB_TYPE_PROCESSING) |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1273 | #ifdef USBHOST_OTHER |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1274 | { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1275 | osEvent event = control->ep_queue.get(TD_TIMEOUT_CTRL); |
kenjiArai | 8:3e7a33f81048 | 1276 | if (event.status == osEventTimeout) { |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1277 | disableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1278 | control->setState(USB_TYPE_ERROR); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1279 | control->ep_queue.get(0); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1280 | control->unqueueTransfer(control->getProcessedTD()); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1281 | enableList(CONTROL_ENDPOINT); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1282 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1283 | } |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1284 | #else |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1285 | control->ep_queue.get(); |
frq08711@LMECWL0871.LME.ST.COM | 5:fc157e6bd5a5 | 1286 | #endif |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1287 | res = control->getState(); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1288 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1289 | USB_DBG_TRANSFER("CONTROL ack stage %s", control->getStateString()); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1290 | |
kenjiArai | 8:3e7a33f81048 | 1291 | if (res != USB_TYPE_IDLE) { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1292 | return res; |
kenjiArai | 8:3e7a33f81048 | 1293 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1294 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1295 | return USB_TYPE_OK; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1296 | } |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1297 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1298 | |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1299 | void USBHost::fillControlBuf(uint8_t requestType, uint8_t request, uint16_t value, uint16_t index, int len) |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1300 | { |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1301 | setupPacket[0] = requestType; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1302 | setupPacket[1] = request; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1303 | setupPacket[2] = (uint8_t) value; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1304 | setupPacket[3] = (uint8_t) (value >> 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1305 | setupPacket[4] = (uint8_t) index; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1306 | setupPacket[5] = (uint8_t) (index >> 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1307 | setupPacket[6] = (uint8_t) len; |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1308 | setupPacket[7] = (uint8_t) (len >> 8); |
frq08711@LMECWL0871.LME.ST.COM | 1:ab240722d7ef | 1309 | } |