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

@@ -16,10 +16,13 @@
appMotionLightDataBegin:
appMotionLightTimer: .byte 2
appMotionLightOnTime: .byte 2
appMotionLightColor: .byte 4
appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE
appMotionLightTimer: .byte 2
appMotionLightOnTime: .byte 2
appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE
appMotionLightLSourceAddr: .byte 1
appMotionLightLSourceValueId: .byte 1
appMotionLightLSourceValue: .byte 2
appMotionLightLastBrightness: .byte 2
appMotionLightDataEnd:

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

View File

@@ -33,6 +33,8 @@ AppMotionLight_OnPacketReceived:
; "report value" message
AppMotionLight_OnPacketReceived_report:
rcall NETMSG_ValueRead ; (none)
rcall appMotionLightIsBrightnessSource ; (R16)
brcs AppMotionLight_OnPacketReceived_isBrightness
mov r16, r18
or r16, r19
breq AppMotionLight_OnPacketReceived_clcRet ; zero value, ignore
@@ -40,41 +42,62 @@ AppMotionLight_OnPacketReceived_report:
brcs AppMotionLight_OnPacketReceived_turnOn
ret
AppMotionLight_OnPacketReceived_turnOn:
lds r16, appMotionLightTimer
lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value?
tst r16
breq AppMotionLight_OnPacketReceived_checkTimer ; no, jmp and don't check brightness
lds r16, appMotionLightLastBrightness
lds r17, appMotionLightLastBrightness+1
tst r16
brne AppMotionLight_OnPacketReceived_checkBrightness
tst r17
breq AppMotionLight_OnPacketReceived_secRet ; we don't have a brightness value, keep light off
AppMotionLight_OnPacketReceived_checkBrightness:
lds r16, appMotionLightLSourceValue ; check last brightness reported
lds r17, appMotionLightLSourceValue+1
lds r24, appMotionLightLastBrightness
lds r25, appMotionLightLastBrightness+1
sub r16, r24
sbc r17, r25
brcs AppMotionLight_OnPacketReceived_secRet ; too bright to turn on
AppMotionLight_OnPacketReceived_checkTimer:
lds r16, appMotionLightTimer ; time up?
lds r17, appMotionLightTimer+1
or r16, r17
brne AppMotionLight_OnPacketReceived_startTimer
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
brne AppMotionLight_OnPacketReceived_startTimer ; no, just restart timer (light already on)
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
AppMotionLight_OnPacketReceived_startTimer:
rcall appMotionLightStartTimer
AppMotionLight_OnPacketReceived_secRet:
sec
ret
AppMotionLight_OnPacketReceived_isBrightness:
sts appMotionLightLastBrightness, r18
sts appMotionLightLastBrightness+1, r19
sec
ret
; "set value" message
AppMotionLight_OnPacketReceived_set:
rcall NETMSG_ValueRead ; (none)
cpi r17, VALUE_ID_MAL_RGBW_VALUE
breq AppMotionLight_OnPacketReceived_setRGBW
cpi r17, VALUE_ID_MAL_ONTIME
breq AppMotionLight_OnPacketReceived_setOnTime
cpi r17, VALUE_ID_MAL_SOURCE1
breq AppMotionLight_OnPacketReceived_setSource1
cpi r17, VALUE_ID_MAL_SOURCE2
breq AppMotionLight_OnPacketReceived_setSource2
cpi r17, VALUE_ID_MAL_BSOURCE
breq AppMotionLight_OnPacketReceived_setBSource
cpi r17, VALUE_ID_MAL_BVALUE
breq AppMotionLight_OnPacketReceived_setBValue
AppMotionLight_OnPacketReceived_clcRet:
clc ; unexpected message
ret
AppMotionLight_OnPacketReceived_setRGBW: ; "setValue nodes/XXXXXXXX/MALRGBWVALUE GRWB"
sts appMotionLightColor, r18
sts appMotionLightColor+1, r19
sts appMotionLightColor+2, r20
sts appMotionLightColor+3, r21
push r24
push r25
rcall appMotionLightStartTimer ; immediately ON with new color (r16)
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
pop r25
pop r24
AppMotionLight_OnPacketReceived_setBSource: ; setValue "nodes/XXXXXXXX/MALSOURCEB 0xVVNN" (VV=value id, NN=node addr)
sts appMotionLightLSourceAddr, r18
sts appMotionLightLSourceValueId, r19
rjmp AppMotionLight_OnPacketReceived_sendAck
AppMotionLight_OnPacketReceived_setBValue: ; "setValue nodes/XXXXXXXX/MALVALUEB n" (n brightness value)
sts appMotionLightLSourceValue, r18
sts appMotionLightLSourceValue+1, r19
rjmp AppMotionLight_OnPacketReceived_sendAck
AppMotionLight_OnPacketReceived_setOnTime: ; "setValue nodes/XXXXXXXX/MALONTIME n" (n in 1/10 secs)
sts appMotionLightOnTime, r18

View File

@@ -80,7 +80,10 @@
.equ EEPROM_OFFS_MAL_CONF_SRC1_VALUEID = 17 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_SRC2_ADDR = 18 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_SRC2_VALUEID = 19 ; 1 byte
.equ EEPROM_OFFS_MAL_CONF_RGBWVALUE = 20 ; 4 bytes
.equ EEPROM_OFFS_MAL_CONF_BSRC_ADDR = 20 ; 1 byte light source addr
.equ EEPROM_OFFS_MAL_CONF_BSRC_VALUEID = 21 ; 1 byte light source value id
.equ EEPROM_OFFS_MAL_CONF_BSRC_VALUE = 22 ; 2 bytes light source trigger value
.equ EEPROM_OFFS_ROUTER_RANGE_BEGIN = 24 ; 1 byte
.equ EEPROM_OFFS_ROUTER_RANGE_END = 25 ; 1 byte

View File

@@ -372,6 +372,8 @@
.include "apps/ma_light/data.asm"
.include "apps/ma_light/main.asm"
.include "apps/ma_light/recv.asm"
;.include "common/eeprom-r.asm"
;.include "common/eeprom-w.asm"
#endif

View File

@@ -14,6 +14,7 @@
<extradist>
defs.asm
eeprom.asm
README
</extradist>

View File

@@ -7,13 +7,15 @@
<values>
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
<value name="RGBWSTATE" id="0x81" type="actor" dataType="uint16" />
<value name="NUMLEDS" id="0x82" type="actor" dataType="int" />
<value name="RGBWVALUE" id="0x83" type="actor" dataType="dword" />
<value name="MALRGBWVALUE" id="0x84" type="actor" dataType="dword" />
<value name="MALONTIME" id="0x85" type="actor" dataType="uint16" />
<value name="MALSOURCE1" id="0x86" type="actor" dataType="uint16" />
<value name="MALSOURCE2" id="0x87" type="actor" dataType="uint16" />
<value name="MALSOURCEB" id="0x89" type="actor" dataType="dword" />
<value name="MALVALUEB" id="0x8a" type="actor" dataType="dword" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -0,0 +1,13 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
.equ EEPROM_OFFS_SK6812_RGBW = 26 ; 4 bytes

View File

@@ -24,6 +24,7 @@
.include "version.asm"
.include "../defs.asm"
.include "../eeprom.asm"
;.include "./data.asm"
.include "devices/all/defs.asm"
@@ -77,16 +78,20 @@
.equ VALUE_ID_DS18B20_TEMP = 0x06
;.equ VALUE_ID_REED_CONF = 0x81
.equ VALUE_ID_LED_STATE = 0x81
.equ VALUE_ID_LED_NUMLEDS = 0x82
.equ VALUE_ID_LED_RGBW_VALUE = 0x83
.equ VALUE_ID_MAL_RGBW_VALUE = 0x84
.equ VALUE_ID_MAL_ONTIME = 0x85
.equ VALUE_ID_MAL_SOURCE1 = 0x86
.equ VALUE_ID_MAL_SOURCE2 = 0x87
.equ VALUE_ID_MAL_BSOURCE = 0x89
.equ VALUE_ID_MAL_BVALUE = 0x8a
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment
@@ -167,12 +172,12 @@ onEveryDay:
onEverySecond:
ret
; debug
ldi r19, 0x00 ; G
ldi r18, 0xff ; R
ldi r20, 0x55 ; B
ldi r21, 0xaa ; W
rcall SK6812_SetAllColor ; r23 (r16, r17)
ret
; ldi r19, 0x00 ; G
; ldi r18, 0xff ; R
; ldi r20, 0x55 ; B
; ldi r21, 0xaa ; W
; rcall SK6812_SetRGBW ; r23 (r16, r17)
; ret

View File

@@ -13,6 +13,7 @@
<extradist>
defs.asm
eeprom.asm
README
</extradist>

View File

@@ -7,13 +7,15 @@
<values>
<value name="DS18B20_TEMP" id="0x06" type="sensor" dataType="rational" modality="temperature" units="C" denom="16" />
<value name="RGBWSTATE" id="0x81" type="actor" dataType="uint16" />
<value name="NUMLEDS" id="0x82" type="actor" dataType="int" />
<value name="RGBWVALUE" id="0x83" type="actor" dataType="dword" />
<value name="MALRGBWVALUE" id="0x84" type="actor" dataType="dword" />
<value name="MALONTIME" id="0x85" type="actor" dataType="uint16" />
<value name="MALSOURCE1" id="0x86" type="actor" dataType="uint16" />
<value name="MALSOURCE2" id="0x87" type="actor" dataType="uint16" />
<value name="MALSOURCEB" id="0x89" type="actor" dataType="dword" />
<value name="MALVALUEB" id="0x8a" type="actor" dataType="dword" />
<value name="LEDTIMING" id="0x88" type="actor" dataType="uint16" />
</values>

