📄 hp_sensor.asm
字号:
set HP_SENSOR_SDIO_PIN ; SDIO HIGH
set HP_SENSOR_SCLK_PIN ; SCLK HIGH
;------------------------------------------------------------------------------
; Function : CheckHPSensorProductID
; Input : None
; Output : None
; Remark : Read product ID register until the data read out is HP_SENSOR_PRODUCT_ID
;------------------------------------------------------------------------------
CheckHPSensorProductID:
call WheelCheck ; 先Polling一次Z轴,提高灵敏度
;----------------------------------------------------------------------
; Remark : Match ID for ADNS2030
;----------------------------------------------------------------------
clr F_Sensor2030 ;
mov A, REG_2030_PRODUCT_ID ;
mov HPSensorAddress, A ;
call ReadHPSensor ;
xor A, ADNS2030_PRODUCT_ID ;
snz ZF ;
jmp CheckHPSensorProductIDFail
set F_Sensor2030 ;
jmp ExitCheckHPSensorProductID
CheckHPSensorProductIDFail:
call ButtonCheck ; (2004-07-21)
call DetermineMouseChange ; (03-17-2004)根据最新的Mouse状态来决定F_MouseChange是否为1
jmp RePowerOnSensor ; 从suspend状态wakeup起来时,直接ret可能SPI会出问题
ExitCheckHPSensorProductID:
;------------------------------------------------------------------------------
; Function : SetHPSensorDPI
; Input : None
; Output : None
; Remark : Set 400/800 dpi to HP_SENSOR configuration for ADNS2030 only
;------------------------------------------------------------------------------
SetHPSensorDPI:
snz F_Sensor2030 ; If ADNS2620 is selected,
jmp ExitSetHPSensorDPI ; then SetHPSensorDPI is skipped.
set SELECT0_PIN_CONTROL ; Set DPI select pin to INPUT
mov A, REG_2030_CONFIGURATION ;
mov HPSensorAddress, A ;
mov A, 00010000B ; Set ADNS-2030 800 dpi
snz SELECT0_PIN ;
mov A, 00000000B ; Set ADNS-2030 400 dpi
mov HPSensorData, A ;
call WriteHPSensor ;
ExitSetHPSensorDPI:
ret
;------------------------------------------------------------------------------
; Function : GetMouseDeltaXY
; Input : None
; Output : DeltaXCounter, DeltaYCounter
; Remark : Read DeltaX and DeltaY from HP_SENSOR
;------------------------------------------------------------------------------
GetMouseDeltaXY:
clr DeltaXCounter ; Clear DelatXCounter
clr DeltaYCounter ; Clear DeltaYCounter
snz F_Sensor2030 ;
jmp GetHPSensorDeltaX
Check2030Motion:
mov A, REG_2030_MOTION ;
mov HPSensorAddress, A ;
call ReadHPSensor ;
GetHPSensorDeltaX:
mov A, REG_2030_DELTA_X ;
mov HPSensorAddress, A ;
call ReadHPSensor ;
mov DeltaXCounter, A ;
GetHPSensorDeltaY:
mov A, REG_2030_DELTA_Y ;
mov HPSensorAddress, A ;
call ReadHPSensor ;
mov DeltaYCounter, A ;
CheckHPSensorSync:
ExitGetMouseDeltaXY:
jmp CheckHPSensorProductID ; Check sensor's SPI by checking its product ID
;------------------------------------------------------------------------------
; Function : WheelCheck
; Input : None
; Output : None
; Remark : Detect mouse wheel for Z-axis change
;------------------------------------------------------------------------------
@maybeps2 equ 0
WheelCheck: ; ZHistoryStatus store z_axis previous state
clr WDT ; Clear WDT
mov a, MOUSE_EVENT_PORT
and A, Z_AXIS_MASK ;
mov ZCurrentStatus,a
xor a,ZHistoryStatus
and a,z_axis_mask
snz z
jmp errorout_of_wheelcheck
sdz WheelDebounceTime
jmp ExitWheelCheck ; jmp for checking Z's level consistency
wheelcheck_cont:
mov A, Z_CONSISTENCY_DURATION
mov WheelDebounceTime,a
mov a,ZHistoryStatus
and a,Z_AXIS_MASK ;000000nnb
swap ACC
clr WheelFlag.5
clr WheelFlag.4
orm a,WheelFlag ;00nnxxxxb
mov a,WheelFlag
and a,11110000b
swap acc
wheel_pcl_17:
addm a,pcl
jmp z_process ;;;; 0 0 0 0 ;; status not change
jmp set_d_n ;;;; 0 0 0 1 ;; d -
jmp set_d_p ;;;; 0 0 1 0 ;; d +
jmp error_process ;;;; 0 0 1 1 ;; status not change
jmp cnt_add_j ;;;; 0 1 0 0 ;; if d + then counter + 1
jmp z_process ;;;; 0 1 0 1 ;; ststus not change
jmp error_process ;;;; 0 1 1 0 ;; signal error
jmp cnt_dec_j ;;;; 0 1 1 1 ;; if d- then counter - 1
jmp cnt_dec_j ;;;; 1 0 0 0 ;; if d- then counter - 1
jmp error_process ;;;; 1 0 0 1 ;; signal error
jmp z_process ;;;; 1 0 1 0 ;; status not change
jmp cnt_add_j ;;;; 1 0 1 1 ;; if d+ then counter + 1
jmp error_process ;;;; 1 1 0 0 ;; status not change
jmp set_d_p ;;;; 1 1 0 1 ;; d set +
jmp set_d_n ;;;; 1 1 1 0 ;; d set -
jmp z_process ;;;; 1 1 1 1 ;; status not change
cnt_add_j:
snz F_ZDirection
jmp setFlag
set DeltaZCounter
setflag:
set F_ZDirection
jmp Z_PROCESS
cnt_DEC_j:
sz F_ZDirection
jmp clrflag
mov a,01h
mov DeltaZCounter,a
clrflag:
clr F_ZDirection
jmp Z_PROCESS
set_D_N:
clr F_ZDirection
jmp z_process
set_d_p:
set F_ZDirection
Z_PROCESS:
error_process:
Exit_of_wheel_movement:
z_process1:
mov a,00111111b
and a, WheelFlag
mov WheelFlag, a
rl acc
rl acc
and a,11000000b
orm a, WheelFlag
ExitWheelCheck:
RET
errorout_of_wheelcheck:
mov A, Z_CONSISTENCY_DURATION
mov WheelDebounceTime,a
mov a,ZCurrentStatus
mov ZHistoryStatus,a
jmp ExitWheelCheck
;------------------------------------------------------------------------------
; Function : ButtonCheck
; Input : None
; Output : None
; Remark :
; Detect all the buttons change, and set F_MouseChange=1 if current
; button status is different from history button status.
;------------------------------------------------------------------------------
ButtonCheck:
mov A, 01111111b ;
mov MOUSE_EVENT_PORT_CONTROL, A ;
mov A, MOUSE_EVENT_PORT ; Get Port A
and A, BUTTON_EVENT_MASK ;
xor A, ButtonHistoryStatus ; Compare with previous state
sz ZF ;
jmp ExitButtonCheck
mov A, BUTTON_CONSISTENCY_DURATION ;
mov ButtonDebounceTime, A ; DebounceTime of button signal
mov A, MOUSE_EVENT_PORT ;
and A, BUTTON_EVENT_MASK ;
mov ButtonCurrentStatus, A ;
ButtonDebounceLoop:
mov A, MOUSE_EVENT_PORT ; Get current MOUSE_EVENT_PORT
and A, BUTTON_EVENT_MASK ;
xor A, ButtonCurrentStatus ; Compare with ButtonHistoryStatus
snz ZF ; If match?
jmp ExitButtonCheck ; Illegal pulse, abort
sdz ButtonDebounceTime ; Decrement DebounceTime
jmp ButtonDebounceLoop
set F_ButtonChange ; Set F_ButtonChange
CheckLButton:
clr F_LButton ; Default F_LButton=0
snz ButtonCurrentStatus.2
set F_LButton ; Set F_LButton=1(LButton pressed)
CheckRButton:
clr F_RButton ; Default F_RButton=0
snz ButtonCurrentStatus.3
set F_RButton ; Set F_RButton=1(RButton pressed)
CheckMButton:
clr F_MButton ; Default F_MButton=0
snz ButtonCurrentStatus.4
set F_MButton ; Set F_MButton=1(MButton pressed)
CheckRB0Button:
clr F_RB0Button ; Default F_RB0Button=0
snz ButtonCurrentStatus.5
set F_RB0Button ; Set F_RB0Button=1(RB0Button pressed)
CheckRB1Button:
clr F_RB1Button ; Default F_RB1Button=0
snz ButtonCurrentStatus.6
set F_RB1Button ; Set F_RB1Button=1(RB1Button pressed)
mov A, ButtonCurrentStatus ;
and A, BUTTON_EVENT_MASK ;
mov ButtonHistoryStatus, A ; Update ButtonHistoryStatus
ExitButtonCheck:
ret
;------------------------------------------------------------------------------
; Function : MoveMouseData
; Input : None
; Output : None
; Remark :
; 1. Copy mouse's button event to fifo_out1
; 2. Copy mouse's DeltaXCounter to fifo_out2
; 3. Copy mouse's DeltaYCounter to fifo_out3
; 4. Copy mouse's DeltaZCounter to fifo_out4
; 5. Reset F_MouseChange, F_ButtonChange, DeltaXCounter, DeltaYCounter, DeltaZCounter
;------------------------------------------------------------------------------
MoveMouseData:
clr F_MouseChange ; Clear F_MouseChange
clr F_ButtonChange ; Clear F_ButtonChange
mov A, MouseEvent ; Get MouseEvent
and A, MOUSE_EVENT_MASK ;
mov fifo_out1, A ; Output MouseEvent
mov A, DeltaXCounter ; Get DeltaXCounter
mov fifo_out2, A ; Output DeltaXCounter
clr DeltaXCounter ; Clear DeltaXCounter
mov A, DeltaYCounter ; Get DeltaYCounter
cpl ACC ;
inc ACC ;
mov fifo_out3, A ; Output DeltaYCounter
clr DeltaYCounter ; Clear DeltaYCounter
mov A, DeltaZCounter ; Get DeltaZCounter
cpl ACC ;
inc ACC ;
mov fifo_out4, A ; Output DeltaZCounter
clr DeltaZCounter ; Clear DeltaZCounter
ExitMoveMouseData:
ret
;------------------------------------------------------------------------------
; Function : MouseSuspend
; Input :
; Output :
; Remark : 将控制optical sensor的I/O line都输出LOW,避免mouse suspend时的漏电
;------------------------------------------------------------------------------
MouseSuspend:
set PAC ; Set PA to HIGH and disconnect HP_SENSOR(LED=HIGH)
clr HP_SENSOR_SDIO_CONTROL ; 将SDIO设成OUTPUT mode
clr HP_SENSOR_SDIO_PIN ;
clr HP_SENSOR_SCLK_PIN ;
clr SELECT0_PIN_CONTROL ;
clr SELECT0_PIN ; Output SELECT0_PIN to 0
clr SELECT1_PIN_CONTROL ;
clr SELECT1_PIN ; Output SELECT1_PIN to 0
ExitMouseSuspend:
ret
;------------------------------------------------------------------------------
END
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -