📄 csd_1hl.asm
字号:
;
; 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_1_bIsSensorActive:
_CSD_1_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_1_baBtnFThreshold
mov A, [X+CSD_1_baBtnFThreshold]
mov [CSD_1_wTmpBtnFThreshold+LSB], A
mov [CSD_1_wTmpBtnFThreshold+MSB], 0
pop A
push A
call CSD_1_GetOnMask
RAM_SETPAGE_IDX >CSD_1_baSnsOnMask
and A, [X+CSD_1_baSnsOnMask]
jnz .WasOn
.WasOff:
; Check the difference counts against the threshold
add [CSD_1_wTmpBtnFThreshold+LSB], CSD_1_HYSTERESIS
adc [CSD_1_wTmpBtnFThreshold+MSB], 0
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_1_waSnsDiff
mov A, [X+CSD_1_waSnsDiff+LSB]
sub A, [CSD_1_wTmpBtnFThreshold+LSB]
mov A, [X+CSD_1_waSnsDiff+MSB]
sbb A, [CSD_1_wTmpBtnFThreshold+MSB]
jc .NotActive
mov A, X
asr A
mov X, A
RAM_SETPAGE_IDX >CSD_1_baSnsDebounce
mov A, [X+CSD_1_baSnsDebounce]
dec A
mov [X+CSD_1_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
sub [CSD_1_wTmpBtnFThreshold+LSB], CSD_1_HYSTERESIS
sbb [CSD_1_wTmpBtnFThreshold+MSB], 0
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_1_waSnsDiff
mov A, [X+CSD_1_waSnsDiff+LSB]
sub A, [CSD_1_wTmpBtnFThreshold+LSB]
mov A, [X+CSD_1_waSnsDiff+MSB]
sbb A, [CSD_1_wTmpBtnFThreshold+MSB]
jc .NotActive
.Active:
mov A, X
asr A
call CSD_1_GetOnMask
RAM_SETPAGE_IDX >CSD_1_baSnsOnMask
or [X+CSD_1_baSnsOnMask], A
mov A, 1
jmp .EndIsSensorActive
.NotActive:
mov A, X
asr A
push A
call CSD_1_GetOnMask
cpl A
RAM_SETPAGE_IDX >CSD_1_baSnsOnMask
and [X+CSD_1_baSnsOnMask], A
RAM_SETPAGE_IDX >CSD_1_baSnsDebounce
pop X
mov [X+CSD_1_baSnsDebounce], CSD_1_Debounce
mov A, 0
jmp .EndIsSensorActive
.NotActiveDebouncing:
mov A, X
asr A
call CSD_1_GetOnMask
cpl A
RAM_SETPAGE_IDX >CSD_1_baSnsOnMask
and [X+CSD_1_baSnsOnMask], A
mov A, 0
.EndIsSensorActive:
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
CSD_1_GetOnMask:
_CSD_1_GetOnMask:
push A
asr A
asr A
asr A
mov X, A
pop A
and A, 7h
index CSD_1_bitlookup
ret
.LITERAL
CSD_1_bitlookup:
db 01h, 02h, 04h, 08h, 10h, 20h, 40h, 80h
.ENDLITERAL
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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_1_SetDefaultFingerThresholds:
_CSD_1_SetDefaultFingerThresholds:
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_X_POINTS_TO_INDEXPAGE
RAM_SETPAGE_IDX >CSD_1_baBtnFThreshold
mov A,CSD_1_TotalSensorCount ; Check if key value in range.
dec A
.ThresholdLoop: ; Loop through all sensors and scan
push A
mov X, A
mov [X+CSD_1_baBtnFThreshold], FINGER_THRESHOLD
pop A
dec A
jnc .ThresholdLoop
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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_1_InitializeBaselines:
_CSD_1_InitializeBaselines:
RAM_PROLOGUE RAM_USE_CLASS_3
mov A,CSD_1_TotalSensorCount ; Get sensor num
dec A
.BaselineLoop: ; Loop through all sensors and scan
push A
call CSD_1_ScanSensor
RAM_X_POINTS_TO_INDEXPAGE
pop A
push A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_1_waSnsResult
mov A, [X+CSD_1_waSnsResult+LSB]
RAM_SETPAGE_IDX >CSD_1_waSnsBaseline
mov [X+CSD_1_waSnsBaseline+LSB], A
RAM_SETPAGE_IDX >CSD_1_waSnsResult
mov A, [X+CSD_1_waSnsResult+MSB]
RAM_SETPAGE_IDX >CSD_1_waSnsBaseline
mov [X+CSD_1_waSnsBaseline+MSB], A
pop A
dec A
jnc .BaselineLoop
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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_1_InitializeSensorBaseline:
_CSD_1_InitializeSensorBaseline:
RAM_PROLOGUE RAM_USE_CLASS_3
push A
call CSD_1_ScanSensor
RAM_X_POINTS_TO_INDEXPAGE
pop A
asl A
mov X, A
RAM_SETPAGE_IDX >CSD_1_waSnsResult
mov A, [X+CSD_1_waSnsResult+LSB]
RAM_SETPAGE_IDX >CSD_1_waSnsBaseline
mov [X+CSD_1_waSnsBaseline+LSB], A
RAM_SETPAGE_IDX >CSD_1_waSnsResult
mov A, [X+CSD_1_waSnsResult+MSB]
RAM_SETPAGE_IDX >CSD_1_waSnsBaseline
mov [X+CSD_1_waSnsBaseline+MSB], A
RAM_EPILOGUE RAM_USE_CLASS_3
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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_1_bIsAnySensorActive:
_CSD_1_bIsAnySensorActive:
RAM_PROLOGUE RAM_USE_CLASS_4
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
mov [CSD_1_fIsPressed], 0
mov A,CSD_1_TotalSensorCount
dec A
.ThresholdLoop: ; Loop through all sensors
push A
call CSD_1_bIsSensorActive
cmp A, 1
jnz .NotActive
mov [CSD_1_fIsPressed], 1
.NotActive:
pop A
dec A
jnc .ThresholdLoop
mov A, [CSD_1_fIsPressed]
.NoneActive:
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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_1_UpdateAllBaselines:
_CSD_1_UpdateAllBaselines:
RAM_PROLOGUE RAM_USE_CLASS_4
mov A,CSD_1_TotalSensorCount
dec A
.ThresholdLoop: ; Loop through all sensors
push A
call CSD_1_UpdateSensorBaseline
pop A
dec A
jnc .ThresholdLoop
RAM_EPILOGUE RAM_USE_CLASS_4
ret
.ENDSECTION
IF CSD_1_SLIDERS_EXIST
.SECTION
;-----------------------------------------------------------------------------
; FUNCTION NAME: CSD_1_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
; 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_1_wGetCentroidPos:
_CSD_1_wGetCentroidPos:
; Legacy function name labels below, do not use for new designs
CSD_1_bGetCentroidPos:
_CSD_1_bGetCentroidPos:
CSD_1_iGetCentroidPos:
_CSD_1_iGetCentroidPos:
; End legacy function names
RAM_PROLOGUE RAM_USE_CLASS_3
RAM_SETPAGE_CUR 0 ; direct access ram will always be in interrupt ram area
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -