?? firmware.a51
字號:
MOV DPTR, #wValueLo
MOVX A, @DPTR ; endpoint
;-- todo: store HALT info for every endpoint
MOV EpHalt, #1
JMP NoDataControl
;-------------------------------------------------------------------------------
;* * * H I D s p e c i f i c r e q u e s t s * * * * * * * * * * * * * *
;-------------------------------------------------------------------------------
;*** HID 7.1.1 Get Descriptor **************************************************
xxxGET_DESCRIPTOR:
MOV DPTR, #wValueHi
MOVX A, @DPTR
CLR C
SUBB A, #21h
JZ hidGET_DESCRIPTOR
DEC A
JZ rptGET_DESCRIPTOR
JMP invalid
;*** HID 7.2.1 Get Report ******************************************************
xxxGET_REPORT:
;-- put report data
MOV DPTR, #usbFIFO
MOV A, #0AAh
MOVX @DPTR, A
MOV A, #1
JMP ControlRead
;*** HID 7.2.2 Set Report ******************************************************
xxxSET_REPORT:
;-- control-write sequence
sr1:
MOV DPTR, #usbCTRL
MOV A, #usbCTRLwrite
MOVX @DPTR, A
;-- wait for next transaction
MOV DPTR, #usbSTAT
sr2:
MOVX A, @DPTR
ANL A, #usbSTATall
JZ sr2
;-- discard data stage
CJNE A, #usbSTATstatus, sr1
JMP AcknowledgeStatus
;-------------------------------------------------------------------------------
;* * * i n v a l i d r e q u e s t s * * * * * * * * * * * * * * * * * * *
;-------------------------------------------------------------------------------
SET_DESCRIPTOR: ; descriptors are static
SET_INTERFACE: ; only one Interface
GET_INTERFACE: ; no alternate setting
devSET_FEATURE: ; no features to be set or cleared
ifSET_FEATURE: ; no features to be set or cleared
devCLEAR_FEATURE: ; no features to be set or cleared
ifCLEAR_FEATURE: ; no features to be set or cleared
epSYNCH_FRAME: ; not an Isonchronous device
invalid:
;--
xxxGET_PROTOCOL: ; not a Boot device
xxxSET_PROTOCOL: ; not a Boot device
xxxSET_DESCRIPTOR: ; descriptors are static
xxxGET_IDLE: ; optional request
xxxSET_IDLE: ; optional request
;-- display "f"
MOV A, #ledREGf
MOV DPTR, #ledREG
MOVX @DPTR, A
;-- STALL endpoint
MOV DPTR, #usbCTRL
MOV A, #usbCTRLstall
MOVX @DPTR, A
RET
;-------------------------------------------------------------------------------
;* * * h e l p e r s * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;-------------------------------------------------------------------------------
devGET_DESCRIPTOR:
MOV DPTR, #DevDescr
MOV A, #DevDescrLen
JMP doGET_DESCRIPTOR
;-------------------
cfgGET_DESCRIPTOR:
MOV DPTR, #CfgDescr
MOV A, #CfgDescrLen
JMP doGET_DESCRIPTOR
;-------------------
strGET_DESCRIPTOR:
MOV DPTR, #wValueLO
MOVX A, @DPTR
MOV DPTR, #String0
JZ sd
MOV DPTR, #String1
DEC A
JZ sd
MOV DPTR, #String2
DEC A
JZ sd
MOV DPTR, #String3
DEC A
JZ sd
MOV DPTR, #String4
sd: MOVX A, @DPTR ; length of string
JMP doGET_DESCRIPTOR
;-------------------------------------------------------------------------------
hidGET_DESCRIPTOR:
MOV DPTR, #HidDescr
MOV A, #HidDescrLen
JMP doGET_DESCRIPTOR
;-------------------
rptGET_DESCRIPTOR:
MOV DPTR, #RptDescr
MOV A, #RptDescrLen
JMP doGET_DESCRIPTOR
;-------------------------------------------------------------------------------
doGET_DESCRIPTOR:
; purpose:
; send descriptor data to host
; entry:
; DPTR - descriptor address
; A - descriptor length
; uses:
; Temp1 - descriptor length, total bytes counter
; Temp2 - min(wLength, 255), fifo bytes counter
; Temp3 - LO(descriptor address)
; Temp4 - HI(descriptor address)
; Temp5 - LO(destination address)
; Temp6 - HI(destination address)
; Temp7 - fifo bytes control
;-- save parameters
MOV Temp1, A
MOV Temp3, DPL
MOV Temp4, DPH
;-- compute min(wLength, 255)
MOV DPTR, #wLengthHi
MOVX A, @DPTR
JZ sd_lo
MOV A, #255
sd_lo:
MOV DPTR, #wLengthLo
MOV Temp2, A
MOVX A, @DPTR
ORL A, Temp2
MOV Temp2, A
;-- compute min(Temp1, Temp2)
CLR C
SUBB A, Temp1
JNC sd_t1
MOV A, Temp2
MOV Temp1, A
sd_t1:
sd_nf:
;-- compute min(Temp1, usbFIFOlen)
MOV A, #usbFIFOlen
MOV Temp2, A
MOV A, Temp1
CLR C
SUBB A, Temp2
JNC sd_ff
MOV A, Temp1
MOV Temp2, A
MOV A, #0
sd_ff:
MOV Temp1, A
MOV A, Temp2
MOV Temp7, A
;-- setup destination pointer
MOV DPTR, #usbFIFO
MOV Temp5, DPL
MOV Temp6, DPH
sd_nb:
;-- load data byte
MOV DPL, Temp3
MOV DPH, Temp4
MOVX A, @DPTR
INC DPTR
MOV Temp3, DPL
MOV Temp4, DPH
;-- store data byte
MOV DPL, Temp5
MOV DPH, Temp6
MOVX @DPTR, A
INC DPTR
MOV Temp5, DPL
MOV Temp6, DPH
;-- maintain fifo counter
MOV A, Temp2
DEC A
MOV Temp2, A
JNZ sd_nb
;-- validate fifo
MOV DPTR, #usbCTRL
MOV A, Temp7
ORL A, #usbCTRLread
MOVX @DPTR, A
;-- wait for next transaction
MOV DPTR, #usbSTAT
sd_io:
MOVX A, @DPTR
ANL A, #usbSTATall
JZ sd_io
CJNE A, #usbSTATdata, sd_x ; early status stage
;-- maintain total counter
MOV A, Temp1
JNZ sd_nf
;-- send zero-length package, if required
MOV A, #0
JMP ControlRead
sd_x:
JMP AcknowledgeStatus
;-------------------------------------------------------------------------------
doGET_STATUS:
MOV DPTR, #usbFIFO
MOVX @DPTR, A
INC DPTR
MOV A, #0
MOVX @DPTR, A
MOV A, #2
JMP ControlRead
;-------------------------------------------------------------------------------
NoDataControl:
MOV DPTR, #usbCTRL
MOV A, #usbCTRLwrite
MOVX @DPTR, A
JMP WaitForStatus
;-------------------
ControlRead:
MOV DPTR, #usbCTRL
ORL A, #usbCTRLread
MOVX @DPTR, A
JMP WaitForStatus
;-------------------
WaitForStatus:
MOV DPTR, #usbSTAT
w2: MOVX A, @DPTR
ANL A, #usbSTATall
CJNE A, #usbSTATstatus, w2
;--
AcknowledgeStatus:
MOV DPTR, #usbCTRL
MOV A, #usbCTRLstatus
MOVX @DPTR, A
RET
;-------------------------------------------------------------------------------
;* * * d a t a * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
;-------------------------------------------------------------------------------
;*** device descriptor *********************************************************
DevDescr:
DB 18, 1 ; Length, Type
DW 101H ; USB Rev 1.1
DB 0, 0, 0 ; Class, Subclass and Protocol
DB usbFIFOlen ; EP0 size
DB 0D0h, 0Bh ; Vendor ID 0x0BD0 (3024)
DB 0, 1 ; Product ID 0x0100
DB 0, 1 ; Version Rev 1.0
DB 1, 2, 0 ; Manufacturer, Product & Serial# Names
DB 1 ; #Configs
DevDescrLen EQU $ - DevDescr
;*** config descriptor *********************************************************
CfgDescr:
DB 9, 2 ; Length, Type
DB LOW(CfgDescrLen), HIGH(CfgDescrLen)
DB 1, 1, 3 ; #Interfaces, Configuration#, Config. Name
DB 10000000b ; Attributes = Bus Powered
DB 50 ; Max. Power is 50x2 = 100mA
;*** interface descriptor ******************************************************
IfDescr:
DB 9, 4 ; Length, Type
DB 0, 0, 1 ; No alternate setting, HID uses EP1
DB 3 ; Class = Human Interface Device
DB 0, 0 ; Subclass and Protocol
DB 4 ; Interface Name
;*** HID descriptor ************************************************************
HidDescr:
DB 9, 21H ; Length, Type
DB 0, 1 ; HID Class Specification compliance
DB 0 ; Country localization (=none)
DB 1 ; Number of descriptors to follow
DB 22H ; And it's a Report descriptor
DB LOW(RptDescrLen), HIGH(RptDescrLen)
HidDescrLen EQU $ - HidDescr
;*** endpoint descriptor *******************************************************
EpDescr:
DB 7, 5 ; Length, Type
DB 10000001b ; Address = IN 1
DB 00000011b ; Interrupt
DB 64, 0 ; Maximum packet size (this example only uses 1)
DB 100 ; Poll every 0.1 seconds
CfgDescrLen EQU $ - CfgDescr
;*** report descriptor *********************************************************
RptDescr: ; Generated with HID Tool, copied to here
DB 6, 0, 0FFH ; Usage_Page (Vendor Defined)
DB 9, 1 ; Usage (I/O Device)
DB 0A1H, 1 ; Collection (Application)
DB 19H, 1 ; Usage_Minimum (Button 1)
DB 29H, 8 ; Usage_Maximum (Button 8)
DB 15H, 0 ; Logical_Minimum (0)
DB 25H, 1 ; Logical_Maximum (1)
DB 75H, 1 ; Report_Size (1)
DB 95H, 8 ; Report_Count (8)
DB 81H, 2 ; Input (Data,Var,Abs)
DB 19H, 1 ; Usage_Minimum (Led 1)
DB 29H, 8 ; Usage_Maximum (Led 8)
DB 91H, 2 ; Output (Data,Var,Abs)
DB 0C0H ; End_Collection
RptDescrLen EQU $ - RptDescr
;*** string #0 *****************************************************************
String0: ; declare the UNICODE strings
DB 4, 3, 9, 4 ; english strings
;String0Len EQU $ - String0
;*** string #1 *****************************************************************
String1: ; Manufacturer
DB (String2-String1), 3 ; Length, Type
DB 'U',0,'S',0,'B',0,' ',0,'D',0,'e',0,'s',0,'i',0,'g',0,'n',0,' ',0
DB 'B',0,'y',0,' ',0,'E',0,'x',0,'a',0,'m',0,'p',0,'l',0,'e',0
;*** string #2 *****************************************************************
String2: ; Product Name
DB (String3-String2), 3
DB 'B',0,'u',0,'t',0,'t',0,'o',0,'n',0,'s',0,' ',0
DB '&',0,' ',0,'L',0,'i',0,'g',0,'h',0,'t',0,'s',0
;*** string #3 *****************************************************************
String3: ; Configuration Name
DB (String4-String3), 3
DB 'S',0,'i',0,'m',0,'p',0,'l',0,'e',0,' ',0,'I',0,'/',0
DB 'O',0,' ',0,'D',0,'e',0,'v',0,'i',0,'c',0,'e',0
;*** string #4 *****************************************************************
String4: ; Interface Name
DB (EndOfDescriptors-String4), 3
DB 'F',0,'i',0,'r',0,'s',0,'t',0,' ',0,'H',0,'I',0,'D',0
DB ' ',0,'E',0,'x',0,'a',0,'m',0,'p',0,'l',0,'e',0
EndOfDescriptors:
DW 0 ; Backstop for String Descriptors
;-------------------------------------------------------------------------------
END
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -