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

📄 sn8_usb_module.lib

📁 Sonix新出的MCU SN8F2255的USB的HID库。
💻 LIB
📖 第 1 页 / 共 3 页
字号:
*   Divide the data and Send to the FIFO	
*----------------------------------------------------------------------------
*****************************************************************************/
table_transmit:
		mov	a,table_index[1]
		mov	y,a
		mov	a,table_index[0]
		mov	z,a

		CALL	check_length

		mov	a,#EP0_PACKET_SIZE	;Tmp_Cnt = 8
		mov	Tmp_Cnt,a

		mov	a,#0x0			;set addr 0
		CALL	EP0_FIFO_WR_addr_set

		mov	a,table_length[1]	;if highbyte != 0
		cmprs	a,#0h
		jmp	table_transmit_20

		mov 	a,table_length[0]
      		b0bts1  FZ
      		jmp 	table_transmit_05
		mov	a, #0xF0
		and	UE0R,a
		jmp	table_transmit_90
;		mov 	a,table_length[0]
;      		b0bts0  FZ
;		jmp	table_transmit_90
table_transmit_05:
      

		mov	a,table_length[0]	;if lowbyte >= 8
		sub	a,#EP0_PACKET_SIZE
		b0bts0	FC
		jmp	table_transmit_20

		mov	a,#0f0h
		and	UE0R,a
		mov	a,table_length[0]
		or	UE0R,a
table_transmit_10:	; < 8 byte transmit
		movc
		CALL	EP0_FIFO_WR_data
		mov	a, #0x01
		CALL	EP0_FIFO_WR_addr_add
		b0bts1	USB_Status.5	;double byte transmit
		jmp	table_transmit_11
		mov	a,r

		CALL	EP0_FIFO_WR_data
		mov	a, #0x01
		CALL	EP0_FIFO_WR_addr_add
		decms	table_length[0]
		jmp	table_transmit_11
		jmp	table_transmit_90	
table_transmit_11:
		mov	a, #0x01
		add	z,a
		b0bts0	fc

		add	y,a
		b0bclr	fc

		decms	table_length[0]
		jmp	table_transmit_10
		jmp	table_transmit_90	

table_transmit_20:	; >= 8 byte transmit
		movc
		CALL	EP0_FIFO_WR_data	
		mov	a, #0x01
		CALL	EP0_FIFO_WR_addr_add

		b0bts1	USB_Status.5	;double byte transmit
		jmp	table_transmit_21
		mov	a,r
		CALL	EP0_FIFO_WR_data
		mov	a, #0x01		
		CALL	EP0_FIFO_WR_addr_add
		CALL	decm_length
		decms	Tmp_Cnt

table_transmit_21:
		mov	a, #0x01
		add	z,a
		b0bts0	fc

		add	y,a
		b0bclr	fc

		incms	table_index[0]	;table_index(low byte)+1
		jmp	$+2
		incms	table_index[1]	;if occur carry then table_index(high_byte)+1

		CALL	decm_length		

		decms	Tmp_Cnt
		jmp	table_transmit_20

		mov	a,#0f0h
		and	UE0R,a
		mov	a,#EP0_PACKET_SIZE
		or	UE0R,a
table_transmit_90:		
		b0bset	UE0R.5
		ret

//******************** End of data structure ********************* //

;***********************************************************************
;		USB FIFO Read & Write function call
;-----------------------------------------------------------------------
; 1. EPX_FIFO_RD_addr_set - Set the EPX FIFO's read address 
; 2. EPX_FIFO_WR_addr_set - Set the EPX FIFO's write address
; 3. EPX_FIFO_RD_data     - Read data from EPX FIFO
; 4. EPX_FIFO_WR_data	  - Write data into EPX FIFO 
; ps. EPX ( X = 0 ~ 3)	
;***********************************************************************

// ==================================================================== //
// EPX_FIFO_RD_addr_set & EPX_FIFO_WR_addr_set				//
// will do this instruction => b0mov udpx,a	x => depend on FFFS bit	//
// ==================================================================== //
EP0_FIFO_RD_addr_set:
EP1_FIFO_RD_addr_set:
EP2_FIFO_RD_addr_set:
EP3_FIFO_RD_addr_set:
		b0mov	UDP0,a	
		ret

EP0_FIFO_RD_addr_add:
		add	UDP0,a
		ret

// ==================================================================== //
// EPX_FIFO_RD_data 							//
// will do this instruction => b0mov a, UDRx	x => depend on FFFS bit	//
// ==================================================================== //

EP0_FIFO_RD_data:
EP1_FIFO_RD_data:
EP2_FIFO_RD_data:
EP3_FIFO_RD_data:
		b0mov	a, UDR0_R	
		ret
// ==================================================================== //
// EPX_FIFO_WR_addr_set & EPX_FIFO_WR_addr_set				//
// will do this instruction => b0mov udp,a				//
// ==================================================================== //

EP0_FIFO_WR_addr_set:
EP1_FIFO_WR_addr_set:
EP2_FIFO_WR_addr_set:
EP3_FIFO_WR_addr_set:
		b0mov	UDP0,a
		ret

EP0_FIFO_WR_addr_add:
		add	UDP0,a
		ret

// ==================================================================== //
// EPX_FIFO_WR_data 							//
// will do this instruction => b0mov UDRx, a 				//
// ==================================================================== //

EP0_FIFO_WR_data:
EP1_FIFO_WR_data:
EP2_FIFO_WR_data:
EP3_FIFO_WR_data:
		b0mov	UDR0_W,a							
		ret



// ==================================================================== //
// 			Get status					//
// ==================================================================== //
get_status:
		b0mov	a, bmRequestType
		and	a, #USB_RECIPIENT
		cmprs	a, #USB_RECIPIENT_DEVICE
		jmp	$+2
		jmp	get_status_DEVICE
		cmprs	a, #USB_RECIPIENT_INTERFACE
		jmp	$+2
		jmp	get_status_INTERFACE
		cmprs	a, #USB_RECIPIENT_ENDPOINT
		jmp	$+2
		jmp	get_status_ENDPOINT
		jmp	stall_ep0

get_status_DEVICE:	// USB_RECIPIENT_DEVICE
		mov	a,#0x0
		CALL	EP0_FIFO_WR_addr_set		
		mov	a,#DEVICE_STATUS	;check usb_setting
		b0bts1	bRemote_Wakeup
		AND	a,#0xFD			;force no remote wakeup
		CALL	EP0_FIFO_WR_data
		mov	a, #0x01
		CALL	EP0_FIFO_WR_addr_add
		mov	a,#0x0
		CALL	EP0_FIFO_WR_data
		mov	a, #0x22
		b0mov	UE0R, a	
		jmp	control_handler_90

get_status_INTERFACE:	// USB_RECIPIENT_INTERFACE
		b0bts1	bSetAddress
		jmp	stall_ep0
		mov	a,#0x0
		cmprs	a, wIndex_L
		jmp	stall_ep0
		mov	a,#0x0
		CALL	EP0_FIFO_WR_addr_set
		CALL	EP0_FIFO_WR_data
		mov	a,#0x1
		CALL	EP0_FIFO_WR_addr_add
		mov	a,#0x0
		CALL	EP0_FIFO_WR_data
		mov	a, #0x22
		b0mov	UE0R, a	
		jmp	control_handler_90

get_status_ENDPOINT:	// USB_RECIPIENT_ENDPOINT
		mov	a,#0x0
		CALL	EP0_FIFO_WR_addr_set
		b0mov	a, wIndex_L
		and	a, #0x03
		add	PCL, a	
		jmp	get_status_ep0		; ep0
		jmp	get_status_ep1		; ep1
		jmp	stall_ep0		
		jmp	stall_ep0

get_status_ep0:
		b0mov	a, Halt0
		jmp	get_status_next

get_status_ep1:
		b0bts1	bSetAddress
		jmp	stall_ep0
		b0mov	a, Halt1
		jmp	get_status_next
		
get_status_next:
		CALL	EP0_FIFO_WR_data
		mov	a,#0x01
		CALL	EP0_FIFO_WR_addr_add
		mov	a,#0x0
		CALL	EP0_FIFO_WR_data
		mov	a, #0x22
		b0mov	UE0R, a		
		jmp	control_handler_90

// ==================================================================== //
// 			Clear Feature	(not support for interface)				//
// ==================================================================== //
clear_feature:						
		b0mov	a, bmRequestType
		and	a, #USB_RECIPIENT
		cmprs	a, #USB_RECIPIENT_DEVICE
		jmp	$+2
		jmp	clear_feature_DEVICE
		cmprs	a, #USB_RECIPIENT_ENDPOINT
		jmp	$+2
		jmp	clear_feature_ENDPOINT
		jmp	stall_ep0

clear_feature_DEVICE:
		b0bts1	bSetAddress
		jmp	stall_ep0
		b0mov	a, wValue_L
		cmprs	a, #USB_FEATURE_REMOTE_WAKEUP
		jmp	stall_ep0
		b0bclr	bRemote_Wakeup
		mov	a, #0x0
		CALL	EP0_FIFO_RD_addr_set
		CALL	EP0_FIFO_WR_data
		mov	a, #0x20
		mov	UE0R,a
		jmp	control_handler_90

clear_feature_ENDPOINT:
		b0mov	a, wValue_L
		cmprs	a, #USB_FEATURE_ENDPOINT_STALL
		jmp	stall_ep0
		; change the endpoint status
		b0mov	a, wIndex_L
		and	a, #0x03
		add	PCL, a	
		jmp	clear_feature_ep0		; ep0
		jmp	clear_feature_ep1		; ep1
		jmp	stall_ep0		
		jmp	stall_ep0

clear_feature_ep0:
		clr	Halt0
		jmp	clear_feature_next

clear_feature_ep1:
		b0bts1	bSetAddress
		jmp	stall_ep0
		clr	Halt1
		jmp	clear_feature_next

clear_feature_next:
		mov	a, #0x20
		mov	UE0R,a
		jmp	control_handler_90

// ==================================================================== //
// 			Set Feature (not support for interface)				//
// ==================================================================== //
set_feature:			
		b0mov	a, bmRequestType
		and	a, #USB_RECIPIENT
		cmprs	a, #USB_RECIPIENT_DEVICE
		jmp	$+2
		jmp	set_feature_DEVICE
		cmprs	a, #USB_RECIPIENT_ENDPOINT
		jmp	$+2
		jmp	set_feature_ENDPOINT
		jmp	stall_ep0

set_feature_DEVICE:
		b0mov	a, wValue_L
		cmprs	a, #USB_FEATURE_REMOTE_WAKEUP
		jmp	stall_ep0
		b0bset	bRemote_Wakeup
		mov	a, #0x0
		CALL	EP0_FIFO_RD_addr_set
		CALL	EP0_FIFO_WR_data
		mov	a, #0x20
		mov	UE0R,a
		jmp	control_handler_90

set_feature_ENDPOINT:
		b0mov	a, wValue_L
		cmprs	a, #USB_FEATURE_ENDPOINT_STALL
		jmp	stall_ep0
		b0mov	a, wIndex_L
		and	a, #0x03
		add	PCL, a	
		jmp	set_feature_ep0		; ep0
		jmp	set_feature_ep1		; ep1
		jmp	stall_ep0
		jmp	stall_ep0

set_feature_ep0:
		mov	a,#0x01
		b0mov	Halt0,a
		jmp	set_feature_next

set_feature_ep1:
		b0bts1	bSetAddress
		jmp	stall_ep0
		mov	a,#0x01
		b0mov	Halt1,a
		jmp	set_feature_next

set_feature_next:		
		mov	a, #0x20
		mov	UE0R,a
		jmp	control_handler_90

// ==================================================================== //
// 			Set Address					//
// ==================================================================== //
;************************************************************************
;NOTE!! Don't set the address in this function call, it must waits the
;	IN token, then the device will set the NEW address.
;************************************************************************
Set_Address:
		b0bset	bSetAddress
		b0mov	a, wValue_L
		b0mov	bdevice_address, a
		mov	a,#0x20
		b0mov	UE0R,a
		jmp	control_handler_90

// ==================================================================== //
// 			Get Descriptor					//
// ==================================================================== //
get_descriptor:	//device descriptor
		b0bclr	USB_Status.5		
		b0mov	a, wValue_H
		cmprs	a, #USB_DEVICE_DESCRIPTOR_TYPE
		jmp	get_descriptor_10
		mov	a,#DeviceDescr_length
		b0mov	table_length[0],a
		mov	a,#DeviceDescr_length_H
		b0mov	table_length[1],a
		mov	a, #DeviceDescr$L
		b0mov	table_index[0],a
		mov	a, #DeviceDescr$M
		b0mov	table_index[1],a
		call	table_transmit
		jmp	get_descriptor_90
	
get_descriptor_10: //configuration descriptor
		b0bclr	USB_Status.5		
		cmprs	a, #USB_CONFIGURATION_DESCRIPTOR_TYPE
		jmp	get_descriptor_20
		mov	a,#config_all_descr_length
		b0mov	table_length[0],a
		mov	a,#config_all_descr_length_H
		b0mov	table_length[1],a
		mov	a, #ConfigDescr$L
		b0mov	table_index[0],a
		mov	a, #ConfigDescr$M
		b0mov	table_index[1],a		
		call	table_transmit
		jmp	get_descriptor_90

get_descriptor_20: //string descriptor
		b0bset	USB_Status.5
		cmprs	a, #USB_STRING_DESCRIPTOR_TYPE
		jmp	get_descriptor_30
		nop
		mov	a, #00000111b
		and	a, wValue_L	
		b0add	PCL, a
		jmp	get_string_Language
		jmp	get_string_Manufacturer
		jmp	get_string_Product
		jmp	get_string_Serialnumber
		jmp	get_string_Configuration
		jmp	get_string_Interface
		jmp	stall_ep0
		jmp	stall_ep0
		jmp	stall_ep0

get_string_Language:
		mov	a,#ilanguageString_len
		b0mov	table_length[0],a
		mov	a,#ilanguageString_len_H
		b0mov	table_length[1],a
		mov	a, #ilanguageString$L
		b0mov	table_index[0],a
		mov	a, #ilanguageString$M
		b0mov	table_index[1],a
		call	table_transmit
		jmp	get_descriptor_90

get_string_Manufacturer:
		mov	a,#imanufacturerString_len
		b0mov	table_length[0],a
		mov	a,#imanufacturerString_len_H
		b0mov	table_length[1],a
		mov	a, #imanufacturerString$L
		b0mov	table_index[0],a

⌨️ 快捷键说明

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