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

📄 ps2main.asm

📁 CY7C63743 usb键盘的源码
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;   C: 0 if command was sucessful
;   C: 1 if command failed 
;========================================================================

ps2_select_alternate_scan_code:
    call    ps2_ack_byte                        ;ack this byte
    call    ps2_wait_byte                       ;wait for alternate code byte
    cmp     A,4                                 ;if out of range
    jnc     .error                              ;exit with C bit set
    call    ps2key_clear_key_buffer             ;clear out buffer and stop any typematic stuff       
    call    ps2key_disable_typematic_action
    or      A,0                                 ;else if 1-4
    jz      .send                                                     
    mov     [ps2key_scan_set],A                 ;  save it
    call    ps2_ack_byte                        ;  ack the byte
    jmp     .exit
.send:                                          ;else, a 0 indicates to send back current scan set
    call    ps2_ack_byte                        ;ack the byte
    jc      .exit                               ;if host inhibit, exit
    mov     A,[ps2key_scan_set]                 ;else return current scan set 
    call       ps2_put_byte
.exit:
    CLEARC
    jmp     endswitch
.error:
    SETC
    jmp     endswitch

;========================================================================
; FUNCTION: ps2_read_id
;
;
; Returns:
;   C: 0, command can't fail
;========================================================================


ps2_read_id:
    call    ps2_ack_byte                        ;ack the byte
    jc      .exit                               ;if host inhibit during ack, exit

    mov     A,0abh                              ;respond with hard coded id bytes
    call    ps2_put_byte                     
    jc      .exit                               ;problem xmitting 1st id, exit

    mov     A,83h                               ;transmit 2nd byte
    call    ps2_put_byte                     
    call     ps2key_clear_key_buffer             ;clear the key buffer
    SETBIT   PS2_SCAN_KBD,ps2_flags              ;enable scanning
.exit:
    CLEARC
    jmp     endswitch
;========================================================================
; FUNCTION: ps2_set_typematic_rate_delay
;
; sets the global typematic rate and delay settings.
; this routine uses 2 lookups to convert the values sent by the host,
; into the proper 4ms counts that will be used to achieve the rate and delay
; functions.  the rate table was derived from an excel spreadsheet rate.xls;
; the shorter delay table was derived by hand
;
; Returns:
;
;   C: 0 if command was sucessful
;   C: 1 if command failed 
;
;========================================================================
XPAGEOFF
ps2_typematic_rate_table:                   ;table of 4ms counts to achieve rate

    db      8,9,10,11,14,14,15,16
    db      17,19,21,23,25,27,29,31
    db      33,38,42,46,50,54,58,63
    db      67,75,83,92,100,108,117,125

ps2_typematic_delay_table:                  ;table of 4ms counts to achieve delay
    db      62,125,187,250
XPAGEON

ps2_set_typematic_rate_delay:
    call    ps2_ack_byte                    ;ack the byte
    call    ps2_wait_byte                   ;get  rate/delay byte
    cmp     A,80h                           ;if out of range
    jc      .l0                                            
    SETC                                        ;scream,cry, and return
    jmp     endswitch
.l0:
    push    A
    rrc                                         ;otherwise, get bits 5 and 6
    rrc 
    rrc
    rrc
    rrc
    and     A,3
    index   ps2_typematic_delay_table           ;get delay
    mov     [ps2key_type_delay],A               ;save it
    pop     A                                   ;get original parameter
    and     A,1fh                               ;use only 5 ls bits
    index   ps2_typematic_rate_table            ;get rate
    mov     [ps2key_type_period],A              ;save it    
    call    ps2_ack_byte                        ;ack byte
    CLEARC
    jmp     endswitch

;========================================================================
; FUNCTION: ps2_enable
;
;
; enables keyboard scanning
;
;
;========================================================================

ps2_enable:
   CLRBIT   PS2_XMIT,ps2_flags                  ;clear any pending transmission       
   call     ps2key_clear_key_buffer             ;clear the key buffer
   SETBIT   PS2_SCAN_KBD,ps2_flags              ;enable scanning
   call     ps2_ack_byte                        ;ack the byte
   CLEARC
   jmp      endswitch


;========================================================================
; FUNCTION: ps2_default_disable
;
;
; disables keyboard scanning
;
;
;========================================================================

ps2_default_disable:
    CLRBIT  PS2_SCAN_KBD,ps2_flags             ;disable scanning       
ps2_set_default:
    CLRBIT  PS2_XMIT,ps2_flags                 ;clear any pending transmissions
    call    ps2key_clear_key_buffer            ;clear the fifo                         
    call    ps2key_set_default_key_types                     
    call    ps2_ack_byte                       ;ack the byte
    CLEARC
    jmp     endswitch


;========================================================================
; FUNCTION: ps2_set_keys
;
;
; sets all the key types to a common type
;
; Returns:
;
;   C: 0 command can't fail
;
;
;========================================================================

ps2_set_keys:
    mov     A,X                             ;the X register contains the zero-based
                                            ;command.
    sub     A,(0f7h-0edh)                   ;derive key type (0,1,or2) from this
    push    A                               ;save it
    mov     A,AT101KB_PAUSE                 ;fetch current pause key setting
    call    ps2key_at101_2_ss3              ;get scan set 3 code for it
    call    ps2key_get_key_type             ;it's returned in X
    pop     A                               ;restore key type into A
    push    X                               ;save pause key setting
    call    ps2key_set_all_keys             ;set all key types now
    mov     A,AT101KB_PAUSE                 ;get scan code for pause key
    call    ps2key_at101_2_ss3              ;get scan set 3 code for it
    pop     X                               ;restore setting for pause key into X
    call    ps2key_save_key_type            ;and set it
    call    ps2_ack_byte                    ;ack the byte
    CLEARC                                  ;indicate we are done.
    jmp     endswitch
;========================================================================
; FUNCTION: ps2_resend
;
;
; sets resend bit
;
; Returns:
;   C: 0 
;
;========================================================================

ps2_resend:
    SETBIT  PS2_RESEND,ps2_flags                ;set the resend flag
    CLEARC                                      ;indicate success
    jmp     endswitch

;========================================================================
; FUNCTION: ps2_reset
;
;
; performs a reset
;
; Returns: C= 0 if command aborted due to host transmit request
;
;========================================================================



ps2_reset:
    iowr    WATCHDOG_REG
    DELAY   250
    call    ps2_ack_byte                         ;ack the byte
    jc      .exit
    DELAY   250
    iowr    WATCHDOG_REG
    DELAY   250
    iowr    WATCHDOG_REG
    iord    USB_STATUS_CONTROL_REG
    and     A,PS2_DATA_BIT                      ;check data line
    jz      .exit                               ;if host xmit request, abort Reset

    jmp     soft_reset                           ;soft restart
    
.exit:
    CLEARC
    jmp     endswitch

;========================================================================
; FUNCTION: ps2_set_key_type
;
;
; sets individual key types to the values indicated
;
;
;========================================================================


ps2_set_key_type:
    mov     A,X                         ;zero-based command is in X, get it in A
    sub     A,(0fbh - 0edH)             ;derive key type (0,1,2,or3)
    push    A                           ;save it                           
    call    ps2_ack_byte                ;ack the byte
.l1:
    call    ps2_wait_byte               ;wait for keycode
    cmp     A,LAST_SCAN3_CODE+1         ;if valid       
    jnc     .error                            
    or      A,0                 
    jz      .error                             
    pop     X                           ;get key type
    push    X                           ;save it again
    call    ps2key_save_key_type        ;set it
    call    ps2_ack_byte                ;ack the byte
    jmp     .l1                         ;continue doing this until we can't recognize
                                        ;a scan code
.error:
    pop     X                           ;restore stack level,return with offending
                                        ;byte in A
    SETC                                ;indicate an error condition
    jmp     endswitch



;========================================================================
; FUNCTION: ps2_ack_byte
;
;
; Sends an ACK byte
;
;
;========================================================================



ps2_ack_byte:
    mov     A,PS2_ACK
    call    ps2_put_byte                     
    ret


;========================================================================
; FUNCTION: ps2_BAT
;
; Performs BAT assurance test. For now, this test does nothing
; but delay for 350 msec before returning.
;
;
; Returns:
;
;   C: 0
;   A: BAT_PASS
; 
;
;
;========================================================================

ps2_BAT:
    ;leds on
    mov     A,(CAPS_LOCK_LED + SCROLL_LOCK_LED + NUM_LOCK_LED)
    call    ksc_writeLED
    mov     A,[dual_ifc_1ms]
    dec     A
.l1:
    iowr    WATCHDOG_REG
    cmp     A,[dual_ifc_1ms]           ;consume 256 msec    
    jnz     .l1
    add     A,100
 .l2:                               ;consume    100 more
    iowr    WATCHDOG_REG
    cmp     A,[dual_ifc_1ms]
    jnz     .l2   
    mov     A,0
    call    ksc_writeLED
    mov     A,BAT_PASS
    ret


;========================================================================
; FUNCTION: ps2_put_byte
;
;
;========================================================================

ps2_put_byte:
    push     X                          ;save X
.l1:
    call    ps2_send                    ;try to send the byte
    jnc     .exit

    mov     X,A                         ;save the byte
    DELAY   5                           ;wait 5 usec
    iord    USB_STATUS_CONTROL_REG      ;if data bit is low
    and     A,PS2_DATA_BIT
    jz      .error                      ;quit due to host transmit request
    mov     A,X                         ;else try again
    jmp     .l1

.error:                                 ;return with carry set
    SETC
.exit:
    mov     [ps2_last_xmit],A           ;save last transmitted byte
    pop     X                           ;pop X register
    ret







⌨️ 快捷键说明

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