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:
@@ -16,8 +16,6 @@
|
||||
|
||||
|
||||
appMotionLightDataBegin:
|
||||
appMotionLightTimer: .byte 2
|
||||
appMotionLightOnTime: .byte 2
|
||||
appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE
|
||||
appMotionLightLSourceAddr: .byte 1
|
||||
appMotionLightLSourceValueId: .byte 1
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -21,116 +21,127 @@
|
||||
; @clobbers any, -X
|
||||
|
||||
AppMotionLight_OnPacketReceived:
|
||||
adiw xh:xl, 2 ; command
|
||||
ld r16, X
|
||||
sbiw xh:xl, 2
|
||||
cpi r16, NETMSG_CMD_VALUE_SET
|
||||
breq AppMotionLight_OnPacketReceived_set
|
||||
cpi r16, NETMSG_CMD_VALUE_REPORT
|
||||
breq AppMotionLight_OnPacketReceived_report
|
||||
clc ; unexpected msg
|
||||
ret
|
||||
; "report value" message
|
||||
AppMotionLight_OnPacketReceived_report:
|
||||
rcall NETMSG_ValueRead ; (none)
|
||||
ldi zl, LOW(appMotionLightMsgTable*2)
|
||||
ldi zh, HIGH(appMotionLightMsgTable*2)
|
||||
rjmp Main_HandleValueMsg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightHandleReport
|
||||
;
|
||||
|
||||
appMotionLightHandleReport:
|
||||
rcall appMotionLightIsBrightnessSource ; (R16)
|
||||
brcs AppMotionLight_OnPacketReceived_isBrightness
|
||||
brcs appMotionLightHandleReport_brightness
|
||||
; motion source?
|
||||
mov r16, r18
|
||||
or r16, r19
|
||||
breq AppMotionLight_OnPacketReceived_clcRet ; zero value, ignore
|
||||
breq appMotionLightHandleReport_ret ; zero value, ignore
|
||||
rcall appMotionLightHasSource ; (r16, r24, Y)
|
||||
brcs AppMotionLight_OnPacketReceived_turnOn
|
||||
ret
|
||||
AppMotionLight_OnPacketReceived_turnOn:
|
||||
brcc appMotionLightHandleReport_ret
|
||||
|
||||
; motion detected, check for brightness source
|
||||
lds r16, appMotionLightLSourceAddr ; do we have a source for brightness value?
|
||||
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
|
||||
andi r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
|
||||
breq AppMotionLight_OnPacketReceived_secRet ; no brightness, yet
|
||||
AppMotionLight_OnPacketReceived_checkBrightness:
|
||||
breq appMotionLightHandleReport_ret ; no brightness, yet
|
||||
appMotionLightHandleReport_checkBrightness:
|
||||
lds r16, appMotionLightLSourceValue ; check last brightness reported
|
||||
lds r17, appMotionLightLSourceValue+1
|
||||
lds r24, appMotionLightLastBrightness ; r25:r24>r17:r16?
|
||||
lds r25, appMotionLightLastBrightness+1 ; appMotionLightLastBrightness>appMotionLightLSourceValue?
|
||||
sub r16, r24
|
||||
sbc r17, r25
|
||||
brcs AppMotionLight_OnPacketReceived_secRet ; yes, too bright to turn on
|
||||
AppMotionLight_OnPacketReceived_checkTimer:
|
||||
lds r16, appMotionLightTimer ; time up?
|
||||
lds r17, appMotionLightTimer+1
|
||||
or r16, r17
|
||||
brne AppMotionLight_OnPacketReceived_startTimer ; no, just restart timer (light already on)
|
||||
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:
|
||||
brcs appMotionLightHandleReport_ret ; yes, too bright to turn on
|
||||
appMotionLightHandleReport_trigger:
|
||||
bigcall SK6812_Trigger
|
||||
rjmp appMotionLightHandleReport_ret
|
||||
; received report is our brightness source
|
||||
appMotionLightHandleReport_brightness:
|
||||
sts appMotionLightLastBrightness, r18
|
||||
sts appMotionLightLastBrightness+1, r19
|
||||
lds r16, appMotionLightFlags
|
||||
ori r16, APP_MOTIONLIGHT_FLAGS_HAVELIGHT
|
||||
sts appMotionLightFlags, r16
|
||||
sec
|
||||
appMotionLightHandleReport_ret:
|
||||
clc
|
||||
ret
|
||||
; "set value" message
|
||||
AppMotionLight_OnPacketReceived_set:
|
||||
rcall NETMSG_ValueRead ; (none)
|
||||
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_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
|
||||
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)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueOnTime
|
||||
;
|
||||
|
||||
appMotionLightSetValueOnTime:
|
||||
rcall SK6812_SetAutoTimerReload
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueSource1
|
||||
;
|
||||
|
||||
appMotionLightSetValueSource1:
|
||||
sts appMotionLightSources, r18 ; peerAddr
|
||||
sts appMotionLightSources+1, r19 ; valueId
|
||||
rjmp AppMotionLight_OnPacketReceived_sendAck
|
||||
AppMotionLight_OnPacketReceived_setSource2: ; setValue "nodes/XXXXXXXX/MALSOURCE2 0xVVNN" (VV=value id, NN=node addr)
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueSource2
|
||||
;
|
||||
|
||||
appMotionLightSetValueSource2:
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
|
||||
AppMotionLight_OnPacketReceived_sendAck:
|
||||
push xl
|
||||
push xh
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
rcall Main_SendValueResponse ; (clobbers all, including Y)
|
||||
rcall appMotionLightWriteConfToEeprom ; (r16, r17, X)
|
||||
pop xh
|
||||
pop xl
|
||||
rjmp appMotionLightSetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightSetValueBValue
|
||||
;
|
||||
|
||||
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
|
||||
ret
|
||||
; @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
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -40,10 +40,6 @@ appsOnEvery100ms:
|
||||
bigcall AppDoor_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef APPS_MA_LIGHT
|
||||
bigcall AppMotionLight_Every100ms
|
||||
#endif
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
@@ -102,6 +102,10 @@ modulesOnEvery100ms:
|
||||
bigcall XPT2046_Every100ms
|
||||
#endif
|
||||
|
||||
#ifdef MODULES_SK6812
|
||||
bigcall SK6812_Every100ms
|
||||
#endif
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
@@ -231,6 +231,7 @@
|
||||
.include "modules/sk6812/io.asm"
|
||||
#ifdef MODULES_NETWORK
|
||||
.include "modules/sk6812/recv.asm"
|
||||
.include "modules/sk6812/send.asm"
|
||||
.include "devices/all/handlevaluemsg.asm"
|
||||
#endif
|
||||
#endif
|
||||
|
||||
@@ -16,6 +16,8 @@ RGB Value for activated light:
|
||||
Example:
|
||||
Set color of LED strip to blue (half intensity)
|
||||
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
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
.equ SK6812_TYPE_BTF_NEW = 0
|
||||
.equ SK6812_TYPE_NUM = 1
|
||||
|
||||
.equ SK6812_DEFAULT_ONTIME = 300 ; 30secs
|
||||
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
@@ -30,11 +32,15 @@
|
||||
.dseg
|
||||
|
||||
sk6812DataBegin:
|
||||
sk6812NumLeds: .byte 1
|
||||
sk6812Pattern: .byte 5*SK6812_PATTERN_NUM ; 1 byte num leds, 4 bytes colour (RGBW)
|
||||
sk6812RGBW: .byte 4 ; current RGBW value
|
||||
sk6812Mode: .byte 1
|
||||
sk6812Type: .byte 1 ; which timing type to use
|
||||
sk6812NumLeds: .byte 1
|
||||
sk6812Pattern: .byte 5*SK6812_PATTERN_NUM ; 1 byte num leds, 4 bytes colour (RGBW)
|
||||
sk6812RGBW: .byte 4 ; current RGBW value
|
||||
sk6812Mode: .byte 1
|
||||
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:
|
||||
|
||||
|
||||
@@ -61,6 +67,11 @@ SK6812_Init:
|
||||
ldi r16, SK6812_MODE_AUTO
|
||||
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
|
||||
cbi SK6812_PORT, SK6812_PINNUM ; set LOW
|
||||
ldi r16, 144
|
||||
@@ -68,8 +79,7 @@ SK6812_Init:
|
||||
|
||||
rcall sk6812ReadConfFromEeprom
|
||||
|
||||
ldi r18, 1 ; ON (DEBUG)
|
||||
rcall SK6812_SetState ; (r16, r17, r18, r19, r20, r21, r23, r24, r25)
|
||||
rcall SK6812_Trigger
|
||||
|
||||
sec
|
||||
ret
|
||||
@@ -87,12 +97,100 @@ SK6812_Init_error:
|
||||
; USED:
|
||||
|
||||
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
|
||||
ret
|
||||
; @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
|
||||
@@ -173,7 +271,7 @@ SK6812_SetRGBW:
|
||||
; 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)
|
||||
; @clobbers R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X
|
||||
|
||||
sk6812SetState:
|
||||
tst r18
|
||||
@@ -182,17 +280,21 @@ sk6812SetState:
|
||||
lds r19, sk6812RGBW+1
|
||||
lds r20, sk6812RGBW+2
|
||||
lds r21, sk6812RGBW+3
|
||||
rjmp sk6812SetState_haveValue
|
||||
rcall sk6812SetAllColor ; (r16, r17, r23, r24, r25)
|
||||
ldi r18, 1
|
||||
rjmp sk6812ReportState
|
||||
sk6812SetState_off:
|
||||
clr r18
|
||||
clr r19
|
||||
clr r20
|
||||
clr r21
|
||||
sk6812SetState_haveValue:
|
||||
rjmp sk6812SetAllColor ; (r16, r17, r23, r24, r25)
|
||||
rcall sk6812SetAllColor ; (r16, r17, r23, r24, r25)
|
||||
ldi r18, 0
|
||||
rjmp sk6812ReportState ; (R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine sk6812SendPattern
|
||||
;
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine SK6812_OnPacketReceived @global
|
||||
;
|
||||
; @clobbers any, -X
|
||||
; @clobbers any, !X
|
||||
|
||||
SK6812_OnPacketReceived:
|
||||
ldi zl, LOW(sk6812MsgTable*2)
|
||||
@@ -24,40 +24,42 @@ SK6812_OnPacketReceived:
|
||||
|
||||
sk6812SetValueRGBW:
|
||||
rcall SK6812_SetRGBW ; value is in R18-R21 (R16, R17, X)
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
sec
|
||||
ret
|
||||
rcall SK6812_Trigger
|
||||
ldi r18, 1
|
||||
rcall sk6812SetState
|
||||
rjmp sk6812SetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
sk6812SetValueNumLeds:
|
||||
sts sk6812NumLeds, r18
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
sec
|
||||
ret
|
||||
rjmp sk6812SetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
sk6812SetValueState:
|
||||
rcall SK6812_SetState ; value is in R18 (r16, r17, r18, r19, r20, r21, r23, r24, r25)
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
sec
|
||||
ret
|
||||
rjmp sk6812SetValueReturn
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
sk6812SetValueMode:
|
||||
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
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
sk6812MsgTable:
|
||||
.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)
|
||||
|
||||
31
avr/modules/sk6812/send.asm
Normal file
31
avr/modules/sk6812/send.asm
Normal 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
|
||||
|
||||
|
||||
Reference in New Issue
Block a user