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

📄 3100_2interface.asm

📁 3100 Tenx MCU Firmware
💻 ASM
📖 第 1 页 / 共 4 页
字号:
  		btfss	Zero
		goto	GetStatusTaskError
		
  GetEndpointStatus:
  		movlw	Endpoint0
  		subwf	WIndex,W
  		btfsc	Zero
  		goto	GetEp0Status
  		
  		testz	ConfigurationStatus		;ConfigurationStatus = Config ?
  		btfsc	Zero
  		goto	GetStatusTaskError
  		
  		movlw	Endpoint1
  		subwf	WIndex,W
  		btfsc	Zero
  		goto	GetEp1Status
  		
  		movlw	Endpoint2
  		subwf	WIndex,W
  		btfss	Zero
  		goto	GetStatusTaskError
  		
  	GetEp2Status:
  		movfw	Endpoint2Status  		
  		movwr	Tx0Fifo0
  		movlw	00h
  		movwr	Tx0Fifo1
  		goto	GetStatusTaskSend
  	
  	GetEp1Status:
  		movfw	Endpoint1Status		
  		movwr	Tx0Fifo0
  		movlw	00h
  		movwr	Tx0Fifo1
  		goto	GetStatusTaskSend
  		
  	GetEp0Status:
  		movlw	00h
  		movwr	Tx0Fifo0
  		movwr	Tx0Fifo1
  		goto	GetStatusTaskSend
  
  GetDeviceStatus:
  		movfw	RemoteWakeupStatus
  		movwr	Tx0Fifo0
  		movlw	00h
  		movwr	Tx0Fifo1
  		goto	GetStatusTaskSend
  
  GetInterfaceStatus:
  		movlw	00h
  		movwr	Tx0Fifo0
  		movwr	Tx0Fifo1
 
GetStatusTaskSend:
  		movlw	c2h
  		movwf	Tx0Reg
  		bsf	Rc0Rdy
		ret
	
GetStatusTaskError:
		bsf	Ep0Stall
		ret
		
;==============================================================================
;Function:GetInterfaceTask(81,0a)
;   The interface status is an 8-bits value that is always zero since
;   there are no alternate interface settings defined
;==============================================================================

GetInterfaceTask:
		movlw	InterfaceToHost
		subwf	BmRequestType,W
  		btfss	Zero
  		goto	GetInterfaceTaskError
  		
   GetInterface:
   		movlw	00h
   		movwr	Tx0Fifo0
   		movlw	c1h
  		movwf	Tx0Reg
  		bsf	Rc0Rdy	 
		ret
  		
GetInterfaceTaskError:
		bsf	Ep0Stall
		ret

;==============================================================================
;Function:SetInterfaceTask(01,0b)
;   Host may attempt to set the interface to an alternate setting. We do not
;   support any alternate setting, but if the alternate setting number is 0
;   then we should not stall that request.
;==============================================================================

SetInterfaceTask:
		movlw	HostToInterface
		subwf	BmRequestType,W
  		btfss	Zero
  		goto	SetInterfaceTaskError
  		
   SetInterface:
		movfw	WValue
		iorwf	WValueHi,W
		btfss	Zero
   		goto	SetInterfaceTaskError
   		bcf	Tx1Tgl
   		bcf	Tx2Tgl
		call	NoDataControl	
		ret
  		
SetInterfaceTaskError:
		bsf	Ep0Stall
		ret

;==============================================================================
;Function:HidGetRequestTask(a1,01)(a1,02)(a1,03)
;   There are three kinds of Hid request to get:
;   1.Get Report returns a report over the control pipe
;   2.Get Protocol sends the current protocol status back to the host.
;   3.Get Idle reads the current idle rate for a particular input report.
;==============================================================================

HidGetRequestTask:
		movlw	GetReport
		subwf	BRequest,W
  		btfsc	Zero
		goto	HidGetReport

		movlw	GetIdle
		subwf	BRequest,W
  		btfsc	Zero
		goto	HidGetIdle

		movlw	GetProtocol
		subwf	BRequest,W
  		btfss	Zero
		goto	HidGetRequestTaskError
  
  HidGetProtocol:
  		movlw	Interface1
  		subwf	WIndex,W
  		btfsc	Zero
  		goto	GetProtocolSend
  		
  		movlw	Interface2
  		subwf	WIndex,W
  		btfss	Zero
  		goto	HidGetRequestTaskError
  		
    GetProtocolSend:	
  		movfw	HidProtocolStatus
  		movwr	Tx0Fifo0
  		goto	HidGetRequestTaskSend
  
  HidGetIdle:
		movfw	IdlePeriodStatus
  		movwr	Tx0Fifo0

HidGetRequestTaskSend:
		movlw	c1h
  		movwf	Tx0Reg
  		bsf	Rc0Rdy	
		ret
	
  HidGetReport:
  		testz	ConfigurationStatus		;ConfigurationStatus = Config ?
  		btfsc	Zero
  		goto	HidGetRequestTaskError
  		
  		movlw	Interface1
  		subwf	WIndex,W
  		btfss	Zero
  		goto	HidGetRequestTaskError
  	
    GetInterface1Report:
 
      SendID0Report:
      		movlw	00h
      		movwr	Tx0Fifo0
      		movwr	Tx0Fifo1
      		movwr	Tx0Fifo2
      		movwr	Tx0Fifo3
      		movwr	Tx0Fifo4
      		movwr	Tx0Fifo5
      		movwr	Tx0Fifo6
      		movwr	Tx0Fifo7
		movlw	c8h
  		movwf	Tx0Reg
  		bsf	Rc0Rdy	
		ret
		
HidGetRequestTaskError:
		bsf	Ep0Stall	
		ret


;==============================================================================
;Function:DataInTask
;==============================================================================

DataInTask:	
		btfss	DataInFlag
		ret
		
		btfsc	Tx1Rdy       
		ret                  

  SendData:
  		clrf	AnyCountTemp
  		
  		testz	UsbCountTemp
     		movlw	10h
  		btfsc	Zero
  		movwf	UsbCountTemp	
  						
  		testz	ReportDataLength
  		btfss	Zero
  		goto	SaveInData
  		bcf	DataInFlag
  		ret
  			 				
     SaveInData:  
  		movlw	DataBuffer
  		movwf	Fsr
  		decf	UsbCountTemp,W
  		movwf	UsbCountTemp
  		addwf	Fsr,F
  		movfw	Indf
  		movwf	UsbDataTemp
  		
  		movlw	InOutBuffer
     		movwf	Fsr
     		movfw	AnyCountTemp
     		addwf	Fsr,F
     		movfw	UsbDataTemp
     		movwf	Indf
     		
      		decfsz	ReportDataLength,F
     		btfsc	Zero
     		goto	DataInTaskEnd
     		
  		incf	AnyCountTemp,F
  		movlw	08h
  		subwf	AnyCountTemp,W
  		btfss	Zero
  		goto	SaveInData
  		
 		movlw	UsbReport
		movwf	UsbRequireState
		ret

DataInTaskEnd: 
		clrf	UsbCountTemp
		bcf	DataInFlag	
		movlw	UsbReport
		movwf	UsbRequireState
		ret


;==============================================================================
;Function:ReportTask
;==============================================================================

ReportTask:		
		movlw	UsbReport
		subwf	UsbRequireState,W
		btfss	Zero
		ret
		 
  		btfsc	Tx1Rdy       
		ret                  

		movfw	InOutBuffer0
 		movwr	Tx1Fifo0
  		movfw	InOutBuffer1
  		movwr	Tx1Fifo1
  		movfw	InOutBuffer2
  		movwr	Tx1Fifo2
  		movfw	InOutBuffer3
  		movwr	Tx1Fifo3
  		movfw	InOutBuffer4
  		movwr	Tx1Fifo4
  		movfw	InOutBuffer5
  		movwr	Tx1Fifo5
  		movfw	InOutBuffer6
  		movwr	Tx1Fifo6
  		movfw	InOutBuffer7
  		movwr	Tx1Fifo7
	
		movlw	08h
		iorwf	Tx1Reg,F		
		movlw	40h
		xorwf	Tx1Reg,F
		bsf	Tx1Rdy

		movlw	UsbNoReport
		movwf	UsbRequireState		
		ret		
		
;========================================================================
;  This is the Tenx keyboard descriptor table file
;========================================================================

;========================================================================
		org	0e00h
;========================================================================

.TABLE

DeviceInfoTable:
		addwf	Pc,F
		
  DeviceDescTable:		
		retlw	12h     	; Size Of Descriptor (18 Bytes)
		retlw	01h     	; Descriptor Type (Device Descriptor)
		retlw   10h		; Usb Spec Release (Ver 1.1)
		retlw	01h 		
		retlw   00h     	; Class Code (Each Interface Specifies Class Information)
		retlw	00h     	; Device Sub-Class (Must Be Set To 0 Because Class code is 0)
		retlw	00h     	; Device Protocol (No Class Specific Protocol)
		retlw   08h     	; Maximum Packet Size (8 Bytes)
		retlw   30h     	; vendor ID (TENX vendor ID)
		retlw	11h     	
		retlw   02h     	; product ID (TENX for Non-Standard test product ID)
		retlw	02h     	
		retlw   00h     	; Device Release Number
		retlw	01h     	
		retlw   00h    		; Index Of Manufacturer String (Used string0)
		retlw   02h     	; Index Of Product String (Used string2)
		retlw   00h     	; Index Of Serial Number String (0=None)
		retlw   01h     	; Number Of Configurations (1)

  ConfigDescTable:
		retlw   09h     	; Length Of Descriptor (9 Bytes)
		retlw   02h     	; Descriptor Type (Configuration)
		retlw   ConfigLen  	; Total Length Of Descriptor (59 Bytes)
		retlw	00h
		retlw   02h     	; Number Of Interfaces To Configure (2)
		retlw   01h     	; Configuration Value (1)
		retlw   00h     	; Configuration String Index
		retlw   80h     	; Configuration Attributes (Bus Powered, Remote Wakeup)
		retlw   32h     	; Maximum Power (100Ma)

  Interface1DescTable: 			; Descriptor For Interface 1 (Hid Keyboard)
		retlw   09h     	; Length Of Descriptor (9 Bytes)
		retlw   04h     	; Descriptor Type (Interface)
		retlw   00h     	; Interface Number (1) Zero-Base
		retlw   00h     	; Alternate Setting (0)
		retlw   01h     	; Number Of Endpoints (1) In each Interface
		retlw   03h     	; Interface Class (3..For HID Interface class)
		retlw   00h     	; Interface Sub-Class 
		retlw   00h     	; Interface Protocol 
		retlw   00h     	; Interface String Index 

  Class1DescTable:			; HID Interfacs class descriptor
		retlw   09h     	; Descriptor Size (9 Bytes)
		retlw	21h     	; Descriptor Type (Hid)
		retlw   10h     	; Class Specification (1.10)
		retlw	01h     	
		retlw   00h     	; Hardware Target Country (Normal is 0)
		retlw   01h     	; Number Of Hid Class Descriptors To Follow (1)
		retlw   22h     	; Report Descriptor Type 
		retlw  	HidReport1Len	; Report Descriptors 65 Bytes
		retlw   00h
		
  Endpoint1DescTable:			; Endpoint descriptor of each interface
		retlw   07h     	; Descriptor Length (7 Bytes)
		retlw   05h     	; Descriptor Type (Endpoint)
		retlw   81h     	; Endpoint Address (In Endpoint, Endpoint 1)
		retlw   03h     	; Endpoint Attributes (Interrupt Type)
		retlw   08h     	; Maximum Packet Size (8 Bytes)
		retlw	00h     	
		retlw   0ah     	; Polling Interval (10Ms)

  Interface2DescTable:  		; descriptor for interface 2 (HID keyboard)
		retlw   09h     	; length of descriptor (9 bytes)
		retlw   04h     	; descriptor type (INTERFACE)
		retlw   01h     	; interface number (2)
		retlw   00h     	; alternate setting (0)
		retlw   01h     	; number of endpoints (1)
		retlw   03h     	; interface class (3..defined by USB spec)
		retlw   00h     	; interface sub-class (1..defined by USB spec)
		retlw   00h     	; interface protocol (2..defined by USB spec)
		retlw   00h     	; interface string index 

  Class2DescTable:
		retlw   09h     	; descriptor size (9 bytes)
		retlw	21h     	; descriptor type (HID)
		retlw   10h     	; class specification (1.10)
		retlw	01h     	
		retlw   21h     	; hardware target country
		retlw   01h     	; number of hid class descriptors to follow (1)
		retlw   22h     	; report descriptor type (2)
		retlw  	HidReport2Len	; Report descriptors 115 bytes
		retlw   00h

  Endpoint2DescTable:
		retlw   07h     	; descriptor length (7 bytes)
		retlw   05h     	; descriptor type (ENDPOINT)
		retlw   82h     	; endpoint address (IN endpoint, endpoint 2)
		retlw   03h     	; endpoint attributes (interrupt)
		retlw   08h     	; maximum packet size (8 bytes)
		retlw	00h     	
		retlw   0ah     	; polling interval (10ms)

  String0Table:
		retlw	04h		;4 bytes
		retlw	03h
		retlw	09h
		retlw	04h	
		
  String2Table:	
  		retlw	46d
  		retlw	03h
  		retlw	'T'		
		retlw	00h
		retlw	'e'
		retlw	00h
		retlw	'n'
		retlw	00h
		
		retlw	'x'
		retlw	00h
		retlw	20h
		retlw	00h
		retlw	'N'		
		retlw	00h
		retlw	'o'
		retlw	00h
		
		retlw	'n'
		retlw	00h
		retlw	's'
		retlw	00h		
		retlw	't'
		retlw	00h	
		retlw	'a'
		retlw	00h
		
		retlw	'n'
		retlw	00h	
		retlw   'd'
		retlw	00h		
		retlw	'a'
		retlw	00h	
		retlw	'r'
		retlw	00h
		
		retlw	'd'
		retlw	00h
		retlw	20h
		retlw	00h	
		retlw	'D'
		retlw	00h
		retlw	'e'
		retlw	00h
		
		retlw	'v'
		retlw	00h
		retlw	'i'
		retlw	00h
		retlw	'c'
		retlw	00h
		retlw	'e'
		retlw	00h
		
EndDeviceInfoTable

.ENDTABLE
		
;========================================================================
		org	0f00h
;========================================================================

.TABLE

DeviceReportTable:
		addwf	Pc,F
		
  Report1DescTable:		
		retlw   05h	
		retlw	01h				
		retlw   09h	
		retlw	00h	
		retlw   a1h	
		retlw	01h
		
		retlw   95h	
		retlw	08h
		retlw   75h	
		retlw	08h 	
		retlw   15h	
		retlw	00h 
		retlw   26h	
		retlw	ffh
		retlw   00h	
		retlw	05h
		retlw   07h	
		retlw	19h		
		retlw   00h	
		retlw	2ah
		retlw   ffh	
		retlw	00h
		retlw   81h	
		retlw	00h 
		
		retlw   15h	
		retlw	00h	
		retlw   25h	
		retlw	01h
		retlw   95h	
		retlw	80h
		retlw   75h	
		retlw	01h	
		retlw   05h	
		retlw	08h 		
		retlw   19h	
		retlw	01h 
		retlw   29h	
		retlw	80h
		retlw   91h	
		retlw	02h
		retlw   C0h		
					
  Report2DescTable:
  		retlw   05h	
		retlw	01h				
		retlw   09h	
		retlw	03h	
		retlw   a1h	
		retlw	01h

		retlw   15h	
		retlw	00h	
		retlw   25h	
		retlw	01h
		retlw   95h	
		retlw	40h
		retlw   75h	
		retlw	01h	
		retlw   05h	
		retlw	08h 		
		retlw   19h	
		retlw	01h 
		retlw   29h	
		retlw	40h
		retlw   91h	
		retlw	02h
		retlw   C0h

EndDeviceReportTable

.ENDTABLE									

⌨️ 快捷键说明

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