View File

@@ -0,0 +1,13 @@
; ***************************************************************************
; 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. *
; ***************************************************************************
.equ EEPROM_OFFS_SK6812_RGBW = 26 ; 4 bytes

View File

@@ -24,6 +24,7 @@
.include "version.asm"
.include "../defs.asm"
.include "../eeprom.asm"
;.include "./data.asm"
.include "devices/all/defs.asm"
@@ -78,16 +79,20 @@
.equ VALUE_ID_DS18B20_TEMP = 0x06
;.equ VALUE_ID_REED_CONF = 0x81
.equ VALUE_ID_LED_STATE = 0x81
.equ VALUE_ID_LED_NUMLEDS = 0x82
.equ VALUE_ID_LED_RGBW_VALUE = 0x83
.equ VALUE_ID_MAL_RGBW_VALUE = 0x84
.equ VALUE_ID_MAL_ONTIME = 0x85
.equ VALUE_ID_MAL_SOURCE1 = 0x86
.equ VALUE_ID_MAL_SOURCE2 = 0x87
.equ VALUE_ID_MAL_BSOURCE = 0x89
.equ VALUE_ID_MAL_BVALUE = 0x8a
.equ VALUE_ID_LEDSIMPLE_TIMING = 0x88
; ***************************************************************************
; code segment

View File

