diff --git a/avr/modules/led_simple/main.asm b/avr/modules/led_simple/main.asm index 3cb5a2d..6562eb3 100644 --- a/avr/modules/led_simple/main.asm +++ b/avr/modules/led_simple/main.asm @@ -1,5 +1,5 @@ ; *************************************************************************** -; copyright : (C) 2023 by Martin Preuss +; copyright : (C) 2026 by Martin Preuss ; 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 @@ -17,6 +35,7 @@ ledSimpleTimer: .byte 1 ledSimpleOnTime: .byte 1 ledSimpleOffTime: .byte 1 +ledSimpleRepeat: .byte 1 @@ -50,7 +69,7 @@ LedSimple_Init: ; --------------------------------------------------------------------------- ; @routine LedSimple_Every100ms @global ; -; @clobbers r16 +; @clobbers r16, r18, r19, r20 LedSimple_Every100ms: lds r16, ledSimpleTimer @@ -65,10 +84,21 @@ LedSimple_Every100ms_zero: 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 @@ -78,12 +108,12 @@ LedSimple_Every100ms_setTimer: ; @routine LedSimple_SetDefaultTiming @global ; ; Set default timing for LED. -; @clobbers R18, R19 -; +; @clobbers R18, R19, R20 LedSimple_SetDefaultTiming: ldi r18, LED_SIMPLE_ONTIME ldi r19, LED_SIMPLE_OFFTIME + clr r20 rjmp LedSimple_SetTiming ; @end @@ -93,23 +123,55 @@ LedSimple_SetDefaultTiming: ; @routine LedSimple_SetFastTiming @global ; ; Set fast blinking timing for LED. Switch LED on. -; @clobbers R18, R19 -; +; @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 ; @@ -117,12 +179,14 @@ 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