; ***************************************************************************
; copyright   : (C) 2025 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.   *
; ***************************************************************************


.equ LED_ACTIVITY_TIME = 2



; ***************************************************************************
; data

.dseg

ledActivityTimer:      .byte 1


; ***************************************************************************
; code

.cseg


LED_ACTIVITY_BEGIN:



; ---------------------------------------------------------------------------
; LedActivity_Init
;
; @return CFLAG: set if okay, clear on error
; USED: R1, R2, R3, R4, R16, R17, X

LedActivity_Init:
  sbi LED_ACTIVITY_DDR, LED_ACTIVITY_PINNUM  ; out
  ldi r16, 50
  sts ledActivityTimer, r16                  ; keep on for 5s at the beginning
  sec
  ret



; ---------------------------------------------------------------------------
; @routine LedActivity_Every100ms @global
;
; @clobbers r16, r17

LedActivity_Every100ms:
  lds r16, ledActivityTimer
  tst r16
  breq LedActivity_Every100ms_ret
  dec r16
  sts ledActivityTimer, r16
  brne LedActivity_Every100ms_ret
  sbi LED_ACTIVITY_PORT, LED_ACTIVITY_PINNUM ; turn LED off
LedActivity_Every100ms_ret:
  ret
; @end



; ---------------------------------------------------------------------------
; @routine LedActivity_Restart @global
;
; @clobbers r16

LedActivity_Trigger:
  lds r16, ledActivityTimer
  tst r16
  brne LedActivity_Trigger_ledIsOn
  cbi LED_ACTIVITY_PORT, LED_ACTIVITY_PINNUM ; turn LED on
LedActivity_Trigger_ledIsOn:
  ldi r16, LED_ACTIVITY_TIME
  sts ledActivityTimer, r16
  ret
; @end




LED_ACTIVITY_END:
.equ MODULE_SIZE_LED_ACTIVITY = LED_ACTIVITY_END-LED_ACTIVITY_BEGIN



