Modified version of NetServices. Fixes an issue where connections failed should the HTTP response status line be received in a packet on its own prior to any further headers. Changes are made to the HTTPClient.cpp file's readHeaders method.
drv/usb/UsbDevice.cpp@0:ec559500a63f, 2011-04-08 (annotated)
- Committer:
- andrewbonney
- Date:
- Fri Apr 08 14:39:41 2011 +0000
- Revision:
- 0:ec559500a63f
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andrewbonney | 0:ec559500a63f | 1 | |
andrewbonney | 0:ec559500a63f | 2 | /* |
andrewbonney | 0:ec559500a63f | 3 | Copyright (c) 2010 Donatien Garnier (donatiengar [at] gmail [dot] com) |
andrewbonney | 0:ec559500a63f | 4 | |
andrewbonney | 0:ec559500a63f | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy |
andrewbonney | 0:ec559500a63f | 6 | of this software and associated documentation files (the "Software"), to deal |
andrewbonney | 0:ec559500a63f | 7 | in the Software without restriction, including without limitation the rights |
andrewbonney | 0:ec559500a63f | 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
andrewbonney | 0:ec559500a63f | 9 | copies of the Software, and to permit persons to whom the Software is |
andrewbonney | 0:ec559500a63f | 10 | furnished to do so, subject to the following conditions: |
andrewbonney | 0:ec559500a63f | 11 | |
andrewbonney | 0:ec559500a63f | 12 | The above copyright notice and this permission notice shall be included in |
andrewbonney | 0:ec559500a63f | 13 | all copies or substantial portions of the Software. |
andrewbonney | 0:ec559500a63f | 14 | |
andrewbonney | 0:ec559500a63f | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
andrewbonney | 0:ec559500a63f | 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
andrewbonney | 0:ec559500a63f | 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
andrewbonney | 0:ec559500a63f | 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
andrewbonney | 0:ec559500a63f | 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
andrewbonney | 0:ec559500a63f | 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
andrewbonney | 0:ec559500a63f | 21 | THE SOFTWARE. |
andrewbonney | 0:ec559500a63f | 22 | */ |
andrewbonney | 0:ec559500a63f | 23 | |
andrewbonney | 0:ec559500a63f | 24 | #include "UsbDevice.h" |
andrewbonney | 0:ec559500a63f | 25 | |
andrewbonney | 0:ec559500a63f | 26 | #include "netCfg.h" |
andrewbonney | 0:ec559500a63f | 27 | #if NET_USB |
andrewbonney | 0:ec559500a63f | 28 | |
andrewbonney | 0:ec559500a63f | 29 | //#define __DEBUG |
andrewbonney | 0:ec559500a63f | 30 | #include "dbg/dbg.h" |
andrewbonney | 0:ec559500a63f | 31 | |
andrewbonney | 0:ec559500a63f | 32 | UsbDevice::UsbDevice( UsbHostMgr* pMgr, int hub, int port, int addr ) : m_pControlEp(NULL), /*m_controlEp( this, 0x00, false, USB_CONTROL, 8 ),*/ |
andrewbonney | 0:ec559500a63f | 33 | m_pMgr(pMgr), m_connected(false), m_enumerated(false), m_hub(hub), m_port(port), m_addr(addr), m_refs(0), |
andrewbonney | 0:ec559500a63f | 34 | m_vid(0), m_pid(0) |
andrewbonney | 0:ec559500a63f | 35 | { |
andrewbonney | 0:ec559500a63f | 36 | |
andrewbonney | 0:ec559500a63f | 37 | } |
andrewbonney | 0:ec559500a63f | 38 | |
andrewbonney | 0:ec559500a63f | 39 | UsbDevice::~UsbDevice() |
andrewbonney | 0:ec559500a63f | 40 | { |
andrewbonney | 0:ec559500a63f | 41 | if(m_pControlEp) |
andrewbonney | 0:ec559500a63f | 42 | delete m_pControlEp; |
andrewbonney | 0:ec559500a63f | 43 | } |
andrewbonney | 0:ec559500a63f | 44 | |
andrewbonney | 0:ec559500a63f | 45 | UsbErr UsbDevice::enumerate() |
andrewbonney | 0:ec559500a63f | 46 | { |
andrewbonney | 0:ec559500a63f | 47 | // USB_INT32S rc; |
andrewbonney | 0:ec559500a63f | 48 | |
andrewbonney | 0:ec559500a63f | 49 | UsbErr rc; |
andrewbonney | 0:ec559500a63f | 50 | |
andrewbonney | 0:ec559500a63f | 51 | DBG("Starting enumeration (m_pMgr = %p)\n", m_pMgr); |
andrewbonney | 0:ec559500a63f | 52 | |
andrewbonney | 0:ec559500a63f | 53 | #if 1 |
andrewbonney | 0:ec559500a63f | 54 | m_pMgr->resetPort(m_hub, m_port); |
andrewbonney | 0:ec559500a63f | 55 | #else |
andrewbonney | 0:ec559500a63f | 56 | wait_ms(100); /* USB 2.0 spec says atleast 50ms delay beore port reset */ |
andrewbonney | 0:ec559500a63f | 57 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRS; // Initiate port reset |
andrewbonney | 0:ec559500a63f | 58 | while (LPC_USB->HcRhPortStatus1 & OR_RH_PORT_PRS) |
andrewbonney | 0:ec559500a63f | 59 | __WFI(); // Wait for port reset to complete... |
andrewbonney | 0:ec559500a63f | 60 | LPC_USB->HcRhPortStatus1 = OR_RH_PORT_PRSC; // ...and clear port reset signal |
andrewbonney | 0:ec559500a63f | 61 | wait_ms(200); /* Wait for 100 MS after port reset */ |
andrewbonney | 0:ec559500a63f | 62 | #endif |
andrewbonney | 0:ec559500a63f | 63 | |
andrewbonney | 0:ec559500a63f | 64 | DBG("Port reset\n"); |
andrewbonney | 0:ec559500a63f | 65 | |
andrewbonney | 0:ec559500a63f | 66 | wait_ms(200); |
andrewbonney | 0:ec559500a63f | 67 | |
andrewbonney | 0:ec559500a63f | 68 | m_pControlEp = new UsbEndpoint( this, 0x00, false, USB_CONTROL, 8, 0 ); |
andrewbonney | 0:ec559500a63f | 69 | |
andrewbonney | 0:ec559500a63f | 70 | //EDCtrl->Control = 8 << 16;/* Put max pkt size = 8 */ |
andrewbonney | 0:ec559500a63f | 71 | /* Read first 8 bytes of device desc */ |
andrewbonney | 0:ec559500a63f | 72 | rc = controlReceive(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, (USB_DESCRIPTOR_TYPE_DEVICE << 8)|(0), 0, m_controlDataBuf, 8); |
andrewbonney | 0:ec559500a63f | 73 | if (rc) |
andrewbonney | 0:ec559500a63f | 74 | { |
andrewbonney | 0:ec559500a63f | 75 | DBG("RC=%d",rc); |
andrewbonney | 0:ec559500a63f | 76 | return (rc); |
andrewbonney | 0:ec559500a63f | 77 | } |
andrewbonney | 0:ec559500a63f | 78 | |
andrewbonney | 0:ec559500a63f | 79 | DBG("Got descriptor, max ep size is %d\n", m_controlDataBuf[7]); |
andrewbonney | 0:ec559500a63f | 80 | |
andrewbonney | 0:ec559500a63f | 81 | m_pControlEp->updateSize(m_controlDataBuf[7]); /* Get max pkt size of endpoint 0 */ |
andrewbonney | 0:ec559500a63f | 82 | rc = controlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_ADDRESS, m_addr, 0, NULL, 0); /* Set the device address to m_addr */ |
andrewbonney | 0:ec559500a63f | 83 | if (rc) |
andrewbonney | 0:ec559500a63f | 84 | { |
andrewbonney | 0:ec559500a63f | 85 | // PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 86 | return (rc); |
andrewbonney | 0:ec559500a63f | 87 | } |
andrewbonney | 0:ec559500a63f | 88 | wait_ms(2); |
andrewbonney | 0:ec559500a63f | 89 | //EDCtrl->Control = (EDCtrl->Control) | 1; /* Modify control pipe with address 1 */ |
andrewbonney | 0:ec559500a63f | 90 | |
andrewbonney | 0:ec559500a63f | 91 | //Update address |
andrewbonney | 0:ec559500a63f | 92 | m_pControlEp->updateAddr(m_addr); |
andrewbonney | 0:ec559500a63f | 93 | DBG("Ep addr is now %d", m_addr); |
andrewbonney | 0:ec559500a63f | 94 | /**/ |
andrewbonney | 0:ec559500a63f | 95 | |
andrewbonney | 0:ec559500a63f | 96 | //rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_DEVICE, 0, TDBuffer, 17); //Read full device descriptor |
andrewbonney | 0:ec559500a63f | 97 | rc = controlReceive(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, (USB_DESCRIPTOR_TYPE_DEVICE << 8)|(0), 0, m_controlDataBuf, 17); |
andrewbonney | 0:ec559500a63f | 98 | if (rc) |
andrewbonney | 0:ec559500a63f | 99 | { |
andrewbonney | 0:ec559500a63f | 100 | //PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 101 | return (rc); |
andrewbonney | 0:ec559500a63f | 102 | } |
andrewbonney | 0:ec559500a63f | 103 | /* |
andrewbonney | 0:ec559500a63f | 104 | rc = SerialCheckVidPid(); |
andrewbonney | 0:ec559500a63f | 105 | if (rc != OK) { |
andrewbonney | 0:ec559500a63f | 106 | PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 107 | return (rc); |
andrewbonney | 0:ec559500a63f | 108 | } |
andrewbonney | 0:ec559500a63f | 109 | */ |
andrewbonney | 0:ec559500a63f | 110 | /**/ |
andrewbonney | 0:ec559500a63f | 111 | |
andrewbonney | 0:ec559500a63f | 112 | m_vid = *((uint16_t*)&m_controlDataBuf[8]); |
andrewbonney | 0:ec559500a63f | 113 | m_pid = *((uint16_t*)&m_controlDataBuf[10]); |
andrewbonney | 0:ec559500a63f | 114 | |
andrewbonney | 0:ec559500a63f | 115 | DBG("VID: %02x, PID: %02x\n", m_vid, m_pid); |
andrewbonney | 0:ec559500a63f | 116 | /* Get the configuration descriptor */ |
andrewbonney | 0:ec559500a63f | 117 | //rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, 9); |
andrewbonney | 0:ec559500a63f | 118 | rc = controlReceive(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, (USB_DESCRIPTOR_TYPE_CONFIGURATION << 8)|(0), 0, m_controlDataBuf, 9); |
andrewbonney | 0:ec559500a63f | 119 | if (rc) |
andrewbonney | 0:ec559500a63f | 120 | { |
andrewbonney | 0:ec559500a63f | 121 | //PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 122 | return (rc); |
andrewbonney | 0:ec559500a63f | 123 | } |
andrewbonney | 0:ec559500a63f | 124 | /* Get the first configuration data */ |
andrewbonney | 0:ec559500a63f | 125 | //rc = HOST_GET_DESCRIPTOR(USB_DESCRIPTOR_TYPE_CONFIGURATION, 0, TDBuffer, *((uint16_t*)&TDBuffer[2])); |
andrewbonney | 0:ec559500a63f | 126 | rc = controlReceive(USB_DEVICE_TO_HOST | USB_RECIPIENT_DEVICE, GET_DESCRIPTOR, (USB_DESCRIPTOR_TYPE_CONFIGURATION << 8)|(0), 0, m_controlDataBuf, *((uint16_t*)&m_controlDataBuf[2])); |
andrewbonney | 0:ec559500a63f | 127 | if (rc) |
andrewbonney | 0:ec559500a63f | 128 | { |
andrewbonney | 0:ec559500a63f | 129 | //PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 130 | return (rc); |
andrewbonney | 0:ec559500a63f | 131 | } |
andrewbonney | 0:ec559500a63f | 132 | |
andrewbonney | 0:ec559500a63f | 133 | DBG("Desc len is %d\n", *((uint16_t*)&m_controlDataBuf[2])); |
andrewbonney | 0:ec559500a63f | 134 | |
andrewbonney | 0:ec559500a63f | 135 | DBG("Set configuration\n"); |
andrewbonney | 0:ec559500a63f | 136 | |
andrewbonney | 0:ec559500a63f | 137 | //rc = USBH_SET_CONFIGURATION(1);/* Select device configuration 1 */ |
andrewbonney | 0:ec559500a63f | 138 | rc = controlSend(USB_HOST_TO_DEVICE | USB_RECIPIENT_DEVICE, SET_CONFIGURATION, 1, 0, NULL, 0); |
andrewbonney | 0:ec559500a63f | 139 | if (rc) |
andrewbonney | 0:ec559500a63f | 140 | { |
andrewbonney | 0:ec559500a63f | 141 | // PRINT_Err(rc); |
andrewbonney | 0:ec559500a63f | 142 | return rc; |
andrewbonney | 0:ec559500a63f | 143 | } |
andrewbonney | 0:ec559500a63f | 144 | wait_ms(100);/* Some devices may require this delay */ |
andrewbonney | 0:ec559500a63f | 145 | |
andrewbonney | 0:ec559500a63f | 146 | m_enumerated = true; |
andrewbonney | 0:ec559500a63f | 147 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 148 | } |
andrewbonney | 0:ec559500a63f | 149 | |
andrewbonney | 0:ec559500a63f | 150 | bool UsbDevice::connected() |
andrewbonney | 0:ec559500a63f | 151 | { |
andrewbonney | 0:ec559500a63f | 152 | return m_connected; |
andrewbonney | 0:ec559500a63f | 153 | } |
andrewbonney | 0:ec559500a63f | 154 | |
andrewbonney | 0:ec559500a63f | 155 | bool UsbDevice::enumerated() |
andrewbonney | 0:ec559500a63f | 156 | { |
andrewbonney | 0:ec559500a63f | 157 | return m_enumerated; |
andrewbonney | 0:ec559500a63f | 158 | } |
andrewbonney | 0:ec559500a63f | 159 | |
andrewbonney | 0:ec559500a63f | 160 | int UsbDevice::getPid() |
andrewbonney | 0:ec559500a63f | 161 | { |
andrewbonney | 0:ec559500a63f | 162 | return m_pid; |
andrewbonney | 0:ec559500a63f | 163 | } |
andrewbonney | 0:ec559500a63f | 164 | |
andrewbonney | 0:ec559500a63f | 165 | int UsbDevice::getVid() |
andrewbonney | 0:ec559500a63f | 166 | { |
andrewbonney | 0:ec559500a63f | 167 | return m_vid; |
andrewbonney | 0:ec559500a63f | 168 | } |
andrewbonney | 0:ec559500a63f | 169 | |
andrewbonney | 0:ec559500a63f | 170 | UsbErr UsbDevice::getConfigurationDescriptor(int config, uint8_t** pBuf) |
andrewbonney | 0:ec559500a63f | 171 | { |
andrewbonney | 0:ec559500a63f | 172 | //For now olny one config |
andrewbonney | 0:ec559500a63f | 173 | *pBuf = m_controlDataBuf; |
andrewbonney | 0:ec559500a63f | 174 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 175 | } |
andrewbonney | 0:ec559500a63f | 176 | |
andrewbonney | 0:ec559500a63f | 177 | UsbErr UsbDevice::getInterfaceDescriptor(int config, int item, uint8_t** pBuf) |
andrewbonney | 0:ec559500a63f | 178 | { |
andrewbonney | 0:ec559500a63f | 179 | byte* desc_ptr = m_controlDataBuf; |
andrewbonney | 0:ec559500a63f | 180 | |
andrewbonney | 0:ec559500a63f | 181 | /* if (desc_ptr[1] != USB_DESCRIPTOR_TYPE_CONFIGURATION) |
andrewbonney | 0:ec559500a63f | 182 | { |
andrewbonney | 0:ec559500a63f | 183 | return USBERR_BADCONFIG; |
andrewbonney | 0:ec559500a63f | 184 | }*/ |
andrewbonney | 0:ec559500a63f | 185 | |
andrewbonney | 0:ec559500a63f | 186 | if(item>=m_controlDataBuf[4])//Interfaces count |
andrewbonney | 0:ec559500a63f | 187 | return USBERR_NOTFOUND; |
andrewbonney | 0:ec559500a63f | 188 | |
andrewbonney | 0:ec559500a63f | 189 | desc_ptr += desc_ptr[0]; |
andrewbonney | 0:ec559500a63f | 190 | |
andrewbonney | 0:ec559500a63f | 191 | *pBuf = NULL; |
andrewbonney | 0:ec559500a63f | 192 | |
andrewbonney | 0:ec559500a63f | 193 | while (desc_ptr < m_controlDataBuf + *((uint16_t*)&m_controlDataBuf[2])) |
andrewbonney | 0:ec559500a63f | 194 | { |
andrewbonney | 0:ec559500a63f | 195 | |
andrewbonney | 0:ec559500a63f | 196 | switch (desc_ptr[1]) { |
andrewbonney | 0:ec559500a63f | 197 | case USB_DESCRIPTOR_TYPE_INTERFACE: |
andrewbonney | 0:ec559500a63f | 198 | if(desc_ptr[2] == item) |
andrewbonney | 0:ec559500a63f | 199 | { |
andrewbonney | 0:ec559500a63f | 200 | *pBuf = desc_ptr; |
andrewbonney | 0:ec559500a63f | 201 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 202 | } |
andrewbonney | 0:ec559500a63f | 203 | desc_ptr += desc_ptr[0]; // Move to next descriptor start |
andrewbonney | 0:ec559500a63f | 204 | break; |
andrewbonney | 0:ec559500a63f | 205 | } |
andrewbonney | 0:ec559500a63f | 206 | |
andrewbonney | 0:ec559500a63f | 207 | } |
andrewbonney | 0:ec559500a63f | 208 | |
andrewbonney | 0:ec559500a63f | 209 | if(*pBuf == NULL) |
andrewbonney | 0:ec559500a63f | 210 | return USBERR_NOTFOUND; |
andrewbonney | 0:ec559500a63f | 211 | |
andrewbonney | 0:ec559500a63f | 212 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 213 | } |
andrewbonney | 0:ec559500a63f | 214 | |
andrewbonney | 0:ec559500a63f | 215 | |
andrewbonney | 0:ec559500a63f | 216 | UsbErr UsbDevice::setConfiguration(int config) |
andrewbonney | 0:ec559500a63f | 217 | { |
andrewbonney | 0:ec559500a63f | 218 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 219 | } |
andrewbonney | 0:ec559500a63f | 220 | |
andrewbonney | 0:ec559500a63f | 221 | UsbErr UsbDevice::controlSend(byte requestType, byte request, word value, word index, const byte* buf, int len) |
andrewbonney | 0:ec559500a63f | 222 | { |
andrewbonney | 0:ec559500a63f | 223 | UsbErr rc; |
andrewbonney | 0:ec559500a63f | 224 | fillControlBuf(requestType, request, value, index, len); |
andrewbonney | 0:ec559500a63f | 225 | m_pControlEp->setNextToken(TD_SETUP); |
andrewbonney | 0:ec559500a63f | 226 | rc = m_pControlEp->transfer(m_controlBuf, 8); |
andrewbonney | 0:ec559500a63f | 227 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 228 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 229 | if(rc) |
andrewbonney | 0:ec559500a63f | 230 | return rc; |
andrewbonney | 0:ec559500a63f | 231 | if(len) |
andrewbonney | 0:ec559500a63f | 232 | { |
andrewbonney | 0:ec559500a63f | 233 | m_pControlEp->setNextToken(TD_OUT); |
andrewbonney | 0:ec559500a63f | 234 | rc = m_pControlEp->transfer((byte*)buf, len); |
andrewbonney | 0:ec559500a63f | 235 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 236 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 237 | if(rc) |
andrewbonney | 0:ec559500a63f | 238 | return rc; |
andrewbonney | 0:ec559500a63f | 239 | } |
andrewbonney | 0:ec559500a63f | 240 | m_pControlEp->setNextToken(TD_IN); |
andrewbonney | 0:ec559500a63f | 241 | rc = m_pControlEp->transfer(NULL, 0); |
andrewbonney | 0:ec559500a63f | 242 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 243 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 244 | if(rc) |
andrewbonney | 0:ec559500a63f | 245 | return rc; |
andrewbonney | 0:ec559500a63f | 246 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 247 | } |
andrewbonney | 0:ec559500a63f | 248 | |
andrewbonney | 0:ec559500a63f | 249 | UsbErr UsbDevice::controlReceive(byte requestType, byte request, word value, word index, const byte* buf, int len) |
andrewbonney | 0:ec559500a63f | 250 | { |
andrewbonney | 0:ec559500a63f | 251 | UsbErr rc; |
andrewbonney | 0:ec559500a63f | 252 | fillControlBuf(requestType, request, value, index, len); |
andrewbonney | 0:ec559500a63f | 253 | m_pControlEp->setNextToken(TD_SETUP); |
andrewbonney | 0:ec559500a63f | 254 | rc = m_pControlEp->transfer(m_controlBuf, 8); |
andrewbonney | 0:ec559500a63f | 255 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 256 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 257 | if(rc) |
andrewbonney | 0:ec559500a63f | 258 | return rc; |
andrewbonney | 0:ec559500a63f | 259 | if(len) |
andrewbonney | 0:ec559500a63f | 260 | { |
andrewbonney | 0:ec559500a63f | 261 | m_pControlEp->setNextToken(TD_IN); |
andrewbonney | 0:ec559500a63f | 262 | rc = m_pControlEp->transfer( (byte*) buf, len); |
andrewbonney | 0:ec559500a63f | 263 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 264 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 265 | if(rc) |
andrewbonney | 0:ec559500a63f | 266 | return rc; |
andrewbonney | 0:ec559500a63f | 267 | } |
andrewbonney | 0:ec559500a63f | 268 | m_pControlEp->setNextToken(TD_OUT); |
andrewbonney | 0:ec559500a63f | 269 | rc = m_pControlEp->transfer(NULL, 0); |
andrewbonney | 0:ec559500a63f | 270 | while(m_pControlEp->status() == USBERR_PROCESSING); |
andrewbonney | 0:ec559500a63f | 271 | rc = (UsbErr) MIN(0, m_pControlEp->status()); |
andrewbonney | 0:ec559500a63f | 272 | if(rc) |
andrewbonney | 0:ec559500a63f | 273 | return rc; |
andrewbonney | 0:ec559500a63f | 274 | return USBERR_OK; |
andrewbonney | 0:ec559500a63f | 275 | } |
andrewbonney | 0:ec559500a63f | 276 | |
andrewbonney | 0:ec559500a63f | 277 | void UsbDevice::fillControlBuf(byte requestType, byte request, word value, word index, int len) |
andrewbonney | 0:ec559500a63f | 278 | { |
andrewbonney | 0:ec559500a63f | 279 | #ifdef __BIG_ENDIAN |
andrewbonney | 0:ec559500a63f | 280 | #error "Must implement BE to LE conv here" |
andrewbonney | 0:ec559500a63f | 281 | #endif |
andrewbonney | 0:ec559500a63f | 282 | m_controlBuf[0] = requestType; |
andrewbonney | 0:ec559500a63f | 283 | m_controlBuf[1] = request; |
andrewbonney | 0:ec559500a63f | 284 | //We are in LE so it's fine |
andrewbonney | 0:ec559500a63f | 285 | *((word*)&m_controlBuf[2]) = value; |
andrewbonney | 0:ec559500a63f | 286 | *((word*)&m_controlBuf[4]) = index; |
andrewbonney | 0:ec559500a63f | 287 | *((word*)&m_controlBuf[6]) = (word) len; |
andrewbonney | 0:ec559500a63f | 288 | } |
andrewbonney | 0:ec559500a63f | 289 | |
andrewbonney | 0:ec559500a63f | 290 | |
andrewbonney | 0:ec559500a63f | 291 | #endif |