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

📄 usb_cls_hid.asm

📁 利用psoc进行usb及capsense的程序编写
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;;*****************************************************************************
;;*****************************************************************************
;;  FILENAME: USB_cls_hid.asm
;;   Version: 1.0, Updated on 2005/04/20 at 22:16:14
;;  Generated by PSoC Designer ver 4.2  b1013 : 02 September, 2004
;;
;;  DESCRIPTION: USB Human Interface Device (HID) Class request implemenatation
;;               for the CY8C24090 family of devices
;;
;;  NOTE: User Module APIs conform to the fastcall convention for marshalling
;;        arguments and observe the associated "Registers are volatile" policy.
;;        This means it is the caller's responsibility to preserve any values
;;        in the X and A registers that are still needed after the API
;;        function returns. Even though these registers may be preserved now,
;;        there is no guarantee they will be preserved in future releases.
;;-----------------------------------------------------------------------------
;;  Copyright (c) Cypress Semiconductor 2005. All Rights Reserved.
;;*****************************************************************************
;;*****************************************************************************

include "m8c.inc"
include "USB_macros.inc"
include "USB.inc"
include "memory.inc"

;-----------------------------------------------
;  Global Symbols
;-----------------------------------------------
EXPORT USB_UpdateHIDTimer
EXPORT _USB_UpdateHIDTimer
EXPORT USB_bGetProtocol
EXPORT _USB_bGetProtocol

AREA InterruptRAM (RAM,REL,CON)
;-----------------------------------------------
;  Constant Definitions
;-----------------------------------------------
;-----------------------------------------------
; Variable Allocation
;-----------------------------------------------
;----------------------------------------------------------------------------
; Interface Setting
;----------------------------------------------------------------------------
 USB_IdleReload:                        BLK   1    ; Idle Timer Reload Value
 USB_IdleTimer:                         BLK   1    ; Idle Timers
 USB_Protocol:                          BLK   1    ; Active Protocol

AREA UserModules (ROM, REL)
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_bGetProtocol
;
;  DESCRIPTION:   Returns the selected protocol value to the application
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:    A: Interface number
;
;  RETURNS:      A: Protocol values
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
 USB_bGetProtocol:
_USB_bGetProtocol:
    RAM_PROLOGUE RAM_USE_CLASS_3
	RAM_SETPAGE_IDX >USB_Protocol
    mov  X, A                          ; Argument is the index
    mov  A, [X + USB_Protocol] ; Return the protocol
	RAM_EPILOGUE RAM_USE_CLASS_3
    ret
.ENDSECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_UpdateHIDTimer
;
;  DESCRIPTION:    Updates the HID report timer and reloads it if it expires
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:     A: Interface number
;
;  RETURNS:       A: USB_IDLE_TIMER_EXPIRED, if the timer is running and expired
;                    USB_IDLE_TIMER_RUNNING, if the timer is running
;                    USB_IDLE_TIMER_INDEFINITE, if the report should be made on change
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
.SECTION
 USB_UpdateHIDTimer:
_USB_UpdateHIDTimer:
    RAM_PROLOGUE RAM_USE_CLASS_3
	RAM_SETPAGE_IDX >USB_IdleReload
    mov  X, A                          ; Make the argument the index
; Flow here to check if the timer is "indefinite"
    cmp	 [X + USB_IdleReload], 0       ; Indefinite?
    jz   .indefinite                   ; Jump if Indefinite?
; Flow here to check the timers
    DEC    [X + USB_IdleTimer]         ; Decrement the timer
    jc   .expired
; Flow here if the timer has not expired
    mov  A, USB_IDLE_TIMER_RUNNING     ; Return value (not expired)
	RAM_EPILOGUE RAM_USE_CLASS_3
    ret                                ; Quick exit
; Jump here if the timer expired
.expired:
    mov  A, [X + USB_IdleReload]       ; Reload the timer
    mov  [X + USB_IdleTimer], A        ; 
    mov  A, USB_IDLE_TIMER_EXPIRED     ; Return value (expired)
    ret                                ; Quick exit
; Jump here to make return "on change/indefinite"
.indefinite:
    mov  A, USB_IDLE_TIMER_INDEFINITE  ; Return value (change/indefinite)
	RAM_EPILOGUE RAM_USE_CLASS_3
    ret                                ; Exit
.ENDSECTION
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ifc_06
;
;  DESCRIPTION:   Get Interface Descriptor
;
;****************************************************************
; STANDARD INTERFACE IN REQUEST: Get_Interface_Descriptor
;****************************************************************
;
; bmRequestType   : (IN | STANDARD | INTERFACE)    = 81h
; bRequest        : GET_DESCRIPTOR                 = 06h    
; wValue          : DESCRIPTOR TYPE | INDEX        = xxxxh  
; wIndex          : INTERFACE                      = --xxh
; wLength         : DESCRIPTOR_LENGTH              = --xxh  
; 
; The GET_INTERFACE_DESCRIPTOR request returns the specified 
; descriptor if the descriptor exists. 
;
; The upper byte of request_value contains the descriptor type and 
; the lower byte contains the descriptor index. request_index 
; contains either 0000h or the Language ID. request_length contains 
; the descriptor length. The actual descriptor information is 
; transferred in subsequent data packets. 
;
; USB defines only a DEVICE recipient but the HID spec added 
; support for the INTERFACE recipient.
;
; Get Descriptor from an HID interface returns either HID, 
; REPORT, or PHYSICAL descriptors.
;
;****************************************************************
IF (USB_CB_SRC_d2h_std_ifc_06 & USB_UM_SUPPLIED)
export  USB_CB_d2h_std_ifc_06
USB_CB_d2h_std_ifc_06:
    call  USB_GetInterfaceLookupTable  ; Point the the interface lookup table
    push  A                            ; Save the MSB
    mov   A, REG[USB_EP0DATA+wValueHi] ; Get descriptor type
    cmp   A, DESCR_TYPE_HID_CLASS      ; HID Class descriptor?
    jz    .send_hid_class_descr
    cmp   A, DESCR_TYPE_HID_REPORT     ; HID Report descriptor?
    jz    .send_hid_report_descr
