Implemented optimal example to compare implementations
This commit is contained in:
parent
e71d103602
commit
9809b34bca
@ -1 +1 @@
|
|||||||
Subproject commit b0f602b3be5608d71a401f5c75609f09e92df4a9
|
Subproject commit 2215491c0b0606d734dcf44e6c4213e36176d25f
|
@ -214,8 +214,10 @@ void newUartUsage()
|
|||||||
uart::uart<uart0> serial;
|
uart::uart<uart0> serial;
|
||||||
uart::uart<softuart> softSerial;
|
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");
|
// softSerial << "Hello World using finalized software interface!" << F("\r\nAlso greetz from progmem\r\n");
|
||||||
|
|
||||||
|
_delay_ms(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void oldUsartUsage()
|
void oldUsartUsage()
|
||||||
@ -223,8 +225,8 @@ void oldUsartUsage()
|
|||||||
USART0 &serial = USART0::inst();
|
USART0 &serial = USART0::inst();
|
||||||
serial.init(9600);
|
serial.init(9600);
|
||||||
|
|
||||||
serial << "Hello World from hardware serial 0!"
|
serial << "Hello World from RAM. "
|
||||||
<< " And greets from ram:(!\r\n";
|
<< "Hello World from flash\r\n";
|
||||||
|
|
||||||
_delay_ms(1000);
|
_delay_ms(1000);
|
||||||
}
|
}
|
||||||
@ -304,13 +306,56 @@ void spiTest()
|
|||||||
spi::spi<uartspi> uartSpi;
|
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()
|
int main()
|
||||||
{
|
{
|
||||||
usartTestUsage();
|
// usartTestUsage();
|
||||||
newUartUsage();
|
newUartUsage();
|
||||||
oldUsartUsage();
|
// oldUsartUsage();
|
||||||
|
// optimalUartTest();
|
||||||
|
|
||||||
spiTest();
|
// spiTest();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit fd7e8e72389dbef3738822974393345a7c981730
|
Subproject commit 8e0ba5a46347beec2ba26e03e2956574577096bf
|
@ -202,9 +202,9 @@
|
|||||||
<Compile Include="main.cpp">
|
<Compile Include="main.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
<Compile Include="uart\usart.cpp">
|
<None Include="uart\usart.cpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</None>
|
||||||
<Compile Include="uart\hardware0.hpp">
|
<Compile Include="uart\hardware0.hpp">
|
||||||
<SubType>compile</SubType>
|
<SubType>compile</SubType>
|
||||||
</Compile>
|
</Compile>
|
||||||
|
Loading…
Reference in New Issue
Block a user