📄 usb_std.asm
字号:
JMP USB_SendConfigDescr ; Configuration Descriptor
IF USB_bNumStringDescrs ; Number of String Descriptor defined with the Wizard
JMP USB_SendStringDescr ; String Descriptor
ELSE
JMP USB_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
;-----------------------------------------------------------------------------
USB_SendConfigDescr:
CALL USB_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 [USB_t2], USB_t1 ; Set up the destination
CALL USB_GETWORD ; Get the pointer
MOV A, [USB_t1] ; Pointer MSB
MOV X, [USB_t1+1] ; Pointer LSB
PUSH A ; Save the MSB
MOV A, REG[USB_EP0DATA+wValueLo] ; Get the descrptor index
MOV [USB_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, [USB_t2] ; Range check
JNC .range_ok
POP A ; Fix the stack
JMP USB_Not_Supported
.range_ok:
POP A ; Get the MSB back
JMP USB_GetTableEntry_Local_Std
;-----------------------------------------------------------------------------
; Device Descriptor Handler
;-----------------------------------------------------------------------------
USB_SendDeviceDescr:
MOV [USB_t2], [USB_bCurrentDevice] ; Use the UM temp var--Selector
MOV A,>USB_DEVICE_DESCR_TABLE ; Get the ROM Address MSB
MOV X,<USB_DEVICE_DESCR_TABLE ; Get the ROM Address LSB
ROMX ; First entry is the table size (only a byte)
CMP A, [USB_t2] ; Range check
JC USB_Not_Supported
MOV A,>USB_DEVICE_DESCR_TABLE ; Get the ROM Address MSB
JMP USB_GetTableEntry_Local_Std
;-----------------------------------------------------------------------------
; String Descriptor Handler
;-----------------------------------------------------------------------------
IF USB_bNumStringDescrs ; Not needed if we don't have any String Descriptors
USB_SendStringDescr:
MOV A, REG[USB_EP0DATA+wValueLo] ; Get the descrptor index
MOV [USB_t2], A ; Use the UM temp var--Selector
MOV A,>USB_StringTable ; Get the ROM Address MSB
MOV X,<USB_StringTable ; Get the ROM Address LSB
ROMX ; First entry is the table size (only a byte)
CMP A, [USB_t2] ; Range check
JC USB_Not_Supported
MOV A,>USB_StringTable ; Get the ROM Address MSB
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -