Implemented optimal example to compare implementations

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

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;
}

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>