Implemented optimal example to compare implementations

This commit is contained in:
BlackMark 2019-07-28 17:33:42 +02:00
parent e71d103602
commit 9809b34bca
4 changed files with 55 additions and 10 deletions

@ -1 +1 @@
Subproject commit b0f602b3be5608d71a401f5c75609f09e92df4a9
Subproject commit 2215491c0b0606d734dcf44e6c4213e36176d25f

View File

@ -214,8 +214,10 @@ void newUartUsage()
uart::uart<uart0> serial;
uart::uart<softuart> softSerial;
serial << "Hello World using finalized interface!" << F("\r\nAlso works from progmem\r\n");
serial << "Hello World from RAM. " << F("Hello World from flash\r\n");
// softSerial << "Hello World using finalized software interface!" << F("\r\nAlso greetz from progmem\r\n");
_delay_ms(1000);
}
void oldUsartUsage()
@ -223,8 +225,8 @@ void oldUsartUsage()
USART0 &serial = USART0::inst();
serial.init(9600);
serial << "Hello World from hardware serial 0!"
<< " And greets from ram:(!\r\n";
serial << "Hello World from RAM. "
<< "Hello World from flash\r\n";
_delay_ms(1000);
}
@ -304,13 +306,56 @@ void spiTest()
spi::spi<uartspi> uartSpi;
}
static inline void initUart(const uint32_t baudRate)
{
UBRR0 = static_cast<uint16_t>((F_CPU / (16 * baudRate)) - 1);
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
}
static inline void txUart(uint8_t byte)
{
while (!(UCSR0A & (1 << UDRE0)))
;
UDR0 = byte;
}
static inline void txString(const char *str)
{
while (char ch = *str++)
txUart(ch);
}
static inline void txString(const detail::FlashString *str)
{
const char *strIt = reinterpret_cast<const char *>(str);
while (char ch = pgm_read_byte(strIt++))
txUart(ch);
}
void optimalUartTest()
{
auto ramString = "Hello World from RAM. ";
auto flashString = F("Hello World from flash\r\n");
initUart(9600);
txString(ramString);
txString(flashString);
_delay_ms(1000);
}
int main()
{
usartTestUsage();
// usartTestUsage();
newUartUsage();
oldUsartUsage();
// oldUsartUsage();
// optimalUartTest();
spiTest();
// spiTest();
return 0;
}

@ -1 +1 @@
Subproject commit fd7e8e72389dbef3738822974393345a7c981730
Subproject commit 8e0ba5a46347beec2ba26e03e2956574577096bf

View File

@ -202,9 +202,9 @@
<Compile Include="main.cpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\usart.cpp">
<None Include="uart\usart.cpp">
<SubType>compile</SubType>
</Compile>
</None>
<Compile Include="uart\hardware0.hpp">
<SubType>compile</SubType>
</Compile>