Jason Engelman
/
USBCDC
Port of Keils USBCDC example, compiles ok. Gets stuck at init
usbcore.c@0:0b777ff85deb, 2010-07-05 (annotated)
- Committer:
- tecnosys
- Date:
- Mon Jul 05 10:16:57 2010 +0000
- Revision:
- 0:0b777ff85deb
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tecnosys | 0:0b777ff85deb | 1 | /*---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 2 | * U S B - K e r n e l |
tecnosys | 0:0b777ff85deb | 3 | *---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 4 | * Name: usbcore.c |
tecnosys | 0:0b777ff85deb | 5 | * Purpose: USB Core Module |
tecnosys | 0:0b777ff85deb | 6 | * Version: V1.20 |
tecnosys | 0:0b777ff85deb | 7 | *---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 8 | * This software is supplied "AS IS" without any warranties, express, |
tecnosys | 0:0b777ff85deb | 9 | * implied or statutory, including but not limited to the implied |
tecnosys | 0:0b777ff85deb | 10 | * warranties of fitness for purpose, satisfactory quality and |
tecnosys | 0:0b777ff85deb | 11 | * noninfringement. Keil extends you a royalty-free right to reproduce |
tecnosys | 0:0b777ff85deb | 12 | * and distribute executable files created using this software for use |
tecnosys | 0:0b777ff85deb | 13 | * on NXP Semiconductors LPC family microcontroller devices only. Nothing |
tecnosys | 0:0b777ff85deb | 14 | * else gives you the right to use this software. |
tecnosys | 0:0b777ff85deb | 15 | * |
tecnosys | 0:0b777ff85deb | 16 | * Copyright (c) 2009 Keil - An ARM Company. All rights reserved. |
tecnosys | 0:0b777ff85deb | 17 | *---------------------------------------------------------------------------- |
tecnosys | 0:0b777ff85deb | 18 | * History: |
tecnosys | 0:0b777ff85deb | 19 | * V1.20 Added vendor specific requests |
tecnosys | 0:0b777ff85deb | 20 | * Changed string descriptor handling |
tecnosys | 0:0b777ff85deb | 21 | * Reworked Endpoint0 |
tecnosys | 0:0b777ff85deb | 22 | * V1.00 Initial Version |
tecnosys | 0:0b777ff85deb | 23 | *----------------------------------------------------------------------------*/ |
tecnosys | 0:0b777ff85deb | 24 | #include "type.h" |
tecnosys | 0:0b777ff85deb | 25 | |
tecnosys | 0:0b777ff85deb | 26 | #include "usb.h" |
tecnosys | 0:0b777ff85deb | 27 | #include "usbcfg.h" |
tecnosys | 0:0b777ff85deb | 28 | #include "usbhw.h" |
tecnosys | 0:0b777ff85deb | 29 | #include "usbcore.h" |
tecnosys | 0:0b777ff85deb | 30 | #include "usbdesc.h" |
tecnosys | 0:0b777ff85deb | 31 | #include "usbuser.h" |
tecnosys | 0:0b777ff85deb | 32 | |
tecnosys | 0:0b777ff85deb | 33 | #if (USB_CLASS) |
tecnosys | 0:0b777ff85deb | 34 | |
tecnosys | 0:0b777ff85deb | 35 | #if (USB_AUDIO) |
tecnosys | 0:0b777ff85deb | 36 | #include "audio.h" |
tecnosys | 0:0b777ff85deb | 37 | #include "adcuser.h" |
tecnosys | 0:0b777ff85deb | 38 | #endif |
tecnosys | 0:0b777ff85deb | 39 | |
tecnosys | 0:0b777ff85deb | 40 | #if (USB_HID) |
tecnosys | 0:0b777ff85deb | 41 | #include "hid.h" |
tecnosys | 0:0b777ff85deb | 42 | #include "hiduser.h" |
tecnosys | 0:0b777ff85deb | 43 | #endif |
tecnosys | 0:0b777ff85deb | 44 | |
tecnosys | 0:0b777ff85deb | 45 | #if (USB_MSC) |
tecnosys | 0:0b777ff85deb | 46 | #include "msc.h" |
tecnosys | 0:0b777ff85deb | 47 | #include "mscuser.h" |
tecnosys | 0:0b777ff85deb | 48 | extern MSC_CSW CSW; |
tecnosys | 0:0b777ff85deb | 49 | #endif |
tecnosys | 0:0b777ff85deb | 50 | |
tecnosys | 0:0b777ff85deb | 51 | #if (USB_CDC) |
tecnosys | 0:0b777ff85deb | 52 | #include "cdc.h" |
tecnosys | 0:0b777ff85deb | 53 | #include "cdcuser.h" |
tecnosys | 0:0b777ff85deb | 54 | #endif |
tecnosys | 0:0b777ff85deb | 55 | |
tecnosys | 0:0b777ff85deb | 56 | #endif |
tecnosys | 0:0b777ff85deb | 57 | |
tecnosys | 0:0b777ff85deb | 58 | #if (USB_VENDOR) |
tecnosys | 0:0b777ff85deb | 59 | #include "vendor.h" |
tecnosys | 0:0b777ff85deb | 60 | #endif |
tecnosys | 0:0b777ff85deb | 61 | |
tecnosys | 0:0b777ff85deb | 62 | #pragma diag_suppress 111,1441 |
tecnosys | 0:0b777ff85deb | 63 | |
tecnosys | 0:0b777ff85deb | 64 | |
tecnosys | 0:0b777ff85deb | 65 | uint16_t USB_DeviceStatus; |
tecnosys | 0:0b777ff85deb | 66 | uint8_t USB_DeviceAddress; |
tecnosys | 0:0b777ff85deb | 67 | uint8_t USB_Configuration; |
tecnosys | 0:0b777ff85deb | 68 | uint32_t USB_EndPointMask; |
tecnosys | 0:0b777ff85deb | 69 | uint32_t USB_EndPointHalt; |
tecnosys | 0:0b777ff85deb | 70 | uint32_t USB_EndPointStall; /* EP must stay stalled */ |
tecnosys | 0:0b777ff85deb | 71 | uint8_t USB_NumInterfaces; |
tecnosys | 0:0b777ff85deb | 72 | uint8_t USB_AltSetting[USB_IF_NUM]; |
tecnosys | 0:0b777ff85deb | 73 | |
tecnosys | 0:0b777ff85deb | 74 | uint8_t EP0Buf[USB_MAX_PACKET0]; |
tecnosys | 0:0b777ff85deb | 75 | |
tecnosys | 0:0b777ff85deb | 76 | |
tecnosys | 0:0b777ff85deb | 77 | USB_EP_DATA EP0Data; |
tecnosys | 0:0b777ff85deb | 78 | |
tecnosys | 0:0b777ff85deb | 79 | USB_SETUP_PACKET SetupPacket; |
tecnosys | 0:0b777ff85deb | 80 | |
tecnosys | 0:0b777ff85deb | 81 | |
tecnosys | 0:0b777ff85deb | 82 | /* |
tecnosys | 0:0b777ff85deb | 83 | * Reset USB Core |
tecnosys | 0:0b777ff85deb | 84 | * Parameters: None |
tecnosys | 0:0b777ff85deb | 85 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 86 | */ |
tecnosys | 0:0b777ff85deb | 87 | |
tecnosys | 0:0b777ff85deb | 88 | void USB_ResetCore (void) { |
tecnosys | 0:0b777ff85deb | 89 | |
tecnosys | 0:0b777ff85deb | 90 | USB_DeviceStatus = USB_POWER; |
tecnosys | 0:0b777ff85deb | 91 | USB_DeviceAddress = 0; |
tecnosys | 0:0b777ff85deb | 92 | USB_Configuration = 0; |
tecnosys | 0:0b777ff85deb | 93 | USB_EndPointMask = 0x00010001; |
tecnosys | 0:0b777ff85deb | 94 | USB_EndPointHalt = 0x00000000; |
tecnosys | 0:0b777ff85deb | 95 | USB_EndPointStall = 0x00000000; |
tecnosys | 0:0b777ff85deb | 96 | } |
tecnosys | 0:0b777ff85deb | 97 | |
tecnosys | 0:0b777ff85deb | 98 | |
tecnosys | 0:0b777ff85deb | 99 | /* |
tecnosys | 0:0b777ff85deb | 100 | * USB Request - Setup Stage |
tecnosys | 0:0b777ff85deb | 101 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 102 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 103 | */ |
tecnosys | 0:0b777ff85deb | 104 | |
tecnosys | 0:0b777ff85deb | 105 | void USB_SetupStage (void) { |
tecnosys | 0:0b777ff85deb | 106 | USB_ReadEP(0x00, (uint8_t *)&SetupPacket); |
tecnosys | 0:0b777ff85deb | 107 | } |
tecnosys | 0:0b777ff85deb | 108 | |
tecnosys | 0:0b777ff85deb | 109 | |
tecnosys | 0:0b777ff85deb | 110 | /* |
tecnosys | 0:0b777ff85deb | 111 | * USB Request - Data In Stage |
tecnosys | 0:0b777ff85deb | 112 | * Parameters: None (global EP0Data) |
tecnosys | 0:0b777ff85deb | 113 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 114 | */ |
tecnosys | 0:0b777ff85deb | 115 | |
tecnosys | 0:0b777ff85deb | 116 | void USB_DataInStage (void) { |
tecnosys | 0:0b777ff85deb | 117 | uint32_t cnt; |
tecnosys | 0:0b777ff85deb | 118 | |
tecnosys | 0:0b777ff85deb | 119 | if (EP0Data.Count > USB_MAX_PACKET0) { |
tecnosys | 0:0b777ff85deb | 120 | cnt = USB_MAX_PACKET0; |
tecnosys | 0:0b777ff85deb | 121 | } else { |
tecnosys | 0:0b777ff85deb | 122 | cnt = EP0Data.Count; |
tecnosys | 0:0b777ff85deb | 123 | } |
tecnosys | 0:0b777ff85deb | 124 | cnt = USB_WriteEP(0x80, EP0Data.pData, cnt); |
tecnosys | 0:0b777ff85deb | 125 | EP0Data.pData += cnt; |
tecnosys | 0:0b777ff85deb | 126 | EP0Data.Count -= cnt; |
tecnosys | 0:0b777ff85deb | 127 | } |
tecnosys | 0:0b777ff85deb | 128 | |
tecnosys | 0:0b777ff85deb | 129 | |
tecnosys | 0:0b777ff85deb | 130 | /* |
tecnosys | 0:0b777ff85deb | 131 | * USB Request - Data Out Stage |
tecnosys | 0:0b777ff85deb | 132 | * Parameters: None (global EP0Data) |
tecnosys | 0:0b777ff85deb | 133 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 134 | */ |
tecnosys | 0:0b777ff85deb | 135 | |
tecnosys | 0:0b777ff85deb | 136 | void USB_DataOutStage (void) { |
tecnosys | 0:0b777ff85deb | 137 | uint32_t cnt; |
tecnosys | 0:0b777ff85deb | 138 | |
tecnosys | 0:0b777ff85deb | 139 | cnt = USB_ReadEP(0x00, EP0Data.pData); |
tecnosys | 0:0b777ff85deb | 140 | EP0Data.pData += cnt; |
tecnosys | 0:0b777ff85deb | 141 | EP0Data.Count -= cnt; |
tecnosys | 0:0b777ff85deb | 142 | } |
tecnosys | 0:0b777ff85deb | 143 | |
tecnosys | 0:0b777ff85deb | 144 | |
tecnosys | 0:0b777ff85deb | 145 | /* |
tecnosys | 0:0b777ff85deb | 146 | * USB Request - Status In Stage |
tecnosys | 0:0b777ff85deb | 147 | * Parameters: None |
tecnosys | 0:0b777ff85deb | 148 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 149 | */ |
tecnosys | 0:0b777ff85deb | 150 | |
tecnosys | 0:0b777ff85deb | 151 | void USB_StatusInStage (void) { |
tecnosys | 0:0b777ff85deb | 152 | USB_WriteEP(0x80, 0, 0); |
tecnosys | 0:0b777ff85deb | 153 | } |
tecnosys | 0:0b777ff85deb | 154 | |
tecnosys | 0:0b777ff85deb | 155 | |
tecnosys | 0:0b777ff85deb | 156 | /* |
tecnosys | 0:0b777ff85deb | 157 | * USB Request - Status Out Stage |
tecnosys | 0:0b777ff85deb | 158 | * Parameters: None |
tecnosys | 0:0b777ff85deb | 159 | * Return Value: None |
tecnosys | 0:0b777ff85deb | 160 | */ |
tecnosys | 0:0b777ff85deb | 161 | |
tecnosys | 0:0b777ff85deb | 162 | void USB_StatusOutStage (void) { |
tecnosys | 0:0b777ff85deb | 163 | USB_ReadEP(0x00, EP0Buf); |
tecnosys | 0:0b777ff85deb | 164 | } |
tecnosys | 0:0b777ff85deb | 165 | |
tecnosys | 0:0b777ff85deb | 166 | |
tecnosys | 0:0b777ff85deb | 167 | /* |
tecnosys | 0:0b777ff85deb | 168 | * Get Status USB Request |
tecnosys | 0:0b777ff85deb | 169 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 170 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 171 | */ |
tecnosys | 0:0b777ff85deb | 172 | |
tecnosys | 0:0b777ff85deb | 173 | __inline uint32_t USB_ReqGetStatus (void) { |
tecnosys | 0:0b777ff85deb | 174 | uint32_t n, m; |
tecnosys | 0:0b777ff85deb | 175 | |
tecnosys | 0:0b777ff85deb | 176 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 177 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 178 | EP0Data.pData = (uint8_t *)&USB_DeviceStatus; |
tecnosys | 0:0b777ff85deb | 179 | break; |
tecnosys | 0:0b777ff85deb | 180 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 181 | if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) { |
tecnosys | 0:0b777ff85deb | 182 | *((__packed uint16_t *)EP0Buf) = 0; |
tecnosys | 0:0b777ff85deb | 183 | EP0Data.pData = EP0Buf; |
tecnosys | 0:0b777ff85deb | 184 | } else { |
tecnosys | 0:0b777ff85deb | 185 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 186 | } |
tecnosys | 0:0b777ff85deb | 187 | break; |
tecnosys | 0:0b777ff85deb | 188 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 189 | n = SetupPacket.wIndex.WB.L & 0x8F; |
tecnosys | 0:0b777ff85deb | 190 | m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); |
tecnosys | 0:0b777ff85deb | 191 | if (((USB_Configuration != 0) || ((n & 0x0F) == 0)) && (USB_EndPointMask & m)) { |
tecnosys | 0:0b777ff85deb | 192 | *((__packed uint16_t *)EP0Buf) = (USB_EndPointHalt & m) ? 1 : 0; |
tecnosys | 0:0b777ff85deb | 193 | EP0Data.pData = EP0Buf; |
tecnosys | 0:0b777ff85deb | 194 | } else { |
tecnosys | 0:0b777ff85deb | 195 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 196 | } |
tecnosys | 0:0b777ff85deb | 197 | break; |
tecnosys | 0:0b777ff85deb | 198 | default: |
tecnosys | 0:0b777ff85deb | 199 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 200 | } |
tecnosys | 0:0b777ff85deb | 201 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 202 | } |
tecnosys | 0:0b777ff85deb | 203 | |
tecnosys | 0:0b777ff85deb | 204 | |
tecnosys | 0:0b777ff85deb | 205 | /* |
tecnosys | 0:0b777ff85deb | 206 | * Set/Clear Feature USB Request |
tecnosys | 0:0b777ff85deb | 207 | * Parameters: sc: 0 - Clear, 1 - Set |
tecnosys | 0:0b777ff85deb | 208 | * (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 209 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 210 | */ |
tecnosys | 0:0b777ff85deb | 211 | |
tecnosys | 0:0b777ff85deb | 212 | __inline uint32_t USB_ReqSetClrFeature (uint32_t sc) { |
tecnosys | 0:0b777ff85deb | 213 | uint32_t n, m; |
tecnosys | 0:0b777ff85deb | 214 | |
tecnosys | 0:0b777ff85deb | 215 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 216 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 217 | if (SetupPacket.wValue.W == USB_FEATURE_REMOTE_WAKEUP) { |
tecnosys | 0:0b777ff85deb | 218 | if (sc) { |
tecnosys | 0:0b777ff85deb | 219 | USB_WakeUpCfg(TRUE); |
tecnosys | 0:0b777ff85deb | 220 | USB_DeviceStatus |= USB_GETSTATUS_REMOTE_WAKEUP; |
tecnosys | 0:0b777ff85deb | 221 | } else { |
tecnosys | 0:0b777ff85deb | 222 | USB_WakeUpCfg(FALSE); |
tecnosys | 0:0b777ff85deb | 223 | USB_DeviceStatus &= ~USB_GETSTATUS_REMOTE_WAKEUP; |
tecnosys | 0:0b777ff85deb | 224 | } |
tecnosys | 0:0b777ff85deb | 225 | } else { |
tecnosys | 0:0b777ff85deb | 226 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 227 | } |
tecnosys | 0:0b777ff85deb | 228 | break; |
tecnosys | 0:0b777ff85deb | 229 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 230 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 231 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 232 | n = SetupPacket.wIndex.WB.L & 0x8F; |
tecnosys | 0:0b777ff85deb | 233 | m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); |
tecnosys | 0:0b777ff85deb | 234 | if ((USB_Configuration != 0) && ((n & 0x0F) != 0) && (USB_EndPointMask & m)) { |
tecnosys | 0:0b777ff85deb | 235 | if (SetupPacket.wValue.W == USB_FEATURE_ENDPOINT_STALL) { |
tecnosys | 0:0b777ff85deb | 236 | if (sc) { |
tecnosys | 0:0b777ff85deb | 237 | USB_SetStallEP(n); |
tecnosys | 0:0b777ff85deb | 238 | USB_EndPointHalt |= m; |
tecnosys | 0:0b777ff85deb | 239 | } else { |
tecnosys | 0:0b777ff85deb | 240 | if ((USB_EndPointStall & m) != 0) { |
tecnosys | 0:0b777ff85deb | 241 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 242 | } |
tecnosys | 0:0b777ff85deb | 243 | USB_ClrStallEP(n); |
tecnosys | 0:0b777ff85deb | 244 | #if (USB_MSC) |
tecnosys | 0:0b777ff85deb | 245 | if ((n == MSC_EP_IN) && ((USB_EndPointHalt & m) != 0)) { |
tecnosys | 0:0b777ff85deb | 246 | /* Compliance Test: rewrite CSW after unstall */ |
tecnosys | 0:0b777ff85deb | 247 | if (CSW.dSignature == MSC_CSW_Signature) { |
tecnosys | 0:0b777ff85deb | 248 | USB_WriteEP(MSC_EP_IN, (uint8_t *)&CSW, sizeof(CSW)); |
tecnosys | 0:0b777ff85deb | 249 | } |
tecnosys | 0:0b777ff85deb | 250 | } |
tecnosys | 0:0b777ff85deb | 251 | #endif |
tecnosys | 0:0b777ff85deb | 252 | USB_EndPointHalt &= ~m; |
tecnosys | 0:0b777ff85deb | 253 | } |
tecnosys | 0:0b777ff85deb | 254 | } else { |
tecnosys | 0:0b777ff85deb | 255 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 256 | } |
tecnosys | 0:0b777ff85deb | 257 | } else { |
tecnosys | 0:0b777ff85deb | 258 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 259 | } |
tecnosys | 0:0b777ff85deb | 260 | break; |
tecnosys | 0:0b777ff85deb | 261 | default: |
tecnosys | 0:0b777ff85deb | 262 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 263 | } |
tecnosys | 0:0b777ff85deb | 264 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 265 | } |
tecnosys | 0:0b777ff85deb | 266 | |
tecnosys | 0:0b777ff85deb | 267 | |
tecnosys | 0:0b777ff85deb | 268 | /* |
tecnosys | 0:0b777ff85deb | 269 | * Set Address USB Request |
tecnosys | 0:0b777ff85deb | 270 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 271 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 272 | */ |
tecnosys | 0:0b777ff85deb | 273 | |
tecnosys | 0:0b777ff85deb | 274 | __inline uint32_t USB_ReqSetAddress (void) { |
tecnosys | 0:0b777ff85deb | 275 | |
tecnosys | 0:0b777ff85deb | 276 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 277 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 278 | USB_DeviceAddress = 0x80 | SetupPacket.wValue.WB.L; |
tecnosys | 0:0b777ff85deb | 279 | break; |
tecnosys | 0:0b777ff85deb | 280 | default: |
tecnosys | 0:0b777ff85deb | 281 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 282 | } |
tecnosys | 0:0b777ff85deb | 283 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 284 | } |
tecnosys | 0:0b777ff85deb | 285 | |
tecnosys | 0:0b777ff85deb | 286 | |
tecnosys | 0:0b777ff85deb | 287 | /* |
tecnosys | 0:0b777ff85deb | 288 | * Get Descriptor USB Request |
tecnosys | 0:0b777ff85deb | 289 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 290 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 291 | */ |
tecnosys | 0:0b777ff85deb | 292 | |
tecnosys | 0:0b777ff85deb | 293 | __inline uint32_t USB_ReqGetDescriptor (void) { |
tecnosys | 0:0b777ff85deb | 294 | uint8_t *pD; |
tecnosys | 0:0b777ff85deb | 295 | uint32_t len, n; |
tecnosys | 0:0b777ff85deb | 296 | |
tecnosys | 0:0b777ff85deb | 297 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 298 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 299 | switch (SetupPacket.wValue.WB.H) { |
tecnosys | 0:0b777ff85deb | 300 | case USB_DEVICE_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 301 | EP0Data.pData = (uint8_t *)USB_DeviceDescriptor; |
tecnosys | 0:0b777ff85deb | 302 | len = USB_DEVICE_DESC_SIZE; |
tecnosys | 0:0b777ff85deb | 303 | break; |
tecnosys | 0:0b777ff85deb | 304 | case USB_CONFIGURATION_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 305 | pD = (uint8_t *)USB_ConfigDescriptor; |
tecnosys | 0:0b777ff85deb | 306 | for (n = 0; n != SetupPacket.wValue.WB.L; n++) { |
tecnosys | 0:0b777ff85deb | 307 | if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength != 0) { |
tecnosys | 0:0b777ff85deb | 308 | pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; |
tecnosys | 0:0b777ff85deb | 309 | } |
tecnosys | 0:0b777ff85deb | 310 | } |
tecnosys | 0:0b777ff85deb | 311 | if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bLength == 0) { |
tecnosys | 0:0b777ff85deb | 312 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 313 | } |
tecnosys | 0:0b777ff85deb | 314 | EP0Data.pData = pD; |
tecnosys | 0:0b777ff85deb | 315 | len = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; |
tecnosys | 0:0b777ff85deb | 316 | break; |
tecnosys | 0:0b777ff85deb | 317 | case USB_STRING_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 318 | pD = (uint8_t *)USB_StringDescriptor; |
tecnosys | 0:0b777ff85deb | 319 | for (n = 0; n != SetupPacket.wValue.WB.L; n++) { |
tecnosys | 0:0b777ff85deb | 320 | if (((USB_STRING_DESCRIPTOR *)pD)->bLength != 0) { |
tecnosys | 0:0b777ff85deb | 321 | pD += ((USB_STRING_DESCRIPTOR *)pD)->bLength; |
tecnosys | 0:0b777ff85deb | 322 | } |
tecnosys | 0:0b777ff85deb | 323 | } |
tecnosys | 0:0b777ff85deb | 324 | if (((USB_STRING_DESCRIPTOR *)pD)->bLength == 0) { |
tecnosys | 0:0b777ff85deb | 325 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 326 | } |
tecnosys | 0:0b777ff85deb | 327 | EP0Data.pData = pD; |
tecnosys | 0:0b777ff85deb | 328 | len = ((USB_STRING_DESCRIPTOR *)EP0Data.pData)->bLength; |
tecnosys | 0:0b777ff85deb | 329 | break; |
tecnosys | 0:0b777ff85deb | 330 | default: |
tecnosys | 0:0b777ff85deb | 331 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 332 | } |
tecnosys | 0:0b777ff85deb | 333 | break; |
tecnosys | 0:0b777ff85deb | 334 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 335 | switch (SetupPacket.wValue.WB.H) { |
tecnosys | 0:0b777ff85deb | 336 | #if USB_HID |
tecnosys | 0:0b777ff85deb | 337 | case HID_HID_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 338 | if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) { |
tecnosys | 0:0b777ff85deb | 339 | return (FALSE); /* Only Single HID Interface is supported */ |
tecnosys | 0:0b777ff85deb | 340 | } |
tecnosys | 0:0b777ff85deb | 341 | EP0Data.pData = (uint8_t *)USB_ConfigDescriptor + HID_DESC_OFFSET; |
tecnosys | 0:0b777ff85deb | 342 | len = HID_DESC_SIZE; |
tecnosys | 0:0b777ff85deb | 343 | break; |
tecnosys | 0:0b777ff85deb | 344 | case HID_REPORT_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 345 | if (SetupPacket.wIndex.WB.L != USB_HID_IF_NUM) { |
tecnosys | 0:0b777ff85deb | 346 | return (FALSE); /* Only Single HID Interface is supported */ |
tecnosys | 0:0b777ff85deb | 347 | } |
tecnosys | 0:0b777ff85deb | 348 | EP0Data.pData = (uint8_t *)HID_ReportDescriptor; |
tecnosys | 0:0b777ff85deb | 349 | len = HID_ReportDescSize; |
tecnosys | 0:0b777ff85deb | 350 | break; |
tecnosys | 0:0b777ff85deb | 351 | case HID_PHYSICAL_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 352 | return (FALSE); /* HID Physical Descriptor is not supported */ |
tecnosys | 0:0b777ff85deb | 353 | #endif |
tecnosys | 0:0b777ff85deb | 354 | default: |
tecnosys | 0:0b777ff85deb | 355 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 356 | } |
tecnosys | 0:0b777ff85deb | 357 | break; |
tecnosys | 0:0b777ff85deb | 358 | default: |
tecnosys | 0:0b777ff85deb | 359 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 360 | } |
tecnosys | 0:0b777ff85deb | 361 | |
tecnosys | 0:0b777ff85deb | 362 | if (EP0Data.Count > len) { |
tecnosys | 0:0b777ff85deb | 363 | EP0Data.Count = len; |
tecnosys | 0:0b777ff85deb | 364 | } |
tecnosys | 0:0b777ff85deb | 365 | |
tecnosys | 0:0b777ff85deb | 366 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 367 | } |
tecnosys | 0:0b777ff85deb | 368 | |
tecnosys | 0:0b777ff85deb | 369 | |
tecnosys | 0:0b777ff85deb | 370 | /* |
tecnosys | 0:0b777ff85deb | 371 | * Get Configuration USB Request |
tecnosys | 0:0b777ff85deb | 372 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 373 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 374 | */ |
tecnosys | 0:0b777ff85deb | 375 | |
tecnosys | 0:0b777ff85deb | 376 | __inline uint32_t USB_ReqGetConfiguration (void) { |
tecnosys | 0:0b777ff85deb | 377 | |
tecnosys | 0:0b777ff85deb | 378 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 379 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 380 | EP0Data.pData = &USB_Configuration; |
tecnosys | 0:0b777ff85deb | 381 | break; |
tecnosys | 0:0b777ff85deb | 382 | default: |
tecnosys | 0:0b777ff85deb | 383 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 384 | } |
tecnosys | 0:0b777ff85deb | 385 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 386 | } |
tecnosys | 0:0b777ff85deb | 387 | |
tecnosys | 0:0b777ff85deb | 388 | |
tecnosys | 0:0b777ff85deb | 389 | /* |
tecnosys | 0:0b777ff85deb | 390 | * Set Configuration USB Request |
tecnosys | 0:0b777ff85deb | 391 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 392 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 393 | */ |
tecnosys | 0:0b777ff85deb | 394 | |
tecnosys | 0:0b777ff85deb | 395 | __inline uint32_t USB_ReqSetConfiguration (void) { |
tecnosys | 0:0b777ff85deb | 396 | USB_COMMON_DESCRIPTOR *pD; |
tecnosys | 0:0b777ff85deb | 397 | uint32_t alt = 0; |
tecnosys | 0:0b777ff85deb | 398 | uint32_t n, m; |
tecnosys | 0:0b777ff85deb | 399 | |
tecnosys | 0:0b777ff85deb | 400 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 401 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 402 | |
tecnosys | 0:0b777ff85deb | 403 | if (SetupPacket.wValue.WB.L) { |
tecnosys | 0:0b777ff85deb | 404 | pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor; |
tecnosys | 0:0b777ff85deb | 405 | while (pD->bLength) { |
tecnosys | 0:0b777ff85deb | 406 | switch (pD->bDescriptorType) { |
tecnosys | 0:0b777ff85deb | 407 | case USB_CONFIGURATION_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 408 | if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue == SetupPacket.wValue.WB.L) { |
tecnosys | 0:0b777ff85deb | 409 | USB_Configuration = SetupPacket.wValue.WB.L; |
tecnosys | 0:0b777ff85deb | 410 | USB_NumInterfaces = ((USB_CONFIGURATION_DESCRIPTOR *)pD)->bNumInterfaces; |
tecnosys | 0:0b777ff85deb | 411 | for (n = 0; n < USB_IF_NUM; n++) { |
tecnosys | 0:0b777ff85deb | 412 | USB_AltSetting[n] = 0; |
tecnosys | 0:0b777ff85deb | 413 | } |
tecnosys | 0:0b777ff85deb | 414 | for (n = 1; n < 16; n++) { |
tecnosys | 0:0b777ff85deb | 415 | if (USB_EndPointMask & (1 << n)) { |
tecnosys | 0:0b777ff85deb | 416 | USB_DisableEP(n); |
tecnosys | 0:0b777ff85deb | 417 | } |
tecnosys | 0:0b777ff85deb | 418 | if (USB_EndPointMask & ((1 << 16) << n)) { |
tecnosys | 0:0b777ff85deb | 419 | USB_DisableEP(n | 0x80); |
tecnosys | 0:0b777ff85deb | 420 | } |
tecnosys | 0:0b777ff85deb | 421 | } |
tecnosys | 0:0b777ff85deb | 422 | USB_EndPointMask = 0x00010001; |
tecnosys | 0:0b777ff85deb | 423 | USB_EndPointHalt = 0x00000000; |
tecnosys | 0:0b777ff85deb | 424 | USB_EndPointStall= 0x00000000; |
tecnosys | 0:0b777ff85deb | 425 | USB_Configure(TRUE); |
tecnosys | 0:0b777ff85deb | 426 | if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bmAttributes & USB_CONFIG_POWERED_MASK) { |
tecnosys | 0:0b777ff85deb | 427 | USB_DeviceStatus |= USB_GETSTATUS_SELF_POWERED; |
tecnosys | 0:0b777ff85deb | 428 | } else { |
tecnosys | 0:0b777ff85deb | 429 | USB_DeviceStatus &= ~USB_GETSTATUS_SELF_POWERED; |
tecnosys | 0:0b777ff85deb | 430 | } |
tecnosys | 0:0b777ff85deb | 431 | } else { |
tecnosys | 0:0b777ff85deb | 432 | pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; // (uint8_t *) |
tecnosys | 0:0b777ff85deb | 433 | continue; |
tecnosys | 0:0b777ff85deb | 434 | } |
tecnosys | 0:0b777ff85deb | 435 | break; |
tecnosys | 0:0b777ff85deb | 436 | case USB_INTERFACE_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 437 | alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; |
tecnosys | 0:0b777ff85deb | 438 | break; |
tecnosys | 0:0b777ff85deb | 439 | case USB_ENDPOINT_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 440 | if (alt == 0) { |
tecnosys | 0:0b777ff85deb | 441 | n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; |
tecnosys | 0:0b777ff85deb | 442 | m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); |
tecnosys | 0:0b777ff85deb | 443 | USB_EndPointMask |= m; |
tecnosys | 0:0b777ff85deb | 444 | USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD); |
tecnosys | 0:0b777ff85deb | 445 | USB_EnableEP(n); |
tecnosys | 0:0b777ff85deb | 446 | USB_ResetEP(n); |
tecnosys | 0:0b777ff85deb | 447 | } |
tecnosys | 0:0b777ff85deb | 448 | break; |
tecnosys | 0:0b777ff85deb | 449 | } |
tecnosys | 0:0b777ff85deb | 450 | pD += pD->bLength; // (uint8_t *) |
tecnosys | 0:0b777ff85deb | 451 | } |
tecnosys | 0:0b777ff85deb | 452 | } |
tecnosys | 0:0b777ff85deb | 453 | else { |
tecnosys | 0:0b777ff85deb | 454 | USB_Configuration = 0; |
tecnosys | 0:0b777ff85deb | 455 | for (n = 1; n < 16; n++) { |
tecnosys | 0:0b777ff85deb | 456 | if (USB_EndPointMask & (1 << n)) { |
tecnosys | 0:0b777ff85deb | 457 | USB_DisableEP(n); |
tecnosys | 0:0b777ff85deb | 458 | } |
tecnosys | 0:0b777ff85deb | 459 | if (USB_EndPointMask & ((1 << 16) << n)) { |
tecnosys | 0:0b777ff85deb | 460 | USB_DisableEP(n | 0x80); |
tecnosys | 0:0b777ff85deb | 461 | } |
tecnosys | 0:0b777ff85deb | 462 | } |
tecnosys | 0:0b777ff85deb | 463 | USB_EndPointMask = 0x00010001; |
tecnosys | 0:0b777ff85deb | 464 | USB_EndPointHalt = 0x00000000; |
tecnosys | 0:0b777ff85deb | 465 | USB_EndPointStall = 0x00000000; |
tecnosys | 0:0b777ff85deb | 466 | USB_Configure(FALSE); |
tecnosys | 0:0b777ff85deb | 467 | } |
tecnosys | 0:0b777ff85deb | 468 | |
tecnosys | 0:0b777ff85deb | 469 | if (USB_Configuration != SetupPacket.wValue.WB.L) { |
tecnosys | 0:0b777ff85deb | 470 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 471 | } |
tecnosys | 0:0b777ff85deb | 472 | break; |
tecnosys | 0:0b777ff85deb | 473 | default: |
tecnosys | 0:0b777ff85deb | 474 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 475 | } |
tecnosys | 0:0b777ff85deb | 476 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 477 | } |
tecnosys | 0:0b777ff85deb | 478 | |
tecnosys | 0:0b777ff85deb | 479 | |
tecnosys | 0:0b777ff85deb | 480 | /* |
tecnosys | 0:0b777ff85deb | 481 | * Get Interface USB Request |
tecnosys | 0:0b777ff85deb | 482 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 483 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 484 | */ |
tecnosys | 0:0b777ff85deb | 485 | |
tecnosys | 0:0b777ff85deb | 486 | __inline uint32_t USB_ReqGetInterface (void) { |
tecnosys | 0:0b777ff85deb | 487 | |
tecnosys | 0:0b777ff85deb | 488 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 489 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 490 | if ((USB_Configuration != 0) && (SetupPacket.wIndex.WB.L < USB_NumInterfaces)) { |
tecnosys | 0:0b777ff85deb | 491 | EP0Data.pData = USB_AltSetting + SetupPacket.wIndex.WB.L; |
tecnosys | 0:0b777ff85deb | 492 | } else { |
tecnosys | 0:0b777ff85deb | 493 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 494 | } |
tecnosys | 0:0b777ff85deb | 495 | break; |
tecnosys | 0:0b777ff85deb | 496 | default: |
tecnosys | 0:0b777ff85deb | 497 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 498 | } |
tecnosys | 0:0b777ff85deb | 499 | return (TRUE); |
tecnosys | 0:0b777ff85deb | 500 | } |
tecnosys | 0:0b777ff85deb | 501 | |
tecnosys | 0:0b777ff85deb | 502 | |
tecnosys | 0:0b777ff85deb | 503 | /* |
tecnosys | 0:0b777ff85deb | 504 | * Set Interface USB Request |
tecnosys | 0:0b777ff85deb | 505 | * Parameters: None (global SetupPacket) |
tecnosys | 0:0b777ff85deb | 506 | * Return Value: TRUE - Success, FALSE - Error |
tecnosys | 0:0b777ff85deb | 507 | */ |
tecnosys | 0:0b777ff85deb | 508 | |
tecnosys | 0:0b777ff85deb | 509 | __inline uint32_t USB_ReqSetInterface (void) { |
tecnosys | 0:0b777ff85deb | 510 | USB_COMMON_DESCRIPTOR *pD; |
tecnosys | 0:0b777ff85deb | 511 | uint32_t ifn = 0, alt = 0, old = 0, msk = 0; |
tecnosys | 0:0b777ff85deb | 512 | uint32_t n, m; |
tecnosys | 0:0b777ff85deb | 513 | uint32_t set; |
tecnosys | 0:0b777ff85deb | 514 | |
tecnosys | 0:0b777ff85deb | 515 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 516 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 517 | if (USB_Configuration == 0) return (FALSE); |
tecnosys | 0:0b777ff85deb | 518 | set = FALSE; |
tecnosys | 0:0b777ff85deb | 519 | pD = (USB_COMMON_DESCRIPTOR *)USB_ConfigDescriptor; |
tecnosys | 0:0b777ff85deb | 520 | while (pD->bLength) { |
tecnosys | 0:0b777ff85deb | 521 | switch (pD->bDescriptorType) { |
tecnosys | 0:0b777ff85deb | 522 | case USB_CONFIGURATION_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 523 | if (((USB_CONFIGURATION_DESCRIPTOR *)pD)->bConfigurationValue != USB_Configuration) { |
tecnosys | 0:0b777ff85deb | 524 | pD += ((USB_CONFIGURATION_DESCRIPTOR *)pD)->wTotalLength; // (uint8_t *) |
tecnosys | 0:0b777ff85deb | 525 | continue; |
tecnosys | 0:0b777ff85deb | 526 | } |
tecnosys | 0:0b777ff85deb | 527 | break; |
tecnosys | 0:0b777ff85deb | 528 | case USB_INTERFACE_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 529 | ifn = ((USB_INTERFACE_DESCRIPTOR *)pD)->bInterfaceNumber; |
tecnosys | 0:0b777ff85deb | 530 | alt = ((USB_INTERFACE_DESCRIPTOR *)pD)->bAlternateSetting; |
tecnosys | 0:0b777ff85deb | 531 | msk = 0; |
tecnosys | 0:0b777ff85deb | 532 | if ((ifn == SetupPacket.wIndex.WB.L) && (alt == SetupPacket.wValue.WB.L)) { |
tecnosys | 0:0b777ff85deb | 533 | set = TRUE; |
tecnosys | 0:0b777ff85deb | 534 | old = USB_AltSetting[ifn]; |
tecnosys | 0:0b777ff85deb | 535 | USB_AltSetting[ifn] = (uint8_t)alt; |
tecnosys | 0:0b777ff85deb | 536 | } |
tecnosys | 0:0b777ff85deb | 537 | break; |
tecnosys | 0:0b777ff85deb | 538 | case USB_ENDPOINT_DESCRIPTOR_TYPE: |
tecnosys | 0:0b777ff85deb | 539 | if (ifn == SetupPacket.wIndex.WB.L) { |
tecnosys | 0:0b777ff85deb | 540 | n = ((USB_ENDPOINT_DESCRIPTOR *)pD)->bEndpointAddress & 0x8F; |
tecnosys | 0:0b777ff85deb | 541 | m = (n & 0x80) ? ((1 << 16) << (n & 0x0F)) : (1 << n); |
tecnosys | 0:0b777ff85deb | 542 | if (alt == SetupPacket.wValue.WB.L) { |
tecnosys | 0:0b777ff85deb | 543 | USB_EndPointMask |= m; |
tecnosys | 0:0b777ff85deb | 544 | USB_EndPointHalt &= ~m; |
tecnosys | 0:0b777ff85deb | 545 | USB_ConfigEP((USB_ENDPOINT_DESCRIPTOR *)pD); |
tecnosys | 0:0b777ff85deb | 546 | USB_EnableEP(n); |
tecnosys | 0:0b777ff85deb | 547 | USB_ResetEP(n); |
tecnosys | 0:0b777ff85deb | 548 | msk |= m; |
tecnosys | 0:0b777ff85deb | 549 | } |
tecnosys | 0:0b777ff85deb | 550 | else if ((alt == old) && ((msk & m) == 0)) { |
tecnosys | 0:0b777ff85deb | 551 | USB_EndPointMask &= ~m; |
tecnosys | 0:0b777ff85deb | 552 | USB_EndPointHalt &= ~m; |
tecnosys | 0:0b777ff85deb | 553 | USB_DisableEP(n); |
tecnosys | 0:0b777ff85deb | 554 | } |
tecnosys | 0:0b777ff85deb | 555 | } |
tecnosys | 0:0b777ff85deb | 556 | break; |
tecnosys | 0:0b777ff85deb | 557 | } |
tecnosys | 0:0b777ff85deb | 558 | pD += pD->bLength; |
tecnosys | 0:0b777ff85deb | 559 | } |
tecnosys | 0:0b777ff85deb | 560 | break; |
tecnosys | 0:0b777ff85deb | 561 | default: |
tecnosys | 0:0b777ff85deb | 562 | return (FALSE); |
tecnosys | 0:0b777ff85deb | 563 | } |
tecnosys | 0:0b777ff85deb | 564 | |
tecnosys | 0:0b777ff85deb | 565 | return (set); |
tecnosys | 0:0b777ff85deb | 566 | } |
tecnosys | 0:0b777ff85deb | 567 | |
tecnosys | 0:0b777ff85deb | 568 | |
tecnosys | 0:0b777ff85deb | 569 | /* |
tecnosys | 0:0b777ff85deb | 570 | * USB Endpoint 0 Event Callback |
tecnosys | 0:0b777ff85deb | 571 | * Parameters: event |
tecnosys | 0:0b777ff85deb | 572 | * Return Value: none |
tecnosys | 0:0b777ff85deb | 573 | */ |
tecnosys | 0:0b777ff85deb | 574 | |
tecnosys | 0:0b777ff85deb | 575 | void USB_EndPoint0 (uint32_t event) { |
tecnosys | 0:0b777ff85deb | 576 | |
tecnosys | 0:0b777ff85deb | 577 | switch (event) { |
tecnosys | 0:0b777ff85deb | 578 | case USB_EVT_SETUP: |
tecnosys | 0:0b777ff85deb | 579 | USB_SetupStage(); |
tecnosys | 0:0b777ff85deb | 580 | USB_DirCtrlEP(SetupPacket.bmRequestType.BM.Dir); |
tecnosys | 0:0b777ff85deb | 581 | EP0Data.Count = SetupPacket.wLength; /* Number of bytes to transfer */ |
tecnosys | 0:0b777ff85deb | 582 | switch (SetupPacket.bmRequestType.BM.Type) { |
tecnosys | 0:0b777ff85deb | 583 | |
tecnosys | 0:0b777ff85deb | 584 | case REQUEST_STANDARD: |
tecnosys | 0:0b777ff85deb | 585 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 586 | case USB_REQUEST_GET_STATUS: |
tecnosys | 0:0b777ff85deb | 587 | if (!USB_ReqGetStatus()) { |
tecnosys | 0:0b777ff85deb | 588 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 589 | } |
tecnosys | 0:0b777ff85deb | 590 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 591 | break; |
tecnosys | 0:0b777ff85deb | 592 | |
tecnosys | 0:0b777ff85deb | 593 | case USB_REQUEST_CLEAR_FEATURE: |
tecnosys | 0:0b777ff85deb | 594 | if (!USB_ReqSetClrFeature(0)) { |
tecnosys | 0:0b777ff85deb | 595 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 596 | } |
tecnosys | 0:0b777ff85deb | 597 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 598 | #if USB_FEATURE_EVENT |
tecnosys | 0:0b777ff85deb | 599 | USB_Feature_Event(); |
tecnosys | 0:0b777ff85deb | 600 | #endif |
tecnosys | 0:0b777ff85deb | 601 | break; |
tecnosys | 0:0b777ff85deb | 602 | |
tecnosys | 0:0b777ff85deb | 603 | case USB_REQUEST_SET_FEATURE: |
tecnosys | 0:0b777ff85deb | 604 | if (!USB_ReqSetClrFeature(1)) { |
tecnosys | 0:0b777ff85deb | 605 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 606 | } |
tecnosys | 0:0b777ff85deb | 607 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 608 | #if USB_FEATURE_EVENT |
tecnosys | 0:0b777ff85deb | 609 | USB_Feature_Event(); |
tecnosys | 0:0b777ff85deb | 610 | #endif |
tecnosys | 0:0b777ff85deb | 611 | break; |
tecnosys | 0:0b777ff85deb | 612 | |
tecnosys | 0:0b777ff85deb | 613 | case USB_REQUEST_SET_ADDRESS: |
tecnosys | 0:0b777ff85deb | 614 | if (!USB_ReqSetAddress()) { |
tecnosys | 0:0b777ff85deb | 615 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 616 | } |
tecnosys | 0:0b777ff85deb | 617 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 618 | break; |
tecnosys | 0:0b777ff85deb | 619 | |
tecnosys | 0:0b777ff85deb | 620 | case USB_REQUEST_GET_DESCRIPTOR: |
tecnosys | 0:0b777ff85deb | 621 | if (!USB_ReqGetDescriptor()) { |
tecnosys | 0:0b777ff85deb | 622 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 623 | } |
tecnosys | 0:0b777ff85deb | 624 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 625 | break; |
tecnosys | 0:0b777ff85deb | 626 | |
tecnosys | 0:0b777ff85deb | 627 | case USB_REQUEST_SET_DESCRIPTOR: |
tecnosys | 0:0b777ff85deb | 628 | /*stall_o:*/ USB_SetStallEP(0x00); /* not supported */ |
tecnosys | 0:0b777ff85deb | 629 | EP0Data.Count = 0; |
tecnosys | 0:0b777ff85deb | 630 | break; |
tecnosys | 0:0b777ff85deb | 631 | |
tecnosys | 0:0b777ff85deb | 632 | case USB_REQUEST_GET_CONFIGURATION: |
tecnosys | 0:0b777ff85deb | 633 | if (!USB_ReqGetConfiguration()) { |
tecnosys | 0:0b777ff85deb | 634 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 635 | } |
tecnosys | 0:0b777ff85deb | 636 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 637 | break; |
tecnosys | 0:0b777ff85deb | 638 | |
tecnosys | 0:0b777ff85deb | 639 | case USB_REQUEST_SET_CONFIGURATION: |
tecnosys | 0:0b777ff85deb | 640 | if (!USB_ReqSetConfiguration()) { |
tecnosys | 0:0b777ff85deb | 641 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 642 | } |
tecnosys | 0:0b777ff85deb | 643 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 644 | #if USB_CONFIGURE_EVENT |
tecnosys | 0:0b777ff85deb | 645 | USB_Configure_Event(); |
tecnosys | 0:0b777ff85deb | 646 | #endif |
tecnosys | 0:0b777ff85deb | 647 | break; |
tecnosys | 0:0b777ff85deb | 648 | |
tecnosys | 0:0b777ff85deb | 649 | case USB_REQUEST_GET_INTERFACE: |
tecnosys | 0:0b777ff85deb | 650 | if (!USB_ReqGetInterface()) { |
tecnosys | 0:0b777ff85deb | 651 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 652 | } |
tecnosys | 0:0b777ff85deb | 653 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 654 | break; |
tecnosys | 0:0b777ff85deb | 655 | |
tecnosys | 0:0b777ff85deb | 656 | case USB_REQUEST_SET_INTERFACE: |
tecnosys | 0:0b777ff85deb | 657 | if (!USB_ReqSetInterface()) { |
tecnosys | 0:0b777ff85deb | 658 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 659 | } |
tecnosys | 0:0b777ff85deb | 660 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 661 | #if USB_INTERFACE_EVENT |
tecnosys | 0:0b777ff85deb | 662 | USB_Interface_Event(); |
tecnosys | 0:0b777ff85deb | 663 | #endif |
tecnosys | 0:0b777ff85deb | 664 | break; |
tecnosys | 0:0b777ff85deb | 665 | |
tecnosys | 0:0b777ff85deb | 666 | default: |
tecnosys | 0:0b777ff85deb | 667 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 668 | } |
tecnosys | 0:0b777ff85deb | 669 | break; /* end case REQUEST_STANDARD */ |
tecnosys | 0:0b777ff85deb | 670 | |
tecnosys | 0:0b777ff85deb | 671 | #if USB_CLASS |
tecnosys | 0:0b777ff85deb | 672 | case REQUEST_CLASS: |
tecnosys | 0:0b777ff85deb | 673 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 674 | |
tecnosys | 0:0b777ff85deb | 675 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 676 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 677 | |
tecnosys | 0:0b777ff85deb | 678 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 679 | #if USB_HID |
tecnosys | 0:0b777ff85deb | 680 | if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 681 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 682 | case HID_REQUEST_GET_REPORT: |
tecnosys | 0:0b777ff85deb | 683 | if (HID_GetReport()) { |
tecnosys | 0:0b777ff85deb | 684 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 685 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 686 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 687 | } |
tecnosys | 0:0b777ff85deb | 688 | break; |
tecnosys | 0:0b777ff85deb | 689 | case HID_REQUEST_SET_REPORT: |
tecnosys | 0:0b777ff85deb | 690 | EP0Data.pData = EP0Buf; /* data to be received */ |
tecnosys | 0:0b777ff85deb | 691 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 692 | case HID_REQUEST_GET_IDLE: |
tecnosys | 0:0b777ff85deb | 693 | if (HID_GetIdle()) { |
tecnosys | 0:0b777ff85deb | 694 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 695 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 696 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 697 | } |
tecnosys | 0:0b777ff85deb | 698 | break; |
tecnosys | 0:0b777ff85deb | 699 | case HID_REQUEST_SET_IDLE: |
tecnosys | 0:0b777ff85deb | 700 | if (HID_SetIdle()) { |
tecnosys | 0:0b777ff85deb | 701 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 702 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 703 | } |
tecnosys | 0:0b777ff85deb | 704 | break; |
tecnosys | 0:0b777ff85deb | 705 | case HID_REQUEST_GET_PROTOCOL: |
tecnosys | 0:0b777ff85deb | 706 | if (HID_GetProtocol()) { |
tecnosys | 0:0b777ff85deb | 707 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 708 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 709 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 710 | } |
tecnosys | 0:0b777ff85deb | 711 | break; |
tecnosys | 0:0b777ff85deb | 712 | case HID_REQUEST_SET_PROTOCOL: |
tecnosys | 0:0b777ff85deb | 713 | if (HID_SetProtocol()) { |
tecnosys | 0:0b777ff85deb | 714 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 715 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 716 | } |
tecnosys | 0:0b777ff85deb | 717 | break; |
tecnosys | 0:0b777ff85deb | 718 | } |
tecnosys | 0:0b777ff85deb | 719 | } |
tecnosys | 0:0b777ff85deb | 720 | #endif /* USB_HID */ |
tecnosys | 0:0b777ff85deb | 721 | #if USB_MSC |
tecnosys | 0:0b777ff85deb | 722 | if (SetupPacket.wIndex.WB.L == USB_MSC_IF_NUM) { /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 723 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 724 | case MSC_REQUEST_RESET: |
tecnosys | 0:0b777ff85deb | 725 | if ((SetupPacket.wValue.W == 0) && /* RESET with invalid parameters -> STALL */ |
tecnosys | 0:0b777ff85deb | 726 | (SetupPacket.wLength == 0)) { |
tecnosys | 0:0b777ff85deb | 727 | if (MSC_Reset()) { |
tecnosys | 0:0b777ff85deb | 728 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 729 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 730 | } |
tecnosys | 0:0b777ff85deb | 731 | } |
tecnosys | 0:0b777ff85deb | 732 | break; |
tecnosys | 0:0b777ff85deb | 733 | case MSC_REQUEST_GET_MAX_LUN: |
tecnosys | 0:0b777ff85deb | 734 | if ((SetupPacket.wValue.W == 0) && /* GET_MAX_LUN with invalid parameters -> STALL */ |
tecnosys | 0:0b777ff85deb | 735 | (SetupPacket.wLength == 1)) { |
tecnosys | 0:0b777ff85deb | 736 | if (MSC_GetMaxLUN()) { |
tecnosys | 0:0b777ff85deb | 737 | EP0Data.pData = EP0Buf; |
tecnosys | 0:0b777ff85deb | 738 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 739 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 740 | } |
tecnosys | 0:0b777ff85deb | 741 | } |
tecnosys | 0:0b777ff85deb | 742 | break; |
tecnosys | 0:0b777ff85deb | 743 | } |
tecnosys | 0:0b777ff85deb | 744 | } |
tecnosys | 0:0b777ff85deb | 745 | #endif /* USB_MSC */ |
tecnosys | 0:0b777ff85deb | 746 | #if USB_AUDIO |
tecnosys | 0:0b777ff85deb | 747 | if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 748 | (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || |
tecnosys | 0:0b777ff85deb | 749 | (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { |
tecnosys | 0:0b777ff85deb | 750 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 751 | case AUDIO_REQUEST_GET_CUR: |
tecnosys | 0:0b777ff85deb | 752 | case AUDIO_REQUEST_GET_MIN: |
tecnosys | 0:0b777ff85deb | 753 | case AUDIO_REQUEST_GET_MAX: |
tecnosys | 0:0b777ff85deb | 754 | case AUDIO_REQUEST_GET_RES: |
tecnosys | 0:0b777ff85deb | 755 | if (ADC_IF_GetRequest()) { |
tecnosys | 0:0b777ff85deb | 756 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 757 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 758 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 759 | } |
tecnosys | 0:0b777ff85deb | 760 | break; |
tecnosys | 0:0b777ff85deb | 761 | case AUDIO_REQUEST_SET_CUR: |
tecnosys | 0:0b777ff85deb | 762 | // case AUDIO_REQUEST_SET_MIN: |
tecnosys | 0:0b777ff85deb | 763 | // case AUDIO_REQUEST_SET_MAX: |
tecnosys | 0:0b777ff85deb | 764 | // case AUDIO_REQUEST_SET_RES: |
tecnosys | 0:0b777ff85deb | 765 | EP0Data.pData = EP0Buf; /* data to be received */ |
tecnosys | 0:0b777ff85deb | 766 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 767 | } |
tecnosys | 0:0b777ff85deb | 768 | } |
tecnosys | 0:0b777ff85deb | 769 | #endif /* USB_AUDIO */ |
tecnosys | 0:0b777ff85deb | 770 | #if USB_CDC |
tecnosys | 0:0b777ff85deb | 771 | if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 772 | (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { |
tecnosys | 0:0b777ff85deb | 773 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 774 | case CDC_SEND_ENCAPSULATED_COMMAND: |
tecnosys | 0:0b777ff85deb | 775 | EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ |
tecnosys | 0:0b777ff85deb | 776 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 777 | case CDC_GET_ENCAPSULATED_RESPONSE: |
tecnosys | 0:0b777ff85deb | 778 | if (CDC_GetEncapsulatedResponse()) { |
tecnosys | 0:0b777ff85deb | 779 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 780 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 781 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 782 | } |
tecnosys | 0:0b777ff85deb | 783 | break; |
tecnosys | 0:0b777ff85deb | 784 | case CDC_SET_COMM_FEATURE: |
tecnosys | 0:0b777ff85deb | 785 | EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ |
tecnosys | 0:0b777ff85deb | 786 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 787 | case CDC_GET_COMM_FEATURE: |
tecnosys | 0:0b777ff85deb | 788 | if (CDC_GetCommFeature(SetupPacket.wValue.W)) { |
tecnosys | 0:0b777ff85deb | 789 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 790 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 791 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 792 | } |
tecnosys | 0:0b777ff85deb | 793 | break; |
tecnosys | 0:0b777ff85deb | 794 | case CDC_CLEAR_COMM_FEATURE: |
tecnosys | 0:0b777ff85deb | 795 | if (CDC_ClearCommFeature(SetupPacket.wValue.W)) { |
tecnosys | 0:0b777ff85deb | 796 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 797 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 798 | } |
tecnosys | 0:0b777ff85deb | 799 | break; |
tecnosys | 0:0b777ff85deb | 800 | case CDC_SET_LINE_CODING: |
tecnosys | 0:0b777ff85deb | 801 | EP0Data.pData = EP0Buf; /* data to be received, see USB_EVT_OUT */ |
tecnosys | 0:0b777ff85deb | 802 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 803 | case CDC_GET_LINE_CODING: |
tecnosys | 0:0b777ff85deb | 804 | if (CDC_GetLineCoding()) { |
tecnosys | 0:0b777ff85deb | 805 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 806 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 807 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 808 | } |
tecnosys | 0:0b777ff85deb | 809 | break; |
tecnosys | 0:0b777ff85deb | 810 | case CDC_SET_CONTROL_LINE_STATE: |
tecnosys | 0:0b777ff85deb | 811 | if (CDC_SetControlLineState(SetupPacket.wValue.W)) { |
tecnosys | 0:0b777ff85deb | 812 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 813 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 814 | } |
tecnosys | 0:0b777ff85deb | 815 | break; |
tecnosys | 0:0b777ff85deb | 816 | case CDC_SEND_BREAK: |
tecnosys | 0:0b777ff85deb | 817 | if (CDC_SendBreak(SetupPacket.wValue.W)) { |
tecnosys | 0:0b777ff85deb | 818 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 819 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 820 | } |
tecnosys | 0:0b777ff85deb | 821 | break; |
tecnosys | 0:0b777ff85deb | 822 | } |
tecnosys | 0:0b777ff85deb | 823 | } |
tecnosys | 0:0b777ff85deb | 824 | #endif /* USB_CDC */ |
tecnosys | 0:0b777ff85deb | 825 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 826 | /* end case REQUEST_TO_INTERFACE */ |
tecnosys | 0:0b777ff85deb | 827 | |
tecnosys | 0:0b777ff85deb | 828 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 829 | #if USB_AUDIO |
tecnosys | 0:0b777ff85deb | 830 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 831 | case AUDIO_REQUEST_GET_CUR: |
tecnosys | 0:0b777ff85deb | 832 | case AUDIO_REQUEST_GET_MIN: |
tecnosys | 0:0b777ff85deb | 833 | case AUDIO_REQUEST_GET_MAX: |
tecnosys | 0:0b777ff85deb | 834 | case AUDIO_REQUEST_GET_RES: |
tecnosys | 0:0b777ff85deb | 835 | if (ADC_EP_GetRequest()) { |
tecnosys | 0:0b777ff85deb | 836 | EP0Data.pData = EP0Buf; /* point to data to be sent */ |
tecnosys | 0:0b777ff85deb | 837 | USB_DataInStage(); /* send requested data */ |
tecnosys | 0:0b777ff85deb | 838 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 839 | } |
tecnosys | 0:0b777ff85deb | 840 | break; |
tecnosys | 0:0b777ff85deb | 841 | case AUDIO_REQUEST_SET_CUR: |
tecnosys | 0:0b777ff85deb | 842 | // case AUDIO_REQUEST_SET_MIN: |
tecnosys | 0:0b777ff85deb | 843 | // case AUDIO_REQUEST_SET_MAX: |
tecnosys | 0:0b777ff85deb | 844 | // case AUDIO_REQUEST_SET_RES: |
tecnosys | 0:0b777ff85deb | 845 | EP0Data.pData = EP0Buf; /* data to be received */ |
tecnosys | 0:0b777ff85deb | 846 | goto setup_class_ok; |
tecnosys | 0:0b777ff85deb | 847 | } |
tecnosys | 0:0b777ff85deb | 848 | #endif /* USB_AUDIO */ |
tecnosys | 0:0b777ff85deb | 849 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 850 | /* end case REQUEST_TO_ENDPOINT */ |
tecnosys | 0:0b777ff85deb | 851 | |
tecnosys | 0:0b777ff85deb | 852 | default: |
tecnosys | 0:0b777ff85deb | 853 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 854 | } |
tecnosys | 0:0b777ff85deb | 855 | setup_class_ok: /* request finished successfully */ |
tecnosys | 0:0b777ff85deb | 856 | break; /* end case REQUEST_CLASS */ |
tecnosys | 0:0b777ff85deb | 857 | #endif /* USB_CLASS */ |
tecnosys | 0:0b777ff85deb | 858 | |
tecnosys | 0:0b777ff85deb | 859 | #if USB_VENDOR |
tecnosys | 0:0b777ff85deb | 860 | case REQUEST_VENDOR: |
tecnosys | 0:0b777ff85deb | 861 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 862 | |
tecnosys | 0:0b777ff85deb | 863 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 864 | if (!USB_ReqVendorDev(TRUE)) { |
tecnosys | 0:0b777ff85deb | 865 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 866 | } |
tecnosys | 0:0b777ff85deb | 867 | break; |
tecnosys | 0:0b777ff85deb | 868 | |
tecnosys | 0:0b777ff85deb | 869 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 870 | if (!USB_ReqVendorIF(TRUE)) { |
tecnosys | 0:0b777ff85deb | 871 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 872 | } |
tecnosys | 0:0b777ff85deb | 873 | break; |
tecnosys | 0:0b777ff85deb | 874 | |
tecnosys | 0:0b777ff85deb | 875 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 876 | if (!USB_ReqVendorEP(TRUE)) { |
tecnosys | 0:0b777ff85deb | 877 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 878 | } |
tecnosys | 0:0b777ff85deb | 879 | break; |
tecnosys | 0:0b777ff85deb | 880 | |
tecnosys | 0:0b777ff85deb | 881 | default: |
tecnosys | 0:0b777ff85deb | 882 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 883 | } |
tecnosys | 0:0b777ff85deb | 884 | |
tecnosys | 0:0b777ff85deb | 885 | if (SetupPacket.wLength) { |
tecnosys | 0:0b777ff85deb | 886 | if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { |
tecnosys | 0:0b777ff85deb | 887 | USB_DataInStage(); |
tecnosys | 0:0b777ff85deb | 888 | } |
tecnosys | 0:0b777ff85deb | 889 | } else { |
tecnosys | 0:0b777ff85deb | 890 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 891 | } |
tecnosys | 0:0b777ff85deb | 892 | |
tecnosys | 0:0b777ff85deb | 893 | break; /* end case REQUEST_VENDOR */ |
tecnosys | 0:0b777ff85deb | 894 | #endif /* USB_VENDOR */ |
tecnosys | 0:0b777ff85deb | 895 | |
tecnosys | 0:0b777ff85deb | 896 | default: |
tecnosys | 0:0b777ff85deb | 897 | stall_i: USB_SetStallEP(0x80); |
tecnosys | 0:0b777ff85deb | 898 | EP0Data.Count = 0; |
tecnosys | 0:0b777ff85deb | 899 | break; |
tecnosys | 0:0b777ff85deb | 900 | } |
tecnosys | 0:0b777ff85deb | 901 | break; /* end case USB_EVT_SETUP */ |
tecnosys | 0:0b777ff85deb | 902 | |
tecnosys | 0:0b777ff85deb | 903 | case USB_EVT_OUT: |
tecnosys | 0:0b777ff85deb | 904 | if (SetupPacket.bmRequestType.BM.Dir == REQUEST_HOST_TO_DEVICE) { |
tecnosys | 0:0b777ff85deb | 905 | if (EP0Data.Count) { /* still data to receive ? */ |
tecnosys | 0:0b777ff85deb | 906 | USB_DataOutStage(); /* receive data */ |
tecnosys | 0:0b777ff85deb | 907 | if (EP0Data.Count == 0) { /* data complete ? */ |
tecnosys | 0:0b777ff85deb | 908 | switch (SetupPacket.bmRequestType.BM.Type) { |
tecnosys | 0:0b777ff85deb | 909 | |
tecnosys | 0:0b777ff85deb | 910 | case REQUEST_STANDARD: |
tecnosys | 0:0b777ff85deb | 911 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 912 | |
tecnosys | 0:0b777ff85deb | 913 | #if (USB_CLASS) |
tecnosys | 0:0b777ff85deb | 914 | case REQUEST_CLASS: |
tecnosys | 0:0b777ff85deb | 915 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 916 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 917 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 918 | |
tecnosys | 0:0b777ff85deb | 919 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 920 | #if USB_HID |
tecnosys | 0:0b777ff85deb | 921 | if (SetupPacket.wIndex.WB.L == USB_HID_IF_NUM) { /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 922 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 923 | case HID_REQUEST_SET_REPORT: |
tecnosys | 0:0b777ff85deb | 924 | if (HID_SetReport()) { |
tecnosys | 0:0b777ff85deb | 925 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 926 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 927 | } |
tecnosys | 0:0b777ff85deb | 928 | break; |
tecnosys | 0:0b777ff85deb | 929 | } |
tecnosys | 0:0b777ff85deb | 930 | } |
tecnosys | 0:0b777ff85deb | 931 | #endif /* USB_HID */ |
tecnosys | 0:0b777ff85deb | 932 | #if USB_AUDIO |
tecnosys | 0:0b777ff85deb | 933 | if ((SetupPacket.wIndex.WB.L == USB_ADC_CIF_NUM) || /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 934 | (SetupPacket.wIndex.WB.L == USB_ADC_SIF1_NUM) || |
tecnosys | 0:0b777ff85deb | 935 | (SetupPacket.wIndex.WB.L == USB_ADC_SIF2_NUM)) { |
tecnosys | 0:0b777ff85deb | 936 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 937 | case AUDIO_REQUEST_SET_CUR: |
tecnosys | 0:0b777ff85deb | 938 | // case AUDIO_REQUEST_SET_MIN: |
tecnosys | 0:0b777ff85deb | 939 | // case AUDIO_REQUEST_SET_MAX: |
tecnosys | 0:0b777ff85deb | 940 | // case AUDIO_REQUEST_SET_RES: |
tecnosys | 0:0b777ff85deb | 941 | if (ADC_IF_SetRequest()) { |
tecnosys | 0:0b777ff85deb | 942 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 943 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 944 | } |
tecnosys | 0:0b777ff85deb | 945 | break; |
tecnosys | 0:0b777ff85deb | 946 | } |
tecnosys | 0:0b777ff85deb | 947 | } |
tecnosys | 0:0b777ff85deb | 948 | #endif /* USB_AUDIO */ |
tecnosys | 0:0b777ff85deb | 949 | #if USB_CDC |
tecnosys | 0:0b777ff85deb | 950 | if ((SetupPacket.wIndex.WB.L == USB_CDC_CIF_NUM) || /* IF number correct? */ |
tecnosys | 0:0b777ff85deb | 951 | (SetupPacket.wIndex.WB.L == USB_CDC_DIF_NUM)) { |
tecnosys | 0:0b777ff85deb | 952 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 953 | case CDC_SEND_ENCAPSULATED_COMMAND: |
tecnosys | 0:0b777ff85deb | 954 | if (CDC_SendEncapsulatedCommand()) { |
tecnosys | 0:0b777ff85deb | 955 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 956 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 957 | } |
tecnosys | 0:0b777ff85deb | 958 | break; |
tecnosys | 0:0b777ff85deb | 959 | case CDC_SET_COMM_FEATURE: |
tecnosys | 0:0b777ff85deb | 960 | if (CDC_SetCommFeature(SetupPacket.wValue.W)) { |
tecnosys | 0:0b777ff85deb | 961 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 962 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 963 | } |
tecnosys | 0:0b777ff85deb | 964 | break; |
tecnosys | 0:0b777ff85deb | 965 | case CDC_SET_LINE_CODING: |
tecnosys | 0:0b777ff85deb | 966 | if (CDC_SetLineCoding()) { |
tecnosys | 0:0b777ff85deb | 967 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 968 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 969 | } |
tecnosys | 0:0b777ff85deb | 970 | break; |
tecnosys | 0:0b777ff85deb | 971 | } |
tecnosys | 0:0b777ff85deb | 972 | } |
tecnosys | 0:0b777ff85deb | 973 | #endif /* USB_CDC */ |
tecnosys | 0:0b777ff85deb | 974 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 975 | /* end case REQUEST_TO_INTERFACE */ |
tecnosys | 0:0b777ff85deb | 976 | |
tecnosys | 0:0b777ff85deb | 977 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 978 | #if USB_AUDIO |
tecnosys | 0:0b777ff85deb | 979 | switch (SetupPacket.bRequest) { |
tecnosys | 0:0b777ff85deb | 980 | case AUDIO_REQUEST_SET_CUR: |
tecnosys | 0:0b777ff85deb | 981 | // case AUDIO_REQUEST_SET_MIN: |
tecnosys | 0:0b777ff85deb | 982 | // case AUDIO_REQUEST_SET_MAX: |
tecnosys | 0:0b777ff85deb | 983 | // case AUDIO_REQUEST_SET_RES: |
tecnosys | 0:0b777ff85deb | 984 | if (ADC_EP_SetRequest()) { |
tecnosys | 0:0b777ff85deb | 985 | USB_StatusInStage(); /* send Acknowledge */ |
tecnosys | 0:0b777ff85deb | 986 | goto out_class_ok; |
tecnosys | 0:0b777ff85deb | 987 | } |
tecnosys | 0:0b777ff85deb | 988 | break; |
tecnosys | 0:0b777ff85deb | 989 | } |
tecnosys | 0:0b777ff85deb | 990 | #endif /* USB_AUDIO */ |
tecnosys | 0:0b777ff85deb | 991 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 992 | /* end case REQUEST_TO_ENDPOINT */ |
tecnosys | 0:0b777ff85deb | 993 | |
tecnosys | 0:0b777ff85deb | 994 | default: |
tecnosys | 0:0b777ff85deb | 995 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 996 | } |
tecnosys | 0:0b777ff85deb | 997 | out_class_ok: /* request finished successfully */ |
tecnosys | 0:0b777ff85deb | 998 | break; /* end case REQUEST_CLASS */ |
tecnosys | 0:0b777ff85deb | 999 | #endif /* USB_CLASS */ |
tecnosys | 0:0b777ff85deb | 1000 | |
tecnosys | 0:0b777ff85deb | 1001 | #if USB_VENDOR |
tecnosys | 0:0b777ff85deb | 1002 | case REQUEST_VENDOR: |
tecnosys | 0:0b777ff85deb | 1003 | switch (SetupPacket.bmRequestType.BM.Recipient) { |
tecnosys | 0:0b777ff85deb | 1004 | |
tecnosys | 0:0b777ff85deb | 1005 | case REQUEST_TO_DEVICE: |
tecnosys | 0:0b777ff85deb | 1006 | if (!USB_ReqVendorDev(FALSE)) { |
tecnosys | 0:0b777ff85deb | 1007 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 1008 | } |
tecnosys | 0:0b777ff85deb | 1009 | break; |
tecnosys | 0:0b777ff85deb | 1010 | |
tecnosys | 0:0b777ff85deb | 1011 | case REQUEST_TO_INTERFACE: |
tecnosys | 0:0b777ff85deb | 1012 | if (!USB_ReqVendorIF(FALSE)) { |
tecnosys | 0:0b777ff85deb | 1013 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 1014 | } |
tecnosys | 0:0b777ff85deb | 1015 | break; |
tecnosys | 0:0b777ff85deb | 1016 | |
tecnosys | 0:0b777ff85deb | 1017 | case REQUEST_TO_ENDPOINT: |
tecnosys | 0:0b777ff85deb | 1018 | if (!USB_ReqVendorEP(FALSE)) { |
tecnosys | 0:0b777ff85deb | 1019 | goto stall_i; /* not supported */ |
tecnosys | 0:0b777ff85deb | 1020 | } |
tecnosys | 0:0b777ff85deb | 1021 | break; |
tecnosys | 0:0b777ff85deb | 1022 | |
tecnosys | 0:0b777ff85deb | 1023 | default: |
tecnosys | 0:0b777ff85deb | 1024 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 1025 | } |
tecnosys | 0:0b777ff85deb | 1026 | |
tecnosys | 0:0b777ff85deb | 1027 | USB_StatusInStage(); |
tecnosys | 0:0b777ff85deb | 1028 | |
tecnosys | 0:0b777ff85deb | 1029 | break; /* end case REQUEST_VENDOR */ |
tecnosys | 0:0b777ff85deb | 1030 | #endif /* USB_VENDOR */ |
tecnosys | 0:0b777ff85deb | 1031 | |
tecnosys | 0:0b777ff85deb | 1032 | default: |
tecnosys | 0:0b777ff85deb | 1033 | goto stall_i; |
tecnosys | 0:0b777ff85deb | 1034 | } |
tecnosys | 0:0b777ff85deb | 1035 | } |
tecnosys | 0:0b777ff85deb | 1036 | } |
tecnosys | 0:0b777ff85deb | 1037 | } else { |
tecnosys | 0:0b777ff85deb | 1038 | USB_StatusOutStage(); /* receive Acknowledge */ |
tecnosys | 0:0b777ff85deb | 1039 | } |
tecnosys | 0:0b777ff85deb | 1040 | break; /* end case USB_EVT_OUT */ |
tecnosys | 0:0b777ff85deb | 1041 | |
tecnosys | 0:0b777ff85deb | 1042 | case USB_EVT_IN : |
tecnosys | 0:0b777ff85deb | 1043 | if (SetupPacket.bmRequestType.BM.Dir == REQUEST_DEVICE_TO_HOST) { |
tecnosys | 0:0b777ff85deb | 1044 | USB_DataInStage(); /* send data */ |
tecnosys | 0:0b777ff85deb | 1045 | } else { |
tecnosys | 0:0b777ff85deb | 1046 | if (USB_DeviceAddress & 0x80) { |
tecnosys | 0:0b777ff85deb | 1047 | USB_DeviceAddress &= 0x7F; |
tecnosys | 0:0b777ff85deb | 1048 | USB_SetAddress(USB_DeviceAddress); |
tecnosys | 0:0b777ff85deb | 1049 | } |
tecnosys | 0:0b777ff85deb | 1050 | } |
tecnosys | 0:0b777ff85deb | 1051 | break; /* end case USB_EVT_IN */ |
tecnosys | 0:0b777ff85deb | 1052 | |
tecnosys | 0:0b777ff85deb | 1053 | case USB_EVT_OUT_STALL: |
tecnosys | 0:0b777ff85deb | 1054 | USB_ClrStallEP(0x00); |
tecnosys | 0:0b777ff85deb | 1055 | break; |
tecnosys | 0:0b777ff85deb | 1056 | |
tecnosys | 0:0b777ff85deb | 1057 | case USB_EVT_IN_STALL: |
tecnosys | 0:0b777ff85deb | 1058 | USB_ClrStallEP(0x80); |
tecnosys | 0:0b777ff85deb | 1059 | break; |
tecnosys | 0:0b777ff85deb | 1060 | |
tecnosys | 0:0b777ff85deb | 1061 | } |
tecnosys | 0:0b777ff85deb | 1062 | } |