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

@@ -16,8 +16,6 @@
appMotionLightDataBegin: appMotionLightDataBegin:
appMotionLightTimer: .byte 2
appMotionLightOnTime: .byte 2
appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE
appMotionLightLSourceAddr: .byte 1 appMotionLightLSourceAddr: .byte 1
appMotionLightLSourceValueId: .byte 1 appMotionLightLSourceValueId: .byte 1

View File

@@ -27,11 +27,6 @@ AppMotionLight_Init:
ldi r17, (appMotionLightDataEnd-appMotionLightDataBegin) ldi r17, (appMotionLightDataEnd-appMotionLightDataBegin)
rcall Utils_FillSram 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 rcall appMotionLightReadConfFromEeprom
ret ret
@@ -44,31 +39,7 @@ AppMotionLight_Init:
; ;
AppMotionLight_Fini: 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 ret
AppMotionLight_Every100ms_off:
rjmp appMotionLightTurnOff ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X)
; @end ; @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 ; @routine appMotionLightReadConfFromEeprom
; ;
@@ -212,8 +118,7 @@ appMotionLightReadConfFromEeprom:
and r16, r18 and r16, r18
cpi r16, 0xff cpi r16, 0xff
breq appMotionLightReadConfFromEeprom_end breq appMotionLightReadConfFromEeprom_end
sts appMotionLightOnTime, r18 bigcall SK6812_SetAutoTimerReload ; (none)
sts appMotionLightOnTime+1, r19
; read source 1 ; read source 1
rcall Utils_ReadEepromIncr ; (R16) rcall Utils_ReadEepromIncr ; (R16)
@@ -265,10 +170,11 @@ appMotionLightWriteConfToEeprom:
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME) ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
ldi xh, HIGH(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) rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1 adiw xh:xl, 1
lds r16, appMotionLightOnTime+1 mov r16, r19
rcall Eeprom_WriteByteIfChanged ; (R17) rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1 adiw xh:xl, 1

View File

@@ -21,116 +21,127 @@
; @clobbers any, -X ; @clobbers any, -X
AppMotionLight_OnPacketReceived: AppMotionLight_OnPacketReceived:
adiw xh:xl, 2 ; command ldi zl, LOW(appMotionLightMsgTable*2)
ld r16, X ldi zh, HIGH(appMotionLightMsgTable*2)
sbiw xh:xl, 2 rjmp Main_HandleValueMsg
cpi r16, NETMSG_CMD_VALUE_SET
breq AppMotionLight_OnPacketReceived_set
cpi r16, NETMSG_CMD_VALUE_REPORT
breq AppMotionLight_OnPacketReceived_report ; ---------------------------------------------------------------------------
clc ; unexpected msg ; @routine appMotionLightHandleReport
ret ;
; "report value" message
AppMotionLight_OnPacketReceived_report: appMotionLightHandleReport:
rcall NETMSG_ValueRead ; (none)
rcall appMotionLightIsBrightnessSource ; (R16) rcall appMotionLightIsBrightnessSource ; (R16)
brcs AppMotionLight_OnPacketReceived_isBrightness brcs appMotionLightHandleReport_brightness
; motion source?
mov r16, r18 mov r16, r18
or r16, r19 or r16, r19
breq AppMotionLight_OnPacketReceived_clcRet ; zero value, ignore breq appMotionLightHandleReport_ret ; zero value, ignore
rcall appMotionLightHasSource ; (r16, r24, Y) rcall appMotionLightHasSource ; (r16, r24, Y)
brcs AppMotionLight_OnPacketReceived_turnOn brcc appMotionLightHandleReport_ret
ret
AppMotionLight_OnPacketReceived_turnOn: ; motion detected, check for brightness source
lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value? lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value?
tst r16 tst r16
breq AppMotionLight_OnPacketReceived_checkTimer ; no, jmp and don't check brightness breq appMotionLightHandleReport_trigger ; no, jmp and don't check brightness
; we have a brightness source configured, do we have a value?
lds r16, appMotionLightFlags ; check last brightness reported lds r16, appMotionLightFlags ; check last brightness reported
andi r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT andi r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
breq AppMotionLight_OnPacketReceived_secRet ; no brightness, yet breq appMotionLightHandleReport_ret ; no brightness, yet
AppMotionLight_OnPacketReceived_checkBrightness: appMotionLightHandleReport_checkBrightness:
lds r16, appMotionLightLSourceValue ; check last brightness reported lds r16, appMotionLightLSourceValue ; check last brightness reported
lds r17, appMotionLightLSourceValue+1 lds r17, appMotionLightLSourceValue+1
lds r24, appMotionLightLastBrightness ; r25:r24>r17:r16? lds r24, appMotionLightLastBrightness ; r25:r24>r17:r16?
lds r25, appMotionLightLastBrightness+1 ; appMotionLightLastBrightness>appMotionLightLSourceValue? lds r25, appMotionLightLastBrightness+1 ; appMotionLightLastBrightness>appMotionLightLSourceValue?
sub r16, r24 sub r16, r24
sbc r17, r25 sbc r17, r25
brcs AppMotionLight_OnPacketReceived_secRet ; yes, too bright to turn on brcs appMotionLightHandleReport_ret ; yes, too bright to turn on
AppMotionLight_OnPacketReceived_checkTimer: appMotionLightHandleReport_trigger:
lds r16, appMotionLightTimer ; time up? bigcall SK6812_Trigger
lds r17, appMotionLightTimer+1 rjmp appMotionLightHandleReport_ret
or r16, r17 ; received report is our brightness source
brne AppMotionLight_OnPacketReceived_startTimer ; no, just restart timer (light already on) appMotionLightHandleReport_brightness:
push xl
push xh
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r22, r23, r24, r25, X)
pop xh
pop xl
AppMotionLight_OnPacketReceived_startTimer:
rcall appMotionLightStartTimer
AppMotionLight_OnPacketReceived_secRet:
sec
ret
AppMotionLight_OnPacketReceived_isBrightness:
sts appMotionLightLastBrightness, r18 sts appMotionLightLastBrightness, r18
sts appMotionLightLastBrightness+1, r19 sts appMotionLightLastBrightness+1, r19
lds r16, appMotionLightFlags lds r16, appMotionLightFlags
ori r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT ori r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
sts appMotionLightFlags, r16 sts appMotionLightFlags, r16
sec appMotionLightHandleReport_ret:
clc
ret ret
; "set value" message ; @end
AppMotionLight_OnPacketReceived_set:
rcall NETMSG_ValueRead ; (none)
cpi r17, VALUE_ID_MAL_ONTIME
breq AppMotionLight_OnPacketReceived_setOnTime ; ---------------------------------------------------------------------------
cpi r17, VALUE_ID_MAL_SOURCE1 ; @routine appMotionLightSetValueOnTime
breq AppMotionLight_OnPacketReceived_setSource1 ;
cpi r17, VALUE_ID_MAL_SOURCE2
breq AppMotionLight_OnPacketReceived_setSource2 appMotionLightSetValueOnTime:
cpi r17, VALUE_ID_MAL_BSOURCE rcall SK6812_SetAutoTimerReload
breq AppMotionLight_OnPacketReceived_setBSource rjmp appMotionLightSetValueReturn
cpi r17, VALUE_ID_MAL_BVALUE ; @end
breq AppMotionLight_OnPacketReceived_setBValue
AppMotionLight_OnPacketReceived_clcRet:
clc ; unexpected message ; ---------------------------------------------------------------------------
ret ; @routine appMotionLightSetValueSource1
AppMotionLight_OnPacketReceived_setBSource: ; setValue "nodes/XXXXXXXX/MALSOURCEB 0xVVNN" (VV=value id, NN=node addr) ;
sts appMotionLightLSourceAddr, r18
sts appMotionLightLSourceValueId, r19 appMotionLightSetValueSource1:
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
sts appMotionLightOnTime+1, r19
lds r16, appMotionLightTimer ; timer active?
lds r17, appMotionLightTimer+1
or r16, r17
breq AppMotionLight_OnPacketReceived_sendAck ; nope, just set it and leave
sts appMotionLightTimer, r18 ; restart timer with new value
sts appMotionLightTimer+1, r19
rjmp AppMotionLight_OnPacketReceived_sendAck
AppMotionLight_OnPacketReceived_setSource1: ; setValue "nodes/XXXXXXXX/MALSOURCE1 0xVVNN" (VV=value id, NN=node addr)
sts appMotionLightSources, r18 ; peerAddr sts appMotionLightSources, r18 ; peerAddr
sts appMotionLightSources+1, r19 ; valueId sts appMotionLightSources+1, r19 ; valueId
rjmp AppMotionLight_OnPacketReceived_sendAck rjmp appMotionLightSetValueReturn
AppMotionLight_OnPacketReceived_setSource2: ; setValue "nodes/XXXXXXXX/MALSOURCE2 0xVVNN" (VV=value id, NN=node addr) ; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueSource2
;
appMotionLightSetValueSource2:
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
AppMotionLight_OnPacketReceived_sendAck: rjmp appMotionLightSetValueReturn
push xl ; @end
push xh
ldi r23, NETMSG_CMD_VALUE_SET_ACK
rcall Main_SendValueResponse ; (clobbers all, including Y)
rcall appMotionLightWriteConfToEeprom ; (r16, r17, X) ; ---------------------------------------------------------------------------
pop xh ; @routine appMotionLightSetValueBValue
pop xl ;
appMotionLightSetValueBValue:
sts appMotionLightSources, r18 ; peerAddr
sts appMotionLightSources+1, r19 ; valueId
rjmp appMotionLightSetValueReturn
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightSetValueReturn
;
; Common return code
appMotionLightSetValueReturn:
rcall appMotionLightWriteConfToEeprom
ldi r23, NETMSG_CMD_VALUE_SET_ACK
sec sec
ret ret
; @end ; @end
appMotionLightMsgTable:
.db NETMSG_CMD_VALUE_REPORT, 0, LOW(appMotionLightHandleReport), HIGH(appMotionLightHandleReport)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_ONTIME, LOW(appMotionLightSetValueOnTime), HIGH(appMotionLightSetValueOnTime)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_SOURCE1, LOW(appMotionLightSetValueSource1), HIGH(appMotionLightSetValueSource1)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_SOURCE2, LOW(appMotionLightSetValueSource2), HIGH(appMotionLightSetValueSource2)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_MAL_BVALUE, LOW(appMotionLightSetValueBValue), HIGH(appMotionLightSetValueBValue)
.db 0, 0, 0, 0

View File

@@ -40,10 +40,6 @@ appsOnEvery100ms:
bigcall AppDoor_Every100ms bigcall AppDoor_Every100ms
#endif #endif
#ifdef APPS_MA_LIGHT
bigcall AppMotionLight_Every100ms
#endif
ret ret
; @end ; @end

View File

@@ -102,6 +102,10 @@ modulesOnEvery100ms:
bigcall XPT2046_Every100ms bigcall XPT2046_Every100ms
#endif #endif
#ifdef MODULES_SK6812
bigcall SK6812_Every100ms
#endif
ret ret
; @end ; @end

View File

@@ -231,6 +231,7 @@
.include "modules/sk6812/io.asm" .include "modules/sk6812/io.asm"
#ifdef MODULES_NETWORK #ifdef MODULES_NETWORK
.include "modules/sk6812/recv.asm" .include "modules/sk6812/recv.asm"
.include "modules/sk6812/send.asm"
.include "devices/all/handlevaluemsg.asm" .include "devices/all/handlevaluemsg.asm"
#endif #endif
#endif #endif

View File

@@ -16,6 +16,8 @@ RGB Value for activated light:
Example: Example:
Set color of LED strip to blue (half intensity) Set color of LED strip to blue (half intensity)
aqhome-tool setdata -N nodes/12345678/RGBWVALUE -v 0x80 aqhome-tool setdata -N nodes/12345678/RGBWVALUE -v 0x80
or in modern format:
aqhome-tool setdata -N nodes/12345678/RGBWVALUE -v GREEN:RED:WHITE:BLUE
1.2. RGBWSTATE 1.2. RGBWSTATE

View File

@@ -22,6 +22,8 @@
.equ SK6812_TYPE_BTF_NEW = 0 .equ SK6812_TYPE_BTF_NEW = 0
.equ SK6812_TYPE_NUM = 1 .equ SK6812_TYPE_NUM = 1
.equ SK6812_DEFAULT_ONTIME = 300 ; 30secs
; *************************************************************************** ; ***************************************************************************
@@ -30,11 +32,15 @@
.dseg .dseg
sk6812DataBegin: sk6812DataBegin:
sk6812NumLeds: .byte 1 sk6812NumLeds: .byte 1
sk6812Pattern: .byte 5*SK6812_PATTERN_NUM ; 1 byte num leds, 4 bytes colour (RGBW) sk6812Pattern: .byte 5*SK6812_PATTERN_NUM ; 1 byte num leds, 4 bytes colour (RGBW)
sk6812RGBW: .byte 4 ; current RGBW value sk6812RGBW: .byte 4 ; current RGBW value
sk6812Mode: .byte 1 sk6812Mode: .byte 1
sk6812Type: .byte 1 ; which timing type to use sk6812Type: .byte 1 ; which timing type to use
sk6812Timer100ms: .byte 2 ; timer in 100msecs before turning light off
sk6812Reload100ms: .byte 2 ; reload value used when triggering light
sk6812DataEnd: sk6812DataEnd:
@@ -61,6 +67,11 @@ SK6812_Init:
ldi r16, SK6812_MODE_AUTO ldi r16, SK6812_MODE_AUTO
sts sk6812Mode, r16 sts sk6812Mode, r16
ldi r16, LOW(SK6812_DEFAULT_ONTIME)
sts sk6812Reload100ms, r16
ldi r16, HIGH(SK6812_DEFAULT_ONTIME)
sts sk6812Reload100ms+1, r16
sbi SK6812_DDR, SK6812_PINNUM ; set to output sbi SK6812_DDR, SK6812_PINNUM ; set to output
cbi SK6812_PORT, SK6812_PINNUM ; set LOW cbi SK6812_PORT, SK6812_PINNUM ; set LOW
ldi r16, 144 ldi r16, 144
@@ -68,8 +79,7 @@ SK6812_Init:
rcall sk6812ReadConfFromEeprom rcall sk6812ReadConfFromEeprom
ldi r18, 1 ; ON (DEBUG) rcall SK6812_Trigger
rcall SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
sec sec
ret ret
@@ -87,12 +97,100 @@ SK6812_Init_error:
; USED: ; USED:
SK6812_Fini: SK6812_Fini:
clr r16
sts sk6812Reload100ms, r16
sts sk6812Reload100ms+1, r16
clr r18 ; turn light off
rcall sk6812SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
sec sec
ret ret
; @end ; @end
; ---------------------------------------------------------------------------
; @routine SK6812_EverySecond
SK6812_Every100ms:
lds r16, sk6812Mode
cpi r16, SK6812_MODE_AUTO
brne SK6812_Every100ms_ret
lds r24, sk6812Timer100ms
lds r25, sk6812Timer100ms+1
mov r16, r24
or r16, r25
breq SK6812_Every100ms_ret
sbiw r25:r24, 1
sts sk6812Timer100ms, r24
sts sk6812Timer100ms+1, r25
brne SK6812_Every100ms_ret
; timer elapsed, turn off light
clr r18
rcall sk6812SetState
SK6812_Every100ms_ret:
ret
; @end
; ---------------------------------------------------------------------------
; @routine SK6812_SetAutoTimerReload @global
;
; @param r19:r18 value
; @clobbers none
SK6812_SetAutoTimerReload:
sts sk6812Reload100ms, r18
sts sk6812Reload100ms+1, r19
ret
; @end
; ---------------------------------------------------------------------------
; @routine SK6812_GetAutoTimerReload @global
;
; @return r19:r18 reload value in secs
; @clobbers none
SK6812_GetAutoTimerReload:
lds r18, sk6812Reload100ms
lds r19, sk6812Reload100ms+1
ret
; @end
; ---------------------------------------------------------------------------
; @routine SK6812_Trigger
;
; Restart on-timer, turn light on if it is off
; @clobbers r16, r17, r18, r19, r20, r21, r23, r24, r25
SK6812_Trigger:
lds r16, sk6812Mode
cpi r16, SK6812_MODE_AUTO
brne SK6812_Trigger_ret
lds r16, sk6812Timer100ms
lds r17, sk6812Timer100ms+1
or r16, r17
lds r17, sk6812Reload100ms
sts sk6812Timer100ms, r17
lds r17, sk6812Reload100ms+1
sts sk6812Timer100ms+1, r17
tst r16
brne SK6812_Trigger_ret
ldi r18, 1
rcall sk6812SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
SK6812_Trigger_ret:
ret
; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine SK6812_SetState @global ; @routine SK6812_SetState @global
@@ -173,7 +271,7 @@ SK6812_SetRGBW:
; Set all LEDs to same colour according to state. ; Set all LEDs to same colour according to state.
; ;
; @param r18 0: all LEDs off, otherwise all LEDs color stored in sk6812RGBW ; @param r18 0: all LEDs off, otherwise all LEDs color stored in sk6812RGBW
; @clobbers r18, r19, r20, r21, (r16, r17, r23, r24, r25) ; @clobbers R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X
sk6812SetState: sk6812SetState:
tst r18 tst r18
@@ -182,17 +280,21 @@ sk6812SetState:
lds r19, sk6812RGBW+1 lds r19, sk6812RGBW+1
lds r20, sk6812RGBW+2 lds r20, sk6812RGBW+2
lds r21, sk6812RGBW+3 lds r21, sk6812RGBW+3
rjmp sk6812SetState_haveValue rcall sk6812SetAllColor ; (r16, r17, r23, r24, r25)
ldi r18, 1
rjmp sk6812ReportState
sk6812SetState_off: sk6812SetState_off:
clr r18 clr r18
clr r19 clr r19
clr r20 clr r20
clr r21 clr r21
sk6812SetState_haveValue: rcall sk6812SetAllColor ; (r16, r17, r23, r24, r25)
rjmp sk6812SetAllColor ; (r16, r17, r23, r24, r25) ldi r18, 0
rjmp sk6812ReportState ; (R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X)
; @end ; @end
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine sk6812SendPattern ; @routine sk6812SendPattern
; ;

View File

@@ -12,7 +12,7 @@
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine SK6812_OnPacketReceived @global ; @routine SK6812_OnPacketReceived @global
; ;
; @clobbers any, -X ; @clobbers any, !X
SK6812_OnPacketReceived: SK6812_OnPacketReceived:
ldi zl, LOW(sk6812MsgTable*2) ldi zl, LOW(sk6812MsgTable*2)
@@ -24,40 +24,42 @@ SK6812_OnPacketReceived:
sk6812SetValueRGBW: sk6812SetValueRGBW:
rcall SK6812_SetRGBW ; value is in R18-R21 (R16, R17, X) rcall SK6812_SetRGBW ; value is in R18-R21 (R16, R17, X)
ldi r23, NETMSG_CMD_VALUE_SET_ACK rcall SK6812_Trigger
sec ldi r18, 1
ret rcall sk6812SetState
rjmp sk6812SetValueReturn
; @end ; @end
sk6812SetValueNumLeds: sk6812SetValueNumLeds:
sts sk6812NumLeds, r18 sts sk6812NumLeds, r18
ldi r23, NETMSG_CMD_VALUE_SET_ACK rjmp sk6812SetValueReturn
sec
ret
; @end ; @end
sk6812SetValueState: sk6812SetValueState:
rcall SK6812_SetState ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25) rcall SK6812_SetState ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
ldi r23, NETMSG_CMD_VALUE_SET_ACK rjmp sk6812SetValueReturn
sec
ret
; @end ; @end
sk6812SetValueMode: sk6812SetValueMode:
rcall SK6812_SetMode ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25) rcall SK6812_SetMode ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
rjmp sk6812SetValueReturn
; @end
sk6812SetValueReturn:
ldi r23, NETMSG_CMD_VALUE_SET_ACK ldi r23, NETMSG_CMD_VALUE_SET_ACK
sec sec
ret ret
; @end ; @end
sk6812MsgTable: sk6812MsgTable:
.db NETMSG_CMD_VALUE_SET, VALUE_ID_LED_RGBW_VALUE, LOW(sk6812SetValueRGBW), HIGH(sk6812SetValueRGBW) .db NETMSG_CMD_VALUE_SET, VALUE_ID_LED_RGBW_VALUE, LOW(sk6812SetValueRGBW), HIGH(sk6812SetValueRGBW)
.db NETMSG_CMD_VALUE_SET, VALUE_ID_LED_NUMLEDS, LOW(sk6812SetValueNumLeds), HIGH(sk6812SetValueNumLeds) .db NETMSG_CMD_VALUE_SET, VALUE_ID_LED_NUMLEDS, LOW(sk6812SetValueNumLeds), HIGH(sk6812SetValueNumLeds)

View File

@@ -0,0 +1,31 @@
; ***************************************************************************
; copyright : (C) 2024 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. *
; ***************************************************************************
; ---------------------------------------------------------------------------
; @routine sk6812ReportState
;
; @param R18 state (0=off, 1=on)
; @clobbers R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X
sk6812ReportState:
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