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

📄 usbfs_1_std.asm

📁 cypresscy74294ic键盘和鼠标原码
💻 ASM
📖 第 1 页 / 共 4 页
字号:
    ASL     A                          ; Make it into a offset
    CMP     A, GET_DESCR_DISPATCH_SIZE         ; Validity check
    JNC     USBFS_1_Not_Supported

    JACC    GET_DESCR_DISPATCH

GET_DESCR_DISPATCH:
    JMP     USBFS_1_Not_Supported      ; Invalid
    JMP     USBFS_1_SendDeviceDescr    ; Device Descriptor
    JMP     USBFS_1_SendConfigDescr    ; Configuration Descriptor
IF  USBFS_1_bNumStringDescrs           ; Number of String Descriptor defined with the Wizard
    JMP     USBFS_1_SendStringDescr    ; String Descriptor
ELSE
    JMP     USBFS_1_Not_Supported      ; Not supported if we don't have
                                            ; any String Descriptor
ENDIF

GET_DESCR_DISPATCH_END:
GET_DESCR_DISPATCH_SIZE: EQU (GET_DESCR_DISPATCH_END - GET_DESCR_DISPATCH)     
;-----------------------------------------------------------------------------
; Configuration Descriptor Handler
;-----------------------------------------------------------------------------
USBFS_1_SendConfigDescr:
    CALL    USBFS_1_GET_DEVICE_TABLE_ENTRY
    SWAP    A, X
    ADD     A, 2                       ; We want the pointer to the descriptor table (second entry)
    SWAP    A, X
    ADC     A, 0                       ; Don't forget the carry
    MOV    [USBFS_1_t2], USBFS_1_t1    ; Set up the destination  
    CALL    USBFS_1_GETWORD            ; Get the pointer
    
    MOV     A, [USBFS_1_t1]            ; Pointer MSB
    MOV     X, [USBFS_1_t1+1]          ; Pointer LSB
    
    PUSH    A                          ; Save the MSB
    
    MOV     A, REG[USBFS_1_EP0DATA+wValueLo]  ; Get the descrptor index
    MOV     [USBFS_1_t2], A            ; Use the UM temp var--Selector
    POP     A                          ; Need the MSB for the range check
    PUSH    A                          ; Save the MSB for after the range check
    ROMX                               ; First entry is the table size (only a byte)
    CMP     A, [USBFS_1_t2]            ; Range check
    JNC     .range_ok
    
    POP     A                          ; Fix the stack
    JMP    USBFS_1_Not_Supported

.range_ok:
    POP     A                          ; Get the MSB back
    JMP     USBFS_1_GetTableEntry_Local_Std
;-----------------------------------------------------------------------------
; Device Descriptor Handler
;-----------------------------------------------------------------------------
USBFS_1_SendDeviceDescr:
    MOV     [USBFS_1_t2], [USBFS_1_bCurrentDevice]  ; Use the UM temp var--Selector
    MOV     A,>USBFS_1_DEVICE_DESCR_TABLE  ; Get the ROM Address MSB
    MOV     X,<USBFS_1_DEVICE_DESCR_TABLE  ; Get the ROM Address LSB
    ROMX                               ; First entry is the table size (only a byte)
    CMP     A, [USBFS_1_t2]            ; Range check
    JC      USBFS_1_Not_Supported

    MOV     A,>USBFS_1_DEVICE_DESCR_TABLE  ; Get the ROM Address MSB

    JMP     USBFS_1_GetTableEntry_Local_Std
;-----------------------------------------------------------------------------
; String Descriptor Handler
;-----------------------------------------------------------------------------
IF  USBFS_1_bNumStringDescrs    ; Not needed if we don't have any String Descriptors
USBFS_1_SendStringDescr:
    MOV     A, REG[USBFS_1_EP0DATA+wValueLo]  ; Get the descrptor index
    MOV     [USBFS_1_t2], A            ; Use the UM temp var--Selector

    MOV     A,>USBFS_1_StringTable     ; Get the ROM Address MSB
    MOV     X,<USBFS_1_StringTable     ; Get the ROM Address LSB
    ROMX                               ; First entry is the table size (only a byte)
    CMP     A, [USBFS_1_t2]            ; Range check
    JC      USBFS_1_Not_Supported

    MOV     A,>USBFS_1_StringTable     ; Get the ROM Address MSB

    JMP     USBFS_1_GetTableEntry_Local_Std
ENDIF
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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, USBFS_1_Configuration, NULL_PTR  ; Current configuration
.ENDLITERAL
export  USBFS_1_CB_d2h_std_dev_08
USBFS_1_CB_d2h_std_dev_08:
    MOV     [USBFS_1_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     USBFS_1_GetTableEntry_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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  USBFS_1_CB_h2d_std_dev_01
USBFS_1_CB_h2d_std_dev_01:
    MOV     A, REG[USBFS_1_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     USBFS_1_Not_Supported      ;      
    AND     [USBFS_1_DeviceStatus], ~USB_DEVICE_STATUS_REMOTE_WAKEUP
    JMP     USBFS_1_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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  USBFS_1_CB_h2d_std_dev_03
USBFS_1_CB_h2d_std_dev_03:
    MOV     A, REG[USBFS_1_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     USBFS_1_Not_Supported
; Jump here to enable remote wake up
.remote_wakeup:
    OR      [USBFS_1_DeviceStatus], USB_DEVICE_STATUS_REMOTE_WAKEUP
    JMP     .finish
; Jump here to enable test mode
.test_mode:
    JMP     USBFS_1_Not_Supported
.finish:
    JMP     USBFS_1_NoDataStageControlTransfer_Local_Std
ENDIF
;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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  USBFS_1_CB_h2d_std_dev_05
USBFS_1_CB_h2d_std_dev_05:
      
    MOV     [USBFS_1_fDataPending], USB_ADDRESS_CHANGE_PENDING       
    MOV     A, REG[USBFS_1_EP0DATA+wValueLo]       
    MOV     [USBFS_1_TransferBuffer],A       
                                                   
    JMP     USBFS_1_NoDataStageControlTransfer_Local_Std
ENDIF


;-----------------------------------------------------------------------------
;  FUNCTION NAME: USBFS_1_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  USBFS_1_CB_h2d_std_dev_09
USBFS_1_CB_h2d_std_dev_09:
    CALL    USBFS_1_GET_DEVICE_TABLE_ENTRY  ; Get the selected device
    MOV     [USBFS_1_t2],USBFS_1_t1    ; Set the GETWORD destination 
    CALL    USBFS_1_GETWORD            ; Get the pointer to the CONFIG_LOOKUP table
                                       ; ITempW has the address
    MOV     A, REG[USBFS_1_EP0DATA+wValueLo]  ; Get the configuration number
    MOV     [USBFS_1_t2],A             ; Save it 
    MOV     A, [USBFS_1_t1]            ; Get the CONFIG_LOOKUP ROM Address MSB
    MOV     X, [USBFS_1_t1+1]          ; Get the CONFIG_LOOKUP ROM Address LSB

⌨️ 快捷键说明

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