avr: more work on fan- and light controller app and modules.

This commit is contained in:
Martin Preuss
2026-08-07 23:45:21 +02:00
parent 296ead3241
commit f973ce1b14
9 changed files with 132 additions and 39 deletions

View File

@@ -201,6 +201,7 @@ appFanControlWriteEeprom_ret:
appFanControlActorOn:
ldd r16, Y+APP_FANCONTROL_RAM_OFFS_VALUE_LO
rcall appFanControlSetFanDutyFromTable
bigcall AppFanControl_ReportState
ret
; @end
@@ -214,7 +215,9 @@ appFanControlActorOn:
appFanControlActorOff:
clr r16
rjmp appFanControlSetFanDutyFromTable
rcall appFanControlSetFanDutyFromTable
bigcall AppFanControl_ReportState
ret
; @end

View File

@@ -0,0 +1,53 @@
; ***************************************************************************
; copyright : (C) 2026 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. *
; ***************************************************************************
#ifndef AQH_AVR_APPS_FAN_CONTROL_SEND_ASM
#define AQH_AVR_APPS_FAN_CONTROL_SEND_ASM
.cseg
; ---------------------------------------------------------------------------
; @routine AppFanControl_ReportState
;
; @clobbers R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X
AppFanControl_ReportState:
push yl
push yh
push zl
push zh
ldi zl, LOW(appFanControlObjectFlash*2)
ldi zh, HIGH(appFanControlObjectFlash*2)
lpm yl, Z+
lpm yh, Z
sbiw zh:zl, 1
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
clr r18
sbrc r16, HTIM_FLAGBIT_STATE
inc r18
ldi r17, VALUE_ID_FANCTRL_STATE
clr r19
ldi r20, 1
clr r21
ldi r22, AQHOME_VALUETYPE_ONOFF
rcall Main_SendValueReport ; (R16, R17, R18, R19, R20, R21, R23, R24, R25, X)
pop zh
pop zl
pop yh
pop yl
ret
; @end
#endif

View File

@@ -11,7 +11,7 @@
#define AQH_AVR_APPS_LIGHT_CONTROL_MAIN_ASM
.equ APP_LIGHTCONTROL_LIGHT_LIMIT = 15
.equ APP_LIGHTCONTROL_LIGHT_LIMIT = 20
@@ -139,9 +139,10 @@ appLightControlUpdate:
appLightControlUpdate_auto:
sbr r16, (1<<HTIM_FLAGBIT_ACTIVE) | (1<<HTIM_FLAGBIT_ACTORENABLED) ; enable timer
std Y+HTIM_RAM_OFFS_FLAGS, r16
sbrs r16, HTIM_FLAGBIT_STATE
rjmp appLightControlUpdate_ret ; jump if clear (actor is off)
rcall appLightControlActorOn
bigcall HTIM_Trigger
; sbrs r16, HTIM_FLAGBIT_STATE
; rjmp appLightControlUpdate_ret ; jump if clear (actor is off)
; rcall appLightControlActorOn
rjmp appLightControlUpdate_ret
appLightControlUpdate_on:
rcall appLightControlActorOn
@@ -185,16 +186,16 @@ appLightControlReadEeprom_ret:
appLightControlWriteEeprom:
ldi r16, APP_LIGHTCONTROL_EEID
bigcall EepromTlv_FindFirst
bigcall EepromTlv_FindFirst ; X=ptr, r17=length (r16, r18)
brcs appLightControlWriteEeprom_write
; create eeprom TLV
ldi r16, APP_LIGHTCONTROL_EEID
ldi r17, APP_LIGHTCONTROL_EE_SIZE
bigcall EepromTlv_AddTlv
bigcall EepromTlv_AddTlv ; X=ptr (r16, r20, r21, r18)
brcc appLightControlWriteEeprom_ret
appLightControlWriteEeprom_write:
; let base class write
bigcall TCA_WriteEepromAt
bigcall TCA_WriteEepromAt ;
brcc appLightControlWriteEeprom_ret
push yl
push yh
@@ -220,12 +221,8 @@ appLightControlActorOn:
ldd r20, Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_BLUE
ldd r21, Y+APP_LIGHTCONTROL_RAM_OFFS_VALUE_WHITE
bigcall SK6812_SetRGBW ; (r16, r24, r25)
ldi r18, 1
push yl
push yh
bigcall AppLightControl_ReportState
pop yh
pop yl
bigcall AppLightControl_ReportState
ret
; @end
@@ -243,14 +240,32 @@ appLightControlActorOff:
clr r20
clr r21
bigcall SK6812_SetRGBW ; (r16, r24, r25)
ldi r18, 0
bigcall AppLightControl_ReportState
ret
; @end
#if 0
appLightControlDebug:
; debug
ldi r17, 0xf0
ldd r18, Y+HTIM_RAM_OFFS_FLAGS
ldd r19, Y+HTIM_RAM_OFFS_MODE
ldd r20, Y+HTIM_RAM_OFFS_CURRVAL_LO
ldd r21, Y+HTIM_RAM_OFFS_CURRVAL_HI
ldi r22, AQHOME_VALUETYPE_ONOFF
push yl
push yh
bigcall AppLightControl_ReportState
rcall Main_SendValueReport ; (R16, R17, R18, R19, R20, R21, R23, R24, R25, X)
pop yh
pop yl
ret
; @end
#endif

View File

@@ -1,5 +1,5 @@
; ***************************************************************************
; copyright : (C) 2024 by Martin Preuss
; copyright : (C) 2026 by Martin Preuss
; email : martin@libchipcard.de
;
; ***************************************************************************
@@ -14,20 +14,33 @@
; ---------------------------------------------------------------------------
; @routine sk6812ReportState
; @routine AppLightControl_ReportState
;
; @param R18 state (0=off, 1=on)
; @clobbers R16, R17, R18, R19, R20, R21, R22, R23, R24, R25, X
AppLightControl_ReportState:
ldi r17, VALUE_ID_LIGHTCONTROL_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)
push zl
push zh
ldi zl, LOW(appLightControlObjectFlash*2)
ldi zh, HIGH(appLightControlObjectFlash*2)
lpm yl, Z+
lpm yh, Z
sbiw zh:zl, 1
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
clr r18
sbrc r16, HTIM_FLAGBIT_STATE
inc r18
ldi r17, VALUE_ID_LIGHTCONTROL_STATE
clr r19
ldi r20, 1
clr r21
ldi r22, AQHOME_VALUETYPE_ONOFF
rcall Main_SendValueReport ; (R16, R17, R18, R19, R20, R21, R23, R24, R25, X)
pop zh
pop zl
pop yh
pop yl
ret

View File

@@ -56,11 +56,11 @@
#define MODULES_NETWORK
#define MODULES_COM2W
#define MODULES_OWI_MASTER
;#define MODULES_DS18B20
#define MODULES_DS18B20
#define MODULES_SK6812
#define APPS_NETWORK
;#define APPS_REPORTSENSORS
#define APPS_REPORTSENSORS
#define APPS_STATS
#define APPS_LIGHTCONTROL
@@ -184,7 +184,7 @@ onEveryLoop:
.include "devices/all/includes.asm"
;.include "common/debug.asm"
.include "common/eeprom_tlv.asm"
.include "common/walktable.asm"
;.include "common/walktable.asm"

View File

@@ -103,6 +103,7 @@
.equ VALUE_ID_FAN3_SPEED = 0x0a ; RPM
; new values
.equ VALUE_ID_FANCTRL_STATE = 0x07
.equ VALUE_ID_FANCTRL_GUARDSRC = 0x90
.equ VALUE_ID_FANCTRL_GUARDLIM = 0x91
.equ VALUE_ID_FANCTRL_TRIGGER1SRC = 0x92

View File

@@ -51,6 +51,8 @@ HTIM_Init:
HTIM_EnableActor:
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
sbrc r16, HTIM_FLAGBIT_ACTORENABLED
rjmp HTIM_EnableActor_ret ; jmp if already enabled
sbr r16, (1<<HTIM_FLAGBIT_ACTORENABLED)
std Y+HTIM_RAM_OFFS_FLAGS, r16
sbrs r16, HTIM_FLAGBIT_ACTIVE
@@ -72,8 +74,11 @@ HTIM_EnableActor_ret:
HTIM_DisableActor:
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
sbrs r16, HTIM_FLAGBIT_ACTORENABLED
rjmp HTIM_DisableActor_ret ; jmp if already disabled
cbr r16, (1<<HTIM_FLAGBIT_ACTORENABLED)
std Y+HTIM_RAM_OFFS_FLAGS, r16
HTIM_DisableActor_ret:
ret
; @end
@@ -116,10 +121,15 @@ HTIM_Stop:
;
; @param Z pointer to timer data in FLASH (byte address for lpm!)
; @param Y pointer to data in RAM
; @clobbers Y
HTIM_Trigger:
rjmp htimReloadTimer
ldd r17, Y+HTIM_RAM_OFFS_FLAGS
sbrs r17, HTIM_FLAGBIT_ACTIVE
rjmp HTIM_Trigger_ret ; jmp if not active
sbrc r17, HTIM_FLAGBIT_ACTORENABLED ; don't reload
rcall htimReloadTimer
HTIM_Trigger_ret:
ret
; @end
@@ -263,17 +273,13 @@ htimCallActorOff_ret:
; @clobbers none
htimReloadTimer:
ldd r17, Y+HTIM_RAM_OFFS_FLAGS
sbrs r17, HTIM_FLAGBIT_ACTIVE
rjmp htimReloadTimer_ret ; jmp if not active
; really reload timer
ldd r16, Y+HTIM_RAM_OFFS_RELOAD_LO
std Y+HTIM_RAM_OFFS_CURRVAL_LO, r16
ldd r16, Y+HTIM_RAM_OFFS_RELOAD_HI
std Y+HTIM_RAM_OFFS_CURRVAL_HI, r16
; switch fans ON
rcall htimCallActorOn ; turn on actor
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
sbrs r16, HTIM_FLAGBIT_STATE
rcall htimCallActorOn ; turn on actor
htimReloadTimer_ret:
ret
; @end

View File

@@ -88,10 +88,10 @@ tcaCheckGuardSource:
rcall tcaCheckValue
ldd r16, Y+HTIM_RAM_OFFS_FLAGS
brcc tcaCheckGuardSource_noMatch
sbr r16, (1<<TCA_FLAGBITS_NEED_ENABLE) | (1<<TCA_FLAGBIT_UPDATED)
sbr r16, (1<<TCA_FLAGBITS_NEED_ENABLE)
rjmp tcaCheckGuardSource_done
tcaCheckGuardSource_noMatch:
sbr r16, (1<<TCA_FLAGBITS_NEED_DISABLE) | (1<<TCA_FLAGBIT_UPDATED)
sbr r16, (1<<TCA_FLAGBITS_NEED_DISABLE)
tcaCheckGuardSource_done:
std Y+HTIM_RAM_OFFS_FLAGS, r16

View File

@@ -15,6 +15,8 @@
<value name="FAN3_SPEED" id="0x0a" type="sensor" dataType="uint16" modality="rpm" denom="1" />
<value name="FANCTL_STATE" id="0x07" type="sensor" dataType="uint16" modality="onOff" />
<value name="FANCTL_GUARD_SOURCE" id="0x90" type="actor" dataType="uint16" denom="1" />
<value name="FANCTL_GUARD_LIMITS" id="0x91" type="actor" dataType="uint32" denom="1" />