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

📄 f3xx_usb0_standard_requests.lst

📁 基于344单片机的HID设备的USB鼠标代码
💻 LST
📖 第 1 页 / 共 3 页
字号:
 240          //
 241          // Return Value - None
C51 COMPILER V8.05a   F3XX_USB0_STANDARD_REQUESTS                                          10/16/2008 16:50:25 PAGE 5   

 242          // Parameters - None
 243          //
 244          // Standard request that should not change in custom HID designs.
 245          //
 246          //-----------------------------------------------------------------------------
 247          void Set_Feature (void)                // This routine will set the EP Halt
 248          {                                      // feature for endpoint 1
 249   1      
 250   1         // Make sure device is configured, SETUP data
 251   1         if ((USB0_STATE != DEV_CONFIGURED) ||
 252   1         // is all valid and that request is directed at an endpoint
 253   1         (SETUP.bmRequestType == IN_DEVICE) ||
 254   1         (SETUP.bmRequestType == IN_INTERFACE) ||
 255   1         SETUP.wValue.c[MSB]  || SETUP.wIndex.c[MSB] ||
 256   1         SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB])
 257   1         {
 258   2            Force_Stall ();                  // Otherwise send stall to host
 259   2         }
 260   1      
 261   1         else
 262   1         {
 263   2                // Make sure endpoint exists and that halt
 264   2            if ( (SETUP.bmRequestType == IN_ENDPOINT)&&
 265   2            // endpoint feature is selected
 266   2            (SETUP.wValue.c[LSB] == ENDPOINT_HALT) &&
 267   2            ((SETUP.wIndex.c[LSB] == IN_EP1)        ||
 268   2            (SETUP.wIndex.c[LSB] == OUT_EP2) ) )
 269   2            {
 270   3               if (SETUP.wIndex.c[LSB] == IN_EP1)
 271   3               {
 272   4                  POLL_WRITE_BYTE (INDEX, 1);// Set feature endpoint 1 halt
 273   4                  POLL_WRITE_BYTE (EINCSR1, rbInSDSTL);
 274   4                  EP_STATUS[1] = EP_HALT;
 275   4               }
 276   3            }
 277   2            else
 278   2            {
 279   3               Force_Stall ();               // Send procedural stall
 280   3            }
 281   2         }
 282   1         POLL_WRITE_BYTE (INDEX, 0);
 283   1         if (EP_STATUS[0] != EP_STALL)
 284   1         {
 285   2            POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
 286   2                                             // Indicate SETUP packet has been
 287   2                                             // serviced
 288   2         }
 289   1      }
 290          
 291          //-----------------------------------------------------------------------------
 292          // Set_Address
 293          //-----------------------------------------------------------------------------
 294          //
 295          // Return Value - None
 296          // Parameters - None
 297          //
 298          // Standard request that should not change in custom HID designs.
 299          //
 300          //-----------------------------------------------------------------------------
 301          void Set_Address (void)                // Set new function address
 302          {
 303   1         // Request must be directed to device
C51 COMPILER V8.05a   F3XX_USB0_STANDARD_REQUESTS                                          10/16/2008 16:50:25 PAGE 6   

 304   1         if ((SETUP.bmRequestType != IN_DEVICE) ||
 305   1         // with index and length set to zero.
 306   1         SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB]||
 307   1         SETUP.wLength.c[MSB] || SETUP.wLength.c[LSB]||
 308   1         SETUP.wValue.c[MSB]  || (SETUP.wValue.c[LSB] & 0x80))
 309   1         {
 310   2           Force_Stall ();                   // Send stall if SETUP data invalid
 311   2         }
 312   1      
 313   1         EP_STATUS[0] = EP_ADDRESS;          // Set endpoint zero to update
 314   1                                                                                 // address next status phase
 315   1         if (SETUP.wValue.c[LSB] != 0)
 316   1         {
 317   2            USB0_STATE = DEV_ADDRESS;        // Indicate that device state is now
 318   2                                                                         // address
 319   2         }
 320   1         else
 321   1         {
 322   2            USB0_STATE = DEV_DEFAULT;        // If new address was 0x00, return
 323   2         }                                   // device to default state
 324   1         if (EP_STATUS[0] != EP_STALL)
 325   1         {
 326   2            POLL_WRITE_BYTE (E0CSR, (rbSOPRDY | rbDATAEND));
 327   2                                             // Indicate SETUP packet has
 328   2                                             // been serviced
 329   2         }
 330   1      }
 331          
 332          //-----------------------------------------------------------------------------
 333          // Get_Descriptor
 334          //-----------------------------------------------------------------------------
 335          //
 336          // Return Value - None
 337          // Parameters - None
 338          //
 339          // Standard request that should not change in custom HID designs.
 340          //
 341          //-----------------------------------------------------------------------------
 342          void Get_Descriptor (void)             // This routine sets the data pointer
 343          {                                      // and size to correct descriptor and
 344   1                                             // sets the endpoint status to transmit
 345   1      
 346   1         switch(SETUP.wValue.c[MSB])         // Determine which type of descriptor
 347   1         {                                   // was requested, and set data ptr and
 348   2            case DSC_DEVICE:                 // size accordingly
 349   2               DATAPTR = (unsigned char*) &DEVICEDESC;
 350   2               DATASIZE = DEVICEDESC.bLength;
 351   2               break;
 352   2      
 353   2            case DSC_CONFIG:
 354   2               DATAPTR = (unsigned char*) &ConfigDesc;
 355   2                                             // Compiler Specific - The next statement
 356   2                                             // reverses the bytes in the configuration
 357   2                                             // descriptor for the compiler
 358   2               DATASIZE = ConfigDesc.wTotalLength.c[MSB] +
 359   2                          256*ConfigDesc.wTotalLength.c[LSB];
 360   2               break;
 361   2      
 362   2                case DSC_STRING:
 363   2               DATAPTR = STRINGDESCTABLE[SETUP.wValue.c[LSB]];
 364   2                                                     // Can have a maximum of 255 strings
 365   2               DATASIZE = *DATAPTR;
C51 COMPILER V8.05a   F3XX_USB0_STANDARD_REQUESTS                                          10/16/2008 16:50:25 PAGE 7   

 366   2               break;
 367   2      
 368   2            case DSC_INTERFACE:
 369   2               DATAPTR = (unsigned char*) &InterfaceDesc;
 370   2               DATASIZE = InterfaceDesc.bLength;
 371   2               break;
 372   2      
 373   2            case DSC_ENDPOINT:
 374   2               if ( (SETUP.wValue.c[LSB] == IN_EP1) )
 375   2               {
 376   3                  if (SETUP.wValue.c[LSB] == IN_EP1)
 377   3                  {
 378   4                     DATAPTR = (unsigned char*) &Endpoint1Desc;
 379   4                     DATASIZE = Endpoint1Desc.bLength;
 380   4                  }
 381   3                  else
 382   3                  {
 383   4                     DATAPTR = (unsigned char*) &Endpoint2Desc;
 384   4                     DATASIZE = Endpoint2Desc.bLength;
 385   4                  }
 386   3               }
 387   2               else
 388   2               {
 389   3                  Force_Stall();
 390   3               }
 391   2               break;
 392   2      
 393   2              case DSC_HID: // HID Specific (HID class descriptor)
 394   2                      DATAPTR = (unsigned char*)&HidDesc;
 395   2                      DATASIZE = HidDesc.bLength;
 396   2                      break;
 397   2      
 398   2              case DSC_HID_REPORT: // HID Specific (HID report descriptor)
 399   2                      DATAPTR = (unsigned char*)&HIDREPORTDESC;
 400   2                      DATASIZE = HID_REPORT_DESCRIPTOR_SIZE;
 401   2                      break;
 402   2      
 403   2            default:
 404   2               Force_Stall ();               // Send Stall if unsupported request
 405   2               break;
 406   2         }
 407   1      
 408   1         // Verify that the requested descriptor is valid
 409   1         if (SETUP.wValue.c[MSB] == DSC_DEVICE ||
 410   1         SETUP.wValue.c[MSB] == DSC_CONFIG     ||
 411   1         SETUP.wValue.c[MSB] == DSC_STRING     ||
 412   1         SETUP.wValue.c[MSB] == DSC_INTERFACE  ||
 413   1         SETUP.wValue.c[MSB] == DSC_ENDPOINT)
 414   1         {
 415   2            if ((SETUP.wLength.c[LSB] < DATASIZE) &&
 416   2            (SETUP.wLength.c[MSB] == 0))
 417   2            {
 418   3               DATASIZE = SETUP.wLength.i;   // Send only requested amount of data
 419   3            }
 420   2         }
 421   1         if (EP_STATUS[0] != EP_STALL)       // Make sure endpoint not in stall mode
 422   1         {
 423   2           POLL_WRITE_BYTE (E0CSR, rbSOPRDY);// Service SETUP Packet
 424   2           EP_STATUS[0] = EP_TX;             // Put endpoint in transmit mode
 425   2           DATASENT = 0;                     // Reset Data Sent counter
 426   2         }
 427   1      }
C51 COMPILER V8.05a   F3XX_USB0_STANDARD_REQUESTS                                          10/16/2008 16:50:25 PAGE 8   

 428          
 429          //-----------------------------------------------------------------------------
 430          // Get_Configuration
 431          //-----------------------------------------------------------------------------
 432          //
 433          // Return Value - None
 434          // Parameters - None
 435          //
 436          // Standard request that should not change in custom HID designs.
 437          //
 438          //-----------------------------------------------------------------------------
 439          void Get_Configuration (void)          // This routine returns current
 440          {                                                                          // configuration value
 441   1         // This request must be directed to the device
 442   1         if ( (SETUP.bmRequestType != OUT_DEVICE)    ||
 443   1         // with value word set to zero
 444   1         SETUP.wValue.c[MSB]  || SETUP.wValue.c[LSB]||
 445   1         // and index set to zero
 446   1         SETUP.wIndex.c[MSB]  || SETUP.wIndex.c[LSB]||
 447   1         // and SETUP length set to one
 448   1         SETUP.wLength.c[MSB] || (SETUP.wLength.c[LSB] != 1) )
 449   1         {
 450   2            Force_Stall ();                  // Otherwise send a stall to host
 451   2         }
 452   1      
 453   1         else
 454   1         {
 455   2            if (USB0_STATE == DEV_CONFIGURED)// If the device is configured, then
 456   2            {                                // return value 0x01 since this software
 457   3                                                                         // only supports one configuration
 458   3               DATAPTR = (unsigned char*)&ONES_PACKET;
 459   3               DATASIZE = 1;
 460   3            }
 461   2            if (USB0_STATE == DEV_ADDRESS)   // If the device is in address state, it
 462   2            {                                // is not configured, so return 0x00
 463   3               DATAPTR = (unsigned char*)&ZERO_PACKET;
 464   3               DATASIZE = 1;
 465   3            }
 466   2         }
 467   1         if (EP_STATUS[0] != EP_STALL)
 468   1         {
 469   2                // Set Serviced Out Packet bit
 470   2            POLL_WRITE_BYTE (E0CSR, rbSOPRDY);
 471   2            EP_STATUS[0] = EP_TX;            // Put endpoint into transmit mode
 472   2            DATASENT = 0;                    // Reset Data Sent counter to zero
 473   2         }
 474   1      }
 475          
 476          //-----------------------------------------------------------------------------
 477          // Set_Configuration
 478          //-----------------------------------------------------------------------------
 479          //
 480          // Return Value - None
 481          // Parameters - None
 482          //
 483          // Standard request that should not change in custom HID designs.
 484          //
 485          //-----------------------------------------------------------------------------

⌨️ 快捷键说明

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