Switch from old usart to new uart library

This commit is contained in:
BlackMark 2020-05-15 09:43:06 +02:00
parent 85e37de950
commit b2065b987a
11 changed files with 92 additions and 46 deletions

15
.gitmodules vendored
View File

@ -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

View File

@ -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 <util/delay.h>
#endif

4
ds3231/clock.hpp Normal file
View File

@ -0,0 +1,4 @@
#pragma once
#define F_CPU 16'000'000
#include <util/delay.h>

@ -1 +1 @@
Subproject commit 727a9745043915d4f5623c11e6744e69d80d572f
Subproject commit 9303fbf5b59bd934ec0c91d5540b851366da92e1

View File

@ -215,7 +215,7 @@
</ToolchainSettings>
</PropertyGroup>
<ItemGroup>
<Compile Include="clock.h">
<Compile Include="clock.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="ds3231\rtc.cpp">
@ -242,19 +242,43 @@
<Compile Include="ds3231\twi.h">
<SubType>compile</SubType>
</Compile>
<Compile Include="flash\flash.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="io\io.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="main.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="usart\usart.cpp">
<Compile Include="type\type.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="usart\usart.h">
<Compile Include="uart\config.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\hardware.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\hardware0.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\hardware1.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\software.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\uart.hpp">
<SubType>compile</SubType>
</Compile>
</ItemGroup>
<ItemGroup>
<Folder Include="ds3231" />
<Folder Include="usart" />
<Folder Include="io" />
<Folder Include="flash" />
<Folder Include="uart" />
<Folder Include="type" />
</ItemGroup>
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
</Project>

1
ds3231/flash Submodule

@ -0,0 +1 @@
Subproject commit 6edb2e5a21e0ce58ff2df936caee8b84e240a46b

1
ds3231/io Submodule

@ -0,0 +1 @@
Subproject commit 80de36ee7ee3e6b0842d5eaee81d54062cb496b2

View File

@ -1,22 +1,42 @@
/*
* Copyright (c) by BlackMark 2017-2018
* Date 02/01/2018
* Version 1.3
*/
#include "clock.hpp"
#include <avr/interrupt.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#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";
}

1
ds3231/type Submodule

@ -0,0 +1 @@
Subproject commit 65d8928ff458aceb74ac44f214427f3ea8eaefc1

1
ds3231/uart Submodule

@ -0,0 +1 @@
Subproject commit 8f88cdccea6b8f1f8521bcad6724cacb1e6acbcf

@ -1 +0,0 @@
Subproject commit b2a3b03867858da5d1f8eb955fcbfc106c851ac2