📄 usbhidio.lst
字号:
01C6 ;Stall unsupported requests.
01C6 ; jmp SendStall
01C6
01C6 ;Host to device with endpoint as recipient
01C6 RequestType02:
01C6 1A 71 [06] mov A, [bRequest] ; load bRequest
01C8
01C8 ; The only standard feature defined for an endpoint is endpoint_stalled.
01C8 ; Clear Feature bRequest = 1
01C8 16 01 [04] cmp A, clear_feature
01CA A2 7E [05] jz ClearEndpointStall
01CC ; Set Feature bRequest = 3
01CC 16 03 [04] cmp A, set_feature
01CE A2 97 [05] jz SetEndpointStall
01D0
01D0 ;Stall unsupported functions.
01D0 81 AD [05] jmp SendStall
01D2
01D2 ;Device to host with device as recipient
01D2 RequestType80:
01D2 1A 71 [06] mov A, [bRequest] ; load bRequest
01D4
01D4 ; Get Status bRequest = 0
01D4 16 00 [04] cmp A, get_status
01D6 A2 A8 [05] jz GetDeviceStatus
01D8
01D8 ; Get Descriptor bRequest = 6
01D8 16 06 [04] cmp A, get_descriptor
01DA A2 B2 [05] jz GetDescriptor
01DC
01DC ; Get Configuration bRequest = 8
01DC 16 08 [04] cmp A, get_configuration
01DE A2 CA [05] jz GetConfiguration
01E0
01E0 ;Stall unsupported requests.
01E0 81 AD [05] jmp SendStall
01E2
01E2 ;Device to host with interface as recipient
01E2 RequestType81:
01E2 1A 71 [06] mov A, [bRequest] ; load bRequest
01E4
01E4 ; Get Status bRequest = 0
01E4 16 00 [04] cmp A, get_status
01E6 A2 D4 [05] jz GetInterfaceStatus
01E8
01E8 ; Get Interface returns the selected alternate setting.
01E8 ; This firmware supports no alternate settings.
01E8 ; Get Interface bRequest = 10 *** not supported ***
01E8
01E8 ;The HID class defines one more request for bmRequestType=10000001
01E8 ; Get Descriptor bRequest = 6
01E8 16 06 [04] cmp A, get_descriptor
01EA A2 B2 [05] jz GetDescriptor
01EC
01EC ;Stall unsupported functions
01EC 81 AD [05] jmp SendStall
01EE
01EE ;Device to host with endpoint as recipient
01EE RequestType82:
01EE 1A 71 [06] mov A, [bRequest] ; load bRequest
01F0 ; Get Status bRequest = 0
01F0 16 00 [04] cmp A, get_status
01F2 A2 DC [05] jz GetEndpointStatus
01F4
01F4 ; Get Descriptor bRequest = 6
01F4 16 06 [04] cmp A, get_descriptor
01F6 A2 B2 [05] jz GetDescriptor
01F8 ; Sync Frame bRequest = 12 *** not supported ***
01F8
01F8 ;Stall unsupported functions.
01F8 81 AD [05] jmp SendStall
01FA
01FA
01FA ;Check for HID class requests
01FA
01FA ;Host to device with endpoint as recipient
01FA RequestType21:
01FA 1A 71 [06] mov A, [bRequest] ; load bRequest
01FC
01FC ; Set Report bRequest = 9
01FC 16 09 [04] cmp A, set_report
01FE 20 [04] NOP
01FF 1F [04] XPAGE
0200 A2 E7 [05] jz SetReport
0202
0202 ; Set Idle bRequest = 10
0202 16 0A [04] cmp A, set_idle
0204 A2 FA [05] jz SetIdle
0206
0206 ; Set Protocol bRequest = 11
0206 16 0B [04] cmp A, set_protocol
0208 A2 FC [05] jz SetProtocol
020A
020A ;Stall unsupported requests
020A 81 AD [05] jmp SendStall
020C
020C RequestType22:
020C 1A 71 [06] mov A, [bRequest] ; load bRequest
020E
020E ; Set Report bRequest = 9
020E 16 09 [04] cmp A, set_report
0210 A2 E7 [05] jz SetReport
0212
0212 ;Stall unsupported requests
0212 81 AD [05] jmp SendStall
0214
0214
0214 ;Device to host with endpoint as recipient
0214 RequestTypeA1:
0214 1A 71 [06] mov A, [bRequest] ; load bRequest
0216
0216 ; Get Report bRequest = 1
0216 16 01 [04] cmp A, get_report
0218 A3 05 [05] jz GetReport
021A
021A ; Get Idle bRequest = 2
021A 16 02 [04] cmp A, get_idle
021C A3 10 [05] jz GetIdle
021E
021E ; Get Protocol bRequest = 3
021E 16 03 [04] cmp A, get_protocol
0220 A3 12 [05] jz GetProtocol
0222
0222 ;Stall unsupported requests
0222 81 AD [05] jmp SendStall
0224
0224 ;----------------------------------------------------------------------
0224 ;Control transfer, stage three
0224 ;Process the request.
0224 ;----------------------------------------------------------------------
0224
0224 ;The host controls whether or not a device can request a remote wakeup.
0224
0224 ; Disable the remote wakeup capability.
0224 ClearRemoteWakeup:
0224 1A 72 [06] mov A, [wValue]
0226 16 01 [04] cmp A, device_remote_wakeup
0228 B1 AD [05] jnz SendStall
022A ;Handshake by sending a data packet
022A 93 79 [10] call Send0ByteDataPacket
022C 19 00 [04] mov A, DISABLE_REMOTE_WAKEUP
022E 31 30 [05] mov [remote_wakeup_status], A
0230 3F [08] ret
0231
0231 ; Enable the remote wakeup capability.
0231 SetRemoteWakeup:
0231 1A 72 [06] mov A, [wValue]
0233 16 01 [04] cmp A, device_remote_wakeup
0235 ;If not a match, stall.
0235 B1 AD [05] jnz SendStall
0237 ;Handshake by sending a 0-byte data packet
0237 93 79 [10] call Send0ByteDataPacket
0239 ;Perform the request.
0239 19 02 [04] mov A, ENABLE_REMOTE_WAKEUP
023B 31 30 [05] mov [remote_wakeup_status], A
023D 3F [08] ret
023E
023E SetAddress:
023E ; Set the device address to match wValue in the Setup packet.
023E ;Complete the requested action after completing the transaction.
023E ;Handshake by sending a 0-byte data packet.
023E 93 79 [10] call Send0ByteDataPacket
0240 ;Perform the request
0240 1A 72 [06] mov A, [wValue]
0242 2A 12 [05] iowr USB_Device_Address
0244 3F [08] ret
0245
0245 SetConfiguration:
0245 ;Unconfigured: wValue=0, configured: wValue=1.
0245 ;Also clear any stall condition and set Data 0/1 to Data0.
0245 ;Handshake by sending a 0-byte data packet.
0245 93 79 [10] call Send0ByteDataPacket
0247 ;Save the configuration status.
0247 1A 72 [06] mov A, [wValue]
0249 31 31 [05] mov [configuration_status], A
024B ;Clear any stall condtion
024B 19 00 [04] mov A, 0
024D 31 29 [05] mov [endpoint_stall], A
024F ;Set data 0/1 to Data0
024F 29 11 [05] iord USB_EP1_TX_Config
0251 10 BF [04] and A, ~DataToggle
0253
0253 ;Set the configuration status.
0253 2A 11 [05] iowr USB_EP1_TX_Config
0255 1A 31 [06] mov A, [configuration_status]
0257 16 00 [04] cmp A, 0
0259 ;If configured, jump.
0259 B2 69 [05] jnz device_configured
025B
025B ;If unconfigured:
025B ;Disable Endpoint 1
025B 29 11 [05] iord USB_EP1_TX_Config
025D 10 EF [04] and A, EFh
025F 2A 11 [05] iowr USB_EP1_TX_Config
0261 ;Disable Endpoint 1 interrupts.
0261 1A 20 [06] mov A, [interrupt_mask]
0263 10 EF [04] and A, EFh
0265 31 20 [05] mov [interrupt_mask], A
0267 82 7D [05] jmp done_configuration
0269
0269 ;If configured:
0269 device_configured:
0269 ;Send NAK in response to IN packets
0269 29 11 [05] iord USB_EP1_TX_Config
026B 10 7F [04] and A,7Fh
026D ;Enable Endpoint 1
026D 0D 10 [04] or A, 10h
026F 2A 11 [05] iowr USB_EP1_TX_Config
0271 ;Enable interrupts: Endpoint 1 and GPIO
0271 1A 20 [06] mov A, [interrupt_mask]
0273 0D 50 [04] or A, 50h
0275 31 20 [05] mov [interrupt_mask], A
0277 ;Send NAK in response to Endpoint 0 OUT packets.
0277 29 13 [05] iord USB_Status_Control
0279 10 EF [04] and A,0EFh
027B 2A 13 [05] iowr USB_Status_Control
027D done_configuration:
027D 3F [08] ret
027E
027E ClearEndpointStall:
027E ;Clear the stall condition for an endpoint.
027E ;For endpoint 1, also set Data 0/1 to Data 0.
027E 1A 72 [06] mov A, [wValue]
0280 16 00 [04] cmp A, endpoint_stalled
0282 B1 AD [05] jnz SendStall
0284 ;
0284 ;Clear Endpoint 1 stall
0284 ;Handshake by sending a 0-byte data packet
0284 93 79 [10] call Send0ByteDataPacket
0286 ;Clear the stall condition
0286 19 00 [04] mov A,0
0288 31 29 [05] mov [endpoint_stall], A
028A ;Set Data 0/1 to Data0
028A 29 11 [05] iord USB_EP1_TX_Config
028C 10 BF [04] and A, ~DataToggle
028E 2A 11 [05] iowr USB_EP1_TX_Config
0290 ;Send NAK in response to Endpoint 0 OUT packets.
0290 29 13 [05] iord USB_Status_Control
0292 10 EF [04] and A,0EFh
0294 2A 13 [05] iowr USB_Status_Control
0296 3F [08] ret
0297
0297 ;Stall Endpoint 1
0297 SetEndpointStall:
0297 1A 72 [06] mov A, [wValue]
0299 16 00 [04] cmp A, endpoint_stalled
029B ;Not a match, so stall
029B B1 AD [05] jnz SendStall
029D ;Handshake by sending a 0-byte data packet.
029D 93 79 [10] call Send0ByteDataPacket
029F ;Stall the endpoint.
029F 19 01 [04] mov A,1
02A1 31 29 [05] mov [endpoint_stall], A
02A3 19 30 [04] mov A, 30h
02A5 2A 11 [05] iowr USB_EP1_TX_Config
02A7 3F [08] ret
02A8
02A8 GetDeviceStatus:
02A8 ;Device Status is two bytes.
02A8 ;Bit 0 must be 0 (bus-powered).
02A8 ;Bit 1 is remote wakeup: 0=disabled, 1=enabled.
02A8 ;All other bits are unused.
02A8 ;Send two bytes.
02A8 19 02 [04] mov A, 2
02AA 31 28 [05] mov [data_count], A
02AC ;The control_read_table holds the two possible values for device status.
02AC ;Get the address of the first value.
02AC 19 9C [04] mov A, (get_dev_status_table - control_read_table)
02AE ;Add an index value to select the correct bytes.
02AE 02 30 [06] add A, [remote_wakeup_status]
02B0 ;Send the value.
02B0 83 3E [05] jmp SendDescriptor
02B2
02B2 GetDescriptor:
02B2 ;The high byte of wValue contains the descriptor type.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -