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