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).
This commit is contained in:
Martin Preuss
2026-03-24 23:13:28 +01:00
parent 42874f27cd
commit 67be74d2ac
10 changed files with 262 additions and 209 deletions

View File

@@ -27,11 +27,6 @@ AppMotionLight_Init:
ldi r17, (appMotionLightDataEnd-appMotionLightDataBegin)
rcall Utils_FillSram
ldi r16, LOW(APP_MOTIONLIGHT_DEFAULT_ONTIME)
sts appMotionLightOnTime, r16
ldi r16, HIGH(APP_MOTIONLIGHT_DEFAULT_ONTIME)
sts appMotionLightOnTime+1, r16
rcall appMotionLightReadConfFromEeprom
ret
@@ -44,31 +39,7 @@ AppMotionLight_Init:
;
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, r22, r23, r24, r25, X)
; @end
@@ -129,71 +100,6 @@ appMotionLightIsBrightnessSource_ret:
; ---------------------------------------------------------------------------
; @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 (r16, r17, r19, r20, r21, r22, r23, r24, r25, X)
appMotionLightTurnOn:
ldi r18, 1
rcall SK6812_SetState ; (R16, R17, R18, R19, R20, R21, R23, R24, R25)
ldi r18, 1
rjmp appMotionLightReportState ; (R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X)
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightTurnOff
;
; @clobbers r18 (r16, r17, r19, r20, r21, r22, r23, r24, r25, X)
appMotionLightTurnOff:
clr r18
rcall SK6812_SetState ; (R16, R17, R18, R19, R20, R21, R23, R24, R25)
clr r18
rjmp appMotionLightReportState ; (R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X)
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightReportState
;
; @param R18 state (0=off, 1=on)
; @clobbers (R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X)
appMotionLightReportState:
ldi r17, VALUE_ID_MAL_STATE
clr r19
ldi r20, 1
clr r21
ldi r22, AQHOME_VALUETYPE_ONOFF
push yl
push yh
rcall Main_SendValueReport ; (R16, R17, R18, R19, R20, R21, R23, R24, R25, X)
pop yh
pop yl
ret
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightReadConfFromEeprom
;
@@ -212,8 +118,7 @@ appMotionLightReadConfFromEeprom:
and r16, r18
cpi r16, 0xff
breq appMotionLightReadConfFromEeprom_end
sts appMotionLightOnTime, r18
sts appMotionLightOnTime+1, r19
bigcall SK6812_SetAutoTimerReload ; (none)
; read source 1
rcall Utils_ReadEepromIncr ; (R16)
@@ -265,10 +170,11 @@ appMotionLightWriteConfToEeprom:
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
lds r16, appMotionLightOnTime
rcall SK6812_GetAutoTimerReload
mov r16, r18
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightOnTime+1
mov r16, r19
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1