📄 csdhl.asm
字号:
mov [X+CSD_waSnsDiff+MSB], 0
.InitLowBaselineReset:
mov A, X
asr A
mov X, A
RAM_SETPAGE_IDX >CSD_LowBaselineReset
mov A, [CSD_bLowBaselineReset]
mov [X+CSD_baLowBaselineReset], A
.EndofUpdateSensorBaseline:
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_bIsSensorActive(BYTE bSensorNum)
;
; DESCRIPTION:
; Returns state of one sensor. Updates the baSnsOnMask array.
; Implements hysteresis based on the Hysteresis parameter.
;-----------------------------------------------------------------------------
; STACK USAGE: 3 BYTES
;
; ARGUMENTS:
; A => sensor index
;
; RETURNS:
; A => 1 if sensor is active, 0 otherwise
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_bIsSensorActive:
_CSD_bIsSensorActive:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
RAM_X_POINTS_TO_INDEXPAGE
push A
mov X,A
RAM_SETPAGE_IDX >CSD_baBtnFThreshold
mov A, [X+CSD_baBtnFThreshold]
mov [CSD_wTmpBtnFThreshold+LSB], A
mov [CSD_wTmpBtnFThreshold+MSB], 0
pop A
push A
call CSD_GetOnMask
RAM_SETPAGE_IDX >CSD_baSnsOnMask
and A, [X+CSD_baSnsOnMask]
jnz .WasOn
.WasOff:
; Check the difference counts against the threshold
mov A, [CSD_bHysteresis]
add [CSD_wTmpBtnFThreshold+LSB], A
adc [CSD_wTmpBtnFThreshold+MSB], 0
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_waSnsDiff
mov A, [X+CSD_waSnsDiff+LSB]
sub A, [CSD_wTmpBtnFThreshold+LSB]
mov A, [X+CSD_waSnsDiff+MSB]
sbb A, [CSD_wTmpBtnFThreshold+MSB]
jc .NotActive
mov A, X
asr A
mov X, A
RAM_SETPAGE_IDX >CSD_baSnsDebounce
mov A, [X+CSD_baSnsDebounce]
dec A
mov [X+CSD_baSnsDebounce], A
push A
mov A, X
asl A
mov X, A
pop A
jnz .NotActiveDebouncing
jmp .Active
.WasOn:
; Check the difference counts against the threshold
mov A, [CSD_bHysteresis]
sub [CSD_wTmpBtnFThreshold+LSB], A
sbb [CSD_wTmpBtnFThreshold+MSB], 0
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_waSnsDiff
mov A, [X+CSD_waSnsDiff+LSB]
sub A, [CSD_wTmpBtnFThreshold+LSB]
mov A, [X+CSD_waSnsDiff+MSB]
sbb A, [CSD_wTmpBtnFThreshold+MSB]
jc .NotActive
.Active:
mov A, X
asr A
call CSD_GetOnMask
RAM_SETPAGE_IDX >CSD_baSnsOnMask
or [X+CSD_baSnsOnMask], A
mov A, 1
jmp .EndIsSensorActive
.NotActive:
mov A, X
asr A
push A
call CSD_GetOnMask
cpl A
RAM_SETPAGE_IDX >CSD_baSnsOnMask
and [X+CSD_baSnsOnMask], A
RAM_SETPAGE_IDX >CSD_baSnsDebounce
pop X
mov A, [CSD_bDebounce]
mov [X+CSD_baSnsDebounce], A
mov A, 0
jmp .EndIsSensorActive
.NotActiveDebouncing:
mov A, X
asr A
call CSD_GetOnMask
cpl A
RAM_SETPAGE_IDX >CSD_baSnsOnMask
and [X+CSD_baSnsOnMask], A
mov A, 0
.EndIsSensorActive:
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
CSD_GetOnMask:
_CSD_GetOnMask:
push A
asr A
asr A
asr A
mov X, A
pop A
and A, 7h
index CSD_bitlookup
ret
.LITERAL
CSD_bitlookup:
db 01h, 02h, 04h, 08h, 10h, 20h, 40h, 80h
.ENDLITERAL
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_SetDefaultFingerThresholds(void)
;
; DESCRIPTION:
; Sets the FingerThreshold RAM array to the user module parameter value
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None.
; RETURNS: None
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_SetDefaultFingerThresholds:
_CSD_SetDefaultFingerThresholds:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_X_POINTS_TO_INDEXPAGE
RAM_SETPAGE_IDX >CSD_baBtnFThreshold
mov A,CSD_TotalSensorCount ; Check if key value in range.
dec A
.ThresholdLoop: ; Loop through all sensors and scan
push A
mov X, A
mov [X+CSD_baBtnFThreshold], CSD_FINGER_THRESHOLD
pop A
dec A
jnc .ThresholdLoop
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_InitializeBaselines(void)
;
; DESCRIPTION:
; Scans all sensors to find their initial raw count values and loads these
; into the baseline
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None.
; RETURNS: None
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_InitializeBaselines:
_CSD_InitializeBaselines:
RAM_PROLOGUE RAM_USE_CLASS_3
mov A,CSD_TotalSensorCount ; Get sensor num
dec A
.BaselineLoop: ; Loop through all sensors and scan
push A
call CSD_ScanSensor
RAM_X_POINTS_TO_INDEXPAGE
pop A
push A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_waSnsResult
mov A, [X+CSD_waSnsResult+LSB]
RAM_SETPAGE_IDX >CSD_waSnsBaseline
mov [X+CSD_waSnsBaseline+LSB], A
RAM_SETPAGE_IDX >CSD_waSnsResult
mov A, [X+CSD_waSnsResult+MSB]
RAM_SETPAGE_IDX >CSD_waSnsBaseline
mov [X+CSD_waSnsBaseline+MSB], A
pop A
dec A
jnc .BaselineLoop
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_InitializeSensorBaseline(BYTE bSensorNum)
;
; DESCRIPTION:
; Scans all sensors to find their initial raw count values and loads these
; into the baseline
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None.
; RETURNS: None
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_InitializeSensorBaseline:
_CSD_InitializeSensorBaseline:
RAM_PROLOGUE RAM_USE_CLASS_3
push A
call CSD_ScanSensor
RAM_X_POINTS_TO_INDEXPAGE
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_waSnsResult
mov A, [X+CSD_waSnsResult+LSB]
RAM_SETPAGE_IDX >CSD_waSnsBaseline
mov [X+CSD_waSnsBaseline+LSB], A
RAM_SETPAGE_IDX >CSD_waSnsResult
mov A, [X+CSD_waSnsResult+MSB]
RAM_SETPAGE_IDX >CSD_waSnsBaseline
mov [X+CSD_waSnsBaseline+MSB], A
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_bIsAnySensorActive(void)
;
; DESCRIPTION:
; Checks to see if any sensor is currently active
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None.
; RETURNS: 1 if any active, 0 if none active
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_bIsAnySensorActive:
_CSD_bIsAnySensorActive:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
mov [CSD_fIsPressed], 0
mov A,CSD_TotalSensorCount
dec A
.ThresholdLoop: ; Loop through all sensors
push A
call CSD_bIsSensorActive
cmp A, 1
jnz .NotActive
mov [CSD_fIsPressed], 1
.NotActive:
pop A
dec A
jnc .ThresholdLoop
mov A, [CSD_fIsPressed]
.NoneActive:
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_UpdateAllBaselines(void)
;
; DESCRIPTION:
; Scans all sensors to find their raw count values
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS: None.
; RETURNS: None
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
; of this function. The same is true for all RAM page pointer registers in
; the Large Memory Model. When necessary, it is the calling function's
; responsibility to perserve their values across calls to fastcall16
; functions.
;
CSD_UpdateAllBaselines:
_CSD_UpdateAllBaselines:
RAM_PROLOGUE RAM_USE_CLASS_4
mov A,CSD_TotalSensorCount
dec A
.ThresholdLoop: ; Loop through all sensors
push A
call CSD_UpdateSensorBaseline
pop A
dec A
jnc .ThresholdLoop
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
IF CSD_SLIDERS_EXIST
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_wGetCentroidPos(BYTE bSnsGroup)
;
; DESCRIPTION:
; Checks the difference array for a centroid. If one exists, the offset
; (within the whole difference arrary) and length are placed in the
; bCentroidLength and bCentroidStart variables.
;
; Then the function finds and returns the position of the centroid in the
; difference array.
;
;-----------------------------------------------------------------------------
;
; ARGUMENTS:
; A => Sensor Group
; Sensor Group = 0 for the independent sensors group
; Sensor Group = 1 for the first slider group
; Sensor Group = 2 for the second slider group
;
; RETURNS:
; iCtrdPos -> position of the centroid
;
; SIDE EFFECTS:
; The A and X registers may be modified by this or future implementations
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -