avr: optimized app MA_LIGHT (from 3295 to 3222 words).

This commit is contained in:
Martin Preuss
2026-04-26 15:18:38 +02:00
parent c6fdc94a46
commit 6948028284
7 changed files with 143 additions and 166 deletions

View File

@@ -27,7 +27,7 @@ AppMotionLight_Init:
ldi r17, (appMotionLightDataEnd-appMotionLightDataBegin)
rcall Utils_FillSram
rcall appMotionLightReadConfFromEeprom
rcall appMotionLightReadConfFromEeprom ; (r16, r17, X, Y)
ret
; @end
@@ -53,23 +53,17 @@ AppMotionLight_Fini:
; @clobbers r16, r24, Y
appMotionLightHasSource:
ldi yl, LOW(appMotionLightSources)
ldi yh, HIGH(appMotionLightSources)
ldi yl, LOW(appMotionLightMSources)
ldi yh, HIGH(appMotionLightMSources)
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:
rcall appMotionLightCheckMsgSrc
brcs appMotionLightHasSource_ret
adiw yh:yl, APP_MOTIONLIGHT_SOURCE_SIZE
dec r24
brne appMotionLightHasSource_loop
brne appMotionLightHasSource_loop
clc
appMotionLightHasSource_ret:
ret
; @end
@@ -81,20 +75,37 @@ appMotionLightHasSource_next:
; @return CFLAGS set if we have a matching source entry, cleared otherwise
; @param r17 value id
; @param r22 source address
; @clobbers R16
; @clobbers R16, Y
appMotionLightIsBrightnessSource:
lds r16, appMotionLightLSourceAddr
cp r16, r22
brne appMotionLightIsBrightnessSource_no
lds r16, appMotionLightLSourceValueId
cp r16, r17
brne appMotionLightIsBrightnessSource_no
ldi yl, LOW(appMotionLightLSource)
ldi yh, HIGH(appMotionLightLSource)
rjmp appMotionLightCheckMsgSrc
; @end
; ---------------------------------------------------------------------------
; @routine appMotionLightCheckMsgSrc
;
; @return CFLAGS set if we have a matching source entry, cleared otherwise
; @param r17 value id
; @param r22 source address
; @param Y pointer to addr/valueid pair to investigate
; @clobbers R16
appMotionLightCheckMsgSrc:
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
cp r16, r22 ; check node addr
brne appMotionLightCheckMsgSrc_no
ldd r16, Y+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
cp r16, r17 ; check value id
brne appMotionLightCheckMsgSrc_no
sec
rjmp appMotionLightIsBrightnessSource_ret
appMotionLightIsBrightnessSource_no:
rjmp appMotionLightCheckMsgSrc_ret
appMotionLightCheckMsgSrc_no:
clc
appMotionLightIsBrightnessSource_ret:
appMotionLightCheckMsgSrc_ret:
ret
; @end
@@ -103,56 +114,29 @@ appMotionLightIsBrightnessSource_ret:
; ---------------------------------------------------------------------------
; @routine appMotionLightReadConfFromEeprom
;
; @clobbers
; @clobbers r16, r17, X, Y
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
bigcall SK6812_SetAutoTimerReload ; (none)
; 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
ldi xl, LOW(EEPROM_OFFS_MAL_CONF)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF)
ldi yl, LOW(appMotionLightSettings)
ldi yh, HIGH(appMotionLightSettings)
ldi r17, APP_MOTIONLIGHT_EE_SIZE
bigcall Eeprom_ReadBytes ; (r16, r17, X, Y)
brcc appMotionLightReadConfFromEeprom_ret
lds r18, appMotionLightOnTime
lds r19, appMotionLightOnTime+1
mov r16, r18
and r16, r19
inc r16
brne appMotionLightReadConfFromEeprom_reload
ldi r18, LOW(APP_MOTIONLIGHT_DEFAULT_ONTIME)
ldi r19, HIGH(APP_MOTIONLIGHT_DEFAULT_ONTIME)
appMotionLightReadConfFromEeprom_reload:
bigcall SK6812_SetAutoTimerReload ; (none)
; 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
; read brightness source
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceAddr, r16
rcall Utils_ReadEepromIncr ; (R16)
sts appMotionLightLSourceValueId, r16
; read brightness limit
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
appMotionLightReadConfFromEeprom_ret:
ret
; @end
@@ -161,59 +145,15 @@ appMotionLightReadConfFromEeprom_end:
; ---------------------------------------------------------------------------
; @routine appMotionLightWriteConfToEeprom
;
; @clobbers r16, r17, X
; @clobbers r16, r17, X, Y
appMotionLightWriteConfToEeprom:
push r15
in r15, SREG
cli
ldi xl, LOW(EEPROM_OFFS_MAL_CONF_ONTIME)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF_ONTIME)
rcall SK6812_GetAutoTimerReload
mov r16, r18
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
mov r16, r19
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
; write source 2
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_ADDR
rcall Eeprom_WriteByteIfChanged ; (R17)
adiw xh:xl, 1
lds r16, appMotionLightSources+APP_MOTIONLIGHT_SOURCE_SIZE+APP_MOTIONLIGHT_SOURCE_OFFS_VALUEID
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
ret
ldi xl, LOW(EEPROM_OFFS_MAL_CONF)
ldi xh, HIGH(EEPROM_OFFS_MAL_CONF)
ldi yl, LOW(appMotionLightSettings)
ldi yh, HIGH(appMotionLightSettings)
ldi r17, APP_MOTIONLIGHT_EE_SIZE
bigjmp Eeprom_WriteBytes ; (r16, r17, r18, X, Y)
; @end