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

📄 usbps2.asm

📁 CY7C63743 usb键盘的源码
💻 ASM
字号:
        CPU 63413
label:          XPAGEON

;========================================================================
;   FILE: usbps2.asm 
;
;   This file includes all the files necessary to build a dual interface 
;   (usb and ps2) keyboard
;   executable.  
;
;========================================================================


;include all "inc" files used by the code

    include "regs.inc"
    include "usb.inc"
    include "ps2.inc"
    include "macros.inc"
    include "at101.inc"
    include "portdef.inc"




PS2_KEYBOARD:   equ 0               
USB_KEYBOARD:   equ 1

;we need to use the endpoint 2 normally used for the mouse, to report
;power key usages. So, the following equate will enable endpoint 2 interrupts
;even though we are not using mouse code.
EP_INTERRUPTS: equ KEYBOARD_PLUS_MOUSE
;========================================================================
;  interrupt vector table -- must be located here
;========================================================================

    ORG     00h

    jmp     sys_reset               ; reset vector

    jmp     USB_Bus_Reset_ISR       ; USB bus reset

    jmp     illegal_int             ; 128us interrupt

    jmp    dual_ifc_1ms_ISR           ; 1.024ms interrupt

    jmp     USB_EP0_ISR             ; endpoint 0 interrupt

    jmp     USB_EP1_ISR             ; endpoint 1 interrupt

	jmp	USB_EP2_ISR			; endpoint 2 interrupt

    jmp     illegal_int             ; reserved interrupt

    jmp     illegal_int             ; reserved interrupt

    jmp     illegal_int             ; reserved interrupt

    jmp     DAC_ISR                 ; DAC interrupt

    jmp     GPIO_ISR                ; GPIO interrupt

    jmp     illegal_int             ; reserved interrupt

;========================================================================
;
;   FUNCTION: dual_ifc_1ms_ISR
;
;   purpose:    
;   provides the entry point for the 1 millisecond tick.
;   This ISR entry point jumps to the USB 1msec ISR if a usb keyboard
;   is connected.  Otherwise, it performs the necessary ps2-specific
;   functions and returns.
;
;
;========================================================================
dual_ifc_1ms_ISR:
    ei                              ;allow nesting
    push    A                       ;save A
    mov     A,[dual_ifc_keyboard]      ;check keyboard type
    cmp     A,PS2_KEYBOARD          ;if USB
    jnz     One_mSec_ISR            ;go direct to USB ISR
    inc    [dual_ifc_1ms]              ;otherwise increment 1msec counter
    pop    a                        ;restore A reg
    reti                            ;return from interrupt

;========================================================================
;
;   FUNCTION: sys_reset
;
;   purpose:    
;   reset entry point for code
;
;
;========================================================================


illegal_int:
sys_reset:
    di                                        ;disable interrupts   
    mov       A,0ffh 
    iowr      PORT3_DATA_REG
    mov        A,NORMAL                        ;configure GPIO reg
    iowr     GPIO_CONFIG_REG



    mov     a,0                             ;set psp stack to 0
    mov     psp,a                           ; 
    mov     a,0ffh                          ;set dsp stack to 0xff
    swap    a,dsp                           ;now we can call functions

    mov     A,0                             ;zero endpoint interrupt reg
    iowr    ENDPOINT_INTERRUPT_REG            
    mov     [dual_ifc_keyboard],A              ;set type to ps2 initially
   
    call    get_keyboard_type               ;get the keyboard type
    mov     [dual_ifc_keyboard],A              ;save it
    mov     A,[dual_ifc_keyboard]              ;get it again
    cmp     A,PS2_KEYBOARD                  ;if USB                             
    jnz      Reset                          ;go to  code usb
    jmp      ps2main                        ;else straight to ps2

.bummer:
    jmp     .bummer                          ;loop if we ever get here


; the dsp will remain at 0 for both ps2 and usb. Allow 30h bytes for it.

dsp_stack_size:                 equ     30h

; the psp will start at 0xff for ps2 and 0xe0 for usb (to avoid the
; USB queues)

psp_stack_size:                 equ     20h

ram_base:                       equ     psp_stack_size  ;application ram start
dual_ifc_keyboard:              equ     ram_base        ;keyboard type
dual_ifc_1ms:                   equ     ram_base+1      ;1msec counter
usbmain_ram_base:               equ     ram_base+2      ;start of usb main ram
ps2main_ram_base:               equ     ram_base+2      ;and ps2 ram also

;include all code which resides in lower 4k now.

include "usbmain.asm"

;use the descriptor file that includes a description of the 2nd endpoint,
;which we'll need here because we're using the 2nd endpoint to report power
;key usage codes.

include "kbm_desc.asm"
include "ps2main.asm"



;include all code which resides in upper 4k now. This code consists entirely
;of subroutines which are called from the lower 4k code.
ORG 1000h
include "ps2_io.asm"

;load ps2key and usbkey, the modules which handle keypresses in the
;two keyboard environments.
;
;

usbkey_ram_base:            equ     (usbmain_ram_base + USBMAIN_RAM_SIZE)
include    "usbkey.asm"
ps2key_ram_base:            equ     (ps2main_ram_base + PS2MAIN_RAM_SIZE)
include    "ps2key.asm"
                                                                                              
;note: usb_ram_end MUST compute to less than 0x70h (see note below).
usb_ram_end:                equ     (usbkey_ram_base + USBKEY_RAM_SIZE)
ps2_ram_end:                equ     (ps2key_ram_base + PS2KEY_RAM_SIZE)

;
;due to a restriction on the USB code, we cannot use RAM from 070h to 07fh.
;locate the ram used by keyscan.asm at 080h to avoid this region.
;

ksc_ram_base:               equ     080h
include "keyscan.asm"
include "util.asm"
include "matrix.asm"
;locate mouse RAM after ksc RAM, and include mouse code in upper 4k.
mouse_RAM_baseC:	equ	(ksc_ram_base + KSC_RAM_SIZE)
include "kbm_stub.asm"



;define some constants which are not used but will show up in the
;listing file in a contiguous block so that we can easily examine the
;ram usage for the project in the listing file.

AAA_RAM_PS2_START:      equ     ps2main_ram_base
AAB_RAM_PS2_END:        equ     ps2main_ram_base + PS2MAIN_RAM_SIZE- 1
AAC_RAM_PS2_START:      equ     ps2key_ram_base
AAD_RAM_PS2_2END:       equ     ps2key_ram_base + PS2KEY_RAM_SIZE - 1

AAE_RAM_USB_START:      equ     usbmain_ram_base
AAF_RAM_USB_END:        equ     usbmain_ram_base + USBMAIN_RAM_SIZE- 1
AAG_RAM_USB_START:      equ     usbkey_ram_base
AAH_RAM_USB_END:        equ     usbkey_ram_base + USBKEY_RAM_SIZE - 1

AAI_RAM_KSC_START:      equ     ksc_ram_base
AAJ_RAM_KSC_END:        equ     ksc_ram_base + KSC_RAM_SIZE - 1



⌨️ 快捷键说明

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