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

📄 mouse.asm

📁 CY7C63231 mouse 源码
💻 ASM
📖 第 1 页 / 共 4 页
字号:
	wakeup_button_read_done:
		mov		A, [int_temp]
		xor		A, [current_button_state]
		jnz		force_wakeup		


	;**********************************
	; test for optics status change

	; turn on optics
	mov		A, LEFT_BUTTON
	iowr	OPTIC_CONTROL_PORT

	; wait 100us for phototransistors to turn on
	mov		A, 80h							
	optic_delay:
		dec	A
		jnz	optic_delay

	; test x-axis for change
	mov		A, 00h
	mov		[int_temp], A

	test_x0:
	iord	X_OPTICS_PORT
	mov		X, A
	and		A, X0
	jz		test_x1
		mov		A, 01h
		or		[int_temp], A
	test_x1:
	mov		A, X
	and		A, X1
	jz		test_x
		mov		A, 02h
		or		[int_temp], A

	test_x:
		mov		A, [int_temp]
		cmp		A, [x_last_state]
		jnz		force_wakeup

	; test y-axis for change
	mov		A, 00h
	mov		[int_temp], A

	test_y0:
	iord	Y_OPTICS_PORT
	mov		X, A
	and		A, Y0
	jz		test_y1
		mov		A, 01h
		or		[int_temp], A
	test_y1:
	mov		A, X
	and		A, Y1
	jz		test_y
		mov		A, 02h
		or		[int_temp], A

	test_y:
		mov		A, [int_temp]
		cmp		A, [y_last_state]
		jnz		force_wakeup

	; test z-axis for change
	mov		A, 00h
	mov		[int_temp], A

	test_z0:
	iord	Z_OPTICS_PORT
	mov		X, A
	and		A, Z0
	jz		test_z1
		mov		A, 01h
		or		[int_temp], A
	test_z1:
	mov		A, X
	and		A, Z1
	jz		test_z
		mov		A, 02h
		or		[int_temp], A

	test_z:
		mov		A, [int_temp]
		cmp		A, [z_last_state]
		jnz		force_wakeup


	; if there is no change in the optics, then we need to go back to sleep
	mov		A, LEFT_BUTTON | OPTIC_CONTROL
	iowr	OPTIC_CONTROL_PORT

	pop		A
	reti


	;**********************************
	; force resume for 14ms
	force_wakeup:
		mov		A, VREG_ENABLE | CONTROL1		; force J
		iowr	usb_status
		mov		A, VREG_ENABLE | CONTROL0		; force K
		iowr	usb_status
	
		mov		A, 48h						; wait 14ms
		outer_wakeup_timer:
			push	A
			iowr	watchdog
			mov		A, FFh
			inner_wakeup_timer:
				dec		A
				jnz		inner_wakeup_timer
			pop		A
			dec		A
			jnz		outer_wakeup_timer

	mov		A, VREG_ENABLE | BUS_ACTIVITY	; disable forcing and signal
	iowr	usb_status						; that we are about to have
											; bus activity
	wakeup_done:
		pop		A
		reti

	
;**********************************************************
;				USB REQUEST JUMP TABLES
;**********************************************************

XPAGEOFF
ORG		700h

		; 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		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		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		clear_device_feature	; 01
			jmp		request_not_supported	; 02
			jmp		set_device_feature		; 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

		h2d_class_interface_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		request_not_supported	; 05
			jmp		request_not_supported	; 06
			jmp		request_not_supported	; 07
			jmp		request_not_supported	; 08
			jmp		request_not_supported	; set_report 09
			jmp		set_interface_idle		; 0A
			jmp		set_interface_protocol	; 0B
									
		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
	
		d2h_class_interface_jumptable:
			jmp		request_not_supported	; 00
			jmp		get_interface_report	; 01
			jmp		get_interface_idle		; 02
			jmp		get_interface_protocol	; 03

		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		request_not_supported
			jmp		configuration_string


;*********************************************************
;       		USB DESCRIPTOR ROM TABLES
;*********************************************************

XPAGEOFF
ORG		800h

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	20h, 63h	; idProduct (Cypress USB mouse product ID)
	db	00h, 01h	; bcdDevice (1.00) 
	db	01h			; iManufacturer (Cypress Semiconductor)
	db	02h			; iProduct (Cypress 632xx Mouse)
	db	00h			; iSerialNumber (not supported)
	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	A0h			; bmAttributes (bus powered, remote wakeup)
	db	32h			; MaxPower (100mA)
   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	48h, 00h	; wDescriptorLength (72 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	04h, 00h	; wMaxPacketSize (4 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	05h, 09h	; usage page (buttons)
	db	19h, 01h	; usage minimum (1 button)
	db	29h, 03h	; usage maximum (3 buttons)
	db	15h, 00h	; logical minimum (0)
	db	25h, 01h	; logical maximum (1)
	db	95h, 03h	; report count (3 reports)
	db	75h, 01h	; report size (1 bit each)
	db	81h, 02h	; input (Data, Var, Abs)
	db	95h, 01h	; report count (1 report)
	db	75h, 05h	; report size (5 bits)
	db	81h, 03h	; input (Cnst, Ary, Abs)
	db	05h, 01h	; usage page (generic desktop)
	db	09h, 01h	; usage (pointer)
	db	A1h, 00h	; collection (linked)
	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 bits each)
	db	95h, 02h	; report count (2 reports)
	db	81h, 06h	; input (Cnst, Var, Rel)
	db	C0h			; end collection	
	db	09h, 38h	; wheel
	db	95h, 01h	; wheel size = 1 byte
	db	81h, 06h	; variable data bit field with relative position
	db	09h, 3ch	; motion wake up
	db	15h, 00h	; 0 no movement
	db	25h, 01h	; 1 movement
	db	75h, 01h	; 1st bit represent movement
	db	95h, 01h	; 1 report
	db	b1h, 22h	; variable data bit field with absolute positioning and no preferred state
	db	95h, 07h	; 7 reports for reversing, upper 7 bits of byte 3
	db	b1h, 01h	; constant array bit field with absolute positioning
	db	0c0h		; end collection, end collection

   device_status_wakeup_enabled:
    db  02h, 00h    ; remote wakeup enabled, bus powered
   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 28h          				; Length
    db 03h          				; Type (3=string)
    dsu "Cypress 632xx Mouse"

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


;**********************************************************
;				TASK LOOP JUMP TABLES
;**********************************************************

XPAGEOFF
ORG 900h

		button_machine_jumptable:
			jmp		no_button_task
			jmp		button_task

		event_machine_jumptable:
			jmp		no_event_task
			jmp		event_pending

		x_jumptable:					; [x_last_state]	[x_current_state]
			jmp	analyze_y_optics		; 00     			00	
			jmp	x_increment				; 00				01
			jmp	x_decrement				; 00				10
			jmp	analyze_y_optics		; 00				11
			jmp	x_decrement				; 01				00
			jmp	analyze_y_optics		; 01				01
			jmp	analyze_y_optics		; 01				10
			jmp	x_increment				; 01				11
			jmp	x_increment				; 10				00
			jmp	analyze_y_optics		; 10				01
			jmp	analyze_y_optics		; 10				10
			jmp	x_decrement				; 10				11
			jmp	analyze_y_optics		; 11				00
			jmp	x_decrement				; 11				01
			jmp	x_increment				; 11				10
			jmp	analyze_y_optics		; 11				11

		y_jumptable:					; [y_last_state]	[y_current_state]
			jmp	analyze_z_optics		; 00     			00	
			jmp	y_decrement				; 00				01
			jmp	y_increment				; 00				10
			jmp	analyze_z_optics		; 00				11
			jmp	y_increment				; 01				00
			jmp	analyze_z_optics		; 01				01
			jmp	analyze_z_optics		; 01				10
			jmp	y_decrement				; 01				11
			jmp	y_decrement				; 10				00
			jmp	analyze_z_optics		; 10				01
			jmp	analyze_z_optics		; 10				10
			jmp	y_increment				; 10				11
			jmp	analyze_z_optics		; 11				00
			jmp	y_increment				; 11				01
			jmp	y_decrement				; 11				10
			jmp	analyze_z_optics		; 11				11

		z_jumptable:					; [z_last_state]	[z_current_state]
			jmp	optic_task_done			; 00     			00	
			jmp	z_backward				; 00				01
			jmp	z_forward				; 00				10
			jmp	optic_task_done			; 00				11
			jmp	z_forward				; 01				00
			jmp	optic_task_done			; 01				01
			jmp	optic_task_done			; 01				10
			jmp	z_backward				; 01				11
			jmp	z_backward				; 10				00
			jmp	optic_task_done			; 10				01
			jmp	optic_task_done			; 10				10
			jmp	z_forward				; 10				11
			jmp	optic_task_done			; 11				00
			jmp	z_forward				; 11				01
			jmp	z_backward				; 11				10
			jmp	optic_task_done			; 11				11

⌨️ 快捷键说明

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