I changed one line of code in the file with path name: USBDeviceHT/targets/TARGET_Maxim
Fork of USBDeviceHT by
targets/TARGET_Silicon_Labs/src/em_usbdep.c@6:c1f162fd7777, 2018-06-01 (annotated)
- Committer:
- dev_alexander
- Date:
- Fri Jun 01 21:43:55 2018 +0000
- Revision:
- 6:c1f162fd7777
- Parent:
- 0:a3ea811f80f2
Fixed Error with code not compiling due to an issue with there not being a (uint32_t) cast of a (void) pointer. Maxim was the only mbed vendor to not have this one (uint32_t) cast in the spot it was added to. Look into public repos for similar cases.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Helmut64 | 0:a3ea811f80f2 | 1 | /**************************************************************************//** |
Helmut64 | 0:a3ea811f80f2 | 2 | * @file em_usbdep.c |
Helmut64 | 0:a3ea811f80f2 | 3 | * @brief USB protocol stack library, USB device endpoint handlers. |
Helmut64 | 0:a3ea811f80f2 | 4 | * @version 3.20.14 |
Helmut64 | 0:a3ea811f80f2 | 5 | ****************************************************************************** |
Helmut64 | 0:a3ea811f80f2 | 6 | * @section License |
Helmut64 | 0:a3ea811f80f2 | 7 | * <b>(C) Copyright 2014 Silicon Labs, http://www.silabs.com</b> |
Helmut64 | 0:a3ea811f80f2 | 8 | ******************************************************************************* |
Helmut64 | 0:a3ea811f80f2 | 9 | * |
Helmut64 | 0:a3ea811f80f2 | 10 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Helmut64 | 0:a3ea811f80f2 | 11 | * you may not use this file except in compliance with the License. |
Helmut64 | 0:a3ea811f80f2 | 12 | * You may obtain a copy of the License at |
Helmut64 | 0:a3ea811f80f2 | 13 | * |
Helmut64 | 0:a3ea811f80f2 | 14 | * http://www.apache.org/licenses/LICENSE-2.0 |
Helmut64 | 0:a3ea811f80f2 | 15 | * |
Helmut64 | 0:a3ea811f80f2 | 16 | * Unless required by applicable law or agreed to in writing, software |
Helmut64 | 0:a3ea811f80f2 | 17 | * distributed under the License is distributed on an "AS IS" BASIS, |
Helmut64 | 0:a3ea811f80f2 | 18 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Helmut64 | 0:a3ea811f80f2 | 19 | * See the License for the specific language governing permissions and |
Helmut64 | 0:a3ea811f80f2 | 20 | * limitations under the License. |
Helmut64 | 0:a3ea811f80f2 | 21 | * |
Helmut64 | 0:a3ea811f80f2 | 22 | ******************************************************************************/ |
Helmut64 | 0:a3ea811f80f2 | 23 | |
Helmut64 | 0:a3ea811f80f2 | 24 | #include "em_device.h" |
Helmut64 | 0:a3ea811f80f2 | 25 | #if defined( USB_PRESENT ) && ( USB_COUNT == 1 ) |
Helmut64 | 0:a3ea811f80f2 | 26 | #include "em_usb.h" |
Helmut64 | 0:a3ea811f80f2 | 27 | #if defined( USB_DEVICE ) |
Helmut64 | 0:a3ea811f80f2 | 28 | |
Helmut64 | 0:a3ea811f80f2 | 29 | #include "em_usbtypes.h" |
Helmut64 | 0:a3ea811f80f2 | 30 | #include "em_usbhal.h" |
Helmut64 | 0:a3ea811f80f2 | 31 | #include "em_usbd.h" |
Helmut64 | 0:a3ea811f80f2 | 32 | |
Helmut64 | 0:a3ea811f80f2 | 33 | #ifdef USB_USE_PRINTF |
Helmut64 | 0:a3ea811f80f2 | 34 | static const char *epStatusStr[] = { |
Helmut64 | 0:a3ea811f80f2 | 35 | "IDLE","TRANS","RECV","IN_S","OUT_S" |
Helmut64 | 0:a3ea811f80f2 | 36 | }; |
Helmut64 | 0:a3ea811f80f2 | 37 | #endif |
Helmut64 | 0:a3ea811f80f2 | 38 | |
Helmut64 | 0:a3ea811f80f2 | 39 | /** @cond DO_NOT_INCLUDE_WITH_DOXYGEN */ |
Helmut64 | 0:a3ea811f80f2 | 40 | |
Helmut64 | 0:a3ea811f80f2 | 41 | /* |
Helmut64 | 0:a3ea811f80f2 | 42 | * USBDEP_Ep0Handler() is called each time a packet has been transmitted |
Helmut64 | 0:a3ea811f80f2 | 43 | * or recieved on the default endpoint. |
Helmut64 | 0:a3ea811f80f2 | 44 | * A state machine navigate us through the phases of a control transfer |
Helmut64 | 0:a3ea811f80f2 | 45 | * according to "chapter 9" in the USB spec. |
Helmut64 | 0:a3ea811f80f2 | 46 | */ |
Helmut64 | 0:a3ea811f80f2 | 47 | #if !defined( USB_DOEP0INT_STUPPKTRCVD ) |
Helmut64 | 0:a3ea811f80f2 | 48 | void USBDEP_Ep0Handler( USBD_Device_TypeDef *device ) |
Helmut64 | 0:a3ea811f80f2 | 49 | { |
Helmut64 | 0:a3ea811f80f2 | 50 | int status; |
Helmut64 | 0:a3ea811f80f2 | 51 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 52 | static bool statusIn; |
Helmut64 | 0:a3ea811f80f2 | 53 | static uint32_t xferred; |
Helmut64 | 0:a3ea811f80f2 | 54 | static USB_XferCompleteCb_TypeDef callback; |
Helmut64 | 0:a3ea811f80f2 | 55 | |
Helmut64 | 0:a3ea811f80f2 | 56 | ep = &device->ep[ 0 ]; |
Helmut64 | 0:a3ea811f80f2 | 57 | |
Helmut64 | 0:a3ea811f80f2 | 58 | #ifdef __MBED__ |
Helmut64 | 0:a3ea811f80f2 | 59 | |
Helmut64 | 0:a3ea811f80f2 | 60 | (void)xferred; |
Helmut64 | 0:a3ea811f80f2 | 61 | (void)statusIn; |
Helmut64 | 0:a3ea811f80f2 | 62 | (void)status; |
Helmut64 | 0:a3ea811f80f2 | 63 | |
Helmut64 | 0:a3ea811f80f2 | 64 | USB_PRINTF("USBDEP: ep0 %s, rem %ld, z %d\n", epStatusStr[ep->state], ep->remaining, ep->zlp); |
Helmut64 | 0:a3ea811f80f2 | 65 | |
Helmut64 | 0:a3ea811f80f2 | 66 | if ( ( ep->state == D_EP_TRANSMITTING ) || ( ep->state == D_EP_RECEIVING ) ) |
Helmut64 | 0:a3ea811f80f2 | 67 | { |
Helmut64 | 0:a3ea811f80f2 | 68 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 69 | |
Helmut64 | 0:a3ea811f80f2 | 70 | if ( ep->xferCompleteCb ) |
Helmut64 | 0:a3ea811f80f2 | 71 | { |
Helmut64 | 0:a3ea811f80f2 | 72 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 73 | ep->xferCompleteCb = NULL; |
Helmut64 | 0:a3ea811f80f2 | 74 | callback( USB_STATUS_OK, ep->xferred, ep->remaining ); |
Helmut64 | 0:a3ea811f80f2 | 75 | } |
Helmut64 | 0:a3ea811f80f2 | 76 | |
Helmut64 | 0:a3ea811f80f2 | 77 | USBDHAL_ReenableEp0Setup(device); |
Helmut64 | 0:a3ea811f80f2 | 78 | } |
Helmut64 | 0:a3ea811f80f2 | 79 | else |
Helmut64 | 0:a3ea811f80f2 | 80 | { |
Helmut64 | 0:a3ea811f80f2 | 81 | device->callbacks->setupCmd(device->setup); |
Helmut64 | 0:a3ea811f80f2 | 82 | } |
Helmut64 | 0:a3ea811f80f2 | 83 | |
Helmut64 | 0:a3ea811f80f2 | 84 | #else /* not __MBED__ */ |
Helmut64 | 0:a3ea811f80f2 | 85 | |
Helmut64 | 0:a3ea811f80f2 | 86 | switch ( ep->state ) |
Helmut64 | 0:a3ea811f80f2 | 87 | { |
Helmut64 | 0:a3ea811f80f2 | 88 | case D_EP_IDLE: |
Helmut64 | 0:a3ea811f80f2 | 89 | ep->remaining = 0; |
Helmut64 | 0:a3ea811f80f2 | 90 | ep->zlp = 0; |
Helmut64 | 0:a3ea811f80f2 | 91 | callback = NULL; |
Helmut64 | 0:a3ea811f80f2 | 92 | statusIn = false; |
Helmut64 | 0:a3ea811f80f2 | 93 | |
Helmut64 | 0:a3ea811f80f2 | 94 | status = USBDCH9_SetupCmd( device ); |
Helmut64 | 0:a3ea811f80f2 | 95 | |
Helmut64 | 0:a3ea811f80f2 | 96 | if ( status == USB_STATUS_REQ_ERR ) |
Helmut64 | 0:a3ea811f80f2 | 97 | { |
Helmut64 | 0:a3ea811f80f2 | 98 | ep->in = true; |
Helmut64 | 0:a3ea811f80f2 | 99 | USBDHAL_StallEp( ep ); /* Stall Ep0 IN */ |
Helmut64 | 0:a3ea811f80f2 | 100 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 101 | USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */ |
Helmut64 | 0:a3ea811f80f2 | 102 | USBDHAL_ReenableEp0Setup( device ); /* Prepare for next SETUP packet*/ |
Helmut64 | 0:a3ea811f80f2 | 103 | } |
Helmut64 | 0:a3ea811f80f2 | 104 | else /* ( Status == USB_STATUS_OK ) */ |
Helmut64 | 0:a3ea811f80f2 | 105 | { |
Helmut64 | 0:a3ea811f80f2 | 106 | if ( (ep->state == D_EP_RECEIVING) || (ep->state == D_EP_TRANSMITTING) ) |
Helmut64 | 0:a3ea811f80f2 | 107 | { |
Helmut64 | 0:a3ea811f80f2 | 108 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 109 | } |
Helmut64 | 0:a3ea811f80f2 | 110 | |
Helmut64 | 0:a3ea811f80f2 | 111 | if ( ep->state != D_EP_RECEIVING ) |
Helmut64 | 0:a3ea811f80f2 | 112 | { |
Helmut64 | 0:a3ea811f80f2 | 113 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 114 | { |
Helmut64 | 0:a3ea811f80f2 | 115 | /* Data will be sent to host, check if a ZLP must be appended */ |
Helmut64 | 0:a3ea811f80f2 | 116 | if ( ( ep->remaining < device->setup->wLength ) && |
Helmut64 | 0:a3ea811f80f2 | 117 | ( ep->remaining % ep->packetSize == 0 ) ) |
Helmut64 | 0:a3ea811f80f2 | 118 | { |
Helmut64 | 0:a3ea811f80f2 | 119 | ep->zlp = 1; |
Helmut64 | 0:a3ea811f80f2 | 120 | } |
Helmut64 | 0:a3ea811f80f2 | 121 | } |
Helmut64 | 0:a3ea811f80f2 | 122 | else |
Helmut64 | 0:a3ea811f80f2 | 123 | { |
Helmut64 | 0:a3ea811f80f2 | 124 | /* Prepare for next SETUP packet*/ |
Helmut64 | 0:a3ea811f80f2 | 125 | USBDHAL_ReenableEp0Setup( device ); |
Helmut64 | 0:a3ea811f80f2 | 126 | |
Helmut64 | 0:a3ea811f80f2 | 127 | /* No data stage, a ZLP may have been sent. If not, send one */ |
Helmut64 | 0:a3ea811f80f2 | 128 | |
Helmut64 | 0:a3ea811f80f2 | 129 | xferred = 0; |
Helmut64 | 0:a3ea811f80f2 | 130 | if ( ep->zlp == 0 ) |
Helmut64 | 0:a3ea811f80f2 | 131 | { |
Helmut64 | 0:a3ea811f80f2 | 132 | USBD_Write( 0, NULL, 0, NULL ); /* ACK to host */ |
Helmut64 | 0:a3ea811f80f2 | 133 | ep->state = D_EP0_IN_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 134 | } |
Helmut64 | 0:a3ea811f80f2 | 135 | else |
Helmut64 | 0:a3ea811f80f2 | 136 | { |
Helmut64 | 0:a3ea811f80f2 | 137 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 138 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 139 | } |
Helmut64 | 0:a3ea811f80f2 | 140 | } |
Helmut64 | 0:a3ea811f80f2 | 141 | } |
Helmut64 | 0:a3ea811f80f2 | 142 | } |
Helmut64 | 0:a3ea811f80f2 | 143 | break; |
Helmut64 | 0:a3ea811f80f2 | 144 | |
Helmut64 | 0:a3ea811f80f2 | 145 | case D_EP_RECEIVING: |
Helmut64 | 0:a3ea811f80f2 | 146 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 147 | { |
Helmut64 | 0:a3ea811f80f2 | 148 | /* There is more data to receive */ |
Helmut64 | 0:a3ea811f80f2 | 149 | USBD_ReArmEp0( ep ); |
Helmut64 | 0:a3ea811f80f2 | 150 | } |
Helmut64 | 0:a3ea811f80f2 | 151 | else |
Helmut64 | 0:a3ea811f80f2 | 152 | { |
Helmut64 | 0:a3ea811f80f2 | 153 | status = USB_STATUS_OK; |
Helmut64 | 0:a3ea811f80f2 | 154 | if ( callback != NULL ) |
Helmut64 | 0:a3ea811f80f2 | 155 | { |
Helmut64 | 0:a3ea811f80f2 | 156 | status = callback( USB_STATUS_OK, ep->xferred, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 157 | callback = NULL; |
Helmut64 | 0:a3ea811f80f2 | 158 | } |
Helmut64 | 0:a3ea811f80f2 | 159 | |
Helmut64 | 0:a3ea811f80f2 | 160 | if ( status != USB_STATUS_OK ) |
Helmut64 | 0:a3ea811f80f2 | 161 | { |
Helmut64 | 0:a3ea811f80f2 | 162 | ep->in = true; |
Helmut64 | 0:a3ea811f80f2 | 163 | USBDHAL_StallEp( ep ); /* Stall Ep0 IN */ |
Helmut64 | 0:a3ea811f80f2 | 164 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 165 | USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */ |
Helmut64 | 0:a3ea811f80f2 | 166 | USBDHAL_ReenableEp0Setup( device ); /* Prepare for next SETUP pkt. */ |
Helmut64 | 0:a3ea811f80f2 | 167 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 168 | } |
Helmut64 | 0:a3ea811f80f2 | 169 | else /* Everything OK, send a ZLP (ACK) to host */ |
Helmut64 | 0:a3ea811f80f2 | 170 | { |
Helmut64 | 0:a3ea811f80f2 | 171 | USBDHAL_ReenableEp0Setup( device );/* Prepare for next SETUP packet*/ |
Helmut64 | 0:a3ea811f80f2 | 172 | |
Helmut64 | 0:a3ea811f80f2 | 173 | ep->state = D_EP_IDLE; /* USBD_Write() sets state back*/ |
Helmut64 | 0:a3ea811f80f2 | 174 | /* to EP_TRANSMITTING */ |
Helmut64 | 0:a3ea811f80f2 | 175 | USBD_Write( 0, NULL, 0, NULL ); |
Helmut64 | 0:a3ea811f80f2 | 176 | ep->state = D_EP0_IN_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 177 | } |
Helmut64 | 0:a3ea811f80f2 | 178 | } |
Helmut64 | 0:a3ea811f80f2 | 179 | break; |
Helmut64 | 0:a3ea811f80f2 | 180 | |
Helmut64 | 0:a3ea811f80f2 | 181 | case D_EP_TRANSMITTING: |
Helmut64 | 0:a3ea811f80f2 | 182 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 183 | { |
Helmut64 | 0:a3ea811f80f2 | 184 | /* There is more data to transmit */ |
Helmut64 | 0:a3ea811f80f2 | 185 | USBD_ReArmEp0( ep ); |
Helmut64 | 0:a3ea811f80f2 | 186 | } |
Helmut64 | 0:a3ea811f80f2 | 187 | else |
Helmut64 | 0:a3ea811f80f2 | 188 | { |
Helmut64 | 0:a3ea811f80f2 | 189 | /* All data transferred, is a ZLP packet needed ? */ |
Helmut64 | 0:a3ea811f80f2 | 190 | if ( ep->zlp == 1 ) |
Helmut64 | 0:a3ea811f80f2 | 191 | { |
Helmut64 | 0:a3ea811f80f2 | 192 | xferred = ep->xferred; |
Helmut64 | 0:a3ea811f80f2 | 193 | ep->state = D_EP_IDLE; /* USBD_Write() sets state back */ |
Helmut64 | 0:a3ea811f80f2 | 194 | /* to EP_TRANSMITTING */ |
Helmut64 | 0:a3ea811f80f2 | 195 | USBD_Write( 0, NULL, 0, NULL ); /* Send ZLP */ |
Helmut64 | 0:a3ea811f80f2 | 196 | ep->zlp = 2; |
Helmut64 | 0:a3ea811f80f2 | 197 | } |
Helmut64 | 0:a3ea811f80f2 | 198 | else |
Helmut64 | 0:a3ea811f80f2 | 199 | { |
Helmut64 | 0:a3ea811f80f2 | 200 | if ( ep->zlp == 0 ) |
Helmut64 | 0:a3ea811f80f2 | 201 | { |
Helmut64 | 0:a3ea811f80f2 | 202 | xferred = ep->xferred; |
Helmut64 | 0:a3ea811f80f2 | 203 | } |
Helmut64 | 0:a3ea811f80f2 | 204 | |
Helmut64 | 0:a3ea811f80f2 | 205 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 206 | USBD_Read( 0, NULL, 0, NULL ); /* Get ZLP packet (ACK) from host */ |
Helmut64 | 0:a3ea811f80f2 | 207 | statusIn = true; |
Helmut64 | 0:a3ea811f80f2 | 208 | ep->state = D_EP0_OUT_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 209 | } |
Helmut64 | 0:a3ea811f80f2 | 210 | } |
Helmut64 | 0:a3ea811f80f2 | 211 | break; |
Helmut64 | 0:a3ea811f80f2 | 212 | |
Helmut64 | 0:a3ea811f80f2 | 213 | case D_EP0_IN_STATUS: |
Helmut64 | 0:a3ea811f80f2 | 214 | case D_EP0_OUT_STATUS: |
Helmut64 | 0:a3ea811f80f2 | 215 | if ( statusIn ) |
Helmut64 | 0:a3ea811f80f2 | 216 | { |
Helmut64 | 0:a3ea811f80f2 | 217 | USBDHAL_ReenableEp0Setup( device ); |
Helmut64 | 0:a3ea811f80f2 | 218 | } |
Helmut64 | 0:a3ea811f80f2 | 219 | |
Helmut64 | 0:a3ea811f80f2 | 220 | if ( callback != NULL ) |
Helmut64 | 0:a3ea811f80f2 | 221 | { |
Helmut64 | 0:a3ea811f80f2 | 222 | callback( USB_STATUS_OK, xferred, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 223 | } |
Helmut64 | 0:a3ea811f80f2 | 224 | |
Helmut64 | 0:a3ea811f80f2 | 225 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 226 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 227 | break; |
Helmut64 | 0:a3ea811f80f2 | 228 | |
Helmut64 | 0:a3ea811f80f2 | 229 | default: |
Helmut64 | 0:a3ea811f80f2 | 230 | EFM_ASSERT( false ); |
Helmut64 | 0:a3ea811f80f2 | 231 | break; |
Helmut64 | 0:a3ea811f80f2 | 232 | } |
Helmut64 | 0:a3ea811f80f2 | 233 | #endif /* __MBED__ */ |
Helmut64 | 0:a3ea811f80f2 | 234 | } |
Helmut64 | 0:a3ea811f80f2 | 235 | #endif |
Helmut64 | 0:a3ea811f80f2 | 236 | |
Helmut64 | 0:a3ea811f80f2 | 237 | #if defined( USB_DOEP0INT_STUPPKTRCVD ) |
Helmut64 | 0:a3ea811f80f2 | 238 | void USBDEP_Ep0Handler( USBD_Device_TypeDef *device ) |
Helmut64 | 0:a3ea811f80f2 | 239 | { |
Helmut64 | 0:a3ea811f80f2 | 240 | int status; |
Helmut64 | 0:a3ea811f80f2 | 241 | USBD_Ep_TypeDef *ep; |
Helmut64 | 0:a3ea811f80f2 | 242 | static uint32_t xferred; |
Helmut64 | 0:a3ea811f80f2 | 243 | static USB_XferCompleteCb_TypeDef callback; |
Helmut64 | 0:a3ea811f80f2 | 244 | |
Helmut64 | 0:a3ea811f80f2 | 245 | #ifdef __MBED__ |
Helmut64 | 0:a3ea811f80f2 | 246 | |
Helmut64 | 0:a3ea811f80f2 | 247 | (void)xferred; |
Helmut64 | 0:a3ea811f80f2 | 248 | (void)status; |
Helmut64 | 0:a3ea811f80f2 | 249 | |
Helmut64 | 0:a3ea811f80f2 | 250 | ep = &device->ep[ 0 ]; |
Helmut64 | 0:a3ea811f80f2 | 251 | |
Helmut64 | 0:a3ea811f80f2 | 252 | if ( ( ep->state == D_EP_TRANSMITTING ) || ( ep->state == D_EP_RECEIVING ) ) |
Helmut64 | 0:a3ea811f80f2 | 253 | { |
Helmut64 | 0:a3ea811f80f2 | 254 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 255 | |
Helmut64 | 0:a3ea811f80f2 | 256 | if ( ep->xferCompleteCb ) |
Helmut64 | 0:a3ea811f80f2 | 257 | { |
Helmut64 | 0:a3ea811f80f2 | 258 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 259 | ep->xferCompleteCb = NULL; |
Helmut64 | 0:a3ea811f80f2 | 260 | callback( USB_STATUS_OK, ep->xferred, ep->remaining ); |
Helmut64 | 0:a3ea811f80f2 | 261 | } |
Helmut64 | 0:a3ea811f80f2 | 262 | |
Helmut64 | 0:a3ea811f80f2 | 263 | USBDHAL_StartEp0Setup( dev ); |
Helmut64 | 0:a3ea811f80f2 | 264 | } |
Helmut64 | 0:a3ea811f80f2 | 265 | else |
Helmut64 | 0:a3ea811f80f2 | 266 | { |
Helmut64 | 0:a3ea811f80f2 | 267 | device->callbacks->setupCmd(device->setup); |
Helmut64 | 0:a3ea811f80f2 | 268 | } |
Helmut64 | 0:a3ea811f80f2 | 269 | |
Helmut64 | 0:a3ea811f80f2 | 270 | #else |
Helmut64 | 0:a3ea811f80f2 | 271 | |
Helmut64 | 0:a3ea811f80f2 | 272 | ep = &device->ep[ 0 ]; |
Helmut64 | 0:a3ea811f80f2 | 273 | |
Helmut64 | 0:a3ea811f80f2 | 274 | switch ( ep->state ) |
Helmut64 | 0:a3ea811f80f2 | 275 | { |
Helmut64 | 0:a3ea811f80f2 | 276 | case D_EP_IDLE: |
Helmut64 | 0:a3ea811f80f2 | 277 | ep->zlp = 0; |
Helmut64 | 0:a3ea811f80f2 | 278 | ep->remaining = 0; |
Helmut64 | 0:a3ea811f80f2 | 279 | callback = NULL; |
Helmut64 | 0:a3ea811f80f2 | 280 | |
Helmut64 | 0:a3ea811f80f2 | 281 | status = USBDCH9_SetupCmd( device ); |
Helmut64 | 0:a3ea811f80f2 | 282 | |
Helmut64 | 0:a3ea811f80f2 | 283 | if ( status == USB_STATUS_REQ_ERR ) |
Helmut64 | 0:a3ea811f80f2 | 284 | { |
Helmut64 | 0:a3ea811f80f2 | 285 | ep->in = true; |
Helmut64 | 0:a3ea811f80f2 | 286 | USBDHAL_StallEp( ep ); /* Stall Ep0 IN */ |
Helmut64 | 0:a3ea811f80f2 | 287 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 288 | USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */ |
Helmut64 | 0:a3ea811f80f2 | 289 | USBDHAL_StartEp0Setup( dev ); /* Prepare for next SETUP packet*/ |
Helmut64 | 0:a3ea811f80f2 | 290 | } |
Helmut64 | 0:a3ea811f80f2 | 291 | else /* ( Status == USB_STATUS_OK ) */ |
Helmut64 | 0:a3ea811f80f2 | 292 | { |
Helmut64 | 0:a3ea811f80f2 | 293 | if ( (ep->state == D_EP_RECEIVING) || (ep->state == D_EP_TRANSMITTING) ) |
Helmut64 | 0:a3ea811f80f2 | 294 | { |
Helmut64 | 0:a3ea811f80f2 | 295 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 296 | } |
Helmut64 | 0:a3ea811f80f2 | 297 | |
Helmut64 | 0:a3ea811f80f2 | 298 | if ( ep->state != D_EP_RECEIVING ) |
Helmut64 | 0:a3ea811f80f2 | 299 | { |
Helmut64 | 0:a3ea811f80f2 | 300 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 301 | { |
Helmut64 | 0:a3ea811f80f2 | 302 | /* Data will be sent to host, check if a ZLP must be appended */ |
Helmut64 | 0:a3ea811f80f2 | 303 | if ( ( ep->remaining < device->setup->wLength ) && |
Helmut64 | 0:a3ea811f80f2 | 304 | ( ep->remaining % ep->packetSize == 0 ) ) |
Helmut64 | 0:a3ea811f80f2 | 305 | { |
Helmut64 | 0:a3ea811f80f2 | 306 | ep->zlp = 1; |
Helmut64 | 0:a3ea811f80f2 | 307 | } |
Helmut64 | 0:a3ea811f80f2 | 308 | } |
Helmut64 | 0:a3ea811f80f2 | 309 | else |
Helmut64 | 0:a3ea811f80f2 | 310 | { |
Helmut64 | 0:a3ea811f80f2 | 311 | /* No data stage, a ZLP may have been sent. If not, send one */ |
Helmut64 | 0:a3ea811f80f2 | 312 | xferred = 0; |
Helmut64 | 0:a3ea811f80f2 | 313 | if ( ep->zlp == 0 ) |
Helmut64 | 0:a3ea811f80f2 | 314 | { |
Helmut64 | 0:a3ea811f80f2 | 315 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 316 | USBD_Write( 0, NULL, 0, NULL ); /* ACK to host */ |
Helmut64 | 0:a3ea811f80f2 | 317 | ep->state = D_EP0_IN_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 318 | } |
Helmut64 | 0:a3ea811f80f2 | 319 | } |
Helmut64 | 0:a3ea811f80f2 | 320 | } |
Helmut64 | 0:a3ea811f80f2 | 321 | } |
Helmut64 | 0:a3ea811f80f2 | 322 | break; |
Helmut64 | 0:a3ea811f80f2 | 323 | |
Helmut64 | 0:a3ea811f80f2 | 324 | case D_EP_RECEIVING: |
Helmut64 | 0:a3ea811f80f2 | 325 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 326 | { |
Helmut64 | 0:a3ea811f80f2 | 327 | ep->in = false; |
Helmut64 | 0:a3ea811f80f2 | 328 | USBD_ReArmEp0( ep ); |
Helmut64 | 0:a3ea811f80f2 | 329 | } |
Helmut64 | 0:a3ea811f80f2 | 330 | else |
Helmut64 | 0:a3ea811f80f2 | 331 | { |
Helmut64 | 0:a3ea811f80f2 | 332 | status = USB_STATUS_OK; |
Helmut64 | 0:a3ea811f80f2 | 333 | if ( callback != NULL ) |
Helmut64 | 0:a3ea811f80f2 | 334 | { |
Helmut64 | 0:a3ea811f80f2 | 335 | status = callback( USB_STATUS_OK, ep->xferred, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 336 | callback = NULL; |
Helmut64 | 0:a3ea811f80f2 | 337 | } |
Helmut64 | 0:a3ea811f80f2 | 338 | |
Helmut64 | 0:a3ea811f80f2 | 339 | if ( status != USB_STATUS_OK ) |
Helmut64 | 0:a3ea811f80f2 | 340 | { |
Helmut64 | 0:a3ea811f80f2 | 341 | ep->in = true; |
Helmut64 | 0:a3ea811f80f2 | 342 | USBDHAL_StallEp( ep ); /* Stall Ep0 IN */ |
Helmut64 | 0:a3ea811f80f2 | 343 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 344 | USBDHAL_StallEp( ep ); /* Stall Ep0 OUT */ |
Helmut64 | 0:a3ea811f80f2 | 345 | USBDHAL_StartEp0Setup( dev ); /* Prepare for next SETUP pkt. */ |
Helmut64 | 0:a3ea811f80f2 | 346 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 347 | } |
Helmut64 | 0:a3ea811f80f2 | 348 | else |
Helmut64 | 0:a3ea811f80f2 | 349 | { |
Helmut64 | 0:a3ea811f80f2 | 350 | |
Helmut64 | 0:a3ea811f80f2 | 351 | USBDHAL_StartEp0Setup( dev ); /* Prepare for next SETUP packet*/ |
Helmut64 | 0:a3ea811f80f2 | 352 | ep->state = D_EP_IDLE; /* USBD_Write() sets state back */ |
Helmut64 | 0:a3ea811f80f2 | 353 | /* to EP_TRANSMITTING */ |
Helmut64 | 0:a3ea811f80f2 | 354 | USBD_Write( 0, NULL, 0, NULL ); |
Helmut64 | 0:a3ea811f80f2 | 355 | ep->state = D_EP0_IN_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 356 | } |
Helmut64 | 0:a3ea811f80f2 | 357 | } |
Helmut64 | 0:a3ea811f80f2 | 358 | break; |
Helmut64 | 0:a3ea811f80f2 | 359 | |
Helmut64 | 0:a3ea811f80f2 | 360 | case D_EP_TRANSMITTING: |
Helmut64 | 0:a3ea811f80f2 | 361 | if ( ep->remaining ) |
Helmut64 | 0:a3ea811f80f2 | 362 | { |
Helmut64 | 0:a3ea811f80f2 | 363 | ep->in = true; |
Helmut64 | 0:a3ea811f80f2 | 364 | USBD_ReArmEp0( ep ); |
Helmut64 | 0:a3ea811f80f2 | 365 | } |
Helmut64 | 0:a3ea811f80f2 | 366 | else |
Helmut64 | 0:a3ea811f80f2 | 367 | { |
Helmut64 | 0:a3ea811f80f2 | 368 | if ( ep->zlp == 1 ) |
Helmut64 | 0:a3ea811f80f2 | 369 | { |
Helmut64 | 0:a3ea811f80f2 | 370 | xferred = ep->xferred; |
Helmut64 | 0:a3ea811f80f2 | 371 | ep->state = D_EP_IDLE; /* USBD_Write() sets state back */ |
Helmut64 | 0:a3ea811f80f2 | 372 | /* to EP_TRANSMITTING */ |
Helmut64 | 0:a3ea811f80f2 | 373 | USBD_Write( 0, NULL, 0, NULL ); /* Send ZLP */ |
Helmut64 | 0:a3ea811f80f2 | 374 | ep->zlp = 2; |
Helmut64 | 0:a3ea811f80f2 | 375 | } |
Helmut64 | 0:a3ea811f80f2 | 376 | else |
Helmut64 | 0:a3ea811f80f2 | 377 | { |
Helmut64 | 0:a3ea811f80f2 | 378 | if ( ep->zlp == 0 ) |
Helmut64 | 0:a3ea811f80f2 | 379 | { |
Helmut64 | 0:a3ea811f80f2 | 380 | xferred = ep->xferred; |
Helmut64 | 0:a3ea811f80f2 | 381 | } |
Helmut64 | 0:a3ea811f80f2 | 382 | |
Helmut64 | 0:a3ea811f80f2 | 383 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 384 | USBD_Read( 0, NULL, 0, NULL ); /* Get ZLP packet (ACK) from host */ |
Helmut64 | 0:a3ea811f80f2 | 385 | ep->state = D_EP0_OUT_STATUS; |
Helmut64 | 0:a3ea811f80f2 | 386 | } |
Helmut64 | 0:a3ea811f80f2 | 387 | } |
Helmut64 | 0:a3ea811f80f2 | 388 | break; |
Helmut64 | 0:a3ea811f80f2 | 389 | |
Helmut64 | 0:a3ea811f80f2 | 390 | case D_EP0_IN_STATUS: |
Helmut64 | 0:a3ea811f80f2 | 391 | if ( ( USB->DOEP0CTL & USB_DOEP0CTL_EPENA ) == 0 ) |
Helmut64 | 0:a3ea811f80f2 | 392 | { |
Helmut64 | 0:a3ea811f80f2 | 393 | /* Prepare for more SETUP Packets */ |
Helmut64 | 0:a3ea811f80f2 | 394 | USBDHAL_StartEp0Setup( dev ); |
Helmut64 | 0:a3ea811f80f2 | 395 | } |
Helmut64 | 0:a3ea811f80f2 | 396 | if ( callback != NULL ) |
Helmut64 | 0:a3ea811f80f2 | 397 | { |
Helmut64 | 0:a3ea811f80f2 | 398 | callback( USB_STATUS_OK, xferred, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 399 | } |
Helmut64 | 0:a3ea811f80f2 | 400 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 401 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 402 | break; |
Helmut64 | 0:a3ea811f80f2 | 403 | |
Helmut64 | 0:a3ea811f80f2 | 404 | case D_EP0_OUT_STATUS: |
Helmut64 | 0:a3ea811f80f2 | 405 | USBDHAL_StartEp0Setup( dev ); /* Prepare for more SETUP Packets */ |
Helmut64 | 0:a3ea811f80f2 | 406 | if ( callback != NULL ) |
Helmut64 | 0:a3ea811f80f2 | 407 | { |
Helmut64 | 0:a3ea811f80f2 | 408 | callback( USB_STATUS_OK, xferred, 0 ); |
Helmut64 | 0:a3ea811f80f2 | 409 | } |
Helmut64 | 0:a3ea811f80f2 | 410 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 411 | ep->in = false; /* OUT for next SETUP */ |
Helmut64 | 0:a3ea811f80f2 | 412 | break; |
Helmut64 | 0:a3ea811f80f2 | 413 | } |
Helmut64 | 0:a3ea811f80f2 | 414 | #endif /* __MBED__ */ |
Helmut64 | 0:a3ea811f80f2 | 415 | } |
Helmut64 | 0:a3ea811f80f2 | 416 | #endif |
Helmut64 | 0:a3ea811f80f2 | 417 | |
Helmut64 | 0:a3ea811f80f2 | 418 | /* |
Helmut64 | 0:a3ea811f80f2 | 419 | * USBDEP_EpHandler() is called each time a packet has been transmitted |
Helmut64 | 0:a3ea811f80f2 | 420 | * or recieved on an endpoint other than the default endpoint. |
Helmut64 | 0:a3ea811f80f2 | 421 | */ |
Helmut64 | 0:a3ea811f80f2 | 422 | void USBDEP_EpHandler( uint8_t epAddr ) |
Helmut64 | 0:a3ea811f80f2 | 423 | { |
Helmut64 | 0:a3ea811f80f2 | 424 | USB_XferCompleteCb_TypeDef callback; |
Helmut64 | 0:a3ea811f80f2 | 425 | USBD_Ep_TypeDef *ep = USBD_GetEpFromAddr( epAddr ); |
Helmut64 | 0:a3ea811f80f2 | 426 | |
Helmut64 | 0:a3ea811f80f2 | 427 | if ( ( ep->state == D_EP_TRANSMITTING ) || ( ep->state == D_EP_RECEIVING ) ) |
Helmut64 | 0:a3ea811f80f2 | 428 | { |
Helmut64 | 0:a3ea811f80f2 | 429 | ep->state = D_EP_IDLE; |
Helmut64 | 0:a3ea811f80f2 | 430 | if ( ep->xferCompleteCb ) |
Helmut64 | 0:a3ea811f80f2 | 431 | { |
Helmut64 | 0:a3ea811f80f2 | 432 | callback = ep->xferCompleteCb; |
Helmut64 | 0:a3ea811f80f2 | 433 | ep->xferCompleteCb = NULL; |
Helmut64 | 0:a3ea811f80f2 | 434 | callback( USB_STATUS_OK, ep->xferred, ep->remaining ); |
Helmut64 | 0:a3ea811f80f2 | 435 | } |
Helmut64 | 0:a3ea811f80f2 | 436 | } |
Helmut64 | 0:a3ea811f80f2 | 437 | else |
Helmut64 | 0:a3ea811f80f2 | 438 | { |
Helmut64 | 0:a3ea811f80f2 | 439 | EFM_ASSERT( false ); |
Helmut64 | 0:a3ea811f80f2 | 440 | } |
Helmut64 | 0:a3ea811f80f2 | 441 | } |
Helmut64 | 0:a3ea811f80f2 | 442 | |
Helmut64 | 0:a3ea811f80f2 | 443 | /** @endcond */ |
Helmut64 | 0:a3ea811f80f2 | 444 | |
Helmut64 | 0:a3ea811f80f2 | 445 | #endif /* defined( USB_DEVICE ) */ |
Helmut64 | 0:a3ea811f80f2 | 446 | #endif /* defined( USB_PRESENT ) && ( USB_COUNT == 1 ) */ |