@@ -23,6 +23,7 @@
sk6812DataBegin:
sk6812NumLeds: .byte 1
sk6812Pattern: .byte 5*SK6812_PATTERN_NUM ; 1 byte num leds, 4 bytes colour (RGBW)
sk6812RGBW: .byte 4 ; current RGBW value
sk6812DataEnd:
@@ -35,36 +36,33 @@ sk6812DataEnd:
; ---------------------------------------------------------------------------
; SK6812_Init
; @routine SK6812_Init
;
; IN:
; - nothing
; OUT:
; - CFLAG: set if okay, clear on error
; USED:
; @return CFLAG set if okay, clear on error
SK6812_Init:
; ldi xh, HIGH(sk6812DataBegin)
; ldi xl, LOW(sk6812DataBegin)
; clr r16
; ldi r17, (sk6812DataEnd-sk6812DataBegin)
; rcall Utils_FillSram
ldi xh, HIGH(sk6812DataBegin)
ldi xl, LOW(sk6812DataBegin)
clr r16
ldi r17, (sk6812DataEnd-sk6812DataBegin)
rcall Utils_FillSram
sbi SK6812_DDR, SK6812_PINNUM ; set to output
cbi SK6812_PORT, SK6812_PINNUM ; set LOW
ldi r16, 150
sts sk6812NumLeds, r16
ldi r18, 255 ; R
ldi r19, 69 ; G
ldi r20, 0 ; B
ldi r21, 0 ; W
rcall SK6812_SetAllColor ; r23 (r16, r17)
rcall sk6812ReadConfFromEeprom
ldi r18, 1 ; ON
rcall SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
sec
ret
SK6812_Init_error:
clc
ret
; @end
; ---------------------------------------------------------------------------
@@ -81,7 +79,7 @@ SK6812_Fini:
; ---------------------------------------------------------------------------
; @routine SK6812_SetAllColor @global
; @routine sk6812SetAllColor
;
; Set all LEDs to same colour.
;
@@ -91,7 +89,7 @@ SK6812_Fini:
; @param r21 white value
; @clobbers r23 (r16, r17, r24, r25)
SK6812_SetAllColor:
sk6812SetAllColor:
push r15
in r15, SREG
cli
@@ -99,10 +97,10 @@ SK6812_SetAllColor:
cbi SK6812_PORT, SK6812_PINNUM
Utils_WaitNanoSecs 80000, 0, r22 ; wait for 80us
lds r23, sk6812NumLeds
SK6812_SetAllColor_loop:
sk6812SetAllColor_loop:
rcall sk6812SendQuadruple ; (r16, r17, r24, r25)
dec r23
brne SK6812_SetAllColor_loop
brne sk6812SetAllColor_loop
; sbi SK6812_PORT, SK6812_PINNUM
out SREG, r15
pop r15
@@ -111,6 +109,62 @@ SK6812_SetAllColor_loop:
; ---------------------------------------------------------------------------
; @routine SK6812_SetState @global
;
; Set all LEDs to same colour according to state.
;
; @param r18 0: all LEDs off, otherwise all LEDs color stored in sk6812RGBW
; @clobbers r18, r19, r20, r21, (r16, r17, r23, r24, r25)
SK6812_SetState:
tst r18
breq SK6812_SetState_off
lds r18, sk6812RGBW
lds r19, sk6812RGBW+1
lds r20, sk6812RGBW+2
lds r22, sk6812RGBW+3
rjmp SK6812_SetState_haveValue
SK6812_SetState_off:
clr r18
clr r19
clr r20
clr r21
SK6812_SetState_haveValue:
rjmp sk6812SetAllColor ; (r16, r17, r23, r24, r25)
; @end
; ---------------------------------------------------------------------------
; @routine SK6812_SetRGBW @global
;
; Store new color for all LEDs.
;
; @param r18 red value
; @param r19 green value
; @param r20 blue color
; @param r21 white color
; @clobbers (r16, r17, r18, r19, r20, r21, r23, r24, r25, X)
SK6812_SetRGBW:
push r15
in r15, SREG
cli
sts sk6812RGBW, r18
sts sk6812RGBW+1, r19
sts sk6812RGBW+2, r20
sts sk6812RGBW+3, r21
rcall sk6812WriteConfToEeprom ; (R16, R17, X)
ldi r18, 1 ; ON
rcall SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
out SREG, r15
pop r15
ret
; @end
; ---------------------------------------------------------------------------
; @routine sk6812SendPattern
;
@@ -226,3 +280,87 @@ sk6812SendByte4:
; ---------------------------------------------------------------------------
; @routine sk6812WriteConfToEeprom
;
; @clobbers r16, r17, X
sk6812WriteConfToEeprom:
push r15
in r15, SREG
cli
ldi xl, LOW(EEPROM_OFFS_SK6812_RGBW)
ldi xh, HIGH(EEPROM_OFFS_SK6812_RGBW)
lds r16, sk6812RGBW
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, sk6812RGBW+1
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, sk6812RGBW+2
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, sk6812RGBW+3
rcall Eeprom_WriteByteIfChanged ; (R17)
out SREG, r15
pop r15
ret
; @end
; ---------------------------------------------------------------------------
; @routine sk6812ReadConfFromEeprom
;
; @clobbers r16, r17, X
sk6812ReadConfFromEeprom:
push r15
in r15, SREG
cli
ldi xl, LOW(EEPROM_OFFS_SK6812_RGBW)
ldi xh, HIGH(EEPROM_OFFS_SK6812_RGBW)
rcall Eeprom_ReadByte
brcc sk6812ReadConfFromEeprom_default
mov r18, r16
adiw xh:xl, 1
rcall Eeprom_ReadByte
brcc sk6812ReadConfFromEeprom_default
mov r19, r16
adiw xh:xl, 1
rcall Eeprom_ReadByte
brcc sk6812ReadConfFromEeprom_default
mov r20, r16
adiw xh:xl, 1
rcall Eeprom_ReadByte
brcc sk6812ReadConfFromEeprom_default
mov r21, r16
mov r16, r18
and r16, r19
and r16, r20
and r16, r21
inc r16
brne sk6812ReadConfFromEeprom_storeColor
; fall through if value from EEPROM is 0xffffffff
sk6812ReadConfFromEeprom_default:
ldi r18, 128 ; R
ldi r19, 69 ; G
ldi r20, 0 ; B
ldi r21, 0 ; W
sk6812ReadConfFromEeprom_storeColor:
sts sk6812RGBW, r18
sts sk6812RGBW+1, r19
sts sk6812RGBW+2, r20
sts sk6812RGBW+3, r21
sk6812ReadConfFromEeprom_end:
out SREG, r15
pop r15
ret
; @end

View File

@@ -28,17 +28,29 @@ SK6812_OnPacketReceived_set:
breq SK6812_OnPacketReceived_setRGBW
cpi r17, VALUE_ID_LED_NUMLEDS
breq SK6812_OnPacketReceived_setNumLeds
cpi r17, VALUE_ID_LED_STATE
breq SK6812_OnPacketReceived_setState
clc
ret
SK6812_OnPacketReceived_setRGBW:
push r17
push r24
push r25
rcall SK6812_SetAllColor ; value is in R18-R21 (r16, r17, r23, r24, r25)
rcall SK6812_SetRGBW ; value is in R18-R21 (R16, R17, X)
pop r25
pop r24
pop r17
rjmp SK6812_OnPacketReceived_sendAck
SK6812_OnPacketReceived_setState:
push r17
push r24
push r25
rcall SK6812_SetState ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
pop r25
pop r24
pop r17
rjmp SK6812_OnPacketReceived_sendAck
SK6812_OnPacketReceived_setNumLeds:
sts sk6812NumLeds, r18
SK6812_OnPacketReceived_sendAck: