📄 usb.lst
字号:
472 2 else
473 2 {
C51 COMPILER V8.05a USB 05/22/2009 15:28:38 PAGE 9
474 3 zeroflag = FALSE;
475 3 }
476 2 }
477 1 else
478 1 {
479 2 data_to_send = UsbCtrlCmd.wLength;
480 2 }
481 1 Usb_clr_rxsetup_bit() ;
482 1
483 1 while (data_to_send > 8)
484 1 {
485 2
486 2 Usb_sel_ep(0);
487 2 for(i=0;i<8;i++){
488 3 UEPDATX = G_pucCtrlDataPointer[desc_ptr] ;
489 3 desc_ptr ++;
490 3 }
491 2
492 2 data_to_send = data_to_send - 8;
493 2 ret = usb_send_data();
494 2 if (ret == 1)return;
495 2
496 2 }
497 1
498 1 Usb_sel_ep(0);
499 1 for(i=0;i<data_to_send;i++){
500 2
501 2 UEPDATX = G_pucCtrlDataPointer[desc_ptr] ;
502 2 desc_ptr ++;
503 2 }
504 1
505 1 data_to_send = 0;
506 1 ret = usb_send_data();
507 1 if (ret == 1)return;
508 1
509 1 if (zeroflag == TRUE)
510 1 {
511 2 ret = usb_send_data();
512 2 if (ret == 1)return;
513 2 }
514 1 while ((!(Usb_receive_out_data())) && (!(Usb_setup_packet_receive())));
515 1
516 1 if (Usb_setup_packet_receive())
517 1 {
518 2 return;
519 2 }
520 1
521 1 if (Usb_receive_out_data())
522 1 {
523 2 Usb_clear_DIR_bit();
524 2 Usb_clear_RXOUTB0_bit();
525 2 }
526 1
527 1 }
528 /**************************************************************************
529 *
-
530 * Function Name:usb_send_data
-
531 *
-
532 * Descriptions:
C51 COMPILER V8.05a USB 05/22/2009 15:28:38 PAGE 10
533 *
534 * Arguments:
535 *
536 * Returns: None
537 *
538 **************************************************************************/
539 UINT8 usb_send_data (void)
540 {
541 1
542 1
543 1 Usb_set_TXRDY_bit(); /*send zero packet*/
544 1 while ((!(Usb_receive_out_data())) && (!(Usb_send_data_complete())));
545 1 if ((Usb_receive_out_data()))
546 1 {
547 2 Usb_clear_RXOUTB0_bit();
548 2 return 1;
549 2 }
550 1 if (Usb_send_data_complete())
551 1 {
552 2 Usb_clear_TXCMPL_bit();
553 2 }
554 1 return 0;
555 1 }
556 /**************************************************************************
557 *
-
558 * Function Name:usb_set_address
-
559 *
-
560 * Descriptions:
561 *
562 * Arguments:
563 *
564 * Returns: None
565 *
566 **************************************************************************/
567 void usb_set_address (void)
568 {
569 1
570 1 UINT8 add;
571 1
572 1 Usb_clear_DIR_bit();
573 1 add = UsbCtrlCmd.wValue&0x00ff;
574 1 Usb_set_EP0RST();
575 1 Usb_clr_EP0RST();
576 1 Usb_clr_rxsetup_bit();
577 1 Usb_set_FADDEN_bit();
578 1
579 1 Usb_set_TXRDY_bit();
580 1 while (!(Usb_send_data_complete()));
581 1 Usb_clear_TXCMPL_bit();
582 1 Usb_set_USBADDR(add);
583 1
584 1 }
585 /**************************************************************************
586 *
-
587 * Function Name:usb_get_configuration
-
588 *
-
C51 COMPILER V8.05a USB 05/22/2009 15:28:38 PAGE 11
589 * Descriptions:
590 *
591 * Arguments:
592 *
593 * Returns: None
594 *
595 **************************************************************************/
596 void usb_get_configuration (void)
597 {
598 1
599 1
600 1 Usb_clr_rxsetup_bit();
601 1 Usb_set_DIR_bit();
602 1
603 1
604 1 if (USBCON & 0x02)
605 1 {
606 2 UEPDATX = 1;
607 2 }
608 1 else
609 1 {
610 2 UEPDATX = 0;
611 2 }
612 1
613 1 Usb_set_TXRDY_bit();
614 1 while (!(Usb_send_data_complete()));
615 1 Usb_clear_TXCMPL_bit();
616 1 while (!(Usb_receive_out_data()));
617 1 Usb_clear_RXOUTB0_bit();
618 1 Usb_clear_DIR_bit();
619 1
620 1 }
621
622 /**************************************************************************
623 *
-
624 * Function Name:usb_set_configuration
-
625 *
-
626 * Descriptions:
627 *
628 * Arguments:
629 *
630 * Returns: None
631 *
632 **************************************************************************/
633 void usb_set_configuration (void)
634 {
635 1 UINT8 configuration_number;
636 1
637 1 configuration_number = UsbCtrlCmd.wValue&0x00ff;
638 1 Usb_clear_DIR_bit();
639 1 Usb_clr_rxsetup_bit();
640 1 Usb_set_TXRDY_bit(); /* send a ZLP for STATUS phase */
641 1 if (configuration_number == 0)
642 1 {
643 2 Usb_clear_CONFG();
644 2 }
645 1 else
646 1 {
647 2 Usb_set_CONFG();
C51 COMPILER V8.05a USB 05/22/2009 15:28:38 PAGE 12
648 2 }
649 1 while (!Usb_send_data_complete());
650 1 Usb_clear_TXCMPL_bit();
651 1 Usb_sel_ep(0x01); /* endpoints configuration */
652 1 UEPCONX = 0x86 ;
653 1 Usb_sel_ep(0x02);
654 1 UEPCONX = 0x82;
655 1
656 1 }
657
658 /**************************************************************************
659 *
-
660 * Function Name:usb_clear_feature
-
661 *
-
662 * Descriptions:
663 *
664 * Arguments:
665 *
666 * Returns: None
667 *
668 **************************************************************************/
669 void usb_clear_feature (void)
670 {
671 1
672 1
673 1
674 1 if (UsbCtrlCmd.bmRequestType == 0x00)
675 1 {
676 2 Usb_clr_rxsetup_bit();
677 2 Usb_set_STALLRQ_bit();
678 2 while (!(Usb_stall_sent_complete()));
679 2 Usb_clear_STALLRQ_bit();
680 2 }
681 1
682 1 if (UsbCtrlCmd.bmRequestType == 0x01)
683 1 {
684 2 Usb_clr_rxsetup_bit();
685 2 Usb_set_STALLRQ_bit();
686 2 while (!(Usb_stall_sent_complete()));
687 2 Usb_clear_STALLRQ_bit();
688 2 }
689 1
690 1 if (UsbCtrlCmd.bmRequestType == 0x02)
691 1 {
692 2
693 2 if ((UsbCtrlCmd.wValue&0xff) == 0x00)/*feature selector*/
694 2 {
695 3
696 3 switch ((UsbCtrlCmd.wIndex&0xff)&0x7f) /*endpoint selector*/
697 3 {
698 4
699 4 case 0x00:
700 4 {
701 5 Usb_clr_rxsetup_bit();
702 5 Usb_set_TXRDY_bit();
703 5 while (!(Usb_send_data_complete()));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -