📄 function.asm
字号:
sz z
JMP SetFeature_1
mov a,FIFO_wValueH
sub a,81H ;target-now
snz C
jmp SendStall0 ;<81H
;>81H
mov a,FIFO_wValueH
sub a,84H ;target-now
sz C
jmp SendStall0 ;>84H
mov a,FIFO_wValueL
xor a,00H
snz z
JMP SendStall0
jmp SetFeature_2 ;<84H
SetFeature_1:
mov a,FIFO_wValueL
xor a,01H
snz z
JMP SendStall0
SetFeature_2:
;;----------------------------------
CALL Send_Hand_Shake
SetFeature_Loop:
SetFeature_End:
JMP USB_EP0_ISR_END
;-----------------------------------------------------------
; Set Feature (Endpoint)
;-----------------------------------------------------------
SetFeature_Endpoint:
clr wdt
snz bFlag_SetConfiguration_Ready
JMP SendStall0
mov a,07FH
and a,FIFO_wIndexL
call GetPipeBit
mov FIFO_TEMP,A
mov a,STALL
or a,FIFO_TEMP
mov STALL,a
CALL Send_Hand_Shake
SetFeature_Endpoint_End:
JMP USB_EP0_ISR_END
;-----------------------------------------------------------
; Get Descriptor
;-----------------------------------------------------------
GetDescriptor:
clr wdt
CLR bFlag_RD_HTable
CLR bFlag_wait_control_out
MOV A,FIFO_WvalueH ;80 06 00 01
XOR A,device
SZ Z
JMP GetDeviceDescriptor
MOV A,FIFO_WvalueH ;80 06 00 02
XOR A,configuration
SZ Z
JMP GetConfigurationDescriptor
MOV A,FIFO_WvalueH ;80 06 00 03
XOR A,string
SZ Z
JMP GetStringDescriptor
;------------------------------------------------------
;Then test for HID class Descriptor
;------------------------------------------------------
MOV A,FIFO_wIndexL
XOR A,03H ;Check Interface Number No.3
SNZ Z
JMP SendStall0
MOV A,FIFO_WvalueH ;81 06 00 22
XOR A,report
SZ Z
JMP GetReportDescriptor
MOV A,FIFO_WvalueH ;81 06 00 21
XOR A,HID
SZ Z
JMP GetHIDDescriptor
JMP SendStall0 ;can't parser
;-----------------------------------------------------------
; GetConfiguration
;-----------------------------------------------------------
GetConfiguration:
clr wdt
mov a,01H
mov FIFO_SendLen,a
mov a,USB_Configuration
mov FIFO_OUT1,a
GetConfiguration_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetConfiguration_End
clr wdt
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetConfiguration_Loop
CALL Write_FIFO0
GetConfiguration_End:
JMP USB_EP0_ISR_END
;------------------------------------------------------
;Report
;------------------------------------------------------
SetReport:
clr wdt
mov a,FIFO_wValueH
xor a,set_output_report
sz z
jmp SetOutputReport
JMP USB_EP0_ISR_END
SetReport_End:
SetOutputReport:
clr wdt
;check interface
mov a,FIFO_wIndexL
xor a,03H
snz z
jmp SendStall0
;check length
mov a,FIFO_wLengthL
xor a,08H
snz z
jmp SendStall0
mov a,21H
mov nCmdIndex1,a
SetOutputReport_End:
JMP USB_EP0_ISR_END
;------------------------------------------------------
;Audio class
;------------------------------------------------------
;21 01
SetCur:
clr wdt
MOV A,FIFO_WVALUEH
XOR A,MUTE_CONTROL
SZ Z
JMP MuteControl
MOV A,FIFO_WVALUEH
XOR A,VOLUME_CONTROL
SZ Z
JMP VolumeControl
JMP SendStall0 ;can't parser
;21 01 00 01
MuteControl: ;(if have more feature , the state must be modify!!)
clr wdt
mov a,02h
xor a,FIFO_wIndexH
sz z
jmp MuteControl_SetSpeaker
mov a,06h
xor a,FIFO_wIndexH
sz z
jmp MuteControl_SetMic
MuteControl_SetSpeaker:
clr wdt
mov a,18h
mov nCmdIndex1,a
RET
MuteControl_SetMic:
clr wdt
mov a,19h
mov nCmdIndex1,a
RET
;21 01 00 02
VolumeControl:
clr wdt
mov a,02h
xor a,FIFO_wIndexH
sz z
jmp VolumeControl_SetSpeaker
mov a,06h
xor a,FIFO_wIndexH
sz z
jmp VolumeControl_SetMic
VolumeControl_SetSpeaker:
clr wdt
mov a,28h
mov nCmdIndex1,a
ret
VolumeControl_SetMic:
clr wdt
mov a,29h
mov nCmdIndex1,a
ret
;return D2 00 = -46 db
;return BC 00 = -32 db
GetMin:
clr wdt
mov a,02h
xor a,FIFO_wIndexH
sz z
jmp GetMin_SetSpeaker
mov a,06h
xor a,FIFO_wIndexH
sz z
jmp GetMin_SetMic
;modify 2006-09-29
jmp SendStall0
GetMin_SetSpeaker:
clr wdt
MOV A,00H
MOV FIFO_OUT1,A
;; MOV A,0E0H
MOV A,Min_Volume
MOV FIFO_OUT2,A
MOV A,02H
MOV FIFO_SendLen,A
jmp GetMin_Loop
GetMin_SetMic:
clr wdt
MOV A,00H
MOV FIFO_OUT1,A
;MOV A,00H
MOV A,MIC_Min_Volume
MOV FIFO_OUT2,A
MOV A,02H
MOV FIFO_SendLen,A
jmp GetMin_Loop
GetMin_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetMin_End
clr wdt
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetMin_Loop
CALL Write_FIFO0
GetMin_End:
RET
;return 0x0C00
GetMax:
clr wdt
mov a,02h
xor a,FIFO_wIndexH
sz z
jmp GetMax_SetSpeaker
mov a,06h
xor a,FIFO_wIndexH
sz z
jmp GetMax_SetMic
;modify 2006-09-29
jmp SendStall0
GetMax_SetSpeaker:
clr wdt
MOV A,00H
MOV FIFO_OUT1,A
;; MOV A,0CH
MOV A,Max_Volume
MOV FIFO_OUT2,A
MOV A,02H
MOV FIFO_SendLen,A
jmp GetMax_Loop
GetMax_SetMic:
clr wdt
MOV A,00H
MOV FIFO_OUT1,A
;MOV A,28H
MOV A,MIC_Max_Volume
MOV FIFO_OUT2,A
MOV A,02H
MOV FIFO_SendLen,A
jmp GetMax_Loop
GetMax_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetMax_End
clr wdt
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetMax_Loop
CALL Write_FIFO0
GetMax_End:
RET
;return 0x0100 1db
GetRes:
clr wdt
MOV A,00H
MOV FIFO_OUT1,A
MOV A,01H
MOV FIFO_OUT2,A
MOV A,02H
MOV FIFO_SendLen,A
GetRes_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetRes_End
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetRes_Loop
CALL Write_FIFO0
GetRes_End:
RET
GetCur:
;; call Check_Real_Cmd
;; sz bFlag_Real_Cmd
;; jmp GetCur_End
;;
;;
;; call FIFO0_WR_CHECK
;; SNZ bFlag_FIFO_Ready
;; JMP GetCur
;;
;; MOV A,FIFO_wLengthL
;; MOV FIFO_SendLen,A
;;
;; MOV FIFO_TEMP,A
;; MOV A,OFFSET FIFO_OUT1
;; MOV MP1,A
;;GetCur_Fill0:
;; MOV A,00H
;; MOV R1,A
;; INC MP1
;; DEC FIFO_TEMP
;; MOV A,00H
;; XOR A,FIFO_TEMP
;; SNZ Z
;; JMP GetCur_Fill0
;; CALL Write_FIFO0
clr wdt
MOV A,FIFO_wLengthL
MOV FIFO_SendLen,A
MOV A,01H
XOR A,FIFO_SendLen
sz z
jmp GetCur_Mute
MOV A,02H
XOR A,FIFO_SendLen
sz z
jmp GetCur_Volume
;modify 2006-09-29
jmp SendStall0
;modify 2006-09-28
GetCur_Mute:
clr wdt
MOV A,02H
XOR A,FIFO_wIndexH
SZ Z
jmp GetCur_Mute_Speaker
MOV A,06H
XOR A,FIFO_wIndexH
SZ Z
jmp GetCur_Mute_Mic
;modify 2006-09-29
jmp SendStall0
GetCur_Mute_Mic:
MOV A,00H
sz bFlag_Mic_Mute
MOV A,01H
mov FIFO_OUT1,A
jmp GetCur_Mute_Loop
GetCur_Mute_Speaker:
MOV A,00H
sz bFlag_Audio_Mute
MOV A,01H
mov FIFO_OUT1,A
GetCur_Mute_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetCur_End
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetCur_Mute_Loop
call Write_FIFO0
jmp GetCur_End
GetCur_Volume:
clr wdt
MOV A,02H
XOR A,FIFO_wIndexH
SZ Z
jmp GetCur_Volume_Speaker
MOV A,06H
XOR A,FIFO_wIndexH
SZ Z
jmp GetCur_Volume_Mic
;modify 2006-09-29
jmp SendStall0
GetCur_Volume_Mic:
MOV A,00H
mov FIFO_OUT1,A
mov A,PGA_CTRL
and A,3FH
mov FIFO_OUT2,A
jmp GetCur_Volume_Loop
GetCur_Volume_Speaker:
MOV A,VolumeH_Save
mov FIFO_OUT1,A
MOV A,VolumeL_Save
mov FIFO_OUT2,A
GetCur_Volume_Loop:
clr wdt
call Check_Real_Cmd
sz bFlag_Real_Cmd
jmp GetCur_End
call FIFO0_WR_CHECK
SNZ bFlag_FIFO_Ready
JMP GetCur_Volume_Loop
call Write_FIFO0
jmp GetCur_End
GetCur_End:
RET
;--------------------------------------------------------------
SetIdle:
JMP SendStall0 ;can't parser
;==============================================================
;Standard Get Descriptor routines
;
;Return the device descriptor to the host
GetDeviceDescriptor:
clr wdt
MOV A,LOW device_desc_table
MOV TBLP,A
TABRDL data_count
JMP Execute
GetConfigurationDescriptor:
clr wdt
MOV A,LOW config_desc_length
MOV TBLP,A
TABRDL data_count
MOV A,LOW config_desc_table
JMP Execute
GetStringDescriptor:
clr wdt
MOV A,FIFO_WVALUEL
XOR A,00H
SZ Z
JMP LanguageString
MOV A,FIFO_WVALUEL
XOR A,01H
SZ Z
JMP ManufacturerString
MOV A,FIFO_WVALUEL
XOR A,02H
SZ Z
JMP ProductString
MOV A,FIFO_WVALUEL
XOR A,03H
SZ Z
JMP SerialNumberString
JMP SendStall0 ;other no support
LanguageString:
clr wdt
MOV A,LOW USBStringLanguageDescription
MOV TBLP,A
TABRDL data_count
MOV A,LOW USBStringLanguageDescription
JMP execute
ManufacturerString:
clr wdt
MOV A,LOW USBStringDescription1
MOV TBLP,A
TABRDL data_count
MOV A,LOW USBStringDescription1
JMP execute
ProductString:
clr wdt
MOV A,LOW USBStringDescription2
MOV TBLP,A
TABRDL data_count
MOV A,LOW USBStringDescription2
JMP execute
SerialNumberString:
clr wdt
MOV A,LOW USBStringDescription3
MOV TBLP,A
TABRDL data_count
MOV A,LOW USBStringDescription3
JMP execute
;--------------------------------------------------
;HID class Get Descriptor routines
;return the HID descriptor and enable endpoint one
;--------------------------------------------------
GetReportDescriptor:
clr wdt
MOV A,LOW report_desc_length
MOV TBLP,A
TABRDL data_count ;Report length = Low byte of Report_Size
MOV A,LOW hid_report_desc_table
CALL execute ;send descriptor to host
;
;Enumeration is complete!!
;
set bFlag_Enum_Ready ;set Enumeration flag
RET
GetHIDDescriptor:
clr wdt
MOV A,LOW hid_desc_length
MOV TBLP,A
TABRDL data_count ;Report length = Low byte of Report_Size
MOV A,LOW HID_Desc
CALL execute ;send descriptor to host
RET
Execute:
clr wdt
MOV data_start,A
call get_descriptor_length
call control_read
RET
;===============================================================
SendStall0:
SET STALL.@STALL_STL0
RET ;return to USB_EP0_ISR
;***************************************************************
; Delay Test Function
; Most instructions Timing is one cycles = 0.33333 us
; call , jmp , ret is 2 cycles
;***************************************************************
Delay_28us:
mov a,1EH
Delay_28us_cont:
clr wdt
sdz acc
jmp Delay_28us_cont
Delay_3us:
clr wdt
NOP
NOP
NOP
NOP
clr wdt
ret
;----BEGIN (Get pipe bit)
;Input : ACC pipe number
;Output: ACC pip bit (D0:pipe 0, D1:pipe 1...)
GetPipeBit:
INC ACC
MOV FIFO_TEMP,A
MOV A,80H
GetPipeBitLoop:
clr wdt
RL ACC
SDZ FIFO_TEMP
JMP GetPipeBitLoop
RET
;----END (Get pipe bit)
Public Control_Read
Public FIFO0_RD_CHECK
Public FIFO1_RD_CHECK
Public FIFO2_RD_CHECK
Public FIFO3_RD_CHECK
Public FIFO4_RD_CHECK
Public FIFO5_RD_CHECK
Public FIFO0_WR_CHECK
Public FIFO1_WR_CHECK
Public FIFO2_WR_CHECK
Public FIFO3_WR_CHECK
Public FIFO4_WR_CHECK
Public FIFO5_WR_CHECK
Public Read_FIFO0
Public Read_FIFO1
Public Read_FIFO2
Public Read_FIFO3
Public Read_FIFO4
Public Read_FIFO5
Public Write_FIFO0
Public Write_FIFO1
Public Write_FIFO2
Public Write_FIFO3
Public Write_FIFO4
Public Write_FIFO5
Public Send_Hand_Shake
Public get_descriptor_length
Public SetAddress
Public SetConfiguration
Public SetInterface
Public GetInterface
Public GetDescriptor
Public SetIdle
Public GetDeviceDescriptor
Public GetConfigurationDescriptor
Public GetStringDescriptor
Public GetStatus
Public SetFeature
Public ClearFeature
Public SetFeature_Endpoint
Public ClearFeature_Endpoint
Public GetStatus_Endpoint
Public SetReport
Public Check_Real_Cmd
Public Execute
Public SendStall0
Public GetConfiguration
Public Delay_3us
Public SetCur
Public GetMin
Public GetMax
Public GetRes
Public GetCur
Public GetPipeBit
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -