avr/apps: added ma_light (was previously a module).
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
<subdirs>
|
||||
door
|
||||
ma_light
|
||||
motion
|
||||
network
|
||||
reportsensors
|
||||
|
||||
18
avr/apps/ma_light/0BUILD
Normal file
18
avr/apps/ma_light/0BUILD
Normal file
@@ -0,0 +1,18 @@
|
||||
<?xml?>
|
||||
|
||||
<gwbuild>
|
||||
|
||||
<subdirs>
|
||||
</subdirs>
|
||||
|
||||
<extradist>
|
||||
data.asm
|
||||
defs.asm
|
||||
main.asm
|
||||
recv.asm
|
||||
</extradist>
|
||||
|
||||
|
||||
</gwbuild>
|
||||
|
||||
|
||||
25
avr/apps/ma_light/data.asm
Normal file
25
avr/apps/ma_light/data.asm
Normal file
@@ -0,0 +1,25 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; data
|
||||
|
||||
.dseg
|
||||
|
||||
|
||||
|
||||
appMotionLightDataBegin:
|
||||
appMotionLightTimer: .byte 2
|
||||
appMotionLightOnTime: .byte 2
|
||||
appMotionLightColor: .byte 4
|
||||
appMotionLightSources: .byte APP_MOTIONLIGHT_SOURCE_NUM*APP_MOTIONLIGHT_SOURCE_SIZE
|
||||
appMotionLightDataEnd:
|
||||
|
||||
|
||||
25
avr/apps/ma_light/defs.asm
Normal file
25
avr/apps/ma_light/defs.asm
Normal file
@@ -0,0 +1,25 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; defines
|
||||
|
||||
.equ APP_MOTIONLIGHT_DEFAULT_ONTIME = 3000 ; 5min (in 1/10 secs)
|
||||
|
||||
.equ APP_MOTIONLIGHT_SOURCE_NUM = 2
|
||||
|
||||
.equ APP_MOTIONLIGHT_SOURCE_OFFS_ADDR = 0
|
||||
.equ APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID = 1
|
||||
.equ APP_MOTIONLIGHT_SOURCE_SIZE = 2
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
240
avr/apps/ma_light/main.asm
Normal file
240
avr/apps/ma_light/main.asm
Normal file
@@ -0,0 +1,240 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppMotionLight_Init @global
|
||||
;
|
||||
|
||||
AppMotionLight_Init:
|
||||
; preset SRAM data area
|
||||
ldi xh, HIGH(appMotionLightDataBegin)
|
||||
ldi xl, LOW(appMotionLightDataBegin)
|
||||
clr r16
|
||||
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)
|
||||
sts appMotionLightOnTime+1, r16
|
||||
|
||||
rcall appMotionLightReadConfFromEeprom
|
||||
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppMotionLight_Fini @global
|
||||
;
|
||||
|
||||
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, r23)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightHasSource
|
||||
;
|
||||
; @return CFLAGS set if we have a matching source entry, cleared otherwise
|
||||
; @param r17 value id
|
||||
; @param r22 source address
|
||||
; @clobbers r16, r24, Y
|
||||
|
||||
appMotionLightHasSource:
|
||||
ldi yl, LOW(appMotionLightSources)
|
||||
ldi yh, HIGH(appMotionLightSources)
|
||||
ldi r24, APP_MOTIONLIGHT_SOURCE_NUM
|
||||
appMotionLightHasSource_loop:
|
||||
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
||||
cp r16, r22
|
||||
brne appMotionLightHasSource_next
|
||||
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
||||
cp r16, r17
|
||||
brne appMotionLightHasSource_next
|
||||
sec
|
||||
ret
|
||||
appMotionLightHasSource_next:
|
||||
adiw yh:yl, APP_MOTIONLIGHT_SOURCE_SIZE
|
||||
dec r24
|
||||
brne appMotionLightHasSource_loop
|
||||
clc
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @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, r19, r20, r21 (r16, t17, r23)
|
||||
|
||||
appMotionLightTurnOn:
|
||||
lds r18, appMotionLightColor
|
||||
lds r19, appMotionLightColor+1
|
||||
lds r20, appMotionLightColor+2
|
||||
lds r21, appMotionLightColor+3
|
||||
rjmp SK6812_SetAllColor ; (r16, r17, r23)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightTurnOff
|
||||
;
|
||||
; @clobbers r18, r19, r20, r21 (r16, t17, r23)
|
||||
|
||||
appMotionLightTurnOff:
|
||||
clr r18
|
||||
clr r19
|
||||
clr r20
|
||||
clr r21
|
||||
rjmp SK6812_SetAllColor ; (r16, r17, r23)
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightReadConfFromEeprom
|
||||
;
|
||||
; @clobbers
|
||||
|
||||
appMotionLightReadConfFromEeprom:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
|
||||
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r18, r16
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r19, r16
|
||||
and r16, r18
|
||||
cpi r16, 0xff
|
||||
breq appMotionLightReadConfFromEeprom_end
|
||||
sts appMotionLightOnTime, r18
|
||||
sts appMotionLightOnTime+1, r19
|
||||
|
||||
; read source 1
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r18, r16
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r19, r16
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR, r18
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID, r19
|
||||
|
||||
; read source 2
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
mov r18, r16
|
||||
rcall Utils_ReadEepromIncr ; (R16)
|
||||
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
|
||||
|
||||
appMotionLightReadConfFromEeprom_end:
|
||||
out SREG, r15
|
||||
pop r15
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine appMotionLightWriteConfToEeprom
|
||||
;
|
||||
; @clobbers r15, r16, r17, X
|
||||
|
||||
appMotionLightWriteConfToEeprom:
|
||||
push r15
|
||||
in r15, SREG
|
||||
cli
|
||||
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
|
||||
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
|
||||
|
||||
lds r16, appMotionLightOnTime
|
||||
rcall Utils_WriteEepromIncr ; (R17)
|
||||
lds r16, appMotionLightOnTime+1
|
||||
rcall Utils_WriteEepromIncr ; (R17)
|
||||
|
||||
; write source 1
|
||||
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
||||
rcall Utils_WriteEepromIncr ; (R16)
|
||||
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
||||
rcall Utils_WriteEepromIncr ; (R16)
|
||||
|
||||
; write source 2
|
||||
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
|
||||
rcall Utils_WriteEepromIncr ; (R16)
|
||||
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
|
||||
rcall Utils_WriteEepromIncr ; (R16)
|
||||
|
||||
out SREG, r15
|
||||
pop r15
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
101
avr/apps/ma_light/recv.asm
Normal file
101
avr/apps/ma_light/recv.asm
Normal file
@@ -0,0 +1,101 @@
|
||||
; ***************************************************************************
|
||||
; 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. *
|
||||
; ***************************************************************************
|
||||
|
||||
|
||||
; ***************************************************************************
|
||||
; code
|
||||
|
||||
.cseg
|
||||
|
||||
|
||||
|
||||
; ---------------------------------------------------------------------------
|
||||
; @routine AppMotionLight_OnPacketReceived @global
|
||||
;
|
||||
; @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)
|
||||
mov r16, r18
|
||||
or r16, r19
|
||||
breq AppMotionLight_OnPacketReceived_clcRet ; zero value, ignore
|
||||
rcall appMotionLightHasSource ; (r16, r24, Y)
|
||||
brcs AppMotionLight_OnPacketReceived_turnOn
|
||||
ret
|
||||
AppMotionLight_OnPacketReceived_turnOn:
|
||||
lds r16, appMotionLightTimer
|
||||
lds r17, appMotionLightTimer+1
|
||||
or r16, r17
|
||||
brne AppMotionLight_OnPacketReceived_startTimer
|
||||
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
|
||||
AppMotionLight_OnPacketReceived_startTimer:
|
||||
rcall appMotionLightStartTimer
|
||||
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
|
||||
AppMotionLight_OnPacketReceived_clcRet:
|
||||
clc ; unexpected message
|
||||
ret
|
||||
AppMotionLight_OnPacketReceived_setRGBW:
|
||||
sts appMotionLightColor, r18
|
||||
sts appMotionLightColor+1, r19
|
||||
sts appMotionLightColor+2, r20
|
||||
sts appMotionLightColor+3, r21
|
||||
rcall appMotionLightStartTimer ; immediately ON with new color (r16)
|
||||
rcall appMotionLightTurnOn ; (r16, r17, r18, r19, r20, r21, r23)
|
||||
rjmp AppMotionLight_OnPacketReceived_sendAck
|
||||
AppMotionLight_OnPacketReceived_setOnTime:
|
||||
sts appMotionLightOnTime, r18
|
||||
sts appMotionLightOnTime+1, r19
|
||||
rjmp AppMotionLight_OnPacketReceived_sendAck
|
||||
AppMotionLight_OnPacketReceived_setSource1:
|
||||
sts appMotionLightSources, r18 ; peerAddr
|
||||
sts appMotionLightSources+1, r19 ; valueId
|
||||
rjmp AppMotionLight_OnPacketReceived_sendAck
|
||||
AppMotionLight_OnPacketReceived_setSource2:
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE, r18 ; peerAddr
|
||||
sts appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+1, r19 ; valueId
|
||||
AppMotionLight_OnPacketReceived_sendAck:
|
||||
push xl
|
||||
push xh
|
||||
mov r16, r22 ; src address
|
||||
ldi r23, NETMSG_CMD_VALUE_SET_ACK
|
||||
clr r17
|
||||
rcall Main_SendValueResponse ; (clobbers all, including Y)
|
||||
rcall appMotionLightWriteConfToEeprom
|
||||
pop xh
|
||||
pop xl
|
||||
sec
|
||||
ret
|
||||
; @end
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user