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

📄 mouse45.asm

📁 USB大全电子版全部资料3~包含源码、协议等
💻 ASM
📖 第 1 页 / 共 5 页
字号:
                                        ; the RAM

        ret                             ; return





GetStringDescriptor:

	mov A, [wValue]

	cmp A, 0h

	jz LanguageString

	cmp A, 01h

	jz ManufacturerString

	cmp A, 02h

	jz ProductString

	cmp A, 03h

	jz SerialNumString

      cmp A, 04h

	jz ConfigurationString

      cmp A, 05h

	jz InterfaceString



; No other strings supported

      jmp SendStall   		; *** not supported ***

LanguageString:

	mov A, (USBStringDescription1 - USBStringLanguageDescription)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringLanguageDescription - control_read_table)

      jmp execute                     ; send the string descriptor

ManufacturerString:	

	mov A, ( USBStringDescription2 - USBStringDescription1)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringDescription1 - control_read_table)

      jmp execute                     ; send the string descriptor

ProductString:

	mov A, ( USBStringDescription3 - USBStringDescription2)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringDescription2 - control_read_table)

      jmp execute                     ; send the string descriptor

SerialNumString:

	mov A, ( USBStringDescription4 - USBStringDescription3)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringDescription3 - control_read_table)

      jmp execute                     ; send the string descriptor

ConfigurationString:

	mov A, ( USBStringDescription5 - USBStringDescription4)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringDescription4 - control_read_table)

      jmp execute

InterfaceString:

	mov A, ( USBStringEnd - USBStringDescription5)

      mov [data_count], A               ; save the descriptor length

	mov A, (USBStringDescription5 - control_read_table)

      jmp execute

	



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

; HID class Get Descriptor routines

;

; Return the HID descriptor and enable endpoint one.

GetHIDDescriptor:

	mov A, (end_config_desc_table - Class_Descriptor)

      mov [data_count], A             ; save descriptor length            



	mov A, ( Class_Descriptor - control_read_table)

      call execute                    ; send descriptor to host

      ret                             ; return



;**********USB library main routines*******************



;******************************************************

; The host sometimes lies about the number of bytes it

; wants from a descriptor.  Any request to get descriptor

; should return the lesser of the number of bytes requested

; or the actual length of the descriptor.

 

get_descriptor_length:

	mov A, [wLengthHi] 	; load requested transfer length

	cmp A, 0			; confirm high byte is zero

	jnz use_actual_length	; no requests should be longer than 256b

	mov A, [wLength]		; test low byte against zero

	cmp A, 0

	jz use_actual_length	; must request some data

	cmp A, [data_count]     ; compare to the amount of data

	jnc use_actual_length

	mov [data_count], A     ; use requested length

use_actual_length:

        ret                   ; return



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

;	function: no_data_control

;	purpose: performs the no-data control operation

;		as defined by the USB specifications

no_data_control:

	mov A, C0h			; set up the transfer

	iowr USB_EP0_TX_Config	; register for data1

					; and 0 byte transfer



	mov A, [interrupt_mask]	; enable interrupts

	iowr Global_Interrupt



wait_nodata_sent:

	iord USB_EP0_TX_Config	; wait for the data to be

	and A, 80h			; transferred

	jnz wait_nodata_sent

	ret				; return to caller



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



;******************************************************

;

;	function:  Control_read

;	Purpose:   Performs the control read operation

;		   as defined by the USB specification

;	SETUP-IN-IN-IN...OUT

;

;	data_start: must be set to the descriptors info

;		    as an offset from the beginning of the

;		    control read table

;		    data count holds the 

;	data_count: must be set to the size of the 

;		    descriptor 

;******************************************************



control_read: 

	push X				; save X on stack

	mov A, 00h				; clear data 0/1 bit

	mov [endp0_data_toggle], A



control_read_data_stage:

	mov X, 00h

	mov A, 00h

	mov [loop_counter], A

	iowr USB_EP0_RX_Status		; clear setup bit



; Fixing a bug seen by NEC hosts	

	iord USB_EP0_RX_Status		; check setup bit

	and A, 01h				; if not cleared, another setup

	jnz control_read_status_stage	; has arrived. Exit ISR

	mov A, 08h				; set BADOUTS BIT

	iowr USB_Status_Control

	mov A, [data_count]

	cmp A, 00h				; if the number of byte to transmit

	jz dma_load_done			; is a multiple of 8 we have to transmit 

						; a zero-byte data packet



dma_load_loop:				; loop to load data into the data buffer

	mov A, [data_start]

	index control_read_table

	mov [X + endpoint_0], A		; load dma buffer

	inc [data_start]

	inc X

	inc [loop_counter]

	dec [data_count]			; exit if descriptor

	jz dma_load_done			; is done

	mov A, [loop_counter]		; or 8 bytes sent

	cmp A, 08h

	jnz dma_load_loop



dma_load_done:



	iord USB_EP0_RX_Status		; check setup bit

	and A, 01h				; if not cleared, another setup

	jnz control_read_status_stage	; has arrived. Exit ISR

	mov A, [endp0_data_toggle]

	xor A, 40h

	mov [endp0_data_toggle], A

	or A, 80h

	or A, [loop_counter]

	iowr USB_EP0_TX_Config

	mov A, [interrupt_mask]

	iowr Global_Interrupt



wait_control_read:

	iord USB_EP0_TX_Config		; wait for the data to be

	and A, 80h				; transfered

	jz control_read_data_stage

	iord USB_EP0_RX_Status

	and A, 02h				; check if out was sent by host

	jz wait_control_read



control_read_status_stage:		; OUT at end of data transfer

	pop X					; restore X from stack

	mov A, [interrupt_mask]

	iowr Global_Interrupt

	ret



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



;******************************************************

;

;	function:  Control_read2

;	Purpose:   Performs the control read operation. 

;		     Sends data from RAM

;	SETUP-IN-IN-IN...OUT

;

;	data_start: must be set to the beginning of the

;		    RAM buffer

;		    

;	data_count: must be set to the size of the 

;		      buffer 

;******************************************************



control_read2: 

	push X				; save X on stack

	mov A, 00h				; clear data 0/1 bit

	mov [endp0_data_toggle], A



control_read_data_stage2:

	mov X, 00h

	mov A, 00h

	mov [loop_counter], A

	iowr USB_EP0_RX_Status		; clear setup bit



; Fixing a bug seen by NEC hosts	

	iord USB_EP0_RX_Status		; check setup bit

	and A, 01h				; if not cleared, another setup

	jnz control_read_status_stage2	; has arrived. Exit ISR

	mov A, 08h				; set BADOUTS BIT

	iowr USB_Status_Control

      mov A, [data_count]

	cmp A, 00h				; if the number of byte to transmit

	jz dma_load_done2			; is a multiple of 8 we have to transmit 

						; a zero-byte data packet



dma_load_loop2:				; loop to load data into the data buffer

	push X

	mov X, [data_start]

	mov A,[X+0]

      pop X

	mov [X + endpoint_0], A		; load dma buffer

	inc [data_start]

	inc X

	inc [loop_counter]

	dec [data_count]			; exit if descriptor

	jz dma_load_done2			; is done

	mov A, [loop_counter]		; or 8 bytes sent

	cmp A, 08h

	jnz dma_load_loop2



dma_load_done2:



	iord USB_EP0_RX_Status		; check setup bit

	and A, 01h				; if not cleared, another setup

	jnz control_read_status_stage2	; has arrived. Exit ISR

	mov A, [endp0_data_toggle]

	xor A, 40h

	mov [endp0_data_toggle], A

	or A, 80h

	or A, [loop_counter]

	iowr USB_EP0_TX_Config

	mov A, [interrupt_mask]

	iowr Global_Interrupt



wait_control_read2:

	iord USB_EP0_TX_Config		; wait for the data to be

	and A, 80h				; transfered

	jz control_read_data_stage2

	iord USB_EP0_RX_Status

	and A, 02h				; check if out was sent by host

	jz wait_control_read2

control_read_status_stage2:		; OUT at end of data transfer

	pop X					; restore X from stack

	mov A, [interrupt_mask]

	iowr Global_Interrupt

	ret







;*********************************************************

;                   rom lookup tables

;*********************************************************



	XPAGEOFF

		

control_read_table:

   device_desc_table:

	db	12h		; size of descriptor (18 bytes)

	db	01h		; descriptor type (device descriptor)

	db	00h, 01h	; USB spec release (ver 1.0)

	db	00h		; class code (each interface specifies class information)

	db	00h		; device sub-class (must be set to 0 because class code is 0)

	db	00h		; device protocol (no class specific protocol)

	db	08h		; maximum packet size (8 bytes)

	db	B4h, 04h	; vendor ID (note Cypress vendor ID)

	db	01h, 00h	; product ID (Cypress USB mouse product ID)

	db	00h, 00h	; device release number

	db	01h		; index of manufacturer string 

	db	02h		; index of product string 

	db	00h		; index of serial number (0=none)

	db	01h		; number of configurations (1)



   config_desc_table:

	db	09h		; length of descriptor (9 bytes)

	db	02h		; descriptor type (CONFIGURATION)

	db	22h, 00h	; total length of descriptor (34 bytes)

	db	01h		; number of interfaces to configure (1)

	db	01h		; configuration value (1)

	db	04h		; configuration string index 

	db	A0h		; configuration attributes (bus powered)

	db	32h		; maximum power (100mA)



   Interface_Descriptor:

	db	09h		; length of descriptor (9 bytes)

	db	04h		; descriptor type (INTERFACE)

	db	00h		; interface number (0)

	db	00h		; alternate setting (0)

	db	01h		; number of endpoints (1)

	db	03h		; interface class (3..defined by USB spec)

	db	01h		; interface sub-class (1..defined by USB spec)

	db	02h		; interface protocol (2..defined by USB spec)

	db	05h		; interface string index 



   Endpoint_Descriptor:

	db	07h		; descriptor length (7 bytes)

	db	05h		; descriptor type (ENDPOINT)

	db	81h		; endpoint address (IN endpoint, endpoint 1)

	db	03h		; endpoint attributes (interrupt)

	db	03h, 00h	; maximum packet size (3 bytes)

	db	0Ah		; polling interval (10ms)



   Class_Descriptor:

	db	09h		; descriptor size (9 bytes)

	db	21h		; descriptor type (HID)

	db	00h,01h		; HID class release number (1.00)

	db	00h		; Localized country code (none)

	db	01h		; # of HID class descriptor to follow (1)

	db	22h		; Report descriptor type (HID)

	db	(end_hid_report_desc_table - hid_report_desc_table)

	db	00h



   end_config_desc_table:



   hid_report_desc_table:

	db	05h, 01h	; usage page (generic desktop)

	db	09h, 02h	; usage (mouse)

	db	A1h, 01h	; collection (application)

	db	09h, 01h	; usage (pointer)

	db	A1h, 00h	; collection (linked)

	db	05h, 09h	; usage page (buttons)

	db	19h, 01h	; usage minimum (1)

	db	29h, 03h	; usage maximum (3)

	db	15h, 00h	; logical minimum (0)

	db	25h, 01h	; logical maximum (1)

	db	95h, 03h	; report count (3 bytes)

	db	75h, 01h	; report size (1)

	db	81h, 02h	; input (3 button bits)

	db	95h, 01h	; report count (1)

	db	75h, 05h	; report size (5)

	db	81h, 01h	; input (constant 5 bit padding)

	db	05h,

⌨️ 快捷键说明

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