⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 f326_usb0_standard_requests.lst

📁 基于F326单片机的RS232转USB程序
💻 LST
📖 第 1 页 / 共 3 页
字号:
 231   2            Force_Stall ();                  // Otherwise send stall to host
 232   2         }
 233   1      
 234   1         else
 235   1         {
 236   2                // Make sure endpoint exists and that halt
 237   2            if ( (SETUP.bmRequestType == IN_ENDPOINT)&&
 238   2            // endpoint feature is selected
 239   2            (SETUP.wValue.c[LSB] == ENDPOINT_HALT) &&
 240   2            ((SETUP.wIndex.c[LSB] == IN_EP1)        ||
 241   2            (SETUP.wIndex.c[LSB] == OUT_EP2) ) )
C51 COMPILER V7.50   F326_USB0_STANDARD_REQUESTS                                           12/29/2007 16:03:24 PAGE 5   

 242   2            {
 243   3               if (SETUP.wIndex.c[LSB] == IN_EP1)
 244   3               {
 245   4                  POLL_WRITE_BYTE (INDEX, 1);// Set feature endpoint 1 halt
 246   4                  POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
 247   4                  EP_STATUS[1] = EP_HALT;
 248   4               }
 249   3            }
 250   2            else
 251   2            {
 252   3               Force_Stall ();               // Send procedural stall
 253   3            }
 254   2         }
 255   1         POLL_WRITE_BYTE (INDEX, 0);
 256   1         if (EP_STATUS[0] != EP_STALL)
 257   1         {
 258   2            POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
 259   2                                             // Indicate SETUP packet has been
 260   2                                             // serviced
 261   2         }
 262   1      }
 263          
 264          //-----------------------------------------------------------------------------
 265          // Set_Address
 266          //-----------------------------------------------------------------------------
 267          //
 268          // Return Value - None
 269          // Parameters - None
 270          //
 271          // Standard request that should not change in custom HID designs.
 272          //
 273          //-----------------------------------------------------------------------------
 274          void Set_Address (void)                // Set new function address
 275          {
 276   1         // Request must be directed to device
 277   1         if ((SETUP.bmRequestType != IN_DEVICE) ||
 278   1         // with index and length set to zero.
 279   1         SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB]||
 280   1         SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB]||
 281   1         SETUP.wValue.c[MSB]  || (SETUP.wValue.c[LSB] & 0x80))
 282   1         {
 283   2           Force_Stall ();                   // Send stall if SETUP data invalid
 284   2         }
 285   1      
 286   1         EP_STATUS[0] = EP_ADDRESS;          // Set endpoint zero to update
 287   1                                                                                 // address next status phase
 288   1         if (SETUP.wValue.c[LSB] != 0)
 289   1         {
 290   2            USB0_STATE = DEV_ADDRESS;        // Indicate that device state is now
 291   2                                                                         // address
 292   2         }
 293   1         else
 294   1         {
 295   2            USB0_STATE = DEV_DEFAULT;        // If new address was 0x00, return
 296   2         }                                   // device to default state
 297   1         if (EP_STATUS[0] != EP_STALL)
 298   1         {
 299   2            POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
 300   2                                             // Indicate SETUP packet has
 301   2                                             // been serviced
 302   2         }
 303   1      }
C51 COMPILER V7.50   F326_USB0_STANDARD_REQUESTS                                           12/29/2007 16:03:24 PAGE 6   

 304          
 305          //-----------------------------------------------------------------------------
 306          // Get_Descriptor
 307          //-----------------------------------------------------------------------------
 308          //
 309          // Return Value - None
 310          // Parameters - None
 311          //
 312          // Standard request that should not change in custom HID designs.
 313          //
 314          //-----------------------------------------------------------------------------
 315          void Get_Descriptor (void)             // This routine sets the data pointer
 316          {                                      // and size to correct descriptor and
 317   1                                             // sets the endpoint status to transmit
 318   1      
 319   1         switch(SETUP.wValue.c[MSB])         // Determine which type of descriptor
 320   1         {                                   // was requested, and set data ptr and
 321   2            case DSC_DEVICE:                 // size accordingly
 322   2               DATAPTR = (unsigned char*) &DEVICEDESC;
 323   2               DATASIZE = DEVICEDESC.bLength;
 324   2               break;
 325   2      
 326   2            case DSC_CONFIG:
 327   2               DATAPTR = (unsigned char*) &ConfigDesc;
 328   2                                             // Compiler Specific - The next statement
 329   2                                             // reverses the bytes in the configuration
 330   2                                             // descriptor for the compiler
 331   2               DATASIZE = ConfigDesc.wTotalLength.c[MSB] +
 332   2                          256*ConfigDesc.wTotalLength.c[LSB];
 333   2               break;
 334   2      
 335   2            case DSC_STRING:
 336   2      
 337   2               DATAPTR = STRINGDESCTABLE[SETUP.wValue.c[LSB]];
 338   2                                                     // Can have a maximum of 255 strings
 339   2               DATASIZE = *DATAPTR;
 340   2               break;
 341   2      
 342   2            case DSC_INTERFACE:
 343   2               DATAPTR = (unsigned char*) &InterfaceDesc;
 344   2               DATASIZE = InterfaceDesc.bLength;
 345   2               break;
 346   2      
 347   2            case DSC_ENDPOINT:
 348   2               if ( (SETUP.wValue.c[LSB] == IN_EP1) )
 349   2               {
 350   3                  if (SETUP.wValue.c[LSB] == IN_EP1)
 351   3                  {
 352   4                     DATAPTR = (unsigned char*) &Endpoint1Desc;
 353   4                     DATASIZE = Endpoint1Desc.bLength;
 354   4                  }
 355   3                  else
 356   3                  {
 357   4                     DATAPTR = (unsigned char*) &Endpoint2Desc;
 358   4                     DATASIZE = Endpoint2Desc.bLength;
 359   4                  }
 360   3               }
 361   2               else
 362   2               {
 363   3                  Force_Stall();
 364   3               }
 365   2               break;
C51 COMPILER V7.50   F326_USB0_STANDARD_REQUESTS                                           12/29/2007 16:03:24 PAGE 7   

 366   2      
 367   2              case DSC_HID: // HID Specific (HID class descriptor)
 368   2                      DATAPTR = (unsigned char*)&HidDesc;
 369   2                      DATASIZE = HidDesc.bLength;
 370   2                      break;
 371   2      
 372   2              case DSC_HID_REPORT: // HID Specific (HID report descriptor)
 373   2                      DATAPTR = (unsigned char*)&HIDREPORTDESC;
 374   2                      DATASIZE = HID_REPORT_DESCRIPTOR_SIZE;
 375   2                      break;
 376   2      
 377   2            default:
 378   2               Force_Stall ();               // Send Stall if unsupported request
 379   2               break;
 380   2         }
 381   1      
 382   1         // Verify that the requested descriptor is valid
 383   1         if (SETUP.wValue.c[MSB] == DSC_DEVICE ||
 384   1         SETUP.wValue.c[MSB] == DSC_CONFIG     ||
 385   1         SETUP.wValue.c[MSB] == DSC_STRING     ||
 386   1         SETUP.wValue.c[MSB] == DSC_INTERFACE  ||
 387   1         SETUP.wValue.c[MSB] == DSC_ENDPOINT)
 388   1         {
 389   2            if ((SETUP.wLength.c[LSB] < DATASIZE) &&
 390   2            (SETUP.wLength.c[MSB] == 0))
 391   2            {
 392   3               DATASIZE = SETUP.wLength.i;   // Send only requested amount of data
 393   3            }
 394   2         }
 395   1         if (EP_STATUS[0] != EP_STALL)       // Make sure endpoint not in stall mode
 396   1         {
 397   2           POLL_WRITE_BYTE (E0CSR, rbSOPRDY);// Service SETUP Packet
 398   2           EP_STATUS[0] = EP_TX;             // Put endpoint in transmit mode
 399   2           DATASENT = 0;                     // Reset Data Sent counter
 400   2         }
 401   1      }
 402          
 403          //-----------------------------------------------------------------------------
 404          // Get_Configuration
 405          //-----------------------------------------------------------------------------
 406          //
 407          // Return Value - None
 408          // Parameters - None
 409          //
 410          // Standard request that should not change in custom HID designs.
 411          //
 412          //-----------------------------------------------------------------------------
 413          void Get_Configuration (void)          // This routine returns current
 414          {                                                                          // configuration value
 415   1         // This request must be directed to the device
 416   1         if ( (SETUP.bmRequestType != OUT_DEVICE)    ||
 417   1         // with value word set to zero
 418   1         SETUP.wValue.c[MSB]  || SETUP.wValue.c[LSB] ||
 419   1         // and index set to zero
 420   1         SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB] ||
 421   1         // and SETUP length set to one
 422   1         SETUP.wLength.c[MSB] || (SETUP.wLength.c[LSB] != 1) )
 423   1         {
 424   2            Force_Stall ();                  // Otherwise send a stall to host
 425   2         }
 426   1      
 427   1         else
C51 COMPILER V7.50   F326_USB0_STANDARD_REQUESTS                                           12/29/2007 16:03:24 PAGE 8   

 428   1         {
 429   2            if (USB0_STATE == DEV_CONFIGURED)// If the device is configured, then
 430   2            {                                // return value 0x01 since this software
 431   3                                                                         // only supports one configuration
 432   3               DATAPTR = (unsigned char*)&ONES_PACKET;
 433   3               DATASIZE = 1;
 434   3            }
 435   2            if (USB0_STATE == DEV_ADDRESS)   // If the device is in address state, it
 436   2            {                                // is not configured, so return 0x00
 437   3               DATAPTR = (unsigned char*)&ZERO_PACKET;
 438   3               DATASIZE = 1;
 439   3            }
 440   2         }
 441   1         if (EP_STATUS[0] != EP_STALL)
 442   1         {
 443   2                // Set Serviced Out Packet bit
 444   2            POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
 445   2            EP_STATUS[0] = EP_TX;            // Put endpoint into transmit mode
 446   2            DATASENT = 0;                    // Reset Data Sent counter to zero
 447   2         }
 448   1      }
 449          
 450          //-----------------------------------------------------------------------------
 451          // Set_Configuration
 452          //-----------------------------------------------------------------------------
 453          //
 454          // Return Value - None
 455          // Parameters - None
 456          //
 457          // Standard request that should not change in custom HID designs.
 458          //
 459          //-----------------------------------------------------------------------------
 460          void Set_Configuration (void)          // This routine allows host to change
 461          {                                      // current device configuration value
 462   1      
 463   1         // Device must be addressed before configured
 464   1         if ((USB0_STATE == DEV_DEFAULT) ||
 465   1         // and request recipient must be the device
 466   1         (SETUP.bmRequestType != IN_DEVICE) ||
 467   1         // the index and length words must be zero

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -