📄 usb_1_cls_hid.asm
字号:
; HID CLASS INTERFACE IN REQUEST: Get_Protocol
;****************************************************************
;
; bmRequestType : (OUT | CLASS | INTERFACE) = A1h
; bRequest : GET_PROTOCOL = 03h
; wValue : RESERVED = 0000h
; wIndex : INTERFACE = --xxh
; wLength : SIZEOF_INTERFACE_PROTOCOL = 0001h
;
; The GET_PROTOCOL request reads which protocol is currently
; active.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_d2h_cls_ifc_03 & USB_UM_SUPPLIED)
.LITERAL
GetProtocolTable:
TD_START_TABLE 2 ; One entry for BOOT/One entry for REPORT
TD_ENTRY USB_DS_ROM, 1, ROM_ZERO, NULL_PTR ; Simply use a a hard coded zero or one
TD_ENTRY USB_DS_ROM, 1, ROM_ONE, NULL_PTR ;
ROM_ZERO: DB 0
ROM_ONE: DB 1
.ENDLITERAL
export USB_1_CB_d2h_cls_ifc_03
USB_1_CB_d2h_cls_ifc_03:
MOV A, REG[USB_1_EP0DATA+wIndexLo] ; Get the interface number
CMP A, 2h ; Range check
JNC USB_1_Not_Supported_Local_Hid
MOV X, A ; Get the protocol for the requested interface
MOV A, [X + USB_1_Protocol] ;
MOV [USB_1_t2], A ; Use the UM temp var--Selector
MOV A,>GetProtocolTable ; Get the ROM Address MSB
MOV X,<GetProtocolTable ; Get the ROM Address LSB
JMP USB_1_GetTableEntry_Local_Hid
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_1_CB_h2d_cls_ifc_09
;
; DESCRIPTION: Set Report
;
;****************************************************************
; HID CLASS INTERFACE OUT REQUEST: Set_Report
;****************************************************************
;
; bmRequestType : (OUT | CLASS | INTERFACE) = 21h
; bRequest : SET_REPORT = 09h
; wValue : REPORT TYPE | REPORT ID = xxxxh
; wIndex : INTERFACE = --xxh
; wLength : REPORT LENGTH = --xxh
;
; The SET_REPORT request allows the host to send a report to the
; device, possibly setting the state of input, output or feature
; controls.
;
;****************************************************************
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_h2d_cls_ifc_09 & USB_UM_SUPPLIED)
export USB_1_CB_h2d_cls_ifc_09
USB_1_CB_h2d_cls_ifc_09:
CALL Find_Report
NULL_PTR_CHECK USB_1_Not_Supported_Local_Hid
JMP USB_1_GetTableEntry_Local_Hid
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_1_CB_h2d_cls_ifc_10
;
; DESCRIPTION: Set Idle
;
;****************************************************************
; HID CLASS INTERFACE OUT REQUEST: Set_Idle
;****************************************************************
;
; bmRequestType : (OUT | CLASS | INTERFACE) = 21h
; bRequest : SET_IDLE = 0Ah
; wValue : DURATION | REPORT ID = xxxxh
; wIndex : INTERFACE = --xxh
; wLength : ZERO = 0000h
;
; The SET_IDLE request silences a particular input report (or all
; input reports) on a specific interface until a new event occurs
; or the specified amount of time passes.
;
;****************************************************************
; Note: This function does not support multiple reports per interface.
;****************************************************************
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_h2d_cls_ifc_10 & USB_UM_SUPPLIED)
export USB_1_CB_h2d_cls_ifc_10
USB_1_CB_h2d_cls_ifc_10:
MOV A, REG[USB_1_EP0DATA+wValueLo] ; Get the report number
CMP A, 0 ; We don't support report by report idle
JNZ USB_1_Not_Supported_Local_Hid
MOV A, REG[USB_1_EP0DATA+wIndexLo] ; Get the interface number
CMP A, 2h ; Range Check
JNC USB_1_Not_Supported_Local_Hid
MOV X, A ; Interface Number becomes an index
MOV A, REG[USB_1_EP0DATA+wValueHi] ; Get the duration
MOV [X+USB_1_IdleReload], A ; Save the reload immediately
CMP A, 0 ; Is this request setting the duration to indefinite?
JZ .reload ; If so, reload the timer
; Otherwise, we need to determine if we reset the current expiry
; (HID Spec says to send the next report if we are within 4 ms (1 count)
; of sending the next report
CMP [X+USB_1_IdleTimer], 1 ; Within 4 ms?
JZ .done ; Jump to let the timer expire "naturally"
; Jump or Flow here to reload the timer
.reload:
MOV [x+USB_1_IdleTimer], A ; Reload the timer
.done:
JMP USB_1_NoDataStageControlTransfer
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: USB_1_CB_h2d_cls_ifc_11
;
; DESCRIPTION: Set Idle
;
;****************************************************************
; HID CLASS INTERFACE OUT REQUEST: Set_Protocol
;****************************************************************
;
; bmRequestType : (OUT | CLASS | INTERFACE) = 21h
; bRequest : SET_PROTOCOL = 0Bh
; wValue : DURATION | REPORT ID = xxxxh
; wIndex : PROTOCOL = --xxh
; wLength : ZERO = 0000h
;
; The SET_PROTOCOL request switches between the boot protocol and
; the report protocol (or vice versa).
;
;****************************************************************
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
IF (USB_CB_SRC_h2d_cls_ifc_11 & USB_UM_SUPPLIED)
export USB_1_CB_h2d_cls_ifc_11
USB_1_CB_h2d_cls_ifc_11:
MOV A, REG[USB_1_EP0DATA+wIndexLo] ; Get the interface number
CMP A, 2h ; Range check
JNC USB_1_Not_Supported_Local_Hid
MOV X, A ; Save the interface number
MOV A, REG[USB_1_EP0DATA+wValueLo] ; Get the protocol
CMP A, (1+1) ; Must be zero or one
JNC USB_1_Not_Supported_Local_Hid
;Workaround for some bad host
; MOV [X + USB_1_Protocol], A ; Save the new protocol
MOV [USB_1_Protocol], A ; Save the new protocol
MOV [1 + USB_1_Protocol], A ; Save the new protocol
LJMP USB_1_NoDataStageControlTransfer
ENDIF
;-----------------------------------------------------------------------------
; FUNCTION NAME: Find_Report
;
; DESCRIPTION: Scan the HID Report Tree and return a pointer to the
; HID Report Transfer Descriptor (TD) or NULL
; This function is called in during the processing of
; GET_REPORT or SET_REPORT HID Class Requests.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
;
; RETURNS:
;
; SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
; THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
Find_Report:
CALL USB_1_GetInterfaceLookupTable ; Point the the interface lookup table
; The first entry of the table point to the report table.
MOV [USB_1_t2],USB_1_t1 ; Set the GETWORD destination
CALL USB_1_GETWORD ; Get the pointer to the transfer descriptor table
; ITempW has the address
MOV A, REG[USB_1_EP0DATA+wIndexLo] ; Get the interface number
;back channel support
CMP A, 0
JNZ .1
MOV [set_output_report_flags], 1 ; Set a flag to off load the data at Status Stage of the control xfer.
.1:
MOV [USB_1_t2], A ; Use the UM temp var--Selector
MOV A, [USB_1_t1] ; Get the Table Address MSB
MOV X, [USB_1_t1+1] ; Get the Table Address LSB
ASL [USB_1_t2] ; Convert the index to offset
SWAP A, X
ADD A, [USB_1_t2]
SWAP A, X
ADC A, 0 ; A:X now points to the table entry we want
; Get the pointer to the Report Type Table
GET_WORD
; Dereference to the requested Report Type
PUSH A ; Don't loose the pointer MSB
MOV A, REG[USB_1_EP0DATA+wValueHi] ; Get the Report Type
DEC A ; Make it 0 based
MOV [USB_1_t2], A ; Use the UM temp var--Selector
POP A ; Get the MSB back
PUSH A ; Don't loose the pointer MSB
ROMX ; Get the table size
CMP A, [USB_1_t2] ; Range check
JC .not_supported_pop_1
POP A ; Get the MSB back
INC X ; Point to the next entry
ADC A, 0 ;
LT_INDEX_TO_OFFSET USB_1_t2 ; Convert the index to offset
SWAP A, X
ADD A, [USB_1_t2]
SWAP A, X
ADC A, 0 ; A:X now points to the table entry we want
; Get the pointer to the requested Report Table
GET_WORD ; A:X points to the
NULL_PTR_CHECK .not_supported ; Null Table entries indicated not supported
; Dereference to the requested TRANSFER DESCRIPTOR
PUSH A ; Don't loose the pointer MSB
MOV A, REG[USB_1_EP0DATA+wValueLo] ; Get the Report ID
MOV [USB_1_t2], A ; Use the UM temp var--Selector
POP A ; Get the MSB back
PUSH A ; Don't loose the pointer MSB
ROMX ; Get the table size
CMP A, [USB_1_t2] ; Range check
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -