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

📄 usb_std.asm

📁 基于Cypress CY3655开发工具的USB鼠标程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
    JMP     USB_GetTableEntry_Local_Std
ENDIF
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_dev_08
;
;  DESCRIPTION:   Get Device Configuration
;
;****************************************************************
; STANDARD DEVICE IN REQUEST: Get_Device_Configuration
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | DEVICE)       = 80h
; bRequest       : GET_CONFIGURATION              = 08h    
; wValue         : RESERVED                       = 0000h  
; wIndex         : RESERVED                       = 0000h
; wLength        : SIZEOF_DEVICE_CONFIGURATION    = 0001h  
; 
; The GET_DEVICE_CONFIGURATION request returns the currently 
; selected device configuration number. 
;
; request_value and request_index contain 0000h. request_length 
; contains 0001h and the one-byte configuration number is returned 
; in a separate data transfer.
;
;-----------------------------------------------------------------------------
;
;  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_std_dev_08 & USB_UM_SUPPLIED)
.LITERAL
GetConfigTransferDescrTable:
    TD_START_TABLE  1                  ; One entry
    TD_ENTRY    USB_DS_RAM, 1, USB_Configuration, NULL_PTR  ; Current configuration
.ENDLITERAL
export  USB_CB_d2h_std_dev_08
USB_CB_d2h_std_dev_08:
    MOV     [USB_t2], 0                ; Use the UM temp var--Selector
    MOV     A,>GetConfigTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetConfigTransferDescrTable  ; Get the ROM Address LSB
    JMP     USB_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_dev_01
;
;  DESCRIPTION:   Clear Device Feature
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Clear_Device_Feature
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | DEVICE)      = 00h
; bRequest       : CLEAR_FEATURE                  = 01h    
; wValue         : FEATURE_SELECTOR               = --xxh  
; wIndex         : RESERVED                       = 0000h
; wLength        : RESERVED                       = 0000h  
; 
; The CLEAR_DEVICE_FEATURE request disables a particular feature 
; for a device. The only feature supported for a device is the 
; REMOTE_WAKEUP 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_dev_01 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_dev_01
USB_CB_h2d_std_dev_01:
    MOV     A, REG[USB_EP0DATA+wValueLo]  ; Get the Feature Selector
                                       ; Check against valid features
                                       ;  for device receipient
    CMP     A, USB_DEVICE_REMOTE_WAKEUP  ; Only remote wakeup is defined for clear
    JNZ     USB_Not_Supported          ;      
    AND     [USB_DeviceStatus], ~USB_DEVICE_STATUS_REMOTE_WAKEUP
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_dev_03
;
;  DESCRIPTION:   Set Device Featue
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Feature
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | DEVICE)      = 00h
; bRequest       : SET_FEATURE                    = 03h    
; wValue         : FEATURE_SELECTOR               = --xxh  
; wIndex         : RESERVED                       = 0000h
; wLength        : RESERVED                       = 0000h  
; 
; The SET_DEVICE_FEATURE request enables a particular feature
; on a device. The only feature supported for a device is the 
; REMOTE_WAKEUP 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_dev_03 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_dev_03
USB_CB_h2d_std_dev_03:
    MOV     A, REG[USB_EP0DATA+wValueLo]  ; Get the Feature Selector
                                       ; Check against valid features
                                       ;  for device receipient
    CMP     A, USB_DEVICE_REMOTE_WAKEUP  ; Remote wakeup?
    JZ      .remote_wakeup

    CMP     A, USB_TEST_MODE           ; Test Mode 
    JZ      .test_mode
; Flow here for any other selector is invalid for device receipient
    JMP     USB_Not_Supported
; Jump here to enable remote wake up
.remote_wakeup:
    OR      [USB_DeviceStatus], USB_DEVICE_STATUS_REMOTE_WAKEUP
    JMP     .finish
; Jump here to enable test mode
.test_mode:
    JMP     USB_Not_Supported
.finish:
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_dev_05
;
;  DESCRIPTION:   Set Device Address
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Address
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | DEVICE)      = 00h
; bRequest       : SET_ADDRESS                    = 05h    
; wValue         : DEVICE_ADDRESS                 = 00xxh  
; wIndex         : RESERVED                       = 0000h
; wLength        : RESERVED                       = 0000h  
; 
; The SET_DEVICE_ADDRESS request sets the USB device address
; for all future USB accesses. 
;
;****************************************************************
;
;-----------------------------------------------------------------------------
;
;  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_dev_05 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_dev_05
USB_CB_h2d_std_dev_05:
      
    MOV     [USB_fDataPending], USB_ADDRESS_CHANGE_PENDING       
    MOV     A, REG[USB_EP0DATA+wValueLo]       
    MOV     [USB_TransferBuffer],A       
                                                   
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_h2d_std_dev_09
;
;  DESCRIPTION:   Set Configuration
;
;****************************************************************
; STANDARD DEVICE OUT REQUEST: Set_Device_Configuration
;****************************************************************
;
; bmRequestType  : (OUT | STANDARD | DEVICE)      = 00h
; bRequest       : SET_CONFIGURATION              = 09h    
; wValue         : CONFIGURATION_VALUE            = --xxh  
; wIndex         : RESERVED                       = 0000h
; wLength        : RESERVED                       = 0000h  
; 
; The SET_DEVICE_CONFIGURATION request selects a device 
; configuration to be activated as the current configuration. 
;
;****************************************************************
;-----------------------------------------------------------------------------
;
;  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_dev_09 & USB_UM_SUPPLIED)
export  USB_CB_h2d_std_dev_09
USB_CB_h2d_std_dev_09:
    CALL    USB_GET_DEVICE_TABLE_ENTRY ; Get the selected device
    MOV     [USB_t2],USB_t1            ; Set the GETWORD destination 
    CALL    USB_GETWORD                ; Get the pointer to the CONFIG_LOOKUP table
                                       ; ITempW has the address
    MOV     A, REG[USB_EP0DATA+wValueLo]  ; Get the configuration number
    MOV     [USB_t2],A                 ; Save it 
    MOV     A, [USB_t1]                ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [USB_t1+1]              ; Get the CONFIG_LOOKUP ROM Address LSB
    ROMX                               ; First entry is the table size (only a byte)
    CMP     A, [USB_t2]                ; Range check
    JC      USB_Not_Supported

; Refactored from the two loops below
    MOV     [USB_Configuration],[USB_t2]  ; Save the config number

    CMP     [USB_t2], 0                ; Unconfigure?
    JZ      .unconfigure

; Flow here to configure the endpoints
    MOV     A, [USB_t1]                ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [USB_t1+1]              ; Get the CONFIG_LOOKUP ROM Address LSB
    INC     X                          ; Point to the first table entry
    ADC     A, 0                       ;
    MOV    [USB_t2], USB_t1            ; Set up the destination  
    CALL    USB_GETWORD                ; Get the pointer to the CONFIG_LOOKUP table
                                       ; ITempW has the address
    MOV     X, 0                       ; Start the index at 0, but we INC first
.configure_next:
    INC     X                          ; Do the next one
    PUSH    X                          ; Save the endpoint number
    MOV     A, [USB_t1]                ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [USB_t1+1]              ; Get the CONFIG_LOOKUP ROM Address LSB
    ROMX
    INC     [USB_t1+1]                 ; Point to the next 
    ADC     [USB_t1], 0                ;
    POP     X
    CALL    ConfigureEP                ; X contains the EP number
                                       ; A contains the EP Direction
    MOV     A, X                       ; 
    CMP     A, USB_MAX_EP_NUMBER       ; Configure each of the endpoints
    JNZ     .configure_next            ; Do another one?
; Flow here when we are done
    JMP     .done

; Jump here to unconfigure the endpoints
.unconfigure:
    MOV     X, USB_MAX_EP_NUMBER       ; Configure each of the endpoints
.unconfigure_next:
    MOV     [X+USB_EndpointAPIStatus], NO_EVENT_ALLOWED ; For the API
    MOV     REG[X+EP0MODE], USB_MODE_DISABLE ; Disable the endpoint
    DEC     X                          ; One more down
    JNZ     .unconfigure_next          ; Don't unconfigure EP0
.done:
    JMP     USB_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ifc_00
;
;  DESCRIPTION:   Get Interface Status
;
;****************************************************************
; STANDARD INTERFACE IN REQUEST: Get_Interface_Status
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | INTERFACE)    = 81h    
; bRequest       : GET_STATUS                     = 00h    
; wValue         : RESERVED                       = 0000h  
; wIndex         : INTERFACE                      = --xxh
; wLength        : SIZEOF_INTERFACE_STATUS        = 0002h  
; 
; The GET_INTERFACE_STATUS request returns status for the 
; specified 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_std_ifc_00 & USB_UM_SUPPLIED)
.LITERAL
GetInterfaceStatusTransferDescrTable:
    TD_START_TABLE  1                  ; One entry
    TD_ENTRY        USB_DS_RAM, 2, USB_TransferBuffer, NULL_PTR  ; Reuse the transfer buffer
.ENDLITERAL
export  USB_CB_d2h_std_ifc_00
USB_CB_d2h_std_ifc_00:

    MOV     [USB_TransferBuffer], 0    ; Zero the transfer buffer
    MOV     [USB_TransferBuffer+1], 0  ; 

    MOV     [USB_t2], 0                ; Use the UM temp var--Selector
    MOV     A,>GetInterfaceStatusTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetInterfaceStatusTransferDescrTable  ; Get the ROM Address LSB

    JMP     USB_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ifc_10
;
;  DESCRIPTION:   Get Interface
;
;****************************************************************
; STANDARD INTERFACE IN REQUEST: Get_Interface
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | INTERFACE)    = 81h
; bRequest       : GET_INTERFACE                  = 0Ah    
; wValue         : RESERVED                       = 0000h  
; wIndex         : INTERFACE                      = xxxxh
; wLength        : SIZEOF_GET_INTERFACE           = 0001h  
; 
; The GET_INTERFACE request returns the selected alternate 
; setting for the specified 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_std_ifc_10 & USB_UM_SUPPLIED)
.LITERAL
GetInterfaceTransferDescrTable:
    TD_START_TABLE  1                  ; One entry
    TD_ENTRY        USB_DS_RAM, 1, USB_TransferBuffer, NULL_PTR  ; Reuse the transfer buffer
.ENDLITERAL
export  USB_CB_d2h_std_ifc_10
USB_CB_d2h_std_ifc_10:
    MOV     A, REG[USB_EP0DATA+wIndexLo]  ; Get the interface number
    CMP     A, 1h                      ; Valid interface number? (UM Parameter: NumInterfaces)
    JNC     USB_Not_Supported

    MOV     X, A                       ; The interface number is the index into alternates settings table

    MOV     A, [X + USB_InterfaceSetting]  ; Save the current interface setting
    MOV     [USB_TransferBuffer], A    ; into the transfer buffer

    MOV     [USB_t2], 0                ; Use the UM temp var--Selector
    MOV     A,>GetInterfaceTransferDescrTable  ; Get the ROM Address MSB
    MOV     X,<GetInterfaceTransferDescrTable  ; Get the ROM Address LSB

    JMP     USB_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USB_CB_d2h_std_ep_00
;
;  DESCRIPTION:   Get Endpoint Status
;
;****************************************************************
; STANDARD ENDPOINT IN REQUEST: Get_Endpoint_Status
;****************************************************************
;
; bmRequestType  : (IN | STANDARD | ENDPOINT)     = 82h    
; bRequest       : GET_STATUS                     = 00h    
; wValue         : RESERVED                       = 0000h  
; wIndex         : ENDPOINT                       = 00xxh

⌨️ 快捷键说明

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