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

📄 usb.lst

📁 HID 设备测试程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
 184          //== 入口参数:无
 185          //== 返 回 值:0
 186          //===============================================================================//
 187          unsigned char usb_bus_suspend(void)
 188          {
 189   1              #ifdef __DEBUG__        //== 打印调试信息
 190   1                      Print_Msg("Runing usb_bus_suspend()!\r\n");
 191   1              #endif
 192   1      
 193   1              #ifdef __DEBUG__        //== 打印调试信息
 194   1                      Print_Msg("USB总线挂起................................\r\n");
 195   1              #endif
 196   1      
 197   1              bEPPflags.bits.suspend = 1;
 198   1      
 199   1              return 0;
 200   1      }
 201          
 202          //===============================================================================//
 203          //== 函 数 名:set_usb_address
 204          //== 功    能:设置D12的地址
 205          //== 说    明:主机请求设置地址时被调用
 206          //== 时    间:2008.8.22 创建函数
 207          //== 入口参数:无
 208          //== 返 回 值:0
 209          //===============================================================================//
 210          unsigned char set_usb_address(void)
 211          {
 212   1              set_usb_addr((unsigned char)(Control_Data.DeviceRequest.wValue & DEVICE_ADDRESS_MASK));
 213   1              Control_Data.wLength = 0;                                                                               //== 发送0字节长度数据到主机做回答
 214   1              Control_Data.wCount = 0;
 215   1              bEPPflags.bits.control_state = USB_TRANSMIT;                                    //== 设置为发送状态,等待in端点中断
 216   1              return 0;
 217   1      }
 218          //===============================================================================//
 219          //== 函 数 名:stall_ep0
 220          //== 功    能:停止端点0
 221          //== 说    明:
 222          //== 时    间:
 223          //== 入口参数:
 224          //== 返 回 值:0
 225          //===============================================================================//
 226          unsigned char stall_ep0(void)
 227          {
 228   1              #ifdef __DEBUG__        //== 打印调试信息
 229   1                      Print_Msg("Runing stall_ep0()!\r\n");
 230   1              #endif
 231   1              set_endpoint_status(0, 1);
 232   1              set_endpoint_status(1, 1);
 233   1              return 0;
 234   1      }
 235          
 236          //===============================================================================//
 237          //== 函 数 名:reserved
 238          //== 功    能:备用函数
 239          //== 说    明:
 240          //== 时    间:
 241          //== 入口参数:
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 5   

 242          //== 返 回 值:0
 243          //===============================================================================//
 244          unsigned char reserved(void)
 245          {
 246   1              #ifdef __DEBUG__        //== 打印调试信息
 247   1                      Print_Msg("Runing reserved()!\r\n");
 248   1              #endif
 249   1              stall_ep0();
 250   1              return 0;
 251   1      }
 252          //===============================================================================//
 253          //== 函 数 名:control_handler
 254          //== 功    能:得到状态
 255          //== 说    明:
 256          //== 时    间:2008.8.20 创建函数
 257          //== 入口参数:receiver: 要得到状态的对象
 258          //== 返 回 值:0
 259          //===============================================================================//
 260          unsigned char get_status(unsigned char receiver)
 261          {
 262   1              unsigned char status[2];
 263   1              unsigned char endp, endp_state;
 264   1      
 265   1              #ifdef __DEBUG__        //== 打印调试信息
 266   1                      Print_Msg("Runing get_status()!\r\n");
 267   1              #endif
 268   1      
 269   1              switch (receiver)
 270   1              {
 271   2                      case USB_RECIPIENT_DEVICE:                                      //== 获取设备状态
 272   2                      {
 273   3                              if (bEPPflags.bits.remote_wakeup == 1)  //== 自给供电+远程唤醒
 274   3                              {
 275   4                                      status[0] = 0x03;
 276   4                              }
 277   3                              else                                                                    //== 自给供电
 278   3                              {
 279   4                                      status[0] = 0x01;
 280   4                              }
 281   3                              status[1] = 0x00;
 282   3                      } break;
 283   2      
 284   2                      case USB_RECIPIENT_INTERFACE:                           //== 获取接口状态
 285   2                      {
 286   3                              status[0] = 0x00;
 287   3                              status[1] = 0x00;
 288   3                      } break;
 289   2      
 290   2                      case USB_RECIPIENT_ENDPOINT:                            //== 获取端点状态
 291   2                      {
 292   3                              endp = (unsigned char)(Control_Data.DeviceRequest.wIndex & MAX_ENDPOINTS);      //== 得到端点号
 293   3      
 294   3                              if (Control_Data.DeviceRequest.wIndex & (unsigned char)USB_ENDPOINT_DIRECTION_MASK)
 295   3                                      endp_state = select_endpoint(endp*2 + 1);       //== Control-in
 296   3                              else
 297   3                                      endp_state = select_endpoint(endp*2);           //== Control-out
 298   3      
 299   3                              if (endp_state & D12_STALL)
 300   3                                      status[0] = 0x01;
 301   3                              else
 302   3                                      status[0] = 0;
 303   3      
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 6   

 304   3                              status[1] = 0;
 305   3                      } break;
 306   2      
 307   2                      default:stall_ep0(); break;
 308   2              }
 309   1      
 310   1              usb_transmit_buf[0] = status[0];
 311   1              usb_transmit_buf[1] = status[1];
 312   1              Control_Data.pData = usb_transmit_buf;
 313   1              Control_Data.wLength = 2;
 314   1              Control_Data.wCount = 0;
 315   1              bEPPflags.bits.control_state = USB_TRANSMIT;            //== 设置为发送状态,等待in端点中断
 316   1              return 0;
 317   1      }
 318          
 319          //===============================================================================//
 320          //== 函 数 名:get_descriptor
 321          //== 功    能:得到描述符
 322          //== 说    明:
 323          //== 时    间:2008.8.20 创建函数
 324          //== 入口参数:无
 325          //== 返 回 值:0
 326          //===============================================================================//
 327          unsigned char get_descriptor(void)
 328          {
 329   1              #ifdef __DEBUG__        //== 打印调试信息
 330   1                      Print_Msg("Runing get_descriptor()!\r\n");
 331   1              #endif
 332   1      
 333   1              #ifdef __DEBUG__        //== 打印调试信息
 334   1                      Print_Msg("获取描述符................................\r\n");
 335   1              #endif
 336   1              switch(MSB(Control_Data.DeviceRequest.wValue))
 337   1              {
 338   2                      case DEVICE_DESCRIPTOR:
 339   2                      {
 340   3                              #ifdef __DEBUG__        //== 打印调试信息
 341   3                                      Print_Msg("     获取设备描述符................................\r\n");
 342   3                              #endif
 343   3                              Control_Data.wCount = sizeof(DEVICE_DESCRIPTOR_STRUCT);
 344   3                              Control_Data.pData = (unsigned char *)(&device_descriptor);
 345   3                              if (Control_Data.DeviceRequest.wLength == 0x40) //== 第一次获取描述符
 346   3                              {
 347   4                                      bEPPflags.bits.first_get_descriptor = 1;
 348   4                              }
 349   3                      } break;
 350   2      
 351   2                      case CONFIGURATION_DESCRIPTOR:
 352   2                      {
 353   3                              #ifdef __DEBUG__        //== 打印调试信息
 354   3                                      Print_Msg("     获取配置描述符................................\r\n");
 355   3                              #endif
 356   3                              Control_Data.wCount = SWAP16(con_int_endp_descriptor.configuration_descriptor.wTotalLength);
 357   3                              Control_Data.pData = (unsigned char *)(&con_int_endp_descriptor);
 358   3                              if (Control_Data.wLength<Control_Data.wCount) Control_Data.wCount = Control_Data.wLength;
 359   3                      } break;
 360   2      
 361   2                      case STRING_DESCRIPTOR:
 362   2                      {
 363   3                              #ifdef __DEBUG__        //== 打印调试信息
 364   3                                      Print_Msg("     获取字符串描述符................................\r\n");
 365   3                              #endif
C51 COMPILER V7.50   USB                                                                   11/24/2008 09:12:36 PAGE 7   

 366   3                              switch(LSB(Control_Data.DeviceRequest.wValue))
 367   3                              {
 368   4                                      case 0x00:
 369   4                                      {
 370   5                                              #ifdef __DEBUG__        //== 打印调试信息
 371   5                                                      Print_Msg("             获取语言ID................................\r\n");
 372   5                                              #endif
 373   5                                              Control_Data.wCount = LANGUAGE_ID[0];
 374   5                                              Control_Data.pData = LANGUAGE_ID;
 375   5                                      } break;

⌨️ 快捷键说明

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