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

📄 usb.lst

📁 HID 设备测试程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 376   4      
 377   4                                      case 0x01:
 378   4                                      {
 379   5                                              #ifdef __DEBUG__        //== 打印调试信息
 380   5                                                      Print_Msg("             获取厂商字符串................................\r\n");
 381   5                                              #endif
 382   5                                              Control_Data.wCount = ManufacturerString[0];
 383   5                                              Control_Data.pData = ManufacturerString;
 384   5                                      } break;
 385   4      
 386   4                                      case 0x02:
 387   4                                      {
 388   5                                              #ifdef __DEBUG__        //== 打印调试信息
 389   5                                                      Print_Msg("             获取产品字符串................................\r\n");
 390   5                                              #endif
 391   5                                              Control_Data.wCount = ProducterString[0];
 392   5                                              Control_Data.pData = ProducterString;
 393   5                                      } break;
 394   4      
 395   4                                      case 0x03:
 396   4                                      {
 397   5                                              #ifdef __DEBUG__        //== 打印调试信息
 398   5                                                      Print_Msg("             获取设备序列号................................\r\n");
 399   5                                              #endif
 400   5                                              Control_Data.wCount = device_serial_number[0];
 401   5                                              Control_Data.pData = device_serial_number;
 402   5                                      } break;
 403   4      
 404   4                                      default: break;
 405   4                              }
 406   3                      } break;
 407   2      
 408   2                      case INTERFACE_DESCRIPTOR: break;
 409   2                      case ENDPOINT_DESCRIPTOR: break;
 410   2                      case HID_DESCRIPTOR: break;
 411   2                      case REPORT_DESCRIPTOR: break;
 412   2                      case PHYSICAL_DESCRIPTOR: break;
 413   2                      
 414   2                      default:
 415   2                      {
 416   3                              #ifdef __DEBUG__        //== 打印调试信息
 417   3                                      Print_Msg("     获取其它描述符..................描述符索引为:");
 418   3                                      Print_Long(MSB(Control_Data.DeviceRequest.wValue));
 419   3                                      Print_Msg("!\r\n");
 420   3                              #endif
 421   3                      } break;
 422   2              }
 423   1      
 424   1              if (Control_Data.wLength > Control_Data.wCount)
 425   1              {
 426   2                      Control_Data.wLength = Control_Data.wCount;
 427   2              }
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 8   

 428   1              Control_Data.wCount = 0;
 429   1              bEPPflags.bits.control_state = USB_TRANSMIT;            //== 设置为发送状态,等待in端点中断
 430   1              return 0;
 431   1      }
 432          
 433          //===============================================================================//
 434          //== 函 数 名:get_descriptor_interface
 435          //== 功    能:得到描述符
 436          //== 说    明:
 437          //== 时    间:2008.8.20 创建函数
 438          //== 入口参数:无
 439          //== 返 回 值:0
 440          //===============================================================================//
 441          unsigned char get_descriptor_interface(void)
 442          {
 443   1              #ifdef __DEBUG__        //== 打印调试信息
 444   1                      Print_Msg("Runing get_descriptor_interface()!\r\n");
 445   1              #endif
 446   1      
 447   1              #ifdef __DEBUG__        //== 打印调试信息
 448   1                      Print_Msg("     获取描述符(从接口)..............................\r\n");
 449   1              #endif
 450   1      
 451   1              switch(MSB(Control_Data.DeviceRequest.wValue))
 452   1              {
 453   2                      case HID_DESCRIPTOR:
 454   2                      {
 455   3                              #ifdef __DEBUG__        //== 打印调试信息
 456   3                                      Print_Msg("             获取HID描述符................................\r\n");
 457   3                              #endif
 458   3      
 459   3                              Control_Data.wCount = sizeof(HID_DESCRIPTOR_STRUCT);
 460   3                              Control_Data.pData = (unsigned char*)(&con_int_endp_descriptor.hid_descriptor);
 461   3                              if (Control_Data.wLength < Control_Data.wCount)
 462   3                              {
 463   4                                      Control_Data.wCount = Control_Data.wLength;
 464   4                              }
 465   3                      } break;
 466   2      
 467   2                      case REPORT_DESCRIPTOR:
 468   2                      {
 469   3                              #ifdef __DEBUG__        //== 打印调试信息
 470   3                                      Print_Msg("             获取报告描述符................................\r\n");
 471   3                              #endif
 472   3      
 473   3                              Control_Data.wCount = sizeof(DataReportDescriptor);
 474   3                              Control_Data.pData = (unsigned char *)(DataReportDescriptor);
 475   3                              if (Control_Data.wLength < Control_Data.wCount)
 476   3                              {
 477   4                                      Control_Data.wCount = Control_Data.wLength;
 478   4                              }
 479   3                      } break;
 480   2      
 481   2                      case PHYSICAL_DESCRIPTOR:
 482   2                      {
 483   3                              #ifdef __DEBUG__        //== 打印调试信息
 484   3                                      Print_Msg("             获取物理描述符................................\r\n");
 485   3                              #endif
 486   3                      } break;
 487   2      
 488   2                      default:
 489   2                      {
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 9   

 490   3                              #ifdef __DEBUG__        //== 打印调试信息
 491   3                                      Print_Msg("             获取其它描述符..................描述符索引为:");
 492   3                                      Print_Long(MSB(Control_Data.DeviceRequest.wValue));
 493   3                                      Print_Msg("!\r\n");
 494   3                              #endif
 495   3                      } break;
 496   2              }
 497   1      
 498   1              if (Control_Data.wLength > Control_Data.wCount)
 499   1              {
 500   2                      Control_Data.wLength = Control_Data.wCount;
 501   2              }
 502   1              Control_Data.wCount = 0;
 503   1              bEPPflags.bits.control_state = USB_TRANSMIT;            //== 设置为发送状态,等待in端点中断
 504   1              return 0;
 505   1      }
 506          //===============================================================================//
 507          //== 函 数 名:set_descriptor
 508          //== 功    能:设置描述符
 509          //== 说    明:
 510          //== 时    间:2008.8.20 创建函数
 511          //== 入口参数:无
 512          //== 返 回 值:0
 513          //===============================================================================//
 514          unsigned char set_descriptor(void)
 515          {
 516   1              #ifdef __DEBUG__        //== 打印调试信息
 517   1                      Print_Msg("                     设置描述符................................\r\n");
 518   1              #endif
 519   1              return 0;
 520   1      }
 521          
 522          //===============================================================================//
 523          //== 函 数 名:get_configuration
 524          //== 功    能:得到配置
 525          //== 说    明:
 526          //== 时    间:2008.8.20 创建函数
 527          //== 入口参数:无
 528          //== 返 回 值:0
 529          //===============================================================================//
 530          unsigned char get_configuration(void)
 531          {
 532   1              #ifdef __DEBUG__        //== 打印调试信息
 533   1                      Print_Msg("Runing get_configuration()!\r\n");
 534   1              #endif
 535   1              usb_transmit_buf[0] = 1;
 536   1              Control_Data.pData = usb_transmit_buf;
 537   1      
 538   1              Control_Data.wLength = 1;
 539   1              Control_Data.wCount = 0;
 540   1              bEPPflags.bits.control_state = USB_TRANSMIT;            //== 设置为发送状态,等待in端点中断
 541   1              return 0;
 542   1      }
 543          
 544          //===============================================================================//
 545          //== 函 数 名:set_configuration
 546          //== 功    能:设置配置
 547          //== 说    明:
 548          //== 时    间:2008.8.20 创建函数
 549          //== 入口参数:无
 550          //== 返 回 值:0
 551          //===============================================================================//
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 10  

 552          unsigned char set_configuration(void)
 553          {
 554   1              #ifdef __DEBUG__        //== 打印调试信息
 555   1                      Print_Msg("Runing set_configuration()!\r\n");
 556   1              #endif
 557   1              if (Control_Data.DeviceRequest.wValue == 0)                                     //== 设备进入未配置状态
 558   1              {
 559   2                      bEPPflags.bits.configuration = 0;
 560   2                      Control_Data.wLength = 0;                                                               //== 发送0字节长度数据到主机做回答
 561   2                      Control_Data.wCount = 0;
 562   2                      bEPPflags.bits.control_state = USB_TRANSMIT;                    //== 设置为发送状态,等待in端点中断
 563   2                      set_endpoint_disable();
 564   2              }
 565   1              else
 566   1              {
 567   2                      if (Control_Data.DeviceRequest.wValue == 1)                             //== 配置设备

⌨️ 快捷键说明

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