Files
aqhomecontrol/avr/apps/ma_light/main.asm
Martin Preuss 67be74d2ac avr: move timing control from ma_light to sk6812.
This allows for better control over the LED strip. We can now trigger the
LED strip externally (e.g. by setting a new RGBW value).
2026-03-24 23:13:28 +01:00

220 lines
5.7 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
rcall appMotionLightReadConfFromEeprom
ret
; @end
; ---------------------------------------------------------------------------
; @routine AppMotionLight_Fini @global
;
AppMotionLight_Fini:
ret
; @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 appMotionLightIsBrightnessSource
;
; @return CFLAGS set if we have a matching source entry, cleared otherwise
; @param r17 value id
; @param r22 source address
; @clobbers R16
appMotionLightIsBrightnessSource:
lds r16, appMotionLightLSourceAddr
cp r16, r22
brne appMotionLightIsBrightnessSource_no
lds r16, appMotionLightLSourceValueId
cp r16, r17
brne appMotionLightIsBrightnessSource_no
sec
rjmp appMotionLightIsBrightnessSource_ret
appMotionLightIsBrightnessSource_no:
clc
appMotionLightIsBrightnessSource_ret:
ret
; @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
bigcall SK6812_SetAutoTimerReload ; (none)
; 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
; read brightness source
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceAddr, r16
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceValueId, r16
; read brightness limit
rcall Utils_ReadEepromIncr ; (R16)
mov r18, r16
rcall Utils_ReadEepromIncr ; (R16)
mov r19, r16
sts appMotionLightLSourceValue, r18
sts appMotionLightLSourceValue+1, 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)
rcall SK6812_GetAutoTimerReload
mov r16, r18
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
mov r16, r19
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 2
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write brightness source
lds r16, appMotionLightLSourceAddr
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightLSourceValueId
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write brightness limit
lds r16, appMotionLightLSourceValue
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightLSourceValue+1
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
out SREG, r15
pop r15
ret
; @end