📄 usb_id_key.asm
字号:
; goto SetFeatureTaskSend
SetEp1Stall:
movlw StallValue
movwf Endpoint1Status
bsf Ep1Stall
goto SetFeatureTaskSend
SetRemoteWakeup:
movlw Device
subwf WValue,W ;This byte must be 01h
btfss Zero
goto SetRemoteWakeupError
movlw EnableRemoteWakeup
movwf RemoteWakeupStatus
SetFeatureTaskSend:
call NoDataControl
ret
SetRemoteWakeupError:
movlw DisableRemoteWakeup
movwf RemoteWakeupStatus
SetFeatureTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:GetStatusTask(80,00)(81,00)(82,00)
; There are three kinds of Status to get:
; 1.The device status is a 16-bits value (two bytes) with only D[1:0]
; defined. D0=0 specifies bus-powered, which never changes. D1
; reflects the status of the device_remote_wakeup feature. This
; feature can either be disabled (D1=0) or enabled (D1=1).
; 2.The interface status is a 16-bits value (two bytes) that is always
; zero for both bytes.
; 3.The endpoint status is a 16-bits value (two bytes) with only one
; bit (D0) defined. If D0=0, then the selected endpoint is not
; stalled. If D0=1, then the selected endpoint is stalled.
;==============================================================================
GetStatusTask:
movlw DeviceToHost
subwf BmRequestType,W
btfsc Zero
goto GetDeviceStatus
movlw InterfaceToHost
subwf BmRequestType,W
btfsc Zero
goto GetInterfaceStatus
movlw EndpointToHost
subwf BmRequestType,W
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
btfsc Zero
goto GetInterface1Report
movlw Interface2
subwf WIndex,W
btfss Zero
goto HidGetRequestTaskError
GetInterface2Report:
movlw ReportID2
subwf WValue,W
btfsc Zero
goto SendReportID2
movlw ReportID3
subwf WValue,W
btfss Zero
goto HidGetRequestTaskError
SendReportID3:
movlw 00h
movwr Tx0Fifo0
movwr Tx0Fifo1
movwr Tx0Fifo2
movwr Tx0Fifo3
movlw c4h
movwf Tx0Reg
; bsf Rc0Rdy
ret
SendReportID2:
movlw 00h
movwr Tx0Fifo0
movwr Tx0Fifo1
movlw c2h
movwf Tx0Reg
; bsf Rc0Rdy
ret
GetInterface1Report:
movlw KeyboardReport
subwf WValueHi,W
btfsc Zero
goto SendKeyboardReport
movlw LedReport
subwf WValueHi,W
btfss Zero
goto HidGetRequestTaskError
SendLedReport:
comf Led,W
call UsbLedTable2
movwr Tx0Fifo0
movlw c1h
movwf Tx0Reg
; bsf Rc0Rdy
ret
SendKeyboardReport:
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
UsbLedTable2:
addwf Pc,F
retlw 00h
retlw 01h
retlw 02h
retlw 03h
retlw 04h
retlw 05h
retlw 06h
retlw 07h
;==============================================================================
;Function:DebounceStart
;==============================================================================
DebounceStart:
movlw DebounceTimes
movwf AnyCountTemp
DebounceCheck:
movlw DebounceKeyBuffer
movwf Fsr
decf Fsr,F
movfw AnyCountTemp
addwf Fsr,F
movlw DebounceBufferEmpty
subwf Indf,W
btfsc Zero
goto DebounceCheckNext
movlw DebounceTimeBuffer
movwf Fsr
decf Fsr,F
movfw AnyCountTemp
addwf Fsr,F
decfsz Indf,F
goto DebounceCheckNext
movlw DebounceKeyBuffer ;Used PIC index to check key scan buffer
movwf Fsr
decf Fsr,F
movfw AnyCountTemp ;Set index shift value
addwf Fsr,F
movlw DebounceBufferEmpty
movwf Indf
DebounceCheckNext:
decfsz AnyCountTemp,F
goto DebounceCheck
ret
;==============================================================================
;Function:DebounceTest
; Test debounce buffer to see if matrix address is still in it.
; If not, exit with zero flag set
;==============================================================================
DebounceTest:
movlw DebounceTimes
movwf AnyCountTemp
DebounceLoop:
movlw DebounceKeyBuffer
movwf Fsr
decf Fsr,F
movfw AnyCountTemp
addwf Fsr,F
movfw Indf
subwf MatrixIndexTemp,W
btfsc Zero
ret
decfsz AnyCountTemp,F
goto DebounceLoop
bcf Zero
ret
;==============================================================================
;Function:NormalKeyTask
;==============================================================================
send_00:
bsf Pdd,0
bsf keyup_1
testz ConfigurationStatus ;ConfigurationStatus = Config ?
btfsc Zero
goto NoSendReportNow
btfsc keyup_0
goto send_0000
btfss host_send_data
goto NoSendReportNow
bsf keyup_0
send_0000:
btfsc usbshowled
goto send_000
bsf senddatm
movfw usbkeyled
movwf usbkeyled_0
movlw 00
subwf usbkeyled,0
btfsc Zero
goto scrolllock
movlw 01
subwf usbkeyled,0
btfsc Zero
goto capslock
movlw 02
subwf usbkeyled,0
btfsc Zero
goto numlock
movlw 03
subwf usbkeyled,0
btfsc Zero
goto send_000
movlw 04
subwf usbkeyled,0
btfsc Zero
goto scrolllock
movlw 05
subwf usbkeyled,0
btfsc Zero
; goto numlock
goto capslock
movlw 06
subwf usbkeyled,0
btfsc Zero
; goto capslock
goto numlock
movlw 07
subwf usbkeyled,0
btfsc Zero
goto send_000
capslock:
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movlw 53h
; movlw 39h
movwr Tx1Fifo2
movlw 00h
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
bsf usbshowled
goto SendReportNow
numlock:
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movlw 39h
; movlw 53h
movwr Tx1Fifo2
movlw 00h
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
bsf usbshowled
goto SendReportNow
scrolllock:
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movlw 53h
movwr Tx1Fifo2
movlw 39h
movwr Tx1Fifo3
movlw 00h
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
bsf usbshowled
goto SendReportNow
send_000:
btfsc usbdelaytime_0
goto send_000000
bsf usbdelaytime_0
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movwr Tx1Fifo2
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
goto SendReportNow
send_000000:
btfsc send_08_15
goto send_0000000
bsf send_08_15
movlw 08h
movwr Tx1Fifo0
movwr Tx1Fifo1
movlw 15h
movwr Tx1Fifo2
movlw 00h
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
goto SendReportNow
send_0000000:
btfsc send_08_15_0
goto send_00000000
bsf send_08_15_0
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movwr Tx1Fifo2
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
goto SendReportNow
send_00000000:
btfss usbdelaytime
call delay1s
bsf usbdelaytime
bsf senddatm
btfsc midshowled
goto renewusbled
bsf senddatm
movfw 33h
call send_data_to_host_0
movwr Tx1Fifo0
movlw 00h
movwr Tx1Fifo1
movfw 33h
call send_data_to_host_3
movwr Tx1Fifo2
movlw 00h
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
incf 33h,1
movlw 0B5h
; movlw fdh
subwf 33h,0
btfsc Zero
goto renewusbled
; goto SendReportNow
SendReportNow:
movlw 08h
iorwf Tx1Reg,F
movlw 40h
xorwf Tx1Reg,F
bsf Tx1Rdy
movlw UsbNoReport
movwf UsbRequireState
ret
SendReportNow_0:
bcf Pdd,0
bcf keyup_1
btfsc lastshowled_0
goto NoSendReportNow
bsf lastshowled_0
; bcf keyup_0
movlw 00h
movwr Tx1Fifo0
movwr Tx1Fifo1
movwr Tx1Fifo2
movwr Tx1Fifo3
movwr Tx1Fifo4
movwr Tx1Fifo5
movwr Tx1Fifo6
movwr Tx1Fifo7
movlw 08h
iorwf Tx1Reg,F
movlw 40h
xorwf Tx1Reg,F
bsf Tx1Rdy
movlw UsbNoReport
movwf UsbRequireState
ret
renewusbled:
CLRF 33h
bsf midshowled
btfsc lastshowled
goto SendReportNow_0
bsf lastshowled
movlw 00
subwf usbkeyled_0,0
btfsc Zero
goto scrolllock_0
movlw 01
subwf usbkeyled_0,0
btfsc Zero
goto capslock_0
movlw 02
subwf usbkeyled_0,0
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -