led_simple: improved module, added repeats, id mode and activity mode.

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.
This commit is contained in:
Martin Preuss
2026-03-24 18:18:02 +01:00
parent 07a6c5a540
commit e23bfde746

View File

@@ -1,5 +1,5 @@
; *************************************************************************** ; ***************************************************************************
; copyright : (C) 2023 by Martin Preuss ; copyright : (C) 2026 by Martin Preuss
; email : martin@libchipcard.de ; email : martin@libchipcard.de
; ;
; *************************************************************************** ; ***************************************************************************
@@ -8,6 +8,24 @@
; *************************************************************************** ; ***************************************************************************
; ***************************************************************************
; 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 ; data
@@ -17,6 +35,7 @@
ledSimpleTimer: .byte 1 ledSimpleTimer: .byte 1
ledSimpleOnTime: .byte 1 ledSimpleOnTime: .byte 1
ledSimpleOffTime: .byte 1 ledSimpleOffTime: .byte 1
ledSimpleRepeat: .byte 1
@@ -50,7 +69,7 @@ LedSimple_Init:
; --------------------------------------------------------------------------- ; ---------------------------------------------------------------------------
; @routine LedSimple_Every100ms @global ; @routine LedSimple_Every100ms @global
; ;
; @clobbers r16 ; @clobbers r16, r18, r19, r20
LedSimple_Every100ms: LedSimple_Every100ms:
lds r16, ledSimpleTimer lds r16, ledSimpleTimer
@@ -65,10 +84,21 @@ LedSimple_Every100ms_zero:
lds r16, ledSimpleOffTime lds r16, ledSimpleOffTime
rjmp LedSimple_Every100ms_setTimer rjmp LedSimple_Every100ms_setTimer
LedSimple_Tick_isOff: 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 cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
lds r16, ledSimpleOnTime lds r16, ledSimpleOnTime
LedSimple_Every100ms_setTimer: LedSimple_Every100ms_setTimer:
sts ledSimpleTimer, r16 sts ledSimpleTimer, r16
LedSimple_Every100ms_ret:
ret ret
; @end ; @end
@@ -78,12 +108,12 @@ LedSimple_Every100ms_setTimer:
; @routine LedSimple_SetDefaultTiming @global ; @routine LedSimple_SetDefaultTiming @global
; ;
; Set default timing for LED. ; Set default timing for LED.
; @clobbers R18, R19 ; @clobbers R18, R19, R20
;
LedSimple_SetDefaultTiming: LedSimple_SetDefaultTiming:
ldi r18, LED_SIMPLE_ONTIME ldi r18, LED_SIMPLE_ONTIME
ldi r19, LED_SIMPLE_OFFTIME ldi r19, LED_SIMPLE_OFFTIME
clr r20
rjmp LedSimple_SetTiming rjmp LedSimple_SetTiming
; @end ; @end
@@ -93,23 +123,55 @@ LedSimple_SetDefaultTiming:
; @routine LedSimple_SetFastTiming @global ; @routine LedSimple_SetFastTiming @global
; ;
; Set fast blinking timing for LED. Switch LED on. ; Set fast blinking timing for LED. Switch LED on.
; @clobbers R18, R19 ; @clobbers R18, R19, R20
;
LedSimple_SetFastTiming: LedSimple_SetFastTiming:
ldi r18, 5 ldi r18, 5
ldi r19, 3 ldi r19, 3
ldi r20, LED_SIMPLE_LED_FAST_REPEATS
rjmp LedSimple_SetTiming rjmp LedSimple_SetTiming
; @end ; @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 ; @routine LedSimple_SetTiming @global
; ;
; Set blinking timing for LED. Switch LED on. ; Set blinking timing for LED. Switch LED on.
; @param r18 ontime (in 1/10s) ; @param r18 ontime (in 1/10s)
; @param r19 offtime (in 1/10s) ; @param r19 offtime (in 1/10s)
; @param r20 repeats (stop after this number of repeats, 0 for continuous mode)
; @clobbers none ; @clobbers none
; ;
@@ -117,12 +179,14 @@ LedSimple_SetTiming:
sts ledSimpleOnTime, r18 sts ledSimpleOnTime, r18
sts ledSimpleTimer, r18 sts ledSimpleTimer, r18
sts ledSimpleOffTime, r19 sts ledSimpleOffTime, r19
sts ledSimpleRepeat, r20
cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on cbi LED_SIMPLE_PORT, LED_SIMPLE_PINNUM ; on
ret ret
; @end ; @end
LED_SIMPLE_END: LED_SIMPLE_END:
.equ MODULE_SIZE_LED_SIMPLE = LED_SIMPLE_END-LED_SIMPLE_BEGIN .equ MODULE_SIZE_LED_SIMPLE = LED_SIMPLE_END-LED_SIMPLE_BEGIN