?? mouse45b.asm
字號:
dec A ; check if idle_period <= idle_period_counter
cmp A, [idle_period_counter]
jnc Nosend
send_packet:
iord USB_EP1_TX_Config
and A, 80h
cmp A, 80h
jz Nosend
mov A, [horizontal]
mov [horiz_position], A
mov A, [vertical]
mov [vert_position], A
mov A, [buttons]
mov [button_position], A
iord USB_EP1_TX_Config
and A, DataToggle ; keep the data 0/1 bit
or A, 93h ; enable transmit 3 bytes
iowr USB_EP1_TX_Config
mov A,[new_idle_flag] ;if it received a new idle
cmp A,0 ;period 4 ms before the previous one
jz prev_idle ;counted finishes, need to upgrade
mov A,[new_idle_period] ;with a new value
mov [idle_period],A
mov A,0
mov [new_idle_flag],A
jmp reset_idle_period_counter
prev_idle: ;
; mov A,[prev_idle_period]
; mov [idle_period],A
reset_idle_period_counter:
mov A,0
mov [idle_period_counter],A
mov [horizontal], A
mov [vertical], A
mov [button_flag], A
Nosend:
jmp main
;========================================================================
; Read the mouse buttons. If the buttons have changed from the last
; value read, then enable data transmission from endpoint one.
;
; Hardware has buttons in MRL order. We need to translate them
; to data bits [2:0].
;
; Port 0 bit[6] Middle => bit 2
; Port 0 bit[5] Right => bit 1
; Port 0 bit[4] Left => bit 0
;
ReadButtons:
mov A, [button1_deb]
cmp A, 0h
jnz DoneButtons
mov A, [port_temp]
cpl A ; buttons are now 1 when pressed
asr ; [6:4] => [5:3]
asr ; [5:3] => [4:2]
asr ; [4:2] => [3:1]
asr ; [3:1] => [2:0]
and A, 7h ; mask out non-buttons
cmp A,[buttons] ; have buttons changed?
jz DoneButtons
mov [buttons], A ; move buttons to dma buffer
mov A, 01h
mov [button_flag], A
mov A, 01h
mov [button1_deb], A
DoneButtons:
ret ; return to main loop
;========================================================================
; This is a state transition table (16 bytes) that has four input bits:
; bit [3:2] previous state
; bit [1:0] current state
;
; The state sequences are:
; 00 => 01 => 11 => 10 increment
; 00 => 10 => 11 => 01 decrement
;
; 00 00 => 0 00 01 => 1 00 10 => -1 00 11 => 0
; 01 00 => -1 01 01 => 0 01 10 => 0 01 11 => 1
; 10 00 => 1 10 01 => 0 10 10 => 0 10 11 => -1
; 11 00 => 0 11 01 => -1 11 10 => 1 11 11 => 0
;
; The count stays the same if either the states are the same or the
; state changed by two transitions (jump).
;
XPAGEOFF ; do not insert XPAGE instructions in a table
StateTable:
db 0, 1, -1, 0
db -1, 0, 0, 1
db 1, 0, 0, -1
db 0, -1, 1, 0
XPAGEON ; insert XPAGE instructions automatically
; If the wheels are configured backwards the StateTable matrix
; 1's and -1's should be exchanged to flip the x and y directions.
; If only one direction has its wheels configured backwards then
; two seperate StateTables should be used and one of them will
; need the 1 to -1 and vice versa exchange.
; A wheel is configured backwards if the two phototransistors
; associated with it are connected in opposite order to this
; reference design.
;========================================================================
; Check for horizontal movement of the mouse.
;
CheckHorizontal:
mov A, [port_temp] ; load current state
and A, 3h ; mask out the rest of the bits
push A ; save the current state on stack
or A, [horiz_state] ; include the previous state
index StateTable ; read increment from PROM
add A, [horizontal] ; add increment
mov [horizontal], A
pop A ; restore current state from stack
asl ; bit[1:0] => bit[2:1]
asl ; bit[2:1] => bit[3:2]
mov [horiz_state],A ; update previous state in memory
ret
;========================================================================
; Check for vertical movement of the mouse. The first time I tried this,
; the horizontal movement worked and the vertical movement was backward.
; To correct the problem, the current and next states are switched in the
; check vertical routine when compared with the horizontal states.
;
CheckVertical:
mov A, [port_temp] ; load current state
and A, 0ch ; mask out the rest of the bits
push A ; save the current state on stack
or A, [vert_state] ; include the previous state
index StateTable ; read increment from PROM
add A, [vertical] ; add increment
mov [vertical], A
pop A ; restore current state from stack
asr A ; bit[3:2] => bit[2:1]
asr A ; bit[2:1] => bit[1:0]
mov [vert_state],A ; update previous state in memory
ret
;*******************************************************
;
; Interrupt handler: endpoint_zero
; Purpose: This interrupt routine handles the specially
; reserved control endpoint 0 and parses setup
; packets. If a IN or OUT is received, this
; handler returns to the control_read
; or no_data_control routines to send more data.
;
;*******************************************************
;========================================================================
; The endpoint zero interrupt service routine supports the control
; endpoint. This firmware enumerates and configures the hardware.
USB_EP0_ISR:
push A ; save accumulator on stack
iord USB_EP0_RX_Status ; load status register into accumulator
and A, 01h ; check if SETUP packet received
jz ep0_continue ; ignore unless SETUP packet
mov A,[interrupt_mask] ; disable endpoint zero interrupts
and A, 0F7h
mov [interrupt_mask], A
iowr Global_Interrupt
call StageOne ; parse SETUP packet
mov A, [interrupt_mask] ; enable endpoint zero interrupts
or A, 08h
mov [interrupt_mask], A
ep0_continue:
mov A, [interrupt_mask] ; enable the interrupts
ipret Global_Interrupt
;========================================================================
; stage one ... test bmRequestType
;========================================================================
StageOne:
;------------------------------------------------------------------------
; Parse standard device requests as per Table 9.2 in USB Spec.
;------------------------------------------------------------------------
mov A, 00h ; clear the setup flag to write DMA
iowr USB_EP0_RX_Status
mov A, 8 ; set BadOut bit
iowr USB_Status_Control
mov A, [bmRequestType] ; load bmRequestType
; host to device
cmp A, 00h
jz RequestType00 ; bmRequestType = 00000000 device
; cmp A, 01h *** not required ***
; jz RequestType01 ; bmRequestType = 00000001 interface
cmp A, 02h
jz RequestType02 ; bmRequestType = 00000010 endpoint
cmp A, 80h
; device to host
jz RequestType80 ; bmRequestType = 10000000 device
cmp A, 81h
jz RequestType81 ; bmRequestType = 10000001 interface
cmp A, 82h
jz RequestType82 ; bmRequestType = 10000010 endpoint
;-----------------------------------------------------------------------
; Parse HID class device requests as per HID version 1.0 Draft #4
;-----------------------------------------------------------------------
; host to device
cmp A, 21h
jz RequestType21 ; bmRequestType = 00100001 interface
cmp A, 22h ; *** not in HID spec ***
jz RequestType22 ; bmRequestType = 00100010 endpoint
; device to host
cmp A, A1h
jz RequestTypeA1 ; bmRequestType = 10100001 interface
cmp A, A2h ; *** not in HID spec ***
jz RequestTypeA2 ; bmRequestType = 10100010 interface
;-----------------------------------------------------------------------
; Stall unsupported functions
;-----------------------------------------------------------------------
SendStall: ; stall unsupported functions
mov A, A0h ; send a stall to indicate the requested
iowr USB_EP0_TX_Config ; function is not supported
ret ; return
;========================================================================
; stage two ... test bRequest
;========================================================================
; host to device with device as recipient
RequestType00:
mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; The only standard feature defined for a "device" recipient is
; device_remote_wakeup. Remote wakeup is the ability to "wakeup" a
; system from power down mode by pressing a key or moving a button.
; The default condition at reset is remote wakeup disabled.
;------------------------------------------------------------------------
; Clear Feature bRequest = 1
cmp A, clear_feature
jz ClearRemoteWakeup
; Set Feature bRequest = 3
cmp A, set_feature
jz SetRemoteWakeup
;------------------------------------------------------------------------
; Set the device address to a non-zero value.
; Set Address bRequest = 5
cmp A, set_address
jz SetAddress
;------------------------------------------------------------------------
; This request is optional. If a device supports this request, existing
; device descriptors may be updated or new descriptors may be added.
; Set Descriptor bRequest = 7 *** not supported ***
;------------------------------------------------------------------------
; If wValue is zero, the device is unconfigured. The only other legal
; configuration for this version of firmware is one.
; Set Configuration bRequest = 9
cmp A, set_configuration
jz SetConfiguration
jmp SendStall ; stall unsupported function calls
;========================================================================
; host to device with interface as recipient *** not required ***
; RequestType01:
; mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; There are no interface features defined in the spec.
; Clear Feature bRequest = 1 *** not supported ***
; Set Feature bRequest = 3 *** not supported ***
;------------------------------------------------------------------------
; This request allows the host to select an alternate setting for the
; specified interface. As the mouse only has one interface setting,
; this request is not supported.
; Set Interface bRequest = 11 *** not supported ***
; jmp SendStall ; stall unsupported functions
;========================================================================
; host to device with endpoint as recipient
RequestType02:
mov A, [bRequest] ; load bRequest
;------------------------------------------------------------------------
; The only standard feature defined for an endpoint is endpoint_stalled.
; Clear Feature bRequest = 1
cmp A, clear_feature
jz ClearEndpointStall
; Set Feature bRequest = 3
cmp A, set_feature
jz SetEndpointStall
jmp SendStall ; stall unsupported functions
;=======================================================================
; device to host with device as recipient
RequestType80:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetDeviceStatus
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
; Get Configuration bRequest = 8
cmp A, get_configuration
jz GetConfiguration
jmp SendStall ; stall unsuported functions
;=======================================================================
; device to host with interface as recipient
RequestType81:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetInterfaceStatus
;------------------------------------------------------------------------
; This request returns the selected alternate setting for the specified
; interface. There are no alternate settings for the mouse.
; Get Interface bRequest = 10 *** not supported ***
;------------------------------------------------------------------------
; HID class defines one more request for bmRequestType=10000001
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
jmp SendStall ; stall unsupported functions
;=======================================================================
; device to host with endpoint as recipient
RequestType82:
mov A, [bRequest] ; load bRequest
; Get Status bRequest = 0
cmp A, get_status
jz GetEndpointStatus
;------------------------------------------------------------------------
; Not defined in the spec, but it must be decoded for the enumeration to
; complete under Memphis.
; Get Descriptor bRequest = 6
cmp A, get_descriptor
jz GetDescriptor
; Sync Frame bRequest = 12 *** not supported ***
jmp SendStall ; stall unsupported functions
;========================================================================
; Now parse HID class Descriptor Types
;========================================================================
; host to device with endpoint as recipient
RequestType21:
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -