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

📄 sionew.asm

📁 使用Cy7c63001A做串口向USB键盘转换
💻 ASM
📖 第 1 页 / 共 4 页
字号:
;========================================================================

;	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

	iowr Watchdog

	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, 09h				; 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:

	iowr Watchdog

	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, 09h				; 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:

	iowr Watchdog

	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	10h, 01h	; USB spec release (ver 1.1)

	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	FFh, FFh	; vendor ID (note Cypress vendor ID)

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

	db	01h, 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	80h		; 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)1

	db	01h		; interface protocol (2..defined by USB spec)*1

	db	05h		; interface string index 



   Class_Descriptor:

	db	09h		; descriptor size (9 bytes)

	db	21h		; descriptor type (HID)

	db	01h,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



   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	08h, 00h	; maximum packet size (3 bytes)

	db	0Ah		; polling interval (10ms)


   end_config_desc_table:


   hid_report_desc_table:

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

	db	09h, 06h	; usage (keyboard)

	db	A1h, 01h	; collection (application)

	db	05h, 07h	; usage page (key code)

	db	19h, E0h	; usage minimum (234)

	db	29h, E7h	; usage maximum (231)

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

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

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

	db	95h, 08h	; report count (8 bytes)?

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

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

	db	75h, 08h	; report size (8)

	db	81h, 01h	; input (constant 5 bit padding)
	
	db	95h, 05h	; report count (5)
	
	db	75h, 01h	; report size (1)

	db	05h, 08h	; usage page (LEDs)

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

	db	29h, 05h	; usage maximum (5)

	db	91h, 02h	; 
	
	db	95h, 01h	; report count (1)
	
	db	75h, 03h	; report size (3)
	
	db	91h, 01h	; output (constant)
	
	db	95h, 06h	; report count (6)
	
	db	75h, 08h	; report size (8)
	
	db	15h, 00h	; logical minimum (0)

	db	25h, 65h	; logical maximum (101)
	
	db	05h, 07h	; usage page (key code)
	
	db	19h, 00h	; usage minimum (0)
	
	db	29h, 65h	; usage maximum (101)
	
	db	81h, 00h	; input
	
	db	C0h			; end collection

  end_hid_report_desc_table:

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



; String Descriptors

; string 0

USBStringLanguageDescription:

    db (USBStringDescription1-USBStringLanguageDescription)         ; Length

    db 03h          ; Type (3=string)

    db 09h          ; Language:  English

    db 04h          ; Sub-language: US



; string 1

USBStringDescription1:	; IManufacturerName

    db (USBStringDescription2-USBStringDescription1)          ; Length

    db 03h          ; Type (3=string)

    dsu "wel" ;



; string 2

USBStringDescription2:	; IProduct

    db (USBStringDescription3 - USBStringDescription2)          ; Length

    db 03h          ; Type (3=string)

    dsu "Litele keyboard"  ;



;string 3

USBStringDescription3:	; serial number

                        ; If a SN is used, this must be unique

                        ; for every device or the device may

                        ; not enumerate properly

; string 4                 

USBStringDescription4:	; configuration string descriptor

    db (USBStringDescription4-USBStringDescription3)         ; Length

    db 03h          ; Type (3=string)

    dsu "HID Key"  ;



;string 5

USBStringDescription5:	; configuration string descriptor

    db (USBStringEnd-USBStringDescription5)          ; Length

    db 03h          ; Type (3=string)

    dsu "EP1 Interrupt Pipe"  ;







USBStringEnd:



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

; These tables are the mechanism used to return status information to the

; host.  The status can be either device, interface, or endpoint.



get_dev_status_table:

        db      00h, 00h        ; remote wakeup disabled, bus powered

        db      02h, 00h        ; remote wakeup enabled, bus powered



get_interface_status_table:

        db      00h, 00h        ; always return both bytes zero



get_endpoint_status_table:

        db      00h, 00h        ; not stalled

        db      01h, 00h        ; stalled



get_configuration_status_table:

        db      00h             ; not configured

        db      01h             ; configured



get_protocol_status_table:

        db      00h             ; boot protocol

        db      01h             ; report protocol



get_interface_table:

        db      00h             ; no alternate settings defined

key_list:

		db	00h, 00h, 00h, 49h, 00h, 4Ch, 00h, 4Ah, 00h, 4Dh, 00h, 52h, 00h, 51h, 00h, 50h
		db	00h, 2Ah, 00h, 2Bh, 00h, 58h, 00h, 4Fh, 00h, 4Bh, 00h, 28h, 00h, 4Eh, 00h, E1h
		db	00h, 5Dh, 00h, 3Ah, 00h, 3Bh, 00h, 3Ch, 00h, 3Dh, 00h, 3Eh, 00h, 3Fh, 00h, 40h
		db	00h, 41h, 00h, 42h, 00h, 43h, 00h, 44h, 00h, 45h, 00h, 29h, 00h, E0h, 00h, E2h
		db	00h, 2Ch, 02h, 1Eh, 02h, 34h, 02h, 20h, 02h, 21h, 02h, 22h, 02h, 24h, 00h, 34h
		db	02h, 26h, 02h, 27h, 02h, 25h, 02h, 2Eh, 00h, 36h, 00h, 2Dh, 00h, 37h, 00h, 38h
		db	00h, 27h, 00h, 1Eh, 00h, 1Fh, 00h, 20h, 00h, 21h, 00h, 22h, 00h, 23h, 00h, 24h
		db	00h, 25h, 00h, 26h, 02h, 33h, 00h, 33h, 02h, 36h, 00h, 2Eh, 02h, 37h, 02h, 38h
		db	02h, 1Fh, 02h, 04h, 02h, 05h, 02h, 06h, 02h, 07h, 02h, 08h, 02h, 09h, 02h, 0Ah
		db	02h, 0Bh, 02h, 0Ch, 02h, 0Dh, 02h, 0Eh, 02h, 0Fh, 02h, 10h, 02h, 11h, 02h, 12h
		db	02h, 13h, 02h, 14h, 02h, 15h, 02h, 16h, 02h, 17h, 02h, 18h, 02h, 19h, 02h, 1Ah
		db	02h, 1Bh, 02h, 1Ch, 02h, 1Dh, 00h, 2Fh, 00h, 31h, 00h, 30h, 02h, 23h, 02h, 2Dh
		db	00h, 35h, 00h, 04h, 00h, 05h, 00h, 06h, 00h, 07h, 00h, 08h, 00h, 09h, 00h, 0Ah
		db	00h, 0Bh, 00h, 0Ch, 00h, 0Dh, 00h, 0Eh, 00h, 0Fh, 00h, 10h, 00h, 11h, 00h, 12h
		db	00h, 13h, 00h, 14h, 00h, 15h, 00h, 16h, 00h, 17h, 00h, 18h, 00h, 19h, 00h, 1Ah
		db	00h, 1Bh, 00h, 1Ch, 00h, 1Dh, 02h, 2Fh, 02h, 31h, 02h, 30h, 02h, 35h, 00h, 4Ch
		
end_of_key_list:

⌨️ 快捷键说明

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