📄 usb_to_serial.asm
字号:
Get_Device_Status:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 02h ;
mov [data_count], A ;
mov A, device_status ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Descriptor
;****************************************************************
; There are five descriptor types. The descriptor type will
; be in the high byte of value. 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. The String descriptor has also
; a subset of different descriptor and those are chosen by
; the low byte of value. There are also two additional
; descriptors added in the case of a this HID device, the
; HID descriptor, and the report descriptor
;****************************************************************
Get_Descriptor:
mov X, SIZEOF_REPORT_ID_TABLE ; get table size
; inc [control_read_counter] ;
; mov A, [control_read_counter] ;
; cmp A, 25h ;
; jnz .loop ;
; halt ;
.loop:
dec X ;
jc Send_Stall ; if we have traversed the table then stall
dec X ;
mov A, X ; get current position
index report_id_table ; fetch value from rom
cmp A, [value_hi] ; is there a match
jnz .loop ; if not then try next entry
mov A, X ;
index (report_id_table + 1) ; check the low byte
cmp A, [value] ; is there a match
jnz .loop ; if not then try next entry
mov A, ROM ;
mov [ram_or_rom], A ; to load data from ROm
mov A, X ; we have found the entry
jacc Report_Jump_Table ; jump to the proper place
;****************************************************************
; REQUEST: Get_Device_Descriptor
;****************************************************************
Get_Device_Descriptor:
mov A, SIZEOF_DEVICE_DESCRIPTOR ;
mov [data_count], A ;
mov A, (device_descriptor - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Configuration_Descriptor
;****************************************************************
; Returns the configuration, interface, and endpoint descriptors.
;****************************************************************
Get_Configuration_Descriptor:
mov A, SIZEOF_ALL_CONFIGURATION_DESCRIPTORS ;
mov [data_count], A ;
mov A, (configuration_descriptor - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Language_String_Descriptor
;****************************************************************
Get_Language_String_Descriptor:
mov A, SIZEOF_LANGUAGE_STRING ;
mov [data_count], A ;
mov A, (language_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Manufacturer_String_Descriptor
;****************************************************************
Get_Manufacturer_String_Descriptor:
mov A, SIZEOF_MANUFACTURER_STRING ;
mov [data_count], A ;
mov A, (manufacturer_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Product_String_Descriptor
;****************************************************************
Get_Product_String_Descriptor:
mov A, SIZEOF_PRODUCT_STRING ;
mov [data_count], A ;
mov A, (product_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Serial_String_Descriptor
;****************************************************************
Get_Serial_String_Descriptor:
mov A, SIZEOF_SERIAL_STRING ;
or A, 00h ;
jz Send_Stall ;
mov [data_count], A ;
mov A, (serial_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Configuration_String_Descriptor
;****************************************************************
Get_Configuration_String_Descriptor:
mov A, SIZEOF_CONFIGURATION_STRING ;
mov [data_count], A ;
mov A, (configuration_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Interface_String_Descriptor
;****************************************************************
Get_Interface_String_Descriptor:
mov A, SIZEOF_INTERFACE_STRING ;
mov [data_count], A ;
mov A, (interface_string - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Hid_Descriptor
;****************************************************************
Get_Hid_Descriptor:
mov A, SIZEOF_HID_DESCRIPTOR ;
mov [data_count], A ;
mov A, (hid_descriptor - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Hid_Report_Descriptor
;****************************************************************
Get_Hid_Report_Descriptor:
mov A, SIZEOF_HID_REPORT_DESCRIPTOR ;
mov [data_count], A ;
mov A, (hid_report_descriptor - control_read_table) ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Configuration
;****************************************************************
Get_Configuration:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 01h ;
mov [data_count], A ;
mov A, configuration ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Interface_Status
;****************************************************************
Get_Interface_Status:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 02h ;
mov [data_count], A ;
mov A, zero_register ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Interface
;****************************************************************
Get_Interface:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 01h ;
mov [data_count], A ;
mov A, zero_register ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Endpoint_Status
;****************************************************************
Get_Endpoint_Status:
mov A, [index_hi] ;
cmp A, 00h ;
jnz Send_Stall ;
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 02h ;
mov [data_count], A ;
;----------------------------------------------------------------
; If the request is for endpoint 0, send
; ep0_status (ep0_status is always 0.)
mov A, [index] ;
and A, 7Fh ;
mov A, zero_register ;
jz Execute ;
;----------------------------------------------------------------
; If the device is unconfigured, stall
; this request for endpoints > 0.
mov A, [configuration] ;
cmp A, UNCONFIGURED ;
jz Send_Stall ;
; Otherwise, send the requested endpoint
; status.
mov A, [index] ;
and A, 7Fh ;
cmp A, 01h ;
jnz .Ge2 ;
mov A, ep1_status ;
jmp Execute ;
.Ge2:
cmp A, 02h ; if it's not endpoint 2 then
jnz Send_Stall ;
mov A, ep2_status ; send ep2 status
jmp Execute ;
;****************************************************************
; REQUEST: Set_Report
;****************************************************************
Set_Report:
mov A, ACK_OUT_STATUS_IN ;
mov [ep0_next_mode], A ;
ret ;
;****************************************************************
; REQUEST: Set_Idle
;****************************************************************
Set_Idle:
mov A, [value_hi] ;
mov [idle], A ;
call No_Data_Control ;
ret ;
;****************************************************************
; REQUEST: Set_Protocol
;****************************************************************
Set_Protocol:
mov A, [value] ;
mov [protocol], A ;
call No_Data_Control ;
ret ;
;****************************************************************
; REQUEST: Get_Report
;****************************************************************
Get_Report:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 05h ;
mov [data_count], A ;
mov A, control_report ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Idle
;****************************************************************
Get_Idle:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 01h ;
mov [data_count], A ;
mov A, idle ;
jmp Execute ;
;****************************************************************
; REQUEST: Get_Protocol
;****************************************************************
Get_Protocol:
mov A, RAM ;
mov [ram_or_rom], A ;
mov A, 01h ;
mov [data_count], A ;
mov A, protocol ;
jmp Execute ;
;****************************************************************
; FUNCTION: No_Data_Control
;****************************************************************
No_Data_Control:
mov A, STATUS_IN_ONLY ; set next mode to react to STATUS IN
mov [ep0_next_mode],A ;
ret ;
;****************************************************************
; FUNCTION: No_Data_Control_Wait
;****************************************************************
No_Data_Control_Wait:
mov A, STATUS_IN_ONLY ; enable TX0 IN
iowr EP0_MODE ;
; wait for the zero-length transfer to complete
No_Data_Control_Loop:
iowr WDT ;
iord EP0_MODE
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -