diff --git a/.gitmodules b/.gitmodules index 78bc58a..c71a746 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,15 @@ -[submodule "ds3231/usart"] - path = ds3231/usart - url = git@git.blackmark.me:avr/usart.git [submodule "ds3231/ds3231"] path = ds3231/ds3231 url = git@git.blackmark.me:avr/ds3231.git +[submodule "ds3231/uart"] + path = ds3231/uart + url = git@git.blackmark.me:avr/uart.git +[submodule "ds3231/io"] + path = ds3231/io + url = git@git.blackmark.me:avr/io.git +[submodule "ds3231/flash"] + path = ds3231/flash + url = git@git.blackmark.me:avr/flash.git +[submodule "ds3231/type"] + path = ds3231/type + url = git@git.blackmark.me:avr/type.git diff --git a/ds3231/clock.h b/ds3231/clock.h deleted file mode 100644 index 95d07be..0000000 --- a/ds3231/clock.h +++ /dev/null @@ -1,14 +0,0 @@ -/* - * Copyright (c) by BlackMark 2015 - * Date 24/11/2015 - * Version 1.1 - */ - -#ifndef CLOCK_H -#define CLOCK_H - -#define F_CPU 16'000'000 - -#include - -#endif diff --git a/ds3231/clock.hpp b/ds3231/clock.hpp new file mode 100644 index 0000000..052799d --- /dev/null +++ b/ds3231/clock.hpp @@ -0,0 +1,4 @@ +#pragma once + +#define F_CPU 16'000'000 +#include diff --git a/ds3231/ds3231 b/ds3231/ds3231 index 727a974..9303fbf 160000 --- a/ds3231/ds3231 +++ b/ds3231/ds3231 @@ -1 +1 @@ -Subproject commit 727a9745043915d4f5623c11e6744e69d80d572f +Subproject commit 9303fbf5b59bd934ec0c91d5540b851366da92e1 diff --git a/ds3231/ds3231.cppproj b/ds3231/ds3231.cppproj index f0119a0..949d764 100644 --- a/ds3231/ds3231.cppproj +++ b/ds3231/ds3231.cppproj @@ -215,7 +215,7 @@ - + compile @@ -242,19 +242,43 @@ compile + + compile + + + compile + compile - + compile - + + compile + + + compile + + + compile + + + compile + + + compile + + compile - + + + + \ No newline at end of file diff --git a/ds3231/flash b/ds3231/flash new file mode 160000 index 0000000..6edb2e5 --- /dev/null +++ b/ds3231/flash @@ -0,0 +1 @@ +Subproject commit 6edb2e5a21e0ce58ff2df936caee8b84e240a46b diff --git a/ds3231/io b/ds3231/io new file mode 160000 index 0000000..80de36e --- /dev/null +++ b/ds3231/io @@ -0,0 +1 @@ +Subproject commit 80de36ee7ee3e6b0842d5eaee81d54062cb496b2 diff --git a/ds3231/main.cpp b/ds3231/main.cpp index 627994b..2d335ee 100644 --- a/ds3231/main.cpp +++ b/ds3231/main.cpp @@ -1,22 +1,42 @@ -/* - * Copyright (c) by BlackMark 2017-2018 - * Date 02/01/2018 - * Version 1.3 - */ +#include "clock.hpp" #include #include #include +#include #include #include "ds3231/systime.h" -#include "usart/usart.h" +#include "uart/uart.hpp" -#include "clock.h" +using uart_t = uart::Uart0<>; + +REGISTER_UART0_INT_VECTORS(uart_t); + +static inline bool receiveLine(char *szBuffer, size_t sizeBufferLength, const char *szLineTerminator = "\r\n") +{ + size_t sizeReceived = 0; + + while (sizeReceived < sizeBufferLength - 1) { + uint8_t ui8ReceiveByte; + + while (!uart_t::rxByte(ui8ReceiveByte)) + ; + szBuffer[sizeReceived++] = ui8ReceiveByte; + szBuffer[sizeReceived] = '\0'; + + if (strstr(szBuffer, szLineTerminator)) { + szBuffer[sizeReceived - strlen(szLineTerminator)] = '\0'; + return true; + } + } + + return false; +} void setup() { - USART0 &cSerial = USART0::inst(); + uart_t cSerial; if (SysTime::init()) { cSerial << "DS3231 detected!" @@ -29,7 +49,7 @@ void setup() void setTime() { - USART0 &cSerial = USART0::inst(); + uart_t cSerial; tm sTime = {}; @@ -39,38 +59,38 @@ void setTime() cSerial << "Set time:" << "\r\n" << "Year: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_year = atoi(szBuffer) - 1900; cSerial << "Set time:" << "\r\n" << "Month: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_mon = atoi(szBuffer) - 1; cSerial << "Set time:" << "\r\n" << "Day: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_mday = atoi(szBuffer); cSerial << "Set time:" << "\r\n" << "Hour: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_hour = atoi(szBuffer); cSerial << "Minute: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_min = atoi(szBuffer); cSerial << "Second: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; sTime.tm_sec = atoi(szBuffer); @@ -81,7 +101,7 @@ void setTime() void setAlarm() { - USART0 &cSerial = USART0::inst(); + uart_t cSerial; rtc_tm *tmAlarm = rtc_get_alarm(); @@ -91,17 +111,17 @@ void setAlarm() cSerial << "Set alarm:" << "\r\n" << "Hour: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; tmAlarm->hour = atoi(szBuffer); cSerial << "Minute: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; tmAlarm->min = atoi(szBuffer); cSerial << "Second: "; - cSerial.receiveLine(szBuffer, BUFFER_SIZE, "\r"); + receiveLine(szBuffer, BUFFER_SIZE, "\r"); cSerial << szBuffer << "\r\n"; tmAlarm->sec = atoi(szBuffer); @@ -110,9 +130,9 @@ void setAlarm() int main() { - USART0 &cSerial = USART0::inst(); + uart_t cSerial; - cSerial.init(9600); + cSerial.init(); sei(); setup(); @@ -139,7 +159,7 @@ int main() uint8_t ui8Cmd; - if (cSerial.receiveByte(ui8Cmd)) { + if (cSerial.rxByte(ui8Cmd)) { if (ui8Cmd == 's') { setTime(); } else if (ui8Cmd == 'a') { @@ -154,7 +174,7 @@ int main() cSerial << szBuffer << "\r\n"; } else { cSerial << "Invalid char: '"; - cSerial.transmitByte(ui8Cmd); + cSerial.txByte(ui8Cmd); cSerial << "'" << "\r\n"; } diff --git a/ds3231/type b/ds3231/type new file mode 160000 index 0000000..65d8928 --- /dev/null +++ b/ds3231/type @@ -0,0 +1 @@ +Subproject commit 65d8928ff458aceb74ac44f214427f3ea8eaefc1 diff --git a/ds3231/uart b/ds3231/uart new file mode 160000 index 0000000..8f88cdc --- /dev/null +++ b/ds3231/uart @@ -0,0 +1 @@ +Subproject commit 8f88cdccea6b8f1f8521bcad6724cacb1e6acbcf diff --git a/ds3231/usart b/ds3231/usart deleted file mode 160000 index b2a3b03..0000000 --- a/ds3231/usart +++ /dev/null @@ -1 +0,0 @@ -Subproject commit b2a3b03867858da5d1f8eb955fcbfc106c851ac2