From 393df322f043ee0529fbc1288189782834212d1a Mon Sep 17 00:00:00 2001 From: Martin Preuss Date: Sun, 15 Mar 2026 20:20:06 +0100 Subject: [PATCH] avr: added rtc module for ds3231 --- avr/modules/0BUILD | 1 + avr/modules/rtc/0BUILD | 10 ++ avr/modules/rtc/ds3231/0BUILD | 13 ++ avr/modules/rtc/ds3231/main.asm | 226 ++++++++++++++++++++++++++++++++ avr/modules/rtc/ds3231/recv.asm | 57 ++++++++ avr/modules/rtc/ds3231/send.asm | 113 ++++++++++++++++ 6 files changed, 420 insertions(+) create mode 100644 avr/modules/rtc/0BUILD create mode 100644 avr/modules/rtc/ds3231/0BUILD create mode 100644 avr/modules/rtc/ds3231/main.asm create mode 100644 avr/modules/rtc/ds3231/recv.asm create mode 100644 avr/modules/rtc/ds3231/send.asm diff --git a/avr/modules/0BUILD b/avr/modules/0BUILD index 4cfef6f..8fe82d9 100644 --- a/avr/modules/0BUILD +++ b/avr/modules/0BUILD @@ -42,6 +42,7 @@ xram heap brightness + rtc diff --git a/avr/modules/rtc/0BUILD b/avr/modules/rtc/0BUILD new file mode 100644 index 0000000..8a211af --- /dev/null +++ b/avr/modules/rtc/0BUILD @@ -0,0 +1,10 @@ + + + + + + ds3231 + + + + diff --git a/avr/modules/rtc/ds3231/0BUILD b/avr/modules/rtc/ds3231/0BUILD new file mode 100644 index 0000000..c7ca6fd --- /dev/null +++ b/avr/modules/rtc/ds3231/0BUILD @@ -0,0 +1,13 @@ + + + + + + main.asm + recv.asm + send.asm + + + + + diff --git a/avr/modules/rtc/ds3231/main.asm b/avr/modules/rtc/ds3231/main.asm new file mode 100644 index 0000000..9400bfe --- /dev/null +++ b/avr/modules/rtc/ds3231/main.asm @@ -0,0 +1,226 @@ +; *************************************************************************** +; 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. * +; *************************************************************************** + + + +; *************************************************************************** +; defs + +.equ DS3231_FLAGS_PRESENT_BIT = 7 +.equ DS3231_FLAGS_VALID_BIT = 6 + + + + + +; *************************************************************************** +; data + +.dseg + +ds3231DataBegin: + ds3231Flags: .byte 1 + ds3231RecvBuffer: .byte 7 +ds3231DataEnd: + + + + +; *************************************************************************** +; code + +.cseg + + + +; --------------------------------------------------------------------------- +; @routine Ds3231_Init @global +; +; @return CFLAG set if okay, cleared on error +; @clobbers + +Ds3231_Init: + ldi xh, HIGH(ds3231DataBegin) + ldi xl, LOW(ds3231DataBegin) + clr r16 + ldi r17, (ds3231DataEnd-ds3231DataBegin) + rcall Utils_FillSram + + rcall ds3231CheckPresence + brcc Ds3231_Init_ret + ldi r16, (1<