📄 usbhidio.lst
字号:
02B2 ;The low byte of wValue contains the descriptor index.
02B2
02B2 1A 73 [06] mov A, [wValueHi] ; load descriptor type
02B4
02B4 ;Test for standard descriptor types first.
02B4 ;Supported descriptor types are device, configuration, string.
02B4 ;Unsupported descriptor types are interface, endpoint.
02B4
02B4 ; Get Descriptor (device) wValueHi = 1
02B4 16 01 [04] cmp A, device
02B6 A3 1C [05] jz GetDeviceDescriptor
02B8 ; Get Descriptor (configuration) wValueHi = 2
02B8 16 02 [04] cmp A, configuration
02BA A3 26 [05] jz GetConfigurationDescriptor
02BC ; Get Descriptor (string) wValueHi = 3
02BC 16 03 [04] cmp A, string
02BE A3 2E [05] jz GetStringDescriptor
02C0
02C0 ; Test for HID-class descriptor types.
02C0 ; Get Descriptor (HID) wValueHi = 21h
02C0 16 21 [04] cmp A, HID
02C2 A3 5D [05] jz GetHIDDescriptor
02C4 ; Get Descriptor (report) wValueHi = 22h
02C4 16 22 [04] cmp A, report
02C6 A3 07 [05] jz GetReportDescriptor
02C8 ; Get Descriptor (physical) wValueHi = 23h *** not supported ***
02C8 ;Stall unsupported requests.
02C8 81 AD [05] jmp SendStall
02CA
02CA GetConfiguration:
02CA ;Send the current device configuration.
02CA ;0 = unconfigured, 1 = configured.
02CA
02CA ;Send 1 byte
02CA 19 01 [04] mov A, 1
02CC 31 28 [05] mov [data_count], A
02CE ;Get the address of the data to send.
02CE 19 A6 [04] mov A, (get_configuration_status_table - control_read_table)
02D0 ;Add an index to point to the correct configuration.
02D0 02 31 [06] add A, [configuration_status]
02D2 ;Send the data.
02D2 83 3E [05] jmp SendDescriptor
02D4
02D4 GetInterfaceStatus:
02D4 ;Interface status is 2 bytes, which are always 0.
02D4 ;Send 2 bytes.
02D4 19 02 [04] mov A, 2
02D6 31 28 [05] mov [data_count], A
02D8 ;Get the address of the data to send.
02D8 19 A0 [04] mov A, (get_interface_status_table - control_read_table)
02DA ;Send the data.
02DA 83 3E [05] jmp SendDescriptor
02DC
02DC GetEndpointStatus:
02DC ;Endpoint status is 2 bytes.
02DC ;Bit 0 = 0 when the endpoint is not stalled.
02DC ;Bit 0 = 1 when the endpoint is stalled.
02DC ;All other bits are unused.
02DC ;Send 2 bytes.
02DC 19 02 [04] mov A, 2
02DE 31 28 [05] mov [data_count], A
02E0 ;Get the stall status.
02E0 1A 29 [06] mov A, [endpoint_stall]
02E2 ;Shift left to get an index (0 or 2) for the endpoint status table
02E2 3B [04] asl A
02E3 ;Get the address of the data to send.
02E3 01 A2 [04] add A, (get_endpoint_status_table - control_read_table)
02E5 ;Send the data.
02E5 83 3E [05] jmp SendDescriptor
02E7
02E7 SetReport:
02E7 ;The CY7C63000 doesn't support interrupt-mode OUT transfers.
02E7 ;So the host uses Control transfers with Set_Report requests
02E7 ;to get data from the device.
02E7
02E7 ;Get the report data.
02E7
02E7 ;For debugging: set Port 0, bit 0 =1 to show that we're here.
02E7 29 00 [05] iord Port0_Data
02E9 0D 01 [04] or a, 1
02EB 2A 00 [05] iowr Port0_Data
02ED
02ED ;Find out how many bytes to read. This value is in WLength.
02ED ;Save the length in data_count.
02ED 1A 76 [06] mov A, [wLength]
02EF 31 28 [05] mov [data_count], A
02F1
02F1 ;Enable receiving data at endpoint 0 by setting the EnableOuts bit
02F1 ;The bit is cleared following any Setup or OUT transaction.
02F1 29 13 [05] iord USB_Status_Control
02F3 0D 10 [04] or A, 10h
02F5 ;Clear the StatusOuts bit to disable auto-Ack after receiving a valid
02F5 ;status packet in a Control read (IN) transfer.
02F5 ;Otherwise, the USB engine will respond to a data OUT packet with a stall.
02F5 10 F7 [04] and A, F7h
02F7 2A 13 [05] iowr USB_Status_Control
02F9 ;Now we're ready to receive the report data.
02F9 ;An Endpoint 0 OUT interrupt signals the arrival of the report data.
02F9 3F [08] ret
02FA
02FA SetIdle:
02FA 81 AD [05] jmp SendStall ; *** not supported ***
02FC
02FC SetProtocol:
02FC ;Switches between a boot protocol (wValue=0) and report protocol (wValue=1).
02FC ;This firmware doesn't distinguish between protocols.
02FC 1A 72 [06] mov A, [wValue]
02FE 20 [04] NOP
02FF 1F [04] XPAGE
0300 31 34 [05] mov [protocol_status], A
0302 93 79 [10] call Send0ByteDataPacket
0304 3F [08] ret
0305
0305 GetReport:
0305 ;Sends a report to the host.
0305 ;The high byte of wValue contains the report type.
0305 ;The low byte of wValue contains the report ID.
0305 ;Not supported (Use interrupt transfers to send data.)
0305 81 AD [05] jmp SendStall
0307
0307 GetReportDescriptor:
0307 ;Save the descriptor length
0307 19 34 [04] mov A, (end_hid_report_desc_table - hid_report_desc_table)
0309 31 28 [05] mov [data_count], A
030B ;Get the descriptor's starting address.
030B 19 34 [04] mov A, (hid_report_desc_table - control_read_table)
030D 93 3E [10] call SendDescriptor
030F
030F 3F [08] ret
0310
0310 GetIdle:
0310 ;Not supported
0310 81 AD [05] jmp SendStall
0312
0312 GetProtocol:
0312 ;Send the current protocol status.
0312 ;Send 1 byte.
0312 19 01 [04] mov A, 1
0314 31 28 [05] mov [data_count], A
0316 ;Get the address of the data to send.
0316 19 A8 [04] mov A, (get_protocol_status_table - control_read_table)
0318 ;Add an index that points to the correct data.
0318 02 34 [06] add A, [protocol_status]
031A ;Send the data.
031A 83 3E [05] jmp SendDescriptor
031C
031C ; Standard Get Descriptor routines
031C ;
031C ;Send the device descriptor.
031C GetDeviceDescriptor:
031C ;Get the length of the descriptor
031C ;(stored in the first byte in the device descriptor table).
031C 19 00 [04] mov A, 0
031E F3 E6 [14] index device_desc_table
0320 31 28 [05] mov [data_count], A
0322 ;Get the starting address of the descriptor.
0322 19 00 [04] mov A, (device_desc_table - control_read_table)
0324 ;Send the descriptor.
0324 83 3E [05] jmp SendDescriptor
0326
0326 GetConfigurationDescriptor:
0326 ;Send the configuration descriptor.
0326 ;Get the length of the descriptor.
0326 19 22 [04] mov A, (end_config_desc_table - config_desc_table)
0328 31 28 [05] mov [data_count], A
032A ;Get the starting address of the descriptor.
032A 19 12 [04] mov A, (config_desc_table - control_read_table)
032C ;Send the descriptor.
032C 83 3E [05] jmp SendDescriptor
032E
032E GetStringDescriptor:
032E ;Use the string index to find out which string it is.
032E 1A 72 [06] mov A, [wValue]
0330 16 00 [04] cmp A, 0h
0332 A3 45 [05] jz LanguageString
0334 16 01 [04] cmp A, 01h
0336 A3 4D [05] jz ManufacturerString
0338 16 02 [04] cmp A, 02h
033A A3 55 [05] jz ProductString
033C ; cmp A, 03h
033C ; jz SerialNumString
033C ; cmp A, 04h
033C ; jz ConfigurationString
033C ; cmp A, 05h
033C ; jz InterfaceString
033C ; No other strings supported
033C 81 AD [05] jmp SendStall
033E
033E SendDescriptor:
033E ;The starting address of the descriptor is in the accumulator. Save it.
033E 31 27 [05] mov [data_start], A
0340 ;Get the descriptor length.
0340 93 66 [10] call get_descriptor_length
0342 ;Send the descriptor.
0342 93 8A [10] call control_read
0344 3F [08] ret
0345
0345 ;Send the requested string.
0345 ;For each, store the descriptor length in data_count, then send the descriptor.
0345 LanguageString:
0345 19 04 [04] mov A, (USBStringDescription1 - USBStringLanguageDescription)
0347 31 28 [05] mov [data_count], A
0349 19 68 [04] mov A, (USBStringLanguageDescription - control_read_table)
034B 83 3E [05] jmp SendDescriptor
034D ManufacturerString:
034D 19 1A [04] mov A, ( USBStringDescription2 - USBStringDescription1)
034F 31 28 [05] mov [data_count], A
0351 19 6C [04] mov A, (USBStringDescription1 - control_read_table)
0353 83 3E [05] jmp SendDescriptor
0355 ProductString:
0355 19 16 [04] mov A, ( USBStringDescription3 - USBStringDescription2)
0357 31 28 [05] mov [data_count], A
0359 19 86 [04] mov A, (USBStringDescription2 - control_read_table)
035B 83 3E [05] jmp SendDescriptor
035D ;SerialNumString:
035D ; mov A, ( USBStringDescription4 - USBStringDescription3)
035D ; mov [data_count], A
035D ; mov A, (USBStringDescription3 - control_read_table)
035D ; jmp SendDescriptor
035D ;ConfigurationString:
035D ; mov A, ( USBStringDescription5 - USBStringDescription4)
035D ; mov [data_count], A
035D ; mov A, (USBStringDescription4 - control_read_table)
035D ; jmp SendDescriptor
035D ;InterfaceString:
035D ; mov A, ( USBStringEnd - USBStringDescription5)
035D ; mov [data_count], A
035D ; mov A, (USBStringDescription5 - control_read_table)
035D ; jmp SendDescriptor
035D
035D ; HID class Get Descriptor routines
035D ;
035D GetHIDDescriptor:
035D ;Send the HID descriptor.
035D ;Get the length of the descriptor.
035D 19 09 [04] mov A, (Endpoint_Descriptor - Class_Descriptor)
035F 31 28 [05] mov [data_count], A
0361 ;Get the descriptor's starting address.
0361 19 24 [04] mov A, ( Class_Descriptor - control_read_table)
0363 ;Send the descriptor.
0363 93 3E [10] call SendDescriptor
0365 3F [08] ret
0366
0366 ;======================================================================
0366 ;USB support routines
0366 ;======================================================================
0366
0366 get_descriptor_length:
0366 ;The host sometimes lies about the number of bytes it
0366 ; wants from a descriptor.
0366 ;A request to get a descriptor should return the smaller of the number
0366 ;of bytes requested or the actual length of the descriptor.
0366 ;Get the requested number of bytes to send
0366 1A 77 [06] mov A, [wLengthHi]
0368 ;If the requested high byte is >0,
0368 ;ignore the high byte and use the firmware's value.
0368 ;(255 bytes is the maximum allowed.)
0368 16 00 [04] cmp A, 0
036A B3 78 [05] jnz use_actual_length
036C ;If the low byte =0, use the firmware's value.
036C 1A 76 [06] mov A, [wLength]
036E 16 00 [04] cmp A, 0
0370 A3 78 [05] jz use_actual_length
0372 ;If the requested number of bytes => the firmware's value,
0372 ;use the firmware's value.
0372 17 28 [06] cmp A, [data_count]
0374 D3 78 [05] jnc use_actual_length
0376 ;If the requested number of bytes < the firmware's value,
0376 ;use the requested number of bytes.
0376 31 28 [05] mov [data_count], A
0378 use_actual_length:
0378 3F [08] ret
0379
0379
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -