These are the examples provided for [[/users/frank26080115/libraries/LPC1700CMSIS_Lib/]] Note, the entire "program" is not compilable!

Committer:
frank26080115
Date:
Sun Mar 20 05:38:56 2011 +0000
Revision:
0:bf7b9fba3924

        

Who changed what in which revision?

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