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

📄 usbproto.lst

📁 Comlete files for fullfile the slave USB function!
💻 LST
📖 第 1 页 / 共 2 页
字号:
 264          void reserved(void)
 265          {
 266   1              stall_ep0();
 267   1      }
 268          
 269          //*************************************************************************
 270          // USB standard device requests
 271          //*************************************************************************
 272          void get_status(void)
 273          {
 274   1              unsigned char endp, txdat[2];
 275   1              unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
 276   1              unsigned char c;
 277   1      
 278   1              if (bRecipient == USB_RECIPIENT_DEVICE) {
 279   2                      if(bEPPflags.bits.remote_wakeup == 1)
 280   2                              txdat[0] = 3;
 281   2                      else
 282   2                              txdat[0] = 1;
 283   2                      txdat[1]=0;
 284   2                      single_transmit(txdat, 2);
 285   2              } else if (bRecipient == USB_RECIPIENT_INTERFACE) {
 286   2                      txdat[0]=0;
 287   2                      txdat[1]=0;
 288   2                      single_transmit(txdat, 2);
 289   2              } else if (bRecipient == USB_RECIPIENT_ENDPOINT) {
 290   2                      endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
 291   2                      if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
 292   2                              c = D12_SelectEndpoint(endp*2 + 1);     /* Control-in */
 293   2                      else
 294   2                              c = D12_SelectEndpoint(endp*2); /* Control-out */
 295   2                      if(c & D12_STALL)
 296   2                              txdat[0] = 1;
 297   2                      else
 298   2                              txdat[0] = 0;
 299   2                      txdat[1] = 0;
 300   2                      single_transmit(txdat, 2);
 301   2              } else
 302   1                      stall_ep0();
 303   1      }
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 6   

 304          
 305          void clear_feature(void)
 306          {
 307   1              unsigned char endp;
 308   1              unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
 309   1      
 310   1              if (bRecipient == USB_RECIPIENT_DEVICE
 311   1                      && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) {
 312   2                      DISABLE;
 313   2                      bEPPflags.bits.remote_wakeup = 0;
 314   2                      ENABLE;
 315   2                      single_transmit(0, 0);
 316   2              }
 317   1              else if (bRecipient == USB_RECIPIENT_ENDPOINT
 318   1                      && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL) {
 319   2                      endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
 320   2                      if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
 321   2                              /* clear TX stall for IN on EPn. */
 322   2                              D12_SetEndpointStatus(endp*2 + 1, 0);
 323   2                      else
 324   2                              /* clear RX stall for OUT on EPn. */
 325   2                              D12_SetEndpointStatus(endp*2, 0);
 326   2                      single_transmit(0, 0);
 327   2              } else
 328   1                      stall_ep0();
 329   1      }
 330          
 331          void set_feature(void)
 332          {
 333   1              unsigned char endp;
 334   1              unsigned char bRecipient = ControlData.DeviceRequest.bmRequestType & USB_RECIPIENT;
 335   1      
 336   1              if (bRecipient == USB_RECIPIENT_DEVICE
 337   1                      && ControlData.DeviceRequest.wValue == USB_FEATURE_REMOTE_WAKEUP) {
 338   2                      DISABLE;
 339   2                      bEPPflags.bits.remote_wakeup = 1;
 340   2                      ENABLE;
 341   2                      single_transmit(0, 0);
 342   2              }
 343   1              else if (bRecipient == USB_RECIPIENT_ENDPOINT
 344   1                      && ControlData.DeviceRequest.wValue == USB_FEATURE_ENDPOINT_STALL) {
 345   2                      endp = (unsigned char)(ControlData.DeviceRequest.wIndex & MAX_ENDPOINTS);
 346   2                      if (ControlData.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
 347   2                              /* clear TX stall for IN on EPn. */
 348   2                              D12_SetEndpointStatus(endp*2 + 1, 1);
 349   2                      else
 350   2                              /* clear RX stall for OUT on EPn. */
 351   2                              D12_SetEndpointStatus(endp*2, 1);
 352   2                      single_transmit(0, 0);
 353   2              } else
 354   1                      stall_ep0();
 355   1      }
 356          
 357          void set_address(void)
 358          {
 359   1              D12_SetAddressEnable((unsigned char)(ControlData.DeviceRequest.wValue &
 360   1                      DEVICE_ADDRESS_MASK), 1);
 361   1              single_transmit(0, 0);
 362   1      }
 363          
 364          extern void blinkLED(unsigned char num);
 365          
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 7   

 366          void get_descriptor(void)
 367          {
 368   1              unsigned char strIndex;
 369   1              unsigned char bDescriptor = MSB(ControlData.DeviceRequest.wValue);
 370   1      
 371   1              if (bDescriptor == USB_DEVICE_DESCRIPTOR_TYPE) {
 372   2                      code_transmit((unsigned char code *)&DeviceDescr, sizeof(USB_DEVICE_DESCRIPTOR));
 373   2              } else if (bDescriptor == USB_CONFIGURATION_DESCRIPTOR_TYPE) {
 374   2                      code_transmit((unsigned char code *)&sConfiguration, CONFIG_DESCRIPTOR_LENGTH);
 375   2              } else if (bDescriptor == USB_INTERFACE_DESCRIPTOR_TYPE) {
 376   2                      code_transmit((unsigned char code *)&sConfiguration.sInterface, 
 377   2                              sizeof(USB_INTERFACE_DESCRIPTOR));
 378   2              } else if (bDescriptor == USB_ENDPOINT_DESCRIPTOR_TYPE) {
 379   2                      code_transmit((unsigned char code *)&sConfiguration.sEndpoint, 
 380   2                              sizeof(USB_ENDPOINT_DESCRIPTOR));
 381   2              } else if (bDescriptor == 0x0021) {     /* HID Descriptor */
 382   2                      code_transmit((unsigned char code *)&sConfiguration.sHID, 
 383   2                              sizeof(USB_HID_DESCRIPTOR));
 384   2              } else if (bDescriptor == 0x0022) {     /*Report Descriptor */
 385   2                      code_transmit((unsigned char code *)&REPORT_DESCRIPTOR, 
 386   2                              sizeof(REPORT_DESCRIPTOR));
 387   2              } else if (bDescriptor == USB_STRING_DESCRIPTOR_TYPE) { /* String Descriptor */
 388   2                      strIndex = LSB(ControlData.DeviceRequest.wValue);
 389   2                      switch (strIndex)
 390   2                      {
 391   3                              case 0x00:
 392   3                                      code_transmit((unsigned char code *)&LANG_ID, sizeof(LANG_ID));
 393   3                                      break;
 394   3                              case 0x01:
 395   3                                      code_transmit((unsigned char code *)&sSTRING1, sizeof(struct STRING1));
 396   3      blinkLED(1);
 397   3                                      break;
 398   3                              case 0x02:
 399   3                                      code_transmit((unsigned char code *)&sSTRING2, sizeof(struct STRING2));
 400   3                                      break;
 401   3                              case 0x03:
 402   3                                      code_transmit((unsigned char code *)&sSTRING3, sizeof(struct STRING3));
 403   3                                      break;
 404   3                              case 0x04:
 405   3                                      code_transmit((unsigned char code *)&sSTRING4, sizeof(struct STRING4));
 406   3                                      break;
 407   3                              default:
 408   3                                      break;
 409   3                      }
 410   2              } else {
 411   2                      stall_ep0();
 412   2              }
 413   1      }
 414          
 415          void get_configuration(void)
 416          {
 417   1              unsigned char c = bEPPflags.bits.configuration;
 418   1      
 419   1              single_transmit(&c, 1);
 420   1      }
 421          
 422          void set_configuration(void)
 423          {
 424   1              if (ControlData.DeviceRequest.wValue == 0) {
 425   2                      /* put device in unconfigured state */
 426   2                      single_transmit(0, 0);
 427   2                      DISABLE;
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 8   

 428   2                      bEPPflags.bits.configuration = 0;
 429   2                      ENABLE;
 430   2                      init_unconfig();
 431   2              } else if (ControlData.DeviceRequest.wValue == 1) {
 432   2                      /* Configure device */
 433   2                      single_transmit(0, 0);
 434   2      
 435   2                      init_unconfig();
 436   2                      init_config();
 437   2                      
 438   2                      DISABLE;
 439   2                      bEPPflags.bits.configuration = 1;
 440   2                      ENABLE;
 441   2              } else
 442   1                      stall_ep0();
 443   1      }
 444          
 445          void get_interface(void)
 446          {
 447   1              unsigned char txdat = 0;        /* Only/Current interface = 0 */
 448   1              single_transmit(&txdat, 1);
 449   1      }
 450          
 451          void set_interface(void)
 452          {
 453   1              if (ControlData.DeviceRequest.wValue == 0 && ControlData.DeviceRequest.wIndex == 0)
 454   1                      single_transmit(0, 0);
 455   1              else
 456   1                      stall_ep0();
 457   1      }
 458          
 459          
 460          //
 461          //      Class Request
 462          //
 463          void get_report (void)
 464          {
 465   1              unsigned char c;
 466   1      
 467   1              //Need to be configured to do this command
 468   1              if (bEPPflags.bits.configuration) {
 469   2                      //Send current switch status to host
 470   2      //      c = Switch;
 471   2              single_transmit(&c, 1);
 472   2              }
 473   1      }
 474          
 475          void get_idle (void)
 476          {
 477   1              unsigned char c;
 478   1      
 479   1              //Need to be configured to do this command
 480   1              if (bEPPflags.bits.configuration) {
 481   2                      c = IDLE_TIME;
 482   2                      single_transmit(&c, 1);
 483   2              }
 484   1      }
 485          
 486          void get_protocol (void)
 487          {
 488   1      // Do nothing,we are not a boot device
 489   1      }
C51 COMPILER V7.50   USBPROTO                                                              04/22/2005 11:54:46 PAGE 9   

 490          
 491          void set_report (void)
 492          {
 493   1              unsigned char len;
 494   1      
 495   1              //Need to be configured to do this command
 496   1              if (bEPPflags.bits.configuration) {
 497   2              // Get LED information from host and set LED
 498   2                      D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */
 499   2                      len = D12_ReadEndpoint(2, GenEpBuf, sizeof(GenEpBuf));
*** WARNING C198 IN LINE 499 OF USBPROTO.C: sizeof returns zero
 500   2                      if(len != 0)
 501   2                              bEPPflags.bits.ep1_rxdone = 1;
 502   2              }
 503   1      }
 504          
 505          void set_idle (void)
 506          {
 507   1              //Need to be configured to do this command
 508   1              if (bEPPflags.bits.configuration) {
 509   2                      //IDLE_TIME = HIBYTE(ControlData.DeviceRequest.wValue);
 510   2                      IDLE_TIME = LSB(ControlData.DeviceRequest.wValue);
 511   2                      single_transmit(0, 0);
 512   2              }
 513   1      }
 514          
 515          void set_protocol (void)
 516          {
 517   1      // Do nothing, we are not a boot device
 518   1      }
 519          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    672    ----
   CONSTANT SIZE    =    377    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      1      14
   IDATA SIZE       =   ----    ----
   BIT SIZE         =   ----    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  1 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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