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

📄 enchid.asm

📁 USB主控器固件程序源码
💻 ASM
📖 第 1 页 / 共 3 页
字号:


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

	control_write_status_stage:
;Jump here if the device has received an IN token packet 
;with ep0_transtype = TRANS_CONTROL_WRITE
;The device has sent a 0-byte In data packet to complete the transfer
;because ep0_mode was set to Status_In_Only at the end of the data stage. 

		mov		A, STATUS_OUT_ONLY
		iowr	ep0_mode

	mov		A, TRANS_NONE
	mov		[ep0_transtype], A

		pop		A
		pop		X
		reti


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

	no_data_control_status_stage:
		mov		A, [ep0_in_flag]		; end of no-data control transaction 
		cmp		A, ADDRESS_CHANGE_PENDING
		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:

;ep0_transtype was set during a previous transaction in the transfer.
	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:
;If the data-valid bit isn't set, we're done with the data stage.
;(logo.asm used mov A, ep0_count (incorrect) instead of iord here.)
		iord		ep0_count					; check that data is valid
		and		A, DATA_VALID
		jz		control_write_data_stage_done

;(logo.asm used mov A, ep0_count (incorrect) instead of iord here.)
		iord		ep0_count					;check 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
;Copy the report's two bytes to data memory.

			mov		A, [ep0_dmabuff0]
			mov		[data_byte_0], A
			mov		A, [ep0_dmabuff1]
			mov		[data_byte_1], A

;Toggle the data-toggle bit.
		mov		A, DATA_TOGGLE
		xor		[ep0_data_toggle], A

;If all of the data has been received,
;configure Endpoint 0 to send a 0-byte data packet in response
;to an IN packet (the transfer's status phase)
;and to Stall an Out packet.
;To do: add the ability to use > 1 data transaction.

		mov		A, STATUS_IN_ONLY
		iowr		ep0_mode

		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
	iord	ep1_mode
; If the interrupt was due to receiving a NAK, 
; exit the ISR.
	and	A, EP_ACK
	jz	     endpoint1_NAK

; Otherwise, toggle the data toggle for the next transaction.
	mov		A, 80h
	xor		[ep1_data_toggle], A

	mov		A, NO_EVENT_PENDING				; clear pending events
	mov		[event_machine], A 

	; set response
	mov		A, [ep1_stall]					; if endpoint is set to stall, then set
	cmp		A, FFh							; mode to stall
	jnz		endpoint1_NAK
		mov		A, STALL_IN_OUT
		iowr	ep1_mode
	jmp		endpoint1_done

endpoint1_NAK:
; If the host returned ACK, the SIE set the ACK bit 
; in the epP1_mode register. Clear the ACK bit.
; The endpoint mode remains NAK_IN.
	mov	A, NAK_IN
	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		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

;h2d_class_interface_jumptable was added to logo.asm
;Host-to-device HID-specific requests
		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		set_report			; 09
			jmp		request_not_supported	; set_idle	; 0A
			jmp		request_not_supported	; set_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

;Device-to-host HID-specific requests
		d2h_class_interface_jumptable:
			jmp		request_not_supported	; 00
			jmp		request_not_supported	; get_report	; 01
			jmp		request_not_supported	; get_idle	; 02
			jmp		request_not_supported	; get_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

;*********************************************************
;                   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	25h, 09h	; idVendor (Lakeview Research: 0925h)
	db	34h, 12h	; idProduct (1234h)
	db	00h, 01h	; bcdDevice (1.00) 
	db	01h			; iManufacturer
	db	02h			; iProduct
	db	00h			; iSerialNumber (unused)
	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	00h			; Configuration string (unused)
	db	80h			; 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	00h			; bInterfaceSubClass (1..defined by USB spec)
	db	00h			; 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	end_hid_report_desc_table - hid_report_desc_table, 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	06h, A0h, FFh	; usage page (vendor defined)
	db	09h, 01h	; usage (vendor defined)
	db	A1h, 01h	; collection (application)
	db	09h, 02h	; usage (vendor defined)
	db	A1h, 00h	; collection (linked)
	db	06h, A1h, FFh	; usage page (vendor defined)

;The input report
     db 09h, 03h     ;               usage - vendor defined
     db 09h, 04h     ;               usage - vendor defined
     db 15h, 80h     ;               Logical Minimum (-128)
     db 25h, 7Fh     ;               Logical Maximum (127)
     db 35h, 00h     ;               Physical Minimum (0)
     db 45h, FFh;                    Physical Maximum (255)
;    db 66h, 00h, 00h;               Unit (None (2 bytes))
     db 75h, 08h     ;               Report Size (8)  (bits)
     db 95h, 02h     ;               Report Count (2)  (fields)
     db 81h, 02h     ;               Input (Data, Variable, Absolute)  

;The output report
     db 09h, 05h     ;               usage - vendor defined
     db 09h, 06h     ;               usage - vendor defined
     db 15h, 80h     ;               Logical Minimum (-128)
     db 25h, 7Fh     ;               Logical Maximum (127)
     db 35h, 00h     ;               Physical Minimum (0)
     db 45h, FFh     ;               Physical Maximum (255)
;    db 66h, 00h, 00h;               Unit (None (2 bytes))
     db 75h, 08h     ;               Report Size (8)  (bits)
     db 95h, 02h     ;               Report Count (2)  (fields)
     db 91h, 02h     ;               Output (Data, Variable, Absolute)  

	db	C0h, C0h	; end collection, end collection

    end_hid_report_desc_table:

   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:
;Length is (# of characters + 1) * 2
    db 38h          				; Length
    db 03h          				; Type (3=string)
    dsu "USB Complete by Jan Axelson"

   iproduct_string:
    db 18h          				; Length
    db 03h          				; Type (3=string)
    dsu "HID Example"

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

ORG		850h


		event_machine_jumptable:
			jmp		no_event_pending
			jmp		no_event_task

⌨️ 快捷键说明

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