📄 hid-kbd.asm
字号:
*****************************************************************************
* Copyright (c) Motorola 1998 *
* File Name: HID-KBD.ASM *
* *
* Description: USB Standard and HID Request Handler *
* *
* *
* Assembler: CASM08Z (P&E Microcomputer Systems Inc) *
* Version: 3.16 *
* *
* Current Revision: 1.0 *
* Current Revision Release Date: 1998.08.03 by Tony Luk *
* *
* Updated History *
* Rev YYYY.MM.DD Author Description of Change *
* --- ----------- ------ --------------------- *
* 0.0 1997.02.21 Tony Luk orginial release *
* 0.7 1997.03.19 Tony Luk updated for Chapter 9 (V3.0) and *
* HIDView (V1.5a) *
* 0.8 1997.05.08 Tony Luk customize Set_Report for keyboard *
* 0.9 1998.04.22 Tony Luk Tx buffer pointed by Long_IDX *
* 1.0 1998.08.03 Tony Luk Get_Desc to support interface & *
* endpoint class request separately *
* (handle boot devices for BIOS & *
* MS-DOS) *
* support keyboard boot device for *
* BIOS & MS-DOS *
*****************************************************************************
* This Program is a freeware to demonstrate the operation of Motorola *
* Microcontroller. Motorola reserves the right to make changes without *
* further notice to any product herein to improve reliability, function, or *
* design. Motorola does not assume any liability arising out of the *
* application or use of any product, circuit, or software described herein; *
* neither does it convey any license under its patent rights nor the rights *
* of others. Motorola products are not designed, intended, or authorized *
* for use as components in systems intended for surgical implant into the *
* body, or other applications intended to support life, or for any other *
* application in which the failure of the Motorola product could create a *
* situation where personal injury or death may occur. Should Buyer purchase *
* or use Motorola products for any such intended or unauthorized *
* application, Buyer shall indemnify and hold Motorola and its officers, *
* employees, subsidiaries, affiliates, and distributors harmless against *
* all claims, costs, damages, and expenses, and reasonable attorney fees *
* arising out of, directly or indirectly, any claim of personal injury or *
* death associated with such unintended or unauthorized use, even if such *
* claim alleges that Motorola was negligent regarding the design or *
* manufacture of the part. Motorola and the Motorola logo* are registered *
* trademarks of Motorola Inc *
*****************************************************************************
* ====== Compile Options =================================================
.CYCLE_ADDER_OFF
$BASE !10
* --- Option to Check Request Fields & Device States
* that may cause un-specified behavior of the device -------
;; (If conditions for un-specified behavior found, the device is stalled.)
$SET CHK_UNSPECIFIED ; check
;;$SETNOT CHK_UNSPECIFIED ; don't check
* ====== MACRO Definition ================================================
;;$INCLUDE "macro8.asm"
.PAGE
* ====== USB Subroutines(Top Level Handler) ==============================
* USB_HANDLER Check Transaction Type & Branch to the Service Routine
* --------------------------------------------------------------------- *
* USB_HANDLER - Check Transaction Type & Branch to the Service Routine *
* ---- ----- ------ ------- -------- --- ---- ---------------- *
* IDLE SETUP IN_END OUT_END STAT_END sup data Action *
* ---- ----- ------ ------- -------- --- ---- ---------------- *
* 1 x x x x x x exit *
* 0 1 x x x 0 x jsr PROC_SETUP *
* 0 x 1 x x x 0 no operation *
* 0 x x 1 x x 0 jsr PROC_DATA *
* 0 x x x 1 1 1 bring dev. idle *
* ---- ----- ------ ------- -------- --- ---- ---------------- *
* In : V_TRANSACT transfer status of control transfer *
* V_PROCESS processing status of control transfer *
* Out : <nil> *
* Call : PROC_SETUP, PROC_DATA, ECHO_IN_STATUS *
* --------------------------------------------------------------------- *
USB_HANDLER:
* --- Check Transact Status ----------------------------------------------
brset b_IDLE,V_TRANSACT,UHR_EXIT ; device Idle ?
*
*
*
* --- Process SETUP Packet -----------------------------------------------
UHR_SETUP:
brset b_sup,V_PROCESS,UHR_DATA ; processed SETUP packet ?
brclr b_SETUP,V_TRANSACT,UHR_DATA ; ~SETUP stage completed ?
*
jsr PROC_SETUP ; process SETUP packet
*
*
*
* --- Process IN/OUT DATA Packet -----------------------------------------
UHR_DATA:
; brset b_Stalled,V_Dev_Status,UHR_EXIT ; device stalled ?
brset b_data,V_PROCESS,UHR_STAT ; processed DATA packet ?
*
* --- IN DATA Stage Completed ----------------------------------
UHR_IN:
brclr b_IN_END,V_TRANSACT,UHR_OUT ; ~IN DATA stage completed ?
bset b_data,V_PROCESS ; processed DATA packet
*
;; (OUT Status is ACK handshake, which is already enabled by
;; clearing b_RXD0F bit in USB_ISR routine.)
;; jsr Echo_OUT_Status ; response with OUT Status stage
*
* --- OUT DATA Stage Completed ---------------------------------
UHR_OUT:
brclr b_OUT_END,V_TRANSACT,UHR_STAT ; ~OUT DATA stage completed ?
*
jsr PROC_DATA ; process Rx Data of the request
jsr ECHO_IN_STATUS ; response with IN Status stage
*
*
*
* --- STATUS Stage Completed ---------------------------------------------
UHR_STAT:
brclr b_STAT_END,V_TRANSACT,UHR_EXIT ; ~STATUS stage completed ?
*
* (STATUS transact aborts all pending transactions and packets processing)
MOV #{1<b_IDLE},V_TRANSACT ; device idle
clr V_PROCESS ; reset processing status
*
;; bra UHR_EXIT
*
*
*
* ------------------------------------------------------------------------
UHR_EXIT:
rts
.PAGE
* ====== USB Subroutines(process SETUP packet) ===========================
* PROC_SETUP branch to serve corresp. Device Request
* after SETUP stage
* --------------------------------------------------------------------- *
* PROC_SETUP - branch to serve corresp. Device Request *
* In : b_Type[0..1] =0 Standard Device Request *
* =1 Class-specific Request *
* =2 Vendor-specific Request *
* Out : <nil> *
* Call : <see tables of PST_STD_REQ & PST_HID_REQ> *
* Note :- b_sup is set after completely processed the SETUP packet *
* --------------------------------------------------------------------- *
PROC_SETUP:
bset b_sup,V_PROCESS ; processed SETUP packet
*
* --- Check Request Type: Standard or Class ------------------------------
lda V_bmReqType
and #%01100000
KCMPEQ %00000000,PST_STANDARD ; Standard Device Request ?
KCMPEQ %00100000,PST_CLASS ; Class-specific Request ?
bra PST_STALL ; device stalled
*
* --- Parser for Standard Device Requests --------------------------------
* (IMPORTANT:- the parser branches to corresp. service routine
* and never returns.)
PST_STANDARD:
$IF CHK_UNSPECIFIED
*
* Check Request for device in DEFAULT state ------------------------------
PST_Chk_State:
brclr b_DEFAULT,V_Dev_State,PST_End_CState ; ~device in DEFAULT
*
lda V_bRequest
KCMPEQ K_SET_ADDRESS,PST_END_CSTATE ; SET_ADDRESS request ?
KCMPEQ K_GET_DESC,PST_END_CSTATE ; GET_DESC request ?
bra PST_STALL
PST_END_CSTATE:
$ENDIF ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
*
lda V_bRequest
KCMPHI 12,PST_STALL ; Request Code > 12 ?
ldx #3
lsla
add V_bRequest ; V_bRequest * 3
tax
jmp PST_STD_REQ,x ; goto corresp. service routine
*
* --- Table of Standard Device Requests ------------------------
PST_STD_REQ: ; Req. Code:
jmp SRQ_GET_STATUS ; = 0
jmp SRQ_CLR_FEATURE ; = 1
jmp PST_STALL ; = 2
jmp SRQ_SET_FEATURE ; = 3
jmp PST_STALL ; = 4
jmp SRQ_SET_ADDRESS ; = 5
jmp SRQ_GET_DESC ; = 6
jmp SRQ_SET_DESC ; = 7 <not supported>
jmp SRQ_GET_CONFIG ; = 8
jmp SRQ_SET_CONFIG ; = 9
jmp SRQ_GET_IF ; = 10
jmp SRQ_SET_IF ; = 11
jmp SRQ_SYNC_FRAME ; = 12 <not supported>
*
*
*
* --- Echo Device Stalled ------------------------------------------------
PST_STALL:
jsr ECHO_STALLED
bra PST_EXIT
*
*
*
* --- Parser for HID Class-specific Requests -----------------------------
* (IMPORTANT:- the parser branches to corresp. service routine
* and never returns.)
PST_CLASS:
lda V_bmReqType
and #%01111111 ; neglect b_Dir bit
KCMPEQ %00100001,PST_CLSCTI ; recipient = interface ?
KCMPEQ %00100010,PST_CLSCTI ; recipient = endpoint ?
bra PST_STALL
PST_CLSCTI:
lda V_bRequest
KCMPHI 11,PST_STALL ; Request Code > 11 ?
lsla
add V_bRequest
tax
jmp PST_HID_REQ,x ; goto corresp. service routine
*
* --- Table of HID Class-specific Requests ---------------------
PST_HID_REQ: ; Req. Code:
jmp PST_STALL ; = 0
jmp HCR_GET_REPORT ; = 1
jmp HCR_GET_IDLE ; = 2 目 not used by
jmp HCR_GET_PROTOCOL ; = 3 馁 Monitor Class
jmp PST_STALL ; = 4
jmp PST_STALL ; = 5
jmp PST_STALL ; = 6
jmp PST_STALL ; = 7
jmp PST_STALL ; = 8
jmp HCR_SET_REPORT ; = 9
jmp HCR_SET_IDLE ; = 10 目 not used by
jmp HCR_SET_PROTOCOL ; = 11 馁 Monitor Class
*
*
*
* ------------------------------------------------------------------------
PST_EXIT:
rts
.PAGE
* ====== USB Subroutines(Standard Device Requests) =======================
* SRQ_SET_FEATURE serve SET_FEATURE Request
* SRQ_CLR_FEATURE serve CLEAR_FEATURE Request
* SRQ_SET_CONFIG serve SET_CONFIGURATION Request
* SRQ_GET_CONFIG serve GET_CONFIGURATION Request
* SRQ_SET_IF serve SET_INTERFACE Request
* SRQ_GET_IF serve GET_INTERFACE Request
* SRQ_SET_ADDRESS serve SET_ADDRESS Request
* SRQ_GET_STATUS serve GET_STATUS Request
* SRQ_SYNC_FRAME serve SYNCH_FRAME Request [not supported]
* SRQ_SET_DESC serve SET_DESCRIPTOR Request [not supported]
* SRQ_GET_DESC serve GET_DESCRIPTOR Request
* [Standard Device Request] ------------------------------------------- *
* SRQ_CLR_FEATURE - serve CLEAR_FEATURE Request *
* SRQ_SET_FEATURE - serve SET_FEATURE Request *
* In : V_bmReqType =0 Device Feature Request *
* =1 Interface Feature Request *
* =2 Endpoint Feature Request *
* V_wIndex_L =0 <for Device> *
* =I/F # <for Interface> *
* =EP # <for Endpoint> *
* V_wValue_L Feature Selector *
* =0 ENDPOINT_STALL <for Endpoint> *
* =1 DEVICE_REMOTE_WAKEUP <for device> *
* Out : b_RWakeup =0 disable Device Remote Wakeup *
* =1 enable Device Remote Wakeup *
* b_Stalled =0 device NOT stalled *
* =1 device stalled *
* Call : ECHO_STALLED, RST_STALLED *
* --------------------------------------------------------------------- *
K_RM_WAKEUP equ 1 ; 目 Feature Selector Options
K_EP_STALL equ 0 ; 馁
*
*
*
SRQ_CLR_FEATURE:
SRQ_SET_FEATURE:
*
* --- Check Constant Fields ----------------------------------------------
lda V_wValue_H
ora V_wIndex_H
$IF CHK_UNSPECIFIED ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ora V_wLength_L
ora V_wLength_H
$ENDIF ; ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bne SCF_STALL
*
*
* --- Check Recipient ----------------------------------------------------
lda V_bmReqType
beq SCF_DEVICE ; recipient = device ?
cbeqa #%00000001,SCF_INTERFACE ; = interface ?
cbeqa #%00000010,SCF_ENDPOINT ; = endpoint ?
*
* --- Echo Device Stalled ------------------------------------------------
SCF_STALL:
jsr ECHO_STALLED
bra SCF_EXIT
*
*
*
* ------------------------------------------------------------------------
*
*
* --- Serve CLEAR_FEATURE/SET_FEATURE to Device --------------------------
SCF_DEVICE:
lda V_wIndex_L ; must be zero
bne SCF_STALL ; for Device Feature
*
lda V_wValue_L ; Feature Selector
KCMPNE K_RM_WAKEUP,SCF_STALL ; = ~Device_Remote_Wakeup ?
*
lda V_bRequest
cbeqa #K_CLR_FEATURE,SCF_DEV_CLR ; CLEAR_FEATURE request ?
SCF_DEV_SET:
bset b_RWakeup,V_Dev_Status ; enable Device Remote Wakeup
bra SCF_EXIT
SCF_DEV_CLR:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -