avr: improved module SK6812 and app MA_LIGHT.

- RGBW values are now only set by SK6812
- MA_LIGHT can now also take into account a brightness value reported
  by any node to switch on light only after dawn
This commit is contained in:
Martin Preuss
2025-09-22 15:09:45 +02:00
parent 42e477098c
commit 666e7690a6
15 changed files with 354 additions and 78 deletions

View File

@@ -27,14 +27,6 @@ AppMotionLight_Init:
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)
@@ -76,7 +68,7 @@ AppMotionLight_Every100ms:
AppMotionLight_Every100ms_ret:
ret
AppMotionLight_Every100ms_off:
rjmp appMotionLightTurnOff ; (r16, r17, r18, r19, r20, r21, r23)
rjmp appMotionLightTurnOff ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
; @end
@@ -112,6 +104,31 @@ appMotionLightHasSource_next:
; ---------------------------------------------------------------------------
; @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 appMotionLightStartTimer
;
@@ -130,14 +147,11 @@ appMotionLightStartTimer:
; ---------------------------------------------------------------------------
; @routine appMotionLightTurnOn
;
; @clobbers r18, r19, r20, r21 (r16, t17, r23)
; @clobbers r18 (r16, r17, r19, r20, r21, r23, r24, r25)
appMotionLightTurnOn:
lds r18, appMotionLightColor
lds r19, appMotionLightColor+1
lds r20, appMotionLightColor+2
lds r21, appMotionLightColor+3
rjmp SK6812_SetAllColor ; (r16, r17, r23)
ldi r18, 1
rjmp SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
; @end
@@ -145,14 +159,11 @@ appMotionLightTurnOn:
; ---------------------------------------------------------------------------
; @routine appMotionLightTurnOff
;
; @clobbers r18, r19, r20, r21 (r16, t17, r23)
; @clobbers r18 (r16, r17, r19, r20, r21, r23, r24, r25)
appMotionLightTurnOff:
clr r18
clr r19
clr r20
clr r21
rjmp SK6812_SetAllColor ; (r16, r17, r23)
rjmp SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
; @end
@@ -193,7 +204,27 @@ appMotionLightReadConfFromEeprom:
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
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_BSRC_ADDR)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_BSRC_ADDR)
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceAddr, r16
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_BSRC_VALUEID)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_BSRC_VALUEID)
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceValueId, r16
; read brightness limit
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_BSRC_VALUE)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_BSRC_VALUE)
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
@@ -215,21 +246,43 @@ appMotionLightWriteConfToEeprom:
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
lds r16, appMotionLightOnTime
rcall Utils_WriteEepromIncr ; (R17)
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightOnTime+1
rcall Utils_WriteEepromIncr ; (R17)
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Utils_WriteEepromIncr ; (R16)
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
rcall Utils_WriteEepromIncr ; (R16)
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 2
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Utils_WriteEepromIncr ; (R16)
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
rcall Utils_WriteEepromIncr ; (R16)
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