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

📄 logo.asm

📁 利用CY单片机CY7C637XX编写的USB鼠标程序
💻 ASM
📖 第 1 页 / 共 3 页
字号:
		jnz		no_data_status_done

		change_address:
			mov		A, [pending_data]	; change the device address if this
			or		A, ADDRESS_ENABLE	; data is pending
			iowr	usb_address

		no_data_status_done:			; otherwise set to stall in/out until
			mov		A, STALL_IN_OUT		; a new setup
			iowr	ep0_mode

			mov		A, TRANS_NONE
			mov		[ep0_transtype], A

			pop		A
			pop		X
			reti


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

	;**********************************
	; OUT - CONTROL READ STATUS STAGE
	;	  - CONTROL WRITE DATA STAGE
	;	  - ERROR DURING NO DATA CONTROL TRANSACTION

	ep0_out_received:
	mov		A, [ep0_transtype]
	jacc	ep0_out_jumptable

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

	control_read_status_stage:
		mov		A, STATUS_IN_ONLY
		iowr	ep0_mode

		mov		A, TRANS_NONE
		mov		[ep0_transtype], A

		pop		A
		pop		X
		reti	


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

	control_write_data_stage:
		mov		A, ep0_count					; check that data is valid
		and		A, DATA_VALID
		jz		control_write_data_stage_done

		mov		A, ep0_count					; check for correct data toggle
		and		A, DATA_TOGGLE
		xor		A, [ep0_data_toggle]
		jnz		control_write_data_stage_done

		; get data and transfer it to a buffer here


		mov		A, DATA_TOGGLE
		xor		[ep0_data_toggle], A

		control_write_data_stage_done:
		pop		A
		pop		X
		reti

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

	no_data_control_error:	
		mov		A, STALL_IN_OUT
		iowr	ep0_mode

		mov		A, TRANS_NONE
		mov		[ep0_transtype], A

		pop		A
		pop		X
		reti

	
;*******************************************************
;
;	Interrupt handler: endpoint1
;	Purpose: This interrupt routine handles the specially
;		 reserved data endpoint 1 (for a mouse).  This
;		 interrupt happens every time a host sends an
;		 IN on endpoint 1.  The data to send (NAK or 3
;		 byte packet) is already loaded, so this routine
;		 just prepares the dma buffers for the next packet
;
;*******************************************************

endpoint1:
	push	A

;	; change data toggle
;	mov		A, 80h
;	xor		[ep1_data_toggle], A
;
;	mov		A, NO_EVENT_PENDING				; clear pending events
;
;	mov		[event_machine], A 
;
;	; clear endpoint variables
;	mov		A, 00h							; clear horz&vert cursor change values
;	mov		[ep1_dmabuff1], A
;	mov		[ep1_dmabuff2], A
;
;	; set response
;	mov		A, [ep1_stall]					; if endpoint is set to stall, then set
;	cmp		A, FFh							; mode to stall
;	jnz		endpoint1_done
;		mov		A, STALL_IN_OUT
;		iowr	ep1_mode
;
;	endpoint1_done:
;		pop		A
		reti

	
;**********************************************************
;	JUMP TABLES
;**********************************************************

XPAGEOFF
ORG		600h

		; bmRequestTypes commented out are not used for this device,
		; but may be used for your device.  They are kept here as
		; an example of how to use this jumptable.

		bmRequestType_jumptable:
			jmp		h2d_std_device			; 00
			jmp		h2d_std_interface		; 01	
			jmp		h2d_std_endpoint		; 02	
			jmp		request_not_supported	; h2d_std_other			03	
			jmp		request_not_supported	; h2d_class_device		04	
			jmp		request_not_supported	; h2d_class_interface	05	
			jmp		request_not_supported	; h2d_class_endpoint	06	
			jmp		request_not_supported	; h2d_class_other		07	
			jmp		request_not_supported	; h2d_vendor_device		08	
			jmp		request_not_supported	; h2d_vendor_interface	09	
			jmp		request_not_supported	; h2d_vendor_endpoint	0A	
			jmp		request_not_supported	; h2d_vendor_other		0B	
			jmp		request_not_supported	; 0C	
			jmp		request_not_supported	; 0D	
			jmp		request_not_supported	; 0E	
			jmp		request_not_supported	; 0F	
			jmp		d2h_std_device			; 10	
			jmp		d2h_std_interface		; 11	
			jmp		d2h_std_endpoint		; 12	
			jmp		request_not_supported	; d2h_std_other			13	
			jmp		request_not_supported	; d2h_class_device		14	
			jmp		request_not_supported	; d2h_class_interface	15	
			jmp		request_not_supported	; d2h_class_endpoint	16	
			jmp		request_not_supported	; d2h_class_other		17	
			jmp		request_not_supported	; d2h_vendor_device		18	
			jmp		request_not_supported	; d2h_vendor_interface	19	
			jmp		request_not_supported	; d2h_vendor_endpoint	1A	
			jmp		request_not_supported	; d2h_vendor_other		1B	
			jmp		request_not_supported	; 1C	
			jmp		request_not_supported	; 1D	
			jmp		request_not_supported	; 1E	
			jmp		request_not_supported	; 1F	

		h2d_std_device_jumptable:
			jmp		request_not_supported	; 00
			jmp		request_not_supported	; 01
			jmp		request_not_supported	; 02
			jmp		request_not_supported		; 03
			jmp		request_not_supported	; 04
			jmp		set_device_address		; 05
			jmp		request_not_supported	; 06
			jmp		request_not_supported	; set_device_descriptor		07
			jmp		request_not_supported	; 08
			jmp		set_device_configuration; 09

		h2d_std_interface_jumptable:
			jmp		request_not_supported	; 00
			jmp		request_not_supported	; clear_interface_feature 01
			jmp		request_not_supported	; 02
			jmp		request_not_supported	; set_interface_feature	 03
			jmp		request_not_supported	; 04
			jmp		request_not_supported	; 05
			jmp		request_not_supported	; 06
			jmp		request_not_supported	; 07
			jmp		request_not_supported	; 08
			jmp		request_not_supported	; 09
			jmp		request_not_supported	; 0A
			jmp		set_interface_interface	; 0B

		h2d_std_endpoint_jumptable:
			jmp		request_not_supported	; 00
			jmp		clear_endpoint_feature	; 01
			jmp		request_not_supported	; 02
			jmp		set_endpoint_feature	; 03
									
		d2h_std_device_jumptable:
			jmp		get_device_status		; 00
			jmp		request_not_supported	; 01
			jmp		request_not_supported	; 02
			jmp		request_not_supported	; 03
			jmp		request_not_supported	; 04
			jmp		request_not_supported	; 05
			jmp		get_device_descriptor	; 06
			jmp		request_not_supported	; 07
			jmp		get_device_configuration; 08

		d2h_std_interface_jumptable:
			jmp		get_interface_status	; 00
			jmp		request_not_supported	; 01
			jmp		request_not_supported	; 02
			jmp		request_not_supported	; 03
			jmp		request_not_supported	; 04
			jmp		request_not_supported	; 05
			jmp		get_interface_hid		; 06
			jmp		request_not_supported	; 07
			jmp		request_not_supported	; 08
			jmp		request_not_supported	; 09
			jmp		get_interface_interface	; 0A
	
		d2h_std_endpoint_jumptable:
			jmp		get_endpoint_status		; 00
			jmp		request_not_supported	; 01
			jmp		request_not_supported	; 02
			jmp		request_not_supported	; 03
			jmp		request_not_supported	; 04
			jmp		request_not_supported	; 05
			jmp		request_not_supported	; 06
			jmp		request_not_supported	; 07
			jmp		request_not_supported	; 08
			jmp		request_not_supported	; 09
			jmp		request_not_supported	; 0A
			jmp		request_not_supported	; 0B
			jmp		request_not_supported	; synch frame 0C
	
		ep0_in_jumptable:
			jmp		request_not_supported
			jmp		control_read_data_stage
			jmp		control_write_status_stage
			jmp		no_data_control_status_stage		

		ep0_out_jumptable:
			jmp		request_not_supported
			jmp		control_read_status_stage
			jmp		control_write_data_stage
			jmp		no_data_control_error


		get_device_descriptor_jumptable:
			jmp		request_not_supported
			jmp		send_device_descriptor
			jmp		send_configuration_descriptor
			jmp		send_string_descriptor
			jmp		send_interface_descriptor
			jmp		send_endpoint_descriptor

		string_jumptable:
			jmp		language_string
			jmp		manufacturer_string
			jmp		product_string
			jmp		serial_string
			jmp		configuration_string


;*********************************************************
;                   rom lookup tables
;*********************************************************

XPAGEOFF
ORG		700h

control_read_table:
   device_desc_table:
	db	12h			; bLength (18 bytes)
	db	01h			; bDescriptorType (device descriptor)
	db	10h, 01h	; bcdUSB (ver 1.1)
	db	00h			; bDeviceClass (each interface specifies class info)
	db	00h			; bDeviceSubClass (not specified)
	db	00h			; bDeviceProtocol (not specified)
	db	08h			; bMaxPacketSize0 (8 bytes)
	db	B4h, 04h	; idVendor (Cypress vendor ID)
	db	70h, 63h	; idProduct (Cypress USB mouse product ID)
	db	00h, 01h	; bcdDevice (1.00) 
	db	01h			; iManufacturer (Cypress Semiconductor)
	db	02h			; iProduct (Cypress Ultra Mouse)
	db	03h			; iSerialNumber (000-000-0001)
	db	01h			; bNumConfigurations (1)

   config_desc_table:
	db	09h			; bLength (9 bytes)
	db	02h			; bDescriptorType (CONFIGURATION)
	db	22h, 00h	; wTotalLength (34 bytes)
	db	01h			; bNumInterfaces (1)
	db	01h			; bConfigurationValue (1)
	db	04h			; iConfiguration (USB HID Compliant Mouse)
	db	00h			; bmAttributes (bus powered, remote wakeup)
	db	0Dh			; MaxPower (13mA)
   interface_desc_table:
	db	09h			; bLength (9 bytes)
	db	04h			; bDescriptorType (INTERFACE)
	db	00h			; bInterfaceNumber (0)
	db	00h			; bAlternateSetting (0)
	db	01h			; bNumEndpoints (1)
	db	03h			; bInterfaceClass (3..defined by USB spec)
	db	01h			; bInterfaceSubClass (1..defined by USB spec)
	db	02h			; bInterfaceProtocol (2..defined by USB spec)
	db	00h			; iInterface (not supported)
   hid_desc_table:
	db	09h			; bLength (9 bytes)
	db	21h			; bDescriptorType (HID)
	db	00h, 01h	; bcdHID (1.00)	
	db	00h			; bCountryCode (US)
	db	01h			; bNumDescriptors (1)
	db	22h			; bDescriptorType (HID)
	db	32h, 00h	; wDescriptorLength (50 bytes) 
   endpoint_desc_table:
	db	07h			; bLength (7 bytes)
	db	05h			; bDescriptorType (ENDPOINT)
	db	81h			; bEndpointAddress (IN endpoint, endpoint 1)
	db	03h			; bmAttributes (interrupt)
	db	03h, 00h	; wMaxPacketSize (3 bytes)
	db	0Ah			; bInterval (10ms)

   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, 03h	; 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, 01h	; usage page (generic desktop)
	db	09h, 30h	; usage (X)
	db	09h, 31h	; usage (Y)
	db	15h, 81h	; logical minimum (-127)
	db	25h, 7Fh	; logical maximum (127)
	db	75h, 08h	; report size (8)
	db	95h, 02h	; report count (2)
	db	81h, 06h	; input (2 position bytes X & Y)
	db	C0h, C0h	; end collection, end collection

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

   device_configured_table:
	db	01h			; device in configured state
   device_unconfigured_table:
	db	00h			; device in unconfigured state

   endpoint_nostall_table:
	db	00h, 00h	; endpoint not stalled
   endpoint_stall_table:
	db	01h, 00h	; endpoint stalled

   interface_status_table:
	db	00h, 00h	; default response

   interface_alternate_table:
	db	00h			; only valid alternate setting

   interface_boot_protocol:
	db	00h
   interface_report_protocol:
	db	01h

   ilanguage_string:
    db 04h          				; Length
    db 03h          				; Type (3=string)
    db 09h          				; Language:  English
    db 04h          				; Sub-language: US

   imanufacturer_string:
    db 1Ch          				; Length
    db 03h          				; Type (3=string)
    dsu "Cypress Semi."

   iproduct_string:
    db 34h          				; Length
    db 03h          				; Type (3=string)
    dsu "CY3654 Development System"

   iserialnumber_string:			; serial number
	db 10h                        	; Length 
    db 03h							; Type (3=string)
    dsu "0000001"

   iconfiguration_string:
    db 28h          				; Length
    db 03h          				; Type (3=string)
    dsu "HID-Compliant Mouse"


;**********************************************************
;	APPLICATION SPECIFIC TABLES
;**********************************************************

ORG		800h


		event_machine_jumptable:
			jmp		no_event_pending
			jmp		no_event_task


	logo_table:
		db 00h, 05h	;1
		db 00h, 05h	;2
		db 00h, 05h	;3
		db 00h, 05h	;4
		db 00h, 05h	;5
		db 05h, 05h	;6
		db 05h, 00h	;7
		db 05h, 00h	;8
		db 05h, FBh	;9
		db 00h, FBh	;10
		db 00h, FBh	;11
		db 00h, FBh	;12
		db 00h, FBh	;13
		db 00h, FBh	;14
		db 23h, 05h	;15
		db FBh, FBh	;16
		db FBh, 00h	;17
		db FBh, 00h	;18
		db FBh, 05h	;19
		db 00h, 05h	;20
		db 05h, 05h	;21
		db 05h, 00h	;22
		db 05h, 00h	;23
		db 05h, 05h	;24
		db 00h, 05h	;25
		db FBh, 05h	;26
		db FBh, 00h	;27
		db FBh, 00h	;28
		db FBh, FBh	;29
		db 05h, 05h	;30
		db 1Eh, 00h	;31
		db 05h, 00h	;32
		db 05h, 00h	;33
		db 05h, 00h	;34
		db 05h, FBh	;35
		db 00h, FBh	;36
		db FBh, FBh	;37
		db FBh, 00h	;38
		db FBh, 00h	;39
		db FBh, 00h	;40
		db 0Fh, 00h	;41
		db 05h, FBh	;42
		db 00h, FBh	;43
		db FBh, FBh	;44
		db FBh, 00h	;45
		db FBh, 00h	;46
		db FBh, 00h	;47
		db 00h, 05h	;48
		db 00h, 05h	;49
		db 00h, 05h	;50
		db 00h, 05h	;51
		db 00h, 05h	;52
		db 00h, 05h	;53
		db 00h, E2h	;54
		db BAh, 00h	;55

⌨️ 快捷键说明

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