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

📄 mouse45b.asm

📁 USB大全电子版全部资料3~包含源码、协议等
💻 ASM
📖 第 1 页 / 共 5 页
字号:
      mov A, [bRequest] 	; load bRequest

; Set Report			bRequest = 9

	cmp A, set_report

	jz SetReport

; Set Idle				bRequest = 10

      cmp A, set_idle

      jz SetIdle

; Set Protocol			bRequest = 11

      cmp A, set_protocol

      jz SetProtocol

	jmp SendStall		; stall unsupported functions



;=======================================================================

; This one is not in the spec, but has been captured with CATC while

; Memphis beta testing. 

RequestType22:

      mov A, [bRequest] 	; load bRequest

; Set Report			bRequest = 9

	cmp A, set_report

	jz SetReport

; Set Idle				bRequest = 10

      cmp A, set_idle

      jz SetIdle

; Set Protocol			bRequest = 11

      cmp A, set_protocol

      jz SetProtocol

	jmp SendStall		; stall unsupported functions



;=======================================================================

; device to host with endpoint as recipient

RequestTypeA1:

        mov A, [bRequest] 	; load bRequest

; Get Report			bRequest = 1

        cmp A, get_report

        jz GetReport

; Get Idle				bRequest = 2

        cmp A, get_idle

        jz GetIdle

; Get Protocol			bRequest = 3

        cmp A, get_protocol

        jz GetProtocol

        jmp SendStall        	; stall unsupported functions



;=======================================================================

; This one is not in the spec, but has been captured with CATC while

; Memphis beta testing. 

RequestTypeA2:

        mov A, [bRequest] 	; load bRequest

; Get Report			bRequest = 1

        cmp A, get_report

        jz GetReport

; Get Idle				bRequest = 2

        cmp A, get_idle

        jz GetIdle

; Get Protocol			bRequest = 3

        cmp A, get_protocol

        jz GetProtocol

        jmp SendStall        	; stall unsupported functions



;========================================================================

;       stage three ... process the request

;========================================================================

; Remote wakeup is the ability to wakeup a system from power down mode

; when the user presses a key or moves a mouse.  These routines

; allow the host to enable/disable the ability to request remote wakeup.

;

; Disable the remote wakeup capability.

ClearRemoteWakeup:

        mov A, [wValue]                 ; load wValue

        cmp A, device_remote_wakeup     ; test for valid feature

        jnz SendStall                   ; stall unsupported features

        call no_data_control            ; handshake with host

        mov A, DISABLE_REMOTE_WAKEUP    ; disable remote wakeup

        mov [remote_wakeup_status], A

        ret                             ; return



; Enable the remote wakeup capability.

SetRemoteWakeup:

        mov A, [wValue]                 ; load wValue

        cmp A, device_remote_wakeup     ; test for valid feature

        jnz SendStall                   ; stall unsupported features

        call no_data_control            ; handshake with host

        mov A, ENABLE_REMOTE_WAKEUP     ; enable remote wakeup

        mov [remote_wakeup_status], A

        ret                             ; return



; Set the device address to the wValue in the SETUP packet at

; the completion of the current transaction.

SetAddress:

        call no_data_control            ; handshake with host

        mov A, [wValue]                 ; load wValue 

        iowr USB_Device_Address         ; write new USB device address

        ret                             ; return



; Set the configuration of the device to either unconfigured (0) or

; configured (1) based on wValue in the SETUP packet.  According to

; the USB spec (page 178), a Set Configuration also clears the endpoint

; stall condition and re-initializes endpoints using data 0/1 toggle to

; Data0.

SetConfiguration:

      call no_data_control

	mov A, [wValue]				; load wValue lsb

      mov [configuration_status], A   	; store configuration byte

      mov A, 0

      mov [endpoint_stall], A  		; not stalled

      iord USB_EP1_TX_Config          	; clear data 0/1 bit

      and A, ~DataToggle

	iowr USB_EP1_TX_Config	

      mov A, [configuration_status]

      cmp A, 0

	jnz device_configured



; device is unconfigured

	iord USB_EP1_TX_Config

	and A, EFh					; disable endpoint 1

	iowr USB_EP1_TX_Config			  

	mov A, [interrupt_mask]			; disable endpoint one interrupts

	and A, EFh

     	mov [interrupt_mask], A

	jmp done_configuration



; device is configured

device_configured:

	iord USB_EP1_TX_Config		; NAK IN packets until data is 	

	and A,7Fh				; ready on endpoint one

	or A, 10h				; enable endpoint one

	iowr USB_EP1_TX_Config			  

	mov A, [interrupt_mask]		; enable endpoint one interrupts

	or A, 10h

     	mov [interrupt_mask], A

      iord USB_Status_Control		; NAK IN packets until data is 	

	and A,0EFh				; ready on endpoint one

	iowr USB_Status_Control			  

done_configuration:		  

        ret                         ; return



; Clear the endpoint stall feature for the selected endpoint.  This

; should also set the data 0/1 bit to Data0 if endpoint one is selected.

ClearEndpointStall:

        mov A, [wValue]                 ; load wValue (which feature)

        cmp A, endpoint_stalled         ; test for valid feature

        jnz SendStall                   ; stall unsupported features

;

; clear endpoint one stall feature

;

      call no_data_control            	; handshake with host

      mov A,0         

      mov [endpoint_stall], A  		; not stalled

      iord USB_EP1_TX_Config          	; clear data 0/1 bit

      and A, ~DataToggle

	iowr USB_EP1_TX_Config		

      iord USB_Status_Control			; NAK IN packets until data is 	

	and A,0EFh					; ready on endpoint one

	iowr USB_Status_Control			  

      ret                             	; return



; Set the endpoint stall feature for the selected endpoint.

SetEndpointStall:

        mov A, [wValue]                 	; load wValue

        cmp A, endpoint_stalled         	; test for valid feature

        jnz SendStall                   	; stall unsupported features

        call no_data_control            	; handshake with host

        mov A,1         

        mov [endpoint_stall], A  		; stalled

        mov A, 30h                    	; stall endpoint one 

        iowr USB_EP1_TX_Config                 

        ret                             	; return



; The device status is a 16-bit value (two bytes) with only D[1:0]

; defined.  D0=0 specifies bus-powered, which never changes.  D1

; reflects the status of the device_remote_wakeup feature.  This

; feature can either be disabled (D1=0) or enabled (D1=1).

GetDeviceStatus:

        mov A, 2                        		; send two bytes

        mov [data_count], A

        mov A, (get_dev_status_table - control_read_table)

        add A, [remote_wakeup_status]   		; get correct remote wakeup

        jmp execute                     		; send device status to host



; There are five descriptor types.  The descriptor type will be in

; the high byte of wValue.  The descriptor index will be in the low

; byte of wValue.  The standard request to a device supports three

; of these types: device, configuration, and string.  The standard

; request does not support interface or endpoint descriptor types.

GetDescriptor:

        mov A, [wValueHi]               ; load descriptor type

;------------------------------------------------------------------------

; Test for standard descriptor types first.

; Get Descriptor (device)               wValueHi = 1

	cmp A, device

      jz GetDeviceDescriptor

; Get Descriptor (configuration)        wValueHi = 2

	cmp A, configuration

      jz GetConfigurationDescriptor

; Get Descriptor (string)               wValueHi = 3

	cmp A, string

	jz GetStringDescriptor

;------------------------------------------------------------------------

; Then test for HID class descriptor types.

; Get Descriptor (HID)                  wValueHi = 21h

        cmp A, HID

        jz GetHIDDescriptor

; Get Descriptor (report)               wValueHi = 22h  

	cmp A, report

	jz GetReportDescriptor

; Get Descriptor (physical)             wValueHi = 23h  *** not supported ***

	jmp SendStall			    ; stall unsupported functions



; Return the current device configuration to the host.  The possible

; values are zero (unconfigured) and one (configured).

GetConfiguration:

        mov A, 1                        ; send one byte

        mov [data_count], A

        mov A, (get_configuration_status_table - control_read_table)

        add A, [configuration_status]   ; get correct configuration

        jmp execute                     ; send configuration to host



; The interface status is a 16-bit value (two bytes) that is always

; zero for both bytes.

GetInterfaceStatus:

        mov A, 2                        ; send two bytes

        mov [data_count], A

        mov A, (get_interface_status_table - control_read_table)

        jmp execute                     ; send interface status to host



; The endpoint status is a 16-bit value (two bytes) with only one

; bit (D0) defined.  If D0=0, then the selected endpoint is not

; stalled.  If D0=1, then the selected endpoint is stalled.

GetEndpointStatus:

        mov A, 2                        ; send two bytes

        mov [data_count], A

        mov A, [endpoint_stall]

        asl A                           ; select the correct entry

        add A, (get_endpoint_status_table - control_read_table)

        jmp execute                     ; send endpoint status to host



;------------------------------------------------------------------------

; Set Report   

SetReport:

	jmp SendStall	; *** not supported ***



; Set Idle silences a particular report on the interrupt pipe until a new

; event occurs or the specified amount of time (wValue) passes.

SetIdle:

        

;      mov A, [idle_period]		

;    	 mov [prev_idle_period], A		; set the previous idle period to the current one



	mov A, [wValueHi]				; load upper byte of wValue

	mov [new_idle_period], A		; copy to new_idle_period

	

	mov A, 0					; if current idle_period is 0 (indefinite)

	cmp A, [idle_period]			; set the idle_period to the new_idle_period

	jz set_new_idle_period

	

	mov A, [idle_period]

	sub A, [idle_period_counter]

	jc set_new_idle_flag			; if idle_period < idle_period_counter then 

							; set new idle flag to true



	cmp A, 2					; if the idle_period - idle_period_counter > 1

	jnc set_new_idle_period			; (i.e. > 4ms), then set idle period to new one

							; otherwise, set the new idle flag to true



set_new_idle_flag:				; set the new_idle_flag to 1 and return

	mov A, 1					; this keeps the current idle period until

	mov [new_idle_flag], A			; the next report is sent to the host

	jmp done_SetIdle	





set_new_idle_period:				

	mov A, [new_idle_period]		; set the current idle period to the new one

	mov [idle_period], A



	dec A						; check if new_idle_period <= idle_period_counter

	cmp A, [idle_period_counter]

	jnc done_SetIdle				; if no, then return

	mov A, 1					; if yes, then set new_idle_flag to true so that

	mov [new_idle_flag], A			; we keep the new idle value after the report is sent



done_SetIdle:

	call no_data_control            ; handshake with host

      ret                             ; return



	



        

; Set Protocol switches between the boot protocol and the report protocol.

; For boot protocol, wValue=0.  For report protocol, wValue=1.

; Note, the mouse firmware does not actually do anything with the

; protocol status, yet.

SetProtocol:

        mov A, [wValue]                 ; load wValue

        mov [protocol_status], A        ; write new protocol value

        call no_data_control            ; handshake with host

        ret                             ; return



; Get Report allows the host to receive a report via the control pipe.

; The report type is specified in the wValue high byte while the low

; byte has a report ID.  

GetReport:

        mov A, 3                        ; three byte

        mov [data_count], A

        mov A,report_buffer

        jmp execute2                    ; send report to host

        

	



GetReportDescriptor:

	mov A, (end_hid_report_desc_table - hid_report_desc_table)

      mov [data_count], A             ; save descriptor length            



	mov A, (hid_report_desc_table - control_read_table)

      call execute                    ; send descriptor to host

;

; Enumeration is complete!  

;

      ret                           ; return





; Get Idle reads the current idle rate for a particular input report.

GetIdle:

        

	  mov A, 1                        ; send one byte

        mov [data_count], A

        mov A, new_idle_period

        jmp execute2                     ; send idle_period to host

        



; Get Protocol sends the current protocol status back to the host.

GetProtocol:

        mov A, 1                        ; send one byte

        mov [data_count], A

        mov A, (get_protocol_status_table - control_read_table)

        add A, [protocol_status]        ; get correct configuration

        jmp execute                     ; send protocol to host

        

;========================================================================

; Standard Get Descriptor routines

;

; Return the device descriptor to the host.

GetDeviceDescriptor:

        mov A, 0                        ; load the device descriptor length

	  index device_desc_table

        mov [data_count], A             ; save the device descriptor length

        mov A, (device_desc_table - control_read_table)

        jmp execute                     ; send the device descriptor



; Return the configuration, interface, and endpoint descriptors.

⌨️ 快捷键说明

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