241 lines
6.1 KiB
NASM
241 lines
6.1 KiB
NASM
; ***************************************************************************
|
|
; copyright : (C) 2025 by Martin Preuss
|
|
; email : martin@libchipcard.de
|
|
;
|
|
; ***************************************************************************
|
|
; * This file is part of the project "AqHome". *
|
|
; * Please see toplevel file COPYING of that project for license details. *
|
|
; ***************************************************************************
|
|
|
|
|
|
; ***************************************************************************
|
|
; code
|
|
|
|
.cseg
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine AppMotionLight_Init @global
|
|
;
|
|
|
|
AppMotionLight_Init:
|
|
; preset SRAM data area
|
|
ldi xh, HIGH(appMotionLightDataBegin)
|
|
ldi xl, LOW(appMotionLightDataBegin)
|
|
clr r16
|
|
ldi r17, (appMotionLightDataEnd-appMotionLightDataBegin)
|
|
rcall Utils_FillSram
|
|
|
|
ldi xh, HIGH(appMotionLightColor)
|
|
ldi xl, LOW(appMotionLightColor)
|
|
clr r16
|
|
ldi r17, 0x80
|
|
st X+, r16 ; R
|
|
st X+, r16 ; G
|
|
st X+, r17 ; B
|
|
st X+, r16 ; WW
|
|
ldi r16, LOW(APP_MOTIONLIGHT_DEFAULT_ONTIME)
|
|
sts appMotionLightOnTime, r16
|
|
ldi r16, HIGH(APP_MOTIONLIGHT_DEFAULT_ONTIME)
|
|
sts appMotionLightOnTime+1, r16
|
|
|
|
rcall appMotionLightReadConfFromEeprom
|
|
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine AppMotionLight_Fini @global
|
|
;
|
|
|
|
AppMotionLight_Fini:
|
|
clr r16
|
|
sts appMotionLightTimer, r16 ; clear timer
|
|
sts appMotionLightTimer+1, r16
|
|
rjmp appMotionLightTurnOff
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine AppMotionLight_Every100ms @global
|
|
;
|
|
; @clobbers r16, r24, r26, (r17, r18, r19, r20, r21, r23)
|
|
|
|
AppMotionLight_Every100ms:
|
|
lds r24, appMotionLightTimer
|
|
lds r25, appMotionLightTimer+1
|
|
sbiw r25:r24, 1
|
|
brcs AppMotionLight_Every100ms_ret
|
|
sts appMotionLightTimer, r24
|
|
sts appMotionLightTimer+1, r25
|
|
breq AppMotionLight_Every100ms_off
|
|
AppMotionLight_Every100ms_ret:
|
|
ret
|
|
AppMotionLight_Every100ms_off:
|
|
rjmp appMotionLightTurnOff ; (r16, r17, r18, r19, r20, r21, r23)
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightHasSource
|
|
;
|
|
; @return CFLAGS set if we have a matching source entry, cleared otherwise
|
|
; @param r17 value id
|
|
; @param r22 source address
|
|
; @clobbers r16, r24, Y
|
|
|
|
appMotionLightHasSource:
|
|
ldi yl, LOW(appMotionLightSources)
|
|
ldi yh, HIGH(appMotionLightSources)
|
|
ldi r24, APP_MOTIONLIGHT_SOURCE_NUM
|
|
appMotionLightHasSource_loop:
|
|
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
|
cp r16, r22
|
|
brne appMotionLightHasSource_next
|
|
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
|
cp r16, r17
|
|
brne appMotionLightHasSource_next
|
|
sec
|
|
ret
|
|
appMotionLightHasSource_next:
|
|
adiw yh:yl, APP_MOTIONLIGHT_SOURCE_SIZE
|
|
dec r24
|
|
brne appMotionLightHasSource_loop
|
|
clc
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightStartTimer
|
|
;
|
|
; @clobbers r16
|
|
|
|
appMotionLightStartTimer:
|
|
lds r16, appMotionLightOnTime
|
|
sts appMotionLightTimer, r16
|
|
lds r16, appMotionLightOnTime+1
|
|
sts appMotionLightTimer+1, r16
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightTurnOn
|
|
;
|
|
; @clobbers r18, r19, r20, r21 (r16, t17, r23)
|
|
|
|
appMotionLightTurnOn:
|
|
lds r18, appMotionLightColor
|
|
lds r19, appMotionLightColor+1
|
|
lds r20, appMotionLightColor+2
|
|
lds r21, appMotionLightColor+3
|
|
rjmp SK6812_SetAllColor ; (r16, r17, r23)
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightTurnOff
|
|
;
|
|
; @clobbers r18, r19, r20, r21 (r16, t17, r23)
|
|
|
|
appMotionLightTurnOff:
|
|
clr r18
|
|
clr r19
|
|
clr r20
|
|
clr r21
|
|
rjmp SK6812_SetAllColor ; (r16, r17, r23)
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightReadConfFromEeprom
|
|
;
|
|
; @clobbers
|
|
|
|
appMotionLightReadConfFromEeprom:
|
|
push r15
|
|
in r15, SREG
|
|
cli
|
|
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
|
|
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r18, r16
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r19, r16
|
|
and r16, r18
|
|
cpi r16, 0xff
|
|
breq appMotionLightReadConfFromEeprom_end
|
|
sts appMotionLightOnTime, r18
|
|
sts appMotionLightOnTime+1, r19
|
|
|
|
; read source 1
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r18, r16
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r19, r16
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR, r18
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID, r19
|
|
|
|
; read source 2
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r18, r16
|
|
rcall Utils_ReadEepromIncr ; (R16)
|
|
mov r19, r16
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR, r18
|
|
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID, r19
|
|
|
|
appMotionLightReadConfFromEeprom_end:
|
|
out SREG, r15
|
|
pop r15
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine appMotionLightWriteConfToEeprom
|
|
;
|
|
; @clobbers r16, r17, X
|
|
|
|
appMotionLightWriteConfToEeprom:
|
|
push r15
|
|
in r15, SREG
|
|
cli
|
|
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
|
|
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
|
|
|
|
lds r16, appMotionLightOnTime
|
|
rcall Utils_WriteEepromIncr ; (R17)
|
|
lds r16, appMotionLightOnTime+1
|
|
rcall Utils_WriteEepromIncr ; (R17)
|
|
|
|
; write source 1
|
|
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
|
rcall Utils_WriteEepromIncr ; (R16)
|
|
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
|
rcall Utils_WriteEepromIncr ; (R16)
|
|
|
|
; write source 2
|
|
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
|
rcall Utils_WriteEepromIncr ; (R16)
|
|
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
|
rcall Utils_WriteEepromIncr ; (R16)
|
|
|
|
out SREG, r15
|
|
pop r15
|
|
ret
|
|
; @end
|
|
|
|
|
|
|