; Jump or flow here if the request is not supported
.not_supported:
    pop   A                            ; Restore the stack
    jmp   USB_Not_Supported_Local1
; Jump here to send the HID Report Descriptor
.send_hid_report_descr:
    pop   A                            ; Restore the interface lookup table MSB
    swap  A, X                         ; Add the offset
    add   A, 2                         ; Point to the right table entry
    jmp   .finish
; Jump here to send the HID Class Descriptor
.send_hid_class_descr:
    pop   A                            ; Restore the interface lookup table MSB
    swap  A, X                         ; Add the offset
    add   A, 4                         ; Point to the right table entry
; Jump or flow here with A:X Pointing to the 
.finish:
    swap  A, X                         ; Back where they belong
    adc   A, 0                         ; Don't forget the carry
    mov   [USB_t2],USB_t1              ; Set the GETWORD destination 
    call  USB_GETWORD                  ; Get the pointer to the transfer descriptor table
                                       ; ITempW has the address
; Get the interface number
    mov   A, REG[USB_EP0DATA+wIndexLo] ; Get the interface number
    mov   [USB_t2], A                  ; Save it for the call to LOOKUP
    mov   A, [USB_t1]                  ; Get the transfer descriptor ROM Address MSB
    mov   X, [USB_t1+1]                ; Get the transfer descriptor ROM Address LSB

    jmp   USB_GetTableEntry
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_cls_ifc_01
;
;  DESCRIPTION:   Get Report
;
;****************************************************************
; HID CLASS INTERFACE IN REQUEST: Get_Report   
;****************************************************************
;
; bmRequestType  : (IN | CLASS | INTERFACE)       = A1h
; bRequest       : GET_REPORT                     = 01h    
; wValue         : REPORT TYPE | REPORT ID        = xxxxh  
; wIndex         : INTERFACE                      = --xxh
; wLength        : REPORT LENGTH                  = --xxh  
; 
; The GET_REPORT request allows the host to receive a report from 
; a specific interface via the control pipe. 
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  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_01 & USB_UM_SUPPLIED)
export  USB_CB_d2h_cls_ifc_01
USB_CB_d2h_cls_ifc_01:

    call  Find_Report
    NULL_PTR_CHECK .not_supported
    
    jmp   USB_GetTableEntry
            
.not_supported:
    jmp   USB_Not_Supported_Local1

ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_cls_ifc_02
;
;  DESCRIPTION:   Get Idle
;
;****************************************************************
; HID CLASS INTERFACE IN REQUEST: Get_Idle
;****************************************************************
;
; bmRequestType  : (OUT | CLASS | INTERFACE)      = A1h
; bRequest       : GET_IDLE                       = 02h    
; wValue         : REPORT ID                      = 00xxh  
; wIndex         : INTERFACE                      = --xxh
; wLength        : Report Size                    = 0001h  
; 
; The GET_IDLE request reads the current idle rate for a given 
; input report on a specific 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_d2h_cls_ifc_02 & USB_UM_SUPPLIED)
; TODO: Should this table move to another file (GetIdleTable)
; TODO: How will we build this table to the correct size? (GetIdleTable)
.LITERAL
GetSetIdleTable:
    TD_START_TABLE  1                  ; One entry for each interface
    TD_ENTRY        USB_DS_RAM, 1, USB_IdleReload,   NULL_PTR  ; Reuse the transfer buffer
    TD_ENTRY        USB_DS_RAM, 1, USB_IdleReload+1, NULL_PTR  ; Reuse the transfer buffer
.ENDLITERAL

export  USB_CB_d2h_cls_ifc_02
USB_CB_d2h_cls_ifc_02:

; TODO: Verify that report numbers 1 to n (or 0 to n-1)
    mov   A, REG[USB_EP0DATA+wValueLo] ; Get the report number
    cmp   A, 0                         ; We don't support report by report idle
    jnz   USB_Not_Supported_Local1

    mov   A, REG[USB_EP0DATA+wIndexLo] ; Get the interface number
    cmp   A, 1                         ; We don't support report by report idle
    jnc   USB_Not_Supported_Local1


    mov   [USB_t2], A                  ; Use the UM temp var--Selector
    mov   A,>GetSetIdleTable           ; Get the ROM Address MSB
    mov   X,<GetSetIdleTable           ; Get the ROM Address LSB
    
    jmp   USB_GetTableEntry

ENDIF

;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_cls_ifc_03
;
;  DESCRIPTION:   Get Protocol
;
;****************************************************************
; 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_CB_d2h_cls_ifc_03
USB_CB_d2h_cls_ifc_03:
    mov   A, REG[USB_EP0DATA+wIndexLo] ; Get the interface number
    cmp   A, 1                         ; Range check
    jnc   USB_Not_Supported_Local1

    mov   X, A                         ; Get the protocol for the requested interface
    mov   A, [X + USB_Protocol]        ; 

    mov   [USB_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_GetTableEntry
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_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_CB_h2d_cls_ifc_09

⌨️ 快捷键说明

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