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

📄 myusb_std.asm

📁 实现2个ps/2接口转到1个USB接口功能
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;-----------------------------------------------------------------------------
;  FUNCTION NAME: myUSB_CB_h2d_std_ep_03
;
;  DESCRIPTION:   Set Endpoint Feature
;
;****************************************************************
; STANDARD ENDPOINT OUT REQUEST: Set_Endpoint_Feature
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | ENDPOINT)    = 02h
; bRequest       : SET_FEATURE                    = 03h    
; wValue         : FEATURE_SELECTOR               = --xxh  
; wIndex         : ENDPOINT                       = 00xxh
; wLength        : RESERVED                       = 0000h  
; 
; The SET_ENDPOINT_FEATURE request enables a particular feature
; for a specific endpoint. The only feature supported for an 
; endpoint is the EP_HALT feature.
; 
;****************************************************************
;-----------------------------------------------------------------------------
;
;  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_std_ep_03 & USB_UM_SUPPLIED)
export  myUSB_CB_h2d_std_ep_03
myUSB_CB_h2d_std_ep_03:
    MOV     A, REG[myUSB_EP0DATA+wValueLo]  ; Get the feature selector
    CMP     A, USB_ENDPOINT_HALT       ; Halt is the only selector defined for endpoints
    JNZ     myUSB_Not_Supported

    MOV     A, REG[myUSB_EP0DATA+wIndexLo]  ; Get the Endpoint number
    AND     A, ~USB_DIR_IN             ; Strip off the direction bit
    CMP     A, 0                       ; Never halt the Control Endpoint
    JZ      .done

    CMP     A, USB_NUM_ENDPOINTS       ; Range check
    JNC     myUSB_Not_Supported

    MOV     X, A                       ; Endpoint number is the index

    OR      [X+myUSB_EndpointStatus], USB_ENDPOINT_STATUS_HALT  ; Halt the endpoint

    TST     REG[myUSB_EP0DATA+wIndexLo], USB_DIR_IN  ; IN or OUT endpoint?
    JNZ     .in

    MOV     REG[X + myUSB_EP0MODE], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_OUT  ; Stall the endpoint
    JMP     .done    
.in:
    MOV     REG[X + myUSB_EP0MODE], USB_MODE_STALL_DATA_EP | USB_MODE_ACK_IN  ; Stall the endpoint
.done:        
    JMP     myUSB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: ConfigureEP
;
;  DESCRIPTION:   Configure an endpoint
;
;  ARGUMENTS:    A contains the endpoint direction
;                X contains the endpoint number
;
;  RETURNS:
;
;  SIDE EFFECTS:  The A REGISTER IS VOLATILE.  X REGISTER IS MAINTAINED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
ConfigureEP:
    CMP     A, USB_DIR_UNUSED          ; Is this endpoint unused?
    JNZ     .enable                    ; Only enable it if it is used
    RET                                ; Quick exit if this endpoint is unused

; Jump here to enable an endpoint
.enable:
    PUSH    A                          ; Save the endpoint direction
    MOV     A, X                       ; We are using a JACC to dispatch to enable the interrupt
    ASL     A                          ;  
    JACC    .EP_INT_ENABLE             ;  
.EP_INT_ENABLE:
    JMP     .EP0IntEnable              ; Enable EP0
    JMP     .EP1IntEnable              ; Enable EP1
    JMP     .EP2IntEnable              ; Enable EP2
; Jump here to enable EP0 Interrupts
.EP0IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP0
    JMP     .cont
.EP1IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP1
    JMP     .cont
.EP2IntEnable:
    M8C_EnableIntMask INT_MSK1, INT_MSK1_USB_EP2
; Jump or flow here to continue configuring the endpoint    
.cont:

    MOV     A, X
    INDEX   myUSB_USB_EP_BIT_LOOKUP
    XOR     A, FFh
    AND     [myUSB_EPDataToggle], A ; Clear the data toggle

    POP     A                          ; Get the endpoint direction back
    AND     A, USB_DIR_IN              ; Is it an IN endpoint?
    JNZ     .in                        ; Jump on IN
; Flow here for an OUT Endpoint
    MOV     REG[X+EP0MODE], USB_MODE_NAK_OUT ; NAK the endpoint
    MOV     [X+myUSB_EndpointAPIStatus], NO_EVENT_PENDING ; For the API
    RET
; Jump here for an IN Endpoint
.in:
    MOV     REG[X+EP0MODE], USB_MODE_NAK_IN ; NAK the endpoint
    MOV     [X+myUSB_EndpointAPIStatus], EVENT_PENDING ; For the API
    RET
;-----------------------------------------------------------------------------
;  USB 2nd Tier Dispactch Jump Tables for Standard 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)
;
;-----------------------------------------------------------------------------
;
;  ARGUMENTS:
;
;  RETURNS:
;
;  SIDE EFFECTS: REGISTERS ARE VOLATILE: THE A AND X REGISTERS MAY BE MODIFIED!
;
;  THEORY of OPERATION or PROCEDURE:
;
;-----------------------------------------------------------------------------
myUSB_DT_d2h_std_dev:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_d2h_std_dev_00
    jmp     myUSB_CB_d2h_std_dev_01
    jmp     myUSB_CB_d2h_std_dev_02
    jmp     myUSB_CB_d2h_std_dev_03
    jmp     myUSB_CB_d2h_std_dev_04
    jmp     myUSB_CB_d2h_std_dev_05
    jmp     myUSB_CB_d2h_std_dev_06
    jmp     myUSB_CB_d2h_std_dev_07
    jmp     myUSB_CB_d2h_std_dev_08

myUSB_DT_d2h_std_dev_End:
myUSB_DT_d2h_std_dev_Size: equ (myUSB_DT_d2h_std_dev_End-myUSB_DT_d2h_std_dev) / 2
myUSB_DT_d2h_std_dev_Dispatch::
    MOV    A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_d2h_std_dev, myUSB_DT_d2h_std_dev_Size, myUSB_Not_Supported 
;-----------------------------------------------------------------------------
myUSB_DT_h2d_std_dev:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_h2d_std_dev_00
    jmp     myUSB_CB_h2d_std_dev_01
    jmp     myUSB_CB_h2d_std_dev_02
    jmp     myUSB_CB_h2d_std_dev_03
    jmp     myUSB_CB_h2d_std_dev_04
    jmp     myUSB_CB_h2d_std_dev_05
    jmp     myUSB_CB_h2d_std_dev_06
    jmp     myUSB_CB_h2d_std_dev_07
    jmp     myUSB_CB_h2d_std_dev_08
    jmp     myUSB_CB_h2d_std_dev_09

myUSB_DT_h2d_std_dev_End:
myUSB_DT_h2d_std_dev_Size: equ (myUSB_DT_h2d_std_dev_End-myUSB_DT_h2d_std_dev) / 2
myUSB_DT_h2d_std_dev_Dispatch::

    MOV     A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_h2d_std_dev, myUSB_DT_h2d_std_dev_Size, myUSB_Not_Supported 

;-----------------------------------------------------------------------------
myUSB_DT_d2h_std_ifc:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_d2h_std_ifc_00
    jmp     myUSB_CB_d2h_std_ifc_01
    jmp     myUSB_CB_d2h_std_ifc_02
    jmp     myUSB_CB_d2h_std_ifc_03
    jmp     myUSB_CB_d2h_std_ifc_04
    jmp     myUSB_CB_d2h_std_ifc_05
    jmp     myUSB_CB_d2h_std_ifc_06
    jmp     myUSB_CB_d2h_std_ifc_07
    jmp     myUSB_CB_d2h_std_ifc_08
    jmp     myUSB_CB_d2h_std_ifc_09
    jmp     myUSB_CB_d2h_std_ifc_10
myUSB_DT_d2h_std_ifc_End:
myUSB_DT_d2h_std_ifc_Size: equ (myUSB_DT_d2h_std_ifc_End-myUSB_DT_d2h_std_ifc) / 2
myUSB_DT_d2h_std_ifc_Dispatch::
    CMP     [myUSB_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP    _myUSB_Not_Supported        ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_d2h_std_ifc, myUSB_DT_d2h_std_ifc_Size, myUSB_Not_Supported 

;-----------------------------------------------------------------------------
myUSB_DT_h2d_std_ifc:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_h2d_std_ifc_00

myUSB_DT_h2d_std_ifc_End:
myUSB_DT_h2d_std_ifc_Size: equ (myUSB_DT_h2d_std_ifc_End-myUSB_DT_h2d_std_ifc) / 2
myUSB_DT_h2d_std_ifc_Dispatch::
    CMP     [myUSB_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured
    JMP    _myUSB_Not_Supported        ; Stall the request if not configured
; Jump here if the device is configured
.configured:
    MOV     A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_h2d_std_ifc, myUSB_DT_h2d_std_ifc_Size, myUSB_Not_Supported 

;-----------------------------------------------------------------------------
myUSB_DT_d2h_std_ep:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_d2h_std_ep_00

myUSB_DT_d2h_std_ep_End:
myUSB_DT_d2h_std_ep_Size: equ (myUSB_DT_d2h_std_ep_End-myUSB_DT_d2h_std_ep) / 2
myUSB_DT_d2h_std_ep_Dispatch::
    CMP     [myUSB_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured

    MOV     A, REG[myUSB_EP0DATA + wIndexHi] ; Is the request for EP0?
    MOV     [myUSB_t2], A              ; Use the UM temp var--Selector
    MOV     A, REG[myUSB_EP0DATA + wIndexLo] ;
    OR      [myUSB_t2], A              ; Use the UM temp var--Selector
    JZ      .ep0_request

    JMP    _myUSB_Not_Supported        ; Stall the request if not configured
; Jump here if the device is configured or EP0 request
.configured:
.ep0_request:
    MOV     A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_d2h_std_ep, myUSB_DT_d2h_std_ep_Size, myUSB_Not_Supported 

;-----------------------------------------------------------------------------
myUSB_DT_h2d_std_ep:
;-----------------------------------------------------------------------------
    jmp     myUSB_CB_h2d_std_ep_00
    jmp     myUSB_CB_h2d_std_ep_01
    jmp     myUSB_CB_h2d_std_ep_02
    jmp     myUSB_CB_h2d_std_ep_03

myUSB_DT_h2d_std_ep_End:
myUSB_DT_h2d_std_ep_Size: equ (myUSB_DT_h2d_std_ep_End-myUSB_DT_h2d_std_ep) / 2
myUSB_DT_h2d_std_ep_Dispatch::
    CMP     [myUSB_Configuration], 0   ; Is the device configured?
    JNZ     .configured                ; Jump on configured

    MOV     A, REG[myUSB_EP0DATA + wIndexHi] ; Is the request for EP0?
    MOV     [myUSB_t2], A              ; Use the UM temp var--Selector
    MOV     A, REG[myUSB_EP0DATA + wIndexLo] ;
    OR      [myUSB_t2], A              ; Use the UM temp var--Selector
    JZ      .ep0_request

    JMP    _myUSB_Not_Supported        ; Stall the request if not configured
; Jump here if the device is configured or EP0 request
.configured:
.ep0_request:
    MOV     A, REG[myUSB_EP0DATA + bRequest]
    DISPATCHER myUSB_DT_h2d_std_ep, myUSB_DT_h2d_std_ep_Size, myUSB_Not_Supported 

myUSB_GetTableEntry_Local_Std:
    LJMP    myUSB_GetTableEntry

myUSB_NoDataStageControlTransfer_Local_Std:
    LJMP    myUSB_NoDataStageControlTransfer

;-----------------------------------------------
; 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
   ;---------------------------------------------------

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

; End of File myUSB_std.asm

⌨️ 快捷键说明

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