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

📄 usb_kbd_enum.lst

📁 at89c5132,at89c51snd1的usb与keyboard驱动程序。
💻 LST
📖 第 1 页 / 共 3 页
字号:
 289   1        while (!(Usb_tx_complete()));
 290   1        Usb_clear_tx_complete();
 291   1        Usb_configure_address(add);
 292   1      }
 293          
 294          
 295          /*F**************************************************************************
 296          * NAME: usb_set_configuration
 297          *----------------------------------------------------------------------------
 298          * PARAMS:
 299          *
 300          * return:
 301          *----------------------------------------------------------------------------
 302          * PURPOSE: 
C51 COMPILER V7.06   USB_KBD_ENUM                                                          01/29/2008 10:59:25 PAGE 6   

 303          * This function manages the SET_CONFIGURATION request.
 304          *----------------------------------------------------------------------------
 305          * EXAMPLE:
 306          *----------------------------------------------------------------------------
 307          * NOTE:
 308          *----------------------------------------------------------------------------
 309          * REQUIREMENTS: 
 310          *****************************************************************************/
 311          void usb_set_configuration (void)
 312          {
 313   1       Uchar configuration_number;
 314   1        configuration_number = Usb_read_byte();   /* read the conf. num. in wValue */
 315   1        Usb_clear_DIR();
 316   1        Usb_clear_rx_setup();
 317   1      /*  switch (configuration_number)
 318   1        {
 319   1          case 0:
 320   1            Usb_clear_CONFG();
 321   1            usb_configurion = 0x00;
 322   1            break;
 323   1          case CONF_NB:
 324   1            Usb_set_CONFG();
 325   1            Usb_set_usb_configured();
 326   1            break;
 327   1          default:
 328   1            Usb_set_stall_request();
 329   1            while (!Usb_stall_sent());
 330   1            Usb_clear_stall_request();
 331   1            Usb_clear_stalled();
 332   1            return;
 333   1        }*/
 334   1        if (configuration_number <= CONF_NB)
 335   1        {
 336   2          usb_configuration_nb = configuration_number;
 337   2        }
 338   1        else
 339   1        {
 340   2          Usb_set_stall_request();
 341   2          while (!Usb_stall_sent());
 342   2          Usb_clear_stall_request();
 343   2          Usb_clear_stalled();
 344   2          return;
 345   2        }
 346   1      
 347   1        Usb_set_tx_ready();                          /* send a ZLP for STATUS phase */
 348   1        while (!Usb_tx_complete());
 349   1        Usb_clear_tx_complete();
 350   1        usb_ep_init();                            /* endpoints configuration */
 351   1      }
 352          
 353          
 354          /*F**************************************************************************
 355          * NAME: usb_get_descriptor
 356          *----------------------------------------------------------------------------
 357          * PARAMS:
 358          *
 359          * return:
 360          *----------------------------------------------------------------------------
 361          * PURPOSE: 
 362          * This function manages the GET_DESCRIPTOR request.
 363          *----------------------------------------------------------------------------
 364          * EXAMPLE:
C51 COMPILER V7.06   USB_KBD_ENUM                                                          01/29/2008 10:59:25 PAGE 7   

 365          *----------------------------------------------------------------------------
 366          * NOTE:
 367          *----------------------------------------------------------------------------
 368          * REQUIREMENTS: 
 369          *****************************************************************************/
 370          void usb_get_descriptor (void)
 371          {
 372   1      Uchar   data_to_transfer;
 373   1      Uint16  wLength;
 374   1      Uchar   descriptor_type;
 375   1      Uchar   string_type;
 376   1      
 377   1        zlp = FALSE;                              /* no zero length packet */
 378   1        string_type = Usb_read_byte();            /* read LSB of wValue */
 379   1        descriptor_type = Usb_read_byte();        /* read MSB of wValue */
 380   1        switch (descriptor_type)
 381   1        {
 382   2          case DEVICE:
 383   2          {
 384   3            data_to_transfer = sizeof (usb_device_descriptor);
 385   3            pbuffer = &(usb_device_descriptor.bLength);
 386   3            break;
 387   3          }
 388   2      
 389   2          case CONFIGURATION:
 390   2          {
 391   3            data_to_transfer = sizeof (usb_configuration);
 392   3            pbuffer = &(usb_configuration.cfg.bLength);
 393   3            break;
 394   3          }
 395   2      
 396   2          case REPORT:
 397   2          {
 398   3            data_to_transfer = SIZE_OF_REPORT;
 399   3            pbuffer = &(usb_configuration.rep[0]);
 400   3            break;
 401   3          }
 402   2      
 403   2          case HID:
 404   2          {
 405   3            data_to_transfer = sizeof(usb_configuration.hid);
 406   3            pbuffer = &(usb_configuration.hid.bLength);
 407   3            break;
 408   3          }
 409   2          case STRING:
 410   2          {
 411   3            switch (string_type)
 412   3            {
 413   4              case LANG_ID:
 414   4              {
 415   5                data_to_transfer = sizeof (usb_language);
 416   5                pbuffer = &(usb_language.bLength);
 417   5                break;
 418   5              }
 419   4              case MAN_INDEX:
 420   4              {
 421   5                data_to_transfer = sizeof (usb_manufacturer);
 422   5                pbuffer = &(usb_manufacturer.bLength);
 423   5                break;
 424   5              }
 425   4              case PROD_INDEX:
 426   4              {
C51 COMPILER V7.06   USB_KBD_ENUM                                                          01/29/2008 10:59:25 PAGE 8   

 427   5                data_to_transfer = sizeof (usb_product);
 428   5                pbuffer = &(usb_product.bLength);
 429   5                break;
 430   5              }
 431   4              case SN_INDEX:
 432   4              {
 433   5                data_to_transfer = sizeof (usb_serial_number);
 434   5                pbuffer = &(usb_serial_number.bLength);
 435   5                break;
 436   5              }
 437   4              default:
 438   4              {
 439   5                Usb_clear_rx_setup();
 440   5                Usb_set_stall_request(); 
 441   5                while ((!(Usb_stall_sent())) && (Usb_setup_received()));
 442   5                Usb_clear_stalled();
 443   5                Usb_clear_stall_request();
 444   5                Usb_clear_DIR();
 445   5                return;
 446   5              }
 447   4            }
 448   3            break;
 449   3          }
 450   2      
 451   2          default:
 452   2          {
 453   3            Usb_clear_rx_setup();
 454   3            Usb_set_stall_request();
 455   3            while ((!(Usb_stall_sent())) && (Usb_setup_received()));
 456   3            Usb_clear_stalled();
 457   3            Usb_clear_stall_request();
 458   3            Usb_clear_DIR();
 459   3            return;
 460   3          }
 461   2        }
 462   1      
 463   1        ACC = Usb_read_byte();                    /* don't care of wIndex field */
 464   1        ACC = Usb_read_byte();
 465   1        ((Uchar*)&wLength)[1] = Usb_read_byte();   /* read wLength */
 466   1        ((Uchar*)&wLength)[0] = Usb_read_byte();
 467   1        if (wLength > data_to_transfer)
 468   1        {
 469   2          if ((data_to_transfer % EP_CONTROL_LENGTH) == 0) { zlp = TRUE; }
 470   2          else { zlp = FALSE; }                        /* no need of zero length packet */
 471   2        }
 472   1        else
 473   1        {
 474   2          data_to_transfer = (Uchar)wLength;       /* send only requested number of data */
 475   2        }
 476   1        Usb_clear_rx_setup() ;                     /* clear the receive setup flag */
 477   1        Usb_set_DIR();                            /* set out on EP0 */
 478   1      
 479   1        while (data_to_transfer > EP_CONTROL_LENGTH)
 480   1        {
 481   2          pbuffer = usb_send_ep0_packet(pbuffer, EP_CONTROL_LENGTH);
 482   2          data_to_transfer -= EP_CONTROL_LENGTH;
 483   2      
 484   2          while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 485   2          Usb_clear_tx_complete();
 486   2          if ((Usb_rx_complete()))                /* if cancel from USB Host */
 487   2          {
 488   3            Usb_clear_tx_ready();
C51 COMPILER V7.06   USB_KBD_ENUM                                                          01/29/2008 10:59:25 PAGE 9   

 489   3            Usb_clear_rx();
 490   3            return;
 491   3          }
 492   2        }
 493   1        /* send last data packet */
 494   1        pbuffer = usb_send_ep0_packet(pbuffer, data_to_transfer);
 495   1        data_to_transfer = 0;
 496   1        while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 497   1        Usb_clear_tx_complete();
 498   1        if ((Usb_rx_complete()))                  /* if cancel from USB Host */
 499   1        {
 500   2          Usb_clear_tx_ready();
 501   2          Usb_clear_rx();
 502   2          return;
 503   2        }
 504   1      
 505   1        if (zlp == TRUE)
 506   1        {
 507   2          usb_send_ep0_packet(pbuffer, 0);
 508   2          while ((!(Usb_rx_complete())) && (!(Usb_tx_complete())));
 509   2          Usb_clear_tx_complete();
 510   2          if ((Usb_rx_complete()))              /* if cancel from USB Host */
 511   2          {
 512   3            Usb_clear_tx_ready();
 513   3            Usb_clear_rx();
 514   3            return;
 515   3          }
 516   2      
 517   2        }
 518   1        while ((!(Usb_rx_complete())) && (!(Usb_setup_received())));
 519   1        if (Usb_setup_received())
 520   1        {
 521   2          return;
 522   2        }
 523   1      
 524   1        if (Usb_rx_complete())
 525   1        {
 526   2          Usb_clear_DIR();                        /* set in on EP0 */
 527   2          Usb_clear_rx();
 528   2        }
 529   1      }
 530          
 531          
 532          /*F**************************************************************************
 533          * NAME: usb_get_configuration
 534          *----------------------------------------------------------------------------
 535          * PARAMS:
 536          *
 537          * return:
 538          *----------------------------------------------------------------------------
 539          * PURPOSE: 
 540          * This function manages the GET_CONFIGURATION request.
 541          *----------------------------------------------------------------------------
 542          * EXAMPLE:
 543          *----------------------------------------------------------------------------
 544          * NOTE:
 545          *----------------------------------------------------------------------------
 546          * REQUIREMENTS: 
 547          *****************************************************************************/
 548          void usb_get_configuration (void)
 549          {
 550   1        Usb_clear_rx_setup();
C51 COMPILER V7.06   USB_KBD_ENUM                                                          01/29/2008 10:59:25 PAGE 10  

 551   1        Usb_set_DIR();
 552   1      
 553   1      /*  if (Usb_get_usb_configured()) { Usb_write_byte(1); }
 554   1        else { Usb_write_byte(0); }
 555   1      */
 556   1        Usb_write_byte(usb_configuration_nb);
 557   1      
 558   1        Usb_set_tx_ready();
 559   1        while (!(Usb_tx_complete()));
 560   1        Usb_clear_tx_complete();
 561   1        while (!(Usb_rx_complete()));
 562   1        Usb_clear_rx();
 563   1        Usb_clear_DIR();
 564   1      }
 565          
 566          /*F**************************************************************************
 567          * NAME: usb_get_interface
 568          *----------------------------------------------------------------------------
 569          * PARAMS:
 570          *
 571          * return:
 572          *----------------------------------------------------------------------------
 573          * PURPOSE: 
 574          * This function manages the GET_INTERFACE request.
 575          *----------------------------------------------------------------------------
 576          * EXAMPLE:
 577          *----------------------------------------------------------------------------
 578          * NOTE:
 579          *----------------------------------------------------------------------------
 580          * REQUIREMENTS: 
 581          *****************************************************************************/
 582          void usb_get_interface (void)
 583          {
 584   1        Usb_clear_rx_setup();

⌨️ 快捷键说明

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