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