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

📄 usb_1_cls_hid.asm

📁 Cypress公司开发的2.4G无线键盘鼠标及其Bridge源代码
💻 ASM
📖 第 1 页 / 共 3 页
字号:
    JC      .not_supported_pop_1
        
    POP     A                          ; Get the MSB back

    RET                                ; Finished A:X point to the TD

.not_supported_pop_1:
    POP     A                          ; Restore the stack
.not_supported:
    MOV     A, 0                       ; Return a null pointer
    MOV     X, A                       ; 
    RET

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_1_GetInterfaceLookupTable
;
;  DESCRIPTION:   Point to the interface lookup table
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
export  USB_1_GetInterfaceLookupTable:
USB_1_GetInterfaceLookupTable:
    CALL    USB_1_GET_CONFIG_TABLE_ENTRY ; Get the CONFIG_LOOKUP entry
    SWAP    A, X                       ; Second entry points to the HID_LOOKUP table
    ADD     A, 2                       ; So add two
    SWAP    A, X                       ; 
    ADC     A, 0                       ; Don't forget the carry
    MOV     [USB_1_t2],USB_1_t1        ; Set the GETWORD destination 
    CALL    USB_1_GETWORD              ; Get the pointer to the HID_LOOKUP table
                                       ; ITempW has the address
    MOV     A, [USB_1_t1]              ; Get the table address MSB
    MOV     X, [USB_1_t1+1]            ; Get the table address LSB
    RET
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
;  USB 2nd Tier Dispactch Jump Tables for HID Class Requests (based on bRequest)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ;  USB 2nd Tier Dispactch Jump Table
;
;  DESCRIPTION:   The following tables dispatch to the Standard request handler
;                 functions.  (Assumes bmRequestType(5:6) is 0, Standard)
;
;-----------------------------------------------------------------------------
;-----------------------------------------------------------------------------
USB_1_DT_h2d_cls_ifc:
;-----------------------------------------------------------------------------
    jmp     USB_1_CB_h2d_cls_ifc_00
    jmp     USB_1_CB_h2d_cls_ifc_01
    jmp     USB_1_CB_h2d_cls_ifc_02
    jmp     USB_1_CB_h2d_cls_ifc_03
    jmp     USB_1_CB_h2d_cls_ifc_04
    jmp     USB_1_CB_h2d_cls_ifc_05
    jmp     USB_1_CB_h2d_cls_ifc_06
    jmp     USB_1_CB_h2d_cls_ifc_07
    jmp     USB_1_CB_h2d_cls_ifc_08
    jmp     USB_1_CB_h2d_cls_ifc_09
    jmp     USB_1_CB_h2d_cls_ifc_10
    jmp     USB_1_CB_h2d_cls_ifc_11
    jmp     USB_1_CB_h2d_cls_ifc_12

USB_1_DT_h2d_cls_ifc_End:
USB_1_DT_h2d_cls_ifc_Size: equ (USB_1_DT_h2d_cls_ifc_End-USB_1_DT_h2d_cls_ifc) / 2
USB_1_DT_h2d_cls_ifc_Dispatch::
    CMP     [USB_1_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP     USB_1_Not_Supported_Local_Hid  ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[USB_1_EP0DATA + bRequest]     ; Get the request number
    DISPATCHER USB_1_DT_h2d_cls_ifc, USB_1_DT_h2d_cls_ifc_Size, USB_1_Not_Supported_Local_Hid 

;-----------------------------------------------------------------------------
USB_1_DT_d2h_cls_ifc:
;-----------------------------------------------------------------------------

    jmp     USB_1_CB_d2h_cls_ifc_00
    jmp     USB_1_CB_d2h_cls_ifc_01
    jmp     USB_1_CB_d2h_cls_ifc_02
    jmp     USB_1_CB_d2h_cls_ifc_03

USB_1_DT_d2h_cls_ifc_End:
USB_1_DT_d2h_cls_ifc_Size: equ (USB_1_DT_d2h_cls_ifc_End-USB_1_DT_d2h_cls_ifc) / 2
USB_1_DT_d2h_cls_ifc_Dispatch::
    CMP     [USB_1_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP     USB_1_Not_Supported_Local_Hid  ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[USB_1_EP0DATA + bRequest]     ; Get the request number
    DISPATCHER USB_1_DT_d2h_cls_ifc, USB_1_DT_d2h_cls_ifc_Size, USB_1_Not_Supported_Local_Hid 

IF (USB_CB_SRC_d2h_cls_ifc_00 & USB_NOT_SUPPORTED)
export  USB_1_CB_d2h_cls_ifc_00
USB_1_CB_d2h_cls_ifc_00:
ENDIF
IF (USB_CB_SRC_d2h_cls_ifc_01 & USB_NOT_SUPPORTED)
export  USB_1_CB_d2h_cls_ifc_01
USB_1_CB_d2h_cls_ifc_01:
ENDIF
IF (USB_CB_SRC_d2h_cls_ifc_02 & USB_NOT_SUPPORTED)
export  USB_1_CB_d2h_cls_ifc_02
USB_1_CB_d2h_cls_ifc_02:
ENDIF
IF (USB_CB_SRC_d2h_cls_ifc_03 & USB_NOT_SUPPORTED)
export  USB_1_CB_d2h_cls_ifc_03
USB_1_CB_d2h_cls_ifc_03:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_00 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_00
USB_1_CB_h2d_cls_ifc_00:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_01 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_01
USB_1_CB_h2d_cls_ifc_01:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_02 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_02
USB_1_CB_h2d_cls_ifc_02:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_03 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_03
USB_1_CB_h2d_cls_ifc_03:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_04 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_04
USB_1_CB_h2d_cls_ifc_04:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_05 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_05
USB_1_CB_h2d_cls_ifc_05:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_06 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_06
USB_1_CB_h2d_cls_ifc_06:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_07 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_07
USB_1_CB_h2d_cls_ifc_07:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_08 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_08
USB_1_CB_h2d_cls_ifc_08:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_09 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_09
USB_1_CB_h2d_cls_ifc_09:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_10 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_10
USB_1_CB_h2d_cls_ifc_10:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_11 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_11
USB_1_CB_h2d_cls_ifc_11:
ENDIF
IF (USB_CB_SRC_h2d_cls_ifc_12 & USB_NOT_SUPPORTED)
export  USB_1_CB_h2d_cls_ifc_12
USB_1_CB_h2d_cls_ifc_12:
ENDIF

USB_1_Not_Supported_Local_Hid:
    LJMP     USB_1_Not_Supported

USB_1_GetTableEntry_Local_Hid:
    LJMP     USB_1_GetTableEntry

;-----------------------------------------------
; Add custom application code for routines 
; redefined by USB_APP_SUPPLIED in USB_HID.INC
;-----------------------------------------------

   ;@PSoC_UserCode_BODY_1@ (Do not change this line.)
   ;---------------------------------------------------
   ; Insert your custom code below this banner
   ;---------------------------------------------------

; Get Report
IF (USB_CB_SRC_d2h_cls_ifc_01 & USB_APP_SUPPLIED)
export  USB_1_CB_d2h_cls_ifc_01
USB_1_CB_d2h_cls_ifc_01:

    MOV     A, REG[USB_1_EP0DATA+wValueLo]  ; Get the Report ID
	CMP		A, 0x4						; Check for Mouse Report ID
	JNZ		.check_keyboard_report_id

	;Build Mouse Report
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 0], A	; Report ID

	MOV		A, [_mouse_battery_level]
	OR		A, 0x80
	MOV		[_mouse_battery_level], A
	AND		A, 0x0F
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 1], A	; Battery Level	

	MOV		A, [_bad_received_packet_count+1]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 4], A	; Bad Packets Low
	MOV		A, [_bad_received_packet_count]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 5], A	; Bad Packets High

	MOV		A, [_total_received_packet_count+1]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 6], A	; Total Packets Low
	MOV		A, [_total_received_packet_count]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 7], A	; Total Packets High

	; Clear counters
	MOV		A, 0x0
	MOV		[_bad_received_packet_count], A
	MOV		[_bad_received_packet_count+1], A
	MOV		[_total_received_packet_count], A
	MOV		[_total_received_packet_count+1], A

	JMP		.send_report
	
.check_keyboard_report_id:
	CMP		A, 0x5						; Check for Keyboard Report ID
	JNZ		.not_supported

	;Build Keyboard Report
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 0], A	; Report ID

	MOV		A, [_keyboard_battery_level]
	OR		A, 0x80
	MOV		[_keyboard_battery_level], A
	AND		A, 0x0F
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 1], A	; Battery Level	

	MOV		A, [_bad_received_packet_count+1]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 4], A	; Bad Packets Low
	MOV		A, [_bad_received_packet_count]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 5], A	; Bad Packets High

	MOV		A, [_total_received_packet_count+1]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 6], A	; Total Packets Low
	MOV		A, [_total_received_packet_count]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 7], A	; Total Packets High

	; Clear counters
	MOV		A, 0x0
	MOV		[_bad_received_packet_count], A
	MOV		[_bad_received_packet_count+1], A
	MOV		[_total_received_packet_count], A
	MOV		[_total_received_packet_count+1], A

.send_report:
	; Common fields
	MOV		A, [_sys_params]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 2], A	; Channel
	MOV		A, [_sys_params + 1]
	MOV		[USB_1_INTERFACE_1_FEATURE_RPT_DATA + 3], A	; PNCode

	MOV		A, 0x0	
	MOV		[USB_1_TransferSize], A		; MSB
	MOV		A, 0x8
	MOV		[USB_1_TransferSize+ 1], A	; LSB
	MOV		A, USB_DS_RAM
	MOV		[USB_1_DataSource], A		; RAM
	MOV		A, USB_1_INTERFACE_1_FEATURE_RPT_DATA
	MOV		[USB_1_DataPtr+1], A		; RAM ADDRESS

    LJMP     USB_1_InitControlRead
            
.not_supported:
    LJMP     USB_1_Not_Supported

ENDIF

   ;---------------------------------------------------
   ; Insert your custom code above this banner
   ;---------------------------------------------------
   ;@PSoC_UserCode_END@ (Do not change this line.)

; End of File USB_1_cls_hid.asm

⌨️ 快捷键说明

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