📄 combi.lst
字号:
631 if (IsUsbInterface()) //if it is USB
632 {
633 UsbReInitialize(); //initialize USB variables
634 usbmain(); //and go to usbmain
635 }
636 ps2main(); //else straight to ps2
637 }
638
639
640 /*
641 **
642 ** FUNCTION: ProcessOptics
643 **
644 ** PURPOSE: Extracts optics data from the queue, and accumulates X,Y, and Z counts
645 ** based on the state data of each quadrature pair.
646 ** PARAMETERS: none
647 **
648 ** DESCRIPTION: This routine is called from the main loop to process the optical data that has
649 ** accumulated during successive 128 usec interrupts. For each byte in the optics queue,
650 ** it extracts the X,Y,and Z state data, and uses the state data from the previous sample
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 12
651 ** to increment/decrement/hold the corresponding count data.
652 **
653 **
654 */
655
656 void ProcessOptics(void)
657 {
658 char temp;
659 char temp1;
660 if (OpticsQueue.bLen > 16) //somehow the queue overflowed
661 {
662 DI(); //this should never happen, but if so
663 OpticsQueue.headP = //reset the queue pointers and quit
664 OpticsQueue.tailP = bOpticsArray;
665 OpticsQueue.bLen = 0;
666 EI();
667 return;
668 }
669 while (OpticsQueue.bLen)
670 {
671 temp = GET_X_OPTICS(*OpticsQueue.tailP); //get X quadrature inputs into [1:0]
672 temp1 = temp; //save temporarily
673 temp |= Optics.bXstate; //or in with previous state
674 Optics.bXstate = temp1 << 2; //shift X inputs into [3:2] and save for next pass
675 temp1 = Mouse.bXcount;
676 Mouse.bXcount += quad_table[temp]; //use quadrature lookup to inc/dec xcount
677 if ((unsigned char) Mouse.bXcount == 0x80) //if overflow in either direction
678 Mouse.bXcount = temp1; //restore old count
679
680 temp = GET_Y_OPTICS(*OpticsQueue.tailP); //repeat for Y.....
681 temp1 = temp;
682 temp |= Optics.bYstate;
683 Optics.bYstate = temp1 << 2;
684 temp1 = Mouse.bYcount;
685 Mouse.bYcount -= quad_table[temp]; //note, y counts need to be negated for proper direction
686 if ((unsigned char) Mouse.bYcount == 0x80)
687 Mouse.bYcount = temp1;
688
689 temp = GET_Z_OPTICS(*OpticsQueue.tailP); //repeat for Z....
690 temp1 = temp;
691 temp |= Optics.bZstate;
692 Optics.bZstate = temp1 << 2;
693 temp1 = Mouse.bZcount;
694 Mouse.bZcount += z_quad_table[temp];
695 if ((unsigned char) Mouse.bZcount == 0x80)
696 Mouse.bZcount = temp1;
697
698 *OpticsQueue.tailP++; //manage queue pointers
699 if (OpticsQueue.tailP == &bOpticsArray[16]) //wrap them if necessary
700 OpticsQueue.tailP = bOpticsArray;
701 OpticsQueue.bLen--;
702 }
703 }
704
705
706 /*
707 **
708 ** FUNCTION: MICROSECONDx128_ISR
709 **
710 ** PURPOSE: 128 usec ISR.
711 **
712 ** PARAMETERS: none
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 13
713 **
714 ** DESCRIPTION:
715 ** This ISR samples the mouse optics and places the sample in a queue for
716 ** later processing by the main loop. This is done to minimize the execution time
717 ** of this ISR, which can interrupt during the time ps/2 bits are being clocked
718 ** to the host. The timing of the ps/2 clocking is critical (20 us margin),
719 ** so the corresponding execution time of this ISR must be kept to less than 20 us.
720 **
721 **
722 */
723
724 void MICROSECONDx128_ISR(void)
725 {
726 PUSHA();
727 PUSHX();
728 *OpticsQueue.headP++ = OPTICS_PORT; //sample optical data
729 OpticsQueue.bLen++; //manage queue pointers and length
730 if (OpticsQueue.headP == &bOpticsArray[16]) //wrap pointers if necessary
731 OpticsQueue.headP = bOpticsArray;
732 POPX();
733 POPA();
734 }
735
736
737 /*
738 **
739 ** FUNCTION: MILLISECOND_ISR
740 **
741 ** PURPOSE: 1 msec ISR.
742 **
743 ** PARAMETERS: none
744 **
745 ** DESCRIPTION:
746 ** This ISR maintains the 1msec counter variable,
747 ** and sets a flag indicating a 1msec interrupt has occurred. The main loop uses
748 ** these variables for timing purposes.
749 */
750
751 void MILLISECOND_ISR(void)
752 {
753 PUSHA(); //save A
754 RESET_COP();
755 MsecStatus.b1msFlags |= ONE_MSEC_FLAG; //set flag for main loop
756 MsecStatus.b1msCounter++; //increment 1msec counter
757 POPA();
758 return;
759 }
760
761
762 /*
763 **
764 ** FUNCTION: DebounceButtons
765 **
766 ** PURPOSE: Debounces the mouse switch inputs
767 **
768 ** PARAMETERS: none
769 **
770 ** DESCRIPTION:
771 ** This routine should be called at regular intervals from the main loop
772 ** to debounce the mouse switch inputs. It maintains a count of the number
773 ** of successive identical samples of the switch inputs, and returns a 1
774 ** if the switch inputs have changed have been stable for the debounce interval.
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 14
775 */
776
777 char GetButtons(void)
778 {
779 char bButtons = 0;
780
781
782 if (LEFT_SWITCH_ASSERTED) //format an internal copy of the switches
783 bButtons |= BIT0; //this happens to be the USB format!
784 if (RIGHT_SWITCH_ASSERTED)
785 bButtons |= BIT1;
786 /*
787 ** if Zwheel is enabled in either USB or PS2 mode, report the middle switch
788 */
789 if ((MouseParms.bZmouse || DeviceStatus.bProtocol) && (MIDDLE_SWITCH_ASSERTED))
790 bButtons |= BIT2;
791 return(bButtons);
792 }
793
794 char DebounceButtons(void)
795 {
796 char bButtons;
797 bButtons = GetButtons();
798 if (bButtons == bLastButtons) //if same as last sample
799 {
800 if (bDebounceCount && !--bDebounceCount) //and debounce interval just expired
801 {
802 Mouse.bButtons = bLastButtons; //record new buttons
803 return(1); //and flag that a button change occurred
804 }
805 return(0); //else no change yet occurred
806 }
807 bLastButtons = bButtons; //buttons aren't stable, reset debounce count
808 bDebounceCount = DEBOUNCE_COUNT; //
809 return(0);
810 }
811
812
813 /*
814 **
815 ** FUNCTION: USB_BUS_RESET_ISR
816 **
817 ** PURPOSE: Bus Reset ISR, vectored to during USB bus reset.
818 **
819 ** PARAMETERS: none
820 **
821 ** DESCRIPTION: This function performs the following initialization:
822 **
823 ** 1)disables interrupts;
824 ** 2)resets the watchdog;
825 ** 3)initialized data stack pointer and program stack pointer;
826 ** 4 clears ram;
827 ** 5)makes a call to initialize system variables;
828 ** 6)enables device to respond at address 0;
829 ** 7)jumps to main loop
830 **
831 **
832 */
833
834 void USB_BUS_RESET_ISR(void)
835 {
836
C51 COMPILER V7.01 COMBI 04/14/2008 22:57:43 PAGE 15
837 DI();
838 RESET_COP(); //tickle watchdog
839 //initialize stacks using assembler
840 #asm (mov A,RAM_START + STACK_SIZE-1)
*** ERROR C315 IN LINE 840 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
841 #asm (swap A,dsp)
*** ERROR C315 IN LINE 841 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
842 #asm (mov A,0)
*** ERROR C315 IN LINE 842 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
843 #asm (mov psp,a)
*** ERROR C315 IN LINE 843 OF ..\..\..\Usb-Mouse\src\combi.c: unknown #directive 'asm'
844 ClearRam();
845 UsbReInitialize(); //reinitialize all system variables
846
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -