📄 3100_2interface.asm
字号:
movwf InOutBuffer5
movfw Rc0Fifo6
movwf InOutBuffer6
movfw Rc0Fifo7
movwf InOutBuffer7
call NoDataControl
call DataOutTask
call CommandTask
ret
NoDataControlWrite:
call NoDataControl
ret
Rc0TaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:CommandTask
;==============================================================================
CommandTask:
btfss CommandOutFlag
ret
bcf CommandOutFlag
movlw 55h
subwf InOutBuffer0,W
btfss Zero
ret
movlw 53h
subwf InOutBuffer1,W
btfss Zero
ret
movlw 42h
subwf InOutBuffer2,W
btfss Zero
ret
movlw 43h
subwf InOutBuffer3,W
btfss Zero
ret
movfw InOutBuffer5
movwf ReportDataLength
InputValueTest:
movlw InputValue
subwf InOutBuffer6,W
btfss Zero
goto OutputValueTest
bsf DataInFlag
ret
OutputValueTest:
movlw OutputValue
subwf InOutBuffer6,W
btfss Zero
ret
bsf DataOutFlag
ret
;==============================================================================
;Function:DataOutTask
;==============================================================================
DataOutTask:
btfss DataOutFlag
ret
GetData:
movlw 00h
movwf AnyCountTemp
testz ReportDataLength
btfss Zero
goto SaveOutData
bcf DataOutFlag
ret
SaveOutData:
movlw InOutBuffer
movwf Fsr
movfw AnyCountTemp
addwf Fsr,F
movfw Indf
movwf UsbDataTemp
movlw DataBuffer
movwf Fsr
decf ReportDataLength,W
movwf ReportDataLength
addwf Fsr,F
movfw UsbDataTemp
movwf Indf
incf AnyCountTemp,F
movlw 08h
subwf AnyCountTemp,W
btfss Zero
goto SaveOutData
ret
;==============================================================================
;Function:HidSetRequestTask(21,09)(21,0a)(21,0b)
; There are three Hid reports to be set:
; 1.Set Report is used to control the LEDs in the keyboard. An OUT packet
; will be received that will have a bit set for every LED that should be
; turned on.
; 2.Set Idle silences a particular report on the interrupt pipe until a new
; event occurs or the specified amount of time (wValueHi) passes.
; The resolution of the specified duration is 4ms (i.e the weight of the
; LSB is 4ms)
; 3.Set Protocol switches between the boot protocol and the report protocol.
; For boot protocol, wValue=0. For report protocol, wValue=1.
;==============================================================================
HidSetRequestTask:
movlw SetReport
subwf BRequest,W
btfsc Zero
goto HidSetReport
movlw SetIdle
subwf BRequest,W
btfsc Zero
goto HidSetIdle
movlw SetProtocol
subwf BRequest,W
btfss Zero
goto HidSetRequestTaskError
HidSetProtocol:
movfw WValue
movwf HidProtocolStatus
goto HidSetRequestTaskSend
HidSetIdle:
movfw WValueHi
movwf IdlePeriodStatus
movwf IdlePeriodTemp
goto HidSetRequestTaskSend
HidSetReport:
testz ConfigurationStatus ;ConfigurationStatus = UnConfig ?
btfsc Zero
goto HidSetRequestTaskError
CheckInterface2:
movlw Interface2
subwf WIndex,W
btfss Zero
goto CheckInterface1
bsf CommandOutFlag
goto HidSetRequestTaskSend
CheckInterface1:
movlw Interface1
subwf WIndex,W
btfss Zero
goto HidSetRequestTaskError
bsf DataOutFlag
HidSetRequestTaskSend:
call NoDataControl
ret
HidSetRequestTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:SetAddressTask(00,05)
; Set the device address to the wValue in the SETUP packet at
; the completion of the current transaction.
;==============================================================================
SetAddressTask:
bsf NewAdrFlag
call NoDataControl
ret
;==============================================================================
;Function:SetConfigurationTask(00,09)
; Set the configuration of the device to either unconfigured (0) or
; configured (1) based on wValue in the SETUP packet. According to
; the USB spec (page 178), a Set Configuration also clears the endpoint
; stall condition and re-initializes endpoints using data 0/1 toggle to
; Data0.
;==============================================================================
SetConfigurationTask:
testz BmRequestType ;BmRequestType = HostToDevice ?
btfss Zero
goto SetConfigurationTaskError
SetConfigurationType:
testz WValue ;WValue = Config ?
btfss Zero
goto ConfigType
UnConfigType:
movfw WValue
movwf ConfigurationStatus
movlw cch
movwr IntEn0
bcf Ep1Cfg
bcf Ep2Cfg
call NoDataControl
ret
ConfigType:
movfw WValue
movwf ConfigurationStatus
movlw DefaultIdlePeriod
movwf IdlePeriodStatus
movwf IdlePeriodTemp
movlw ech ;Only enable EP1
movwr IntEn0
bsf Ep1Cfg
; bsf Ep2Cfg
bsf Tx1Tgl
; bsf Tx2Tgl
bsf StartScanFlag
call NoDataControl
ret
SetConfigurationTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:GetDescriptorTask(80,06)(81,06)(82,06)
; There are five descriptor types. The descriptor type will be in
; the high byte of wValue. The descriptor index will be in the low
; byte of wValue. The standard request to a device supports three
; of these types: device, configuration, and string. The standard
; request does not support interface or endpoint descriptor types.
; But keyboard is a HID device, so we have to support HID class and
; HID report two types.
;==============================================================================
GetDescriptorTask:
movlw DeviceToHost
subwf BmRequestType,W
btfsc Zero
goto GetDescriptorType
movlw InterfaceToHost
subwf BmRequestType,W
btfsc Zero
goto GetDescriptorType
movlw EndpointToHost
subwf BmRequestType,W
btfss Zero
goto GetDescriptorTaskError
GetDescriptorType:
movlw Device
subwf WValueHi,W
btfsc Zero
goto DeviceType
movlw Configuration
subwf WValueHi,W
btfsc Zero
goto ConfigurationType
movlw String
subwf WValueHi,W
btfsc Zero
goto StringType
movlw HidClass
subwf WValueHi,W
btfsc Zero
goto HidClassType
movlw HidReport
subwf WValueHi,W
btfsc Zero
goto HidReportType
goto GetDescriptorTaskError
DeviceType:
clrf TableCnt
movlw DeviceLen
movwf DataLength
goto GetDescriptorTaskSend
ConfigurationType:
movlw ConfigIndex
movwf TableCnt
movlw ConfigLen
movwf DataLength
goto GetDescriptorTaskSend
StringType:
movlw String0
subwf WValue,W
btfsc Zero
goto SendString0
movlw String2
subwf WValue,W
btfsc Zero
goto SendString2
goto GetDescriptorTaskError
SendString0:
movlw Strind0Index
movwf TableCnt
movlw String0Len
movwf DataLength
goto GetDescriptorTaskSend
SendString2:
movlw Strind2Index
movwf TableCnt
movlw String2Len
movwf DataLength
goto GetDescriptorTaskSend
HidClassType:
movlw HidClass1Index
movwf TableCnt
movlw HidClass1Len
movwf DataLength
goto GetDescriptorTaskSend
HidReportType:
movlw Report1
subwf WIndex,W
btfsc Zero
goto SendReport1
movlw Report2
subwf WIndex,W
btfsc Zero
goto SendReport2
goto GetDescriptorTaskError
SendReport1:
clrf TableCnt
movlw HidReport1Len
movwf DataLength
bsf TableSelBit
goto GetDescriptorTaskSend
SendReport2:
movlw HidReport2Index
movwf TableCnt
movlw HidReport2Len
movwf DataLength
bsf TableSelBit
GetDescriptorTaskSend:
call CheckLength
call Tx0Transfer
ret
GetDescriptorTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:GetConfigurationTask(80,08)
; Return the current device configuration to the host. The possible
; values are zero (unconfigured) and one (configured).
;==============================================================================
GetConfigurationTask:
movlw DeviceToHost
subwf BmRequestType,W
btfss Zero
goto GetConfigurationTaskError
GetConfiguration:
movfw ConfigurationStatus
movwr Tx0Fifo0
movlw c1h
movwf Tx0Reg
bsf Rc0Rdy
ret
GetConfigurationTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:ClearFeatureTask(00,01)(02,01)
; There are two kinds of situation to be clear:
; 1.These routines allow the host to disable the ability to request
; remote wakeup.
; 2.Clear the endpoint stall feature for the selected endpoint. This
; should also set the data 0/1 bit to Data0 if endpoint one is selected.
;==============================================================================
ClearFeatureTask:
movlw HostToDevice
subwf BmRequestType,W
btfsc Zero
goto ClearRemoteWakeup
movlw HostToEndpoint
subwf BmRequestType,W
btfss Zero
goto ClearFeatureTaskError
ClearEndpointStall:
testz ConfigurationStatus ;ConfigurationStatus = Config ?
btfsc Zero
goto ClearFeatureTaskError
CheckClrEndpointStall:
movlw Endpoint1
subwf WIndex,W
btfsc Zero
goto ClrEp1Stall
movlw Endpoint2
subwf WIndex,W
btfss Zero
goto ClearFeatureTaskError
ClrEp2Stall:
clrf Endpoint2Status
bcf Ep2Stall
goto ClearFeatureTaskSend
ClrEp1Stall:
clrf Endpoint1Status
bcf Ep1Stall
goto ClearFeatureTaskSend
ClearRemoteWakeup:
movlw Device
subwf WValue,W ;This byte must be 01h
btfss Zero
goto ClearFeatureTaskError
movlw DisableRemoteWakeup
movwf RemoteWakeupStatus
ClearFeatureTaskSend:
call NoDataControl
ret
ClearFeatureTaskError:
bsf Ep0Stall
ret
;==============================================================================
;Function:SetFeatureTask(00,03)(02,03)
; There are two kinds of situation to be set:
; 1.These routines allow the host to enable the ability to request
; remote wakeup.
; 2.Set the endpoint stall feature for the selected endpoint.
;==============================================================================
SetFeatureTask:
movlw HostToDevice
subwf BmRequestType,W
btfsc Zero
goto SetRemoteWakeup
movlw HostToEndpoint
subwf BmRequestType,W
btfss Zero
goto SetFeatureTaskError
SetEndpointStall:
testz ConfigurationStatus ;ConfigurationStatus = Config ?
btfsc Zero
goto SetFeatureTaskError
CheckSetEndpointStall:
movlw Endpoint1
subwf WIndex,W
btfsc Zero
goto SetEp1Stall
movlw Endpoint2
subwf WIndex,W
btfss Zero
goto SetFeatureTaskError
SetEp2Stall:
movlw StallValue
movwf Endpoint2Status
bsf Ep2Stall
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 ClearFeatureTaskError
movlw EnableRemoteWakeup
movwf RemoteWakeupStatus
SetFeatureTaskSend:
call NoDataControl
ret
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
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -