modes: - heartbeat mode (as before) - id mode (slowly blink for 30s after receiving PING) - activity mode (short blink to signal e.g. network activity) The latter two modes fallback to heartbeat mode after some time.
195 lines
4.5 KiB
NASM
195 lines
4.5 KiB
NASM
; ***************************************************************************
|
|
; 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. *
|
|
; ***************************************************************************
|
|
|
|
|
|
; ***************************************************************************
|
|
; defines
|
|
|
|
.equ LED_SIMPLE_LED_FAST_REPEATS = 20
|
|
.equ LED_SIMPLE_LED_FAST_ONTIME = 2
|
|
.equ LED_SIMPLE_LED_FAST_OFFTIME = 2
|
|
|
|
|
|
.equ LED_SIMPLE_LED_ACTIVITY_REPEATS = 1
|
|
.equ LED_SIMPLE_LED_ACTIVITY_ONTIME = 3
|
|
.equ LED_SIMPLE_LED_ACTIVITY_OFFTIME = 5
|
|
|
|
|
|
.equ LED_SIMPLE_LED_ID_REPEATS = 30
|
|
.equ LED_SIMPLE_LED_ID_ONTIME = 5
|
|
.equ LED_SIMPLE_LED_ID_OFFTIME = 5
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; data
|
|
|
|
.dseg
|
|
|
|
ledSimpleTimer: .byte 1
|
|
ledSimpleOnTime: .byte 1
|
|
ledSimpleOffTime: .byte 1
|
|
ledSimpleRepeat: .byte 1
|
|
|
|
|
|
|
|
; ***************************************************************************
|
|
; code
|
|
|
|
.cseg
|
|
|
|
|
|
LED_SIMPLE_BEGIN:
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; LedSimple_Init
|
|
;
|
|
; IN:
|
|
; - nothing
|
|
; OUT:
|
|
; - CFLAG: set if okay, clear on error
|
|
; USED: R1, R2, R3, R4, R16, R17, X
|
|
|
|
LedSimple_Init:
|
|
sbi LED_SIMPLE_DDR, LED_SIMPLE_PINNUM ; out
|
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
|
rcall LedSimple_SetDefaultTiming ; (R16)
|
|
sec
|
|
ret
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_Every100ms @global
|
|
;
|
|
; @clobbers r16, r18, r19, r20
|
|
|
|
LedSimple_Every100ms:
|
|
lds r16, ledSimpleTimer
|
|
dec r16
|
|
breq LedSimple_Every100ms_zero
|
|
rjmp LedSimple_Every100ms_setTimer
|
|
LedSimple_Every100ms_zero:
|
|
sbic LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; skip next op if LED is on
|
|
rjmp LedSimple_Tick_isOff
|
|
; is on
|
|
sbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; off
|
|
lds r16, ledSimpleOffTime
|
|
rjmp LedSimple_Every100ms_setTimer
|
|
LedSimple_Tick_isOff:
|
|
lds r16, ledSimpleRepeat
|
|
tst r16
|
|
breq LedSimple_Tick_restartTimer
|
|
dec r16
|
|
sts ledSimpleRepeat, r16
|
|
brne LedSimple_Tick_restartTimer
|
|
; repeat counter reached 0, enter heartbeat mode
|
|
rcall LedSimple_SetDefaultTiming
|
|
rjmp LedSimple_Every100ms_ret
|
|
LedSimple_Tick_restartTimer:
|
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
|
lds r16, ledSimpleOnTime
|
|
LedSimple_Every100ms_setTimer:
|
|
sts ledSimpleTimer, r16
|
|
LedSimple_Every100ms_ret:
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_SetDefaultTiming @global
|
|
;
|
|
; Set default timing for LED.
|
|
; @clobbers R18, R19, R20
|
|
|
|
LedSimple_SetDefaultTiming:
|
|
ldi r18, LED_SIMPLE_ONTIME
|
|
ldi r19, LED_SIMPLE_OFFTIME
|
|
clr r20
|
|
rjmp LedSimple_SetTiming
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_SetFastTiming @global
|
|
;
|
|
; Set fast blinking timing for LED. Switch LED on.
|
|
; @clobbers R18, R19, R20
|
|
|
|
LedSimple_SetFastTiming:
|
|
ldi r18, 5
|
|
ldi r19, 3
|
|
ldi r20, LED_SIMPLE_LED_FAST_REPEATS
|
|
rjmp LedSimple_SetTiming
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_SignalId @global
|
|
;
|
|
; Set ID timing for LED (used to id a device).
|
|
; @clobbers R18, R19, R20
|
|
|
|
LedSimple_SignalId:
|
|
ldi r18, LED_SIMPLE_LED_ID_ONTIME
|
|
ldi r19, LED_SIMPLE_LED_ID_OFFTIME
|
|
ldi r20, LED_SIMPLE_LED_ID_REPEATS
|
|
rjmp LedSimple_SetTiming
|
|
; @end
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_SignalActivity @global
|
|
;
|
|
; Set ID timing for LED (used to id a device).
|
|
; @clobbers R18, R19, R20
|
|
|
|
LedSimple_SignalActivity:
|
|
ldi r18, LED_SIMPLE_LED_ACTIVITY_ONTIME
|
|
ldi r19, LED_SIMPLE_LED_ACTIVITY_OFFTIME
|
|
ldi r20, LED_SIMPLE_LED_ACTIVITY_REPEATS
|
|
rjmp LedSimple_SetTiming
|
|
; @end
|
|
|
|
|
|
|
|
|
|
; ---------------------------------------------------------------------------
|
|
; @routine LedSimple_SetTiming @global
|
|
;
|
|
; Set blinking timing for LED. Switch LED on.
|
|
; @param r18 ontime (in 1/10s)
|
|
; @param r19 offtime (in 1/10s)
|
|
; @param r20 repeats (stop after this number of repeats, 0 for continuous mode)
|
|
; @clobbers none
|
|
;
|
|
|
|
LedSimple_SetTiming:
|
|
sts ledSimpleOnTime, r18
|
|
sts ledSimpleTimer, r18
|
|
sts ledSimpleOffTime, r19
|
|
sts ledSimpleRepeat, r20
|
|
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
|
|
ret
|
|
; @end
|
|
|
|
|
|
|
|
|
|
LED_SIMPLE_END:
|
|
.equ MODULE_SIZE_LED_SIMPLE = LED_SIMPLE_END-LED_SIMPLE_BEGIN
|
|
|
|
|
|
|