Compare commits
8 Commits
991a67bd86
...
example
| Author | SHA1 | Date | |
|---|---|---|---|
| d1452b6dc0 | |||
| e760cf541c | |||
| 6b90c1779f | |||
| 8bb1bd7397 | |||
| 24d17688c0 | |||
| 414ebbebff | |||
| 717a69c231 | |||
| f0abf335e5 |
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -7,3 +7,6 @@
|
||||
[submodule "uart/flash"]
|
||||
path = uart/flash
|
||||
url = git@git.blackmark.me:avr/flash.git
|
||||
[submodule "uart/util"]
|
||||
path = uart/util
|
||||
url = git@git.blackmark.me:avr/util.git
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
#pragma once
|
||||
|
||||
#define F_CPU 20000000
|
||||
#define F_CPU 16'000'000
|
||||
#include <util/delay.h>
|
||||
|
||||
Submodule uart/flash updated: 9245b49e4c...6edb2e5a21
2
uart/io
2
uart/io
Submodule uart/io updated: 986ceef65d...80de36ee7e
@@ -8,44 +8,67 @@
|
||||
#include "io/io.hpp"
|
||||
#include "uart/uart.hpp"
|
||||
|
||||
#define UART1_INT_VECTORS
|
||||
#include "uart/hardware1.hpp"
|
||||
using uart0_interface_t =
|
||||
uart::Uart<uart::Hardware0<uart::Config<115200>, uart::Driven::INTERRUPT, uart::Mode::ASYNCHRONOUS>>;
|
||||
|
||||
using uart1_interface_t = uart::Uart1<>;
|
||||
|
||||
REGISTER_UART0_INT_VECTORS(uart0_interface_t);
|
||||
REGISTER_UART1_INT_VECTORS(uart1_interface_t);
|
||||
|
||||
void doubleSpeedTest()
|
||||
{
|
||||
uart0_interface_t serial;
|
||||
serial.init();
|
||||
|
||||
uint8_t counter = 100;
|
||||
uint8_t data;
|
||||
|
||||
while (counter) {
|
||||
if (serial.rxByte(data)) {
|
||||
serial.txByte(data);
|
||||
--counter;
|
||||
}
|
||||
}
|
||||
|
||||
serial << F("\r\n");
|
||||
|
||||
serial.flushTx();
|
||||
}
|
||||
|
||||
void newUartUsage()
|
||||
{
|
||||
using namespace uart;
|
||||
Uart<Hardware1<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial1;
|
||||
serial1.init();
|
||||
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
|
||||
serial.init();
|
||||
|
||||
serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
|
||||
serial << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
|
||||
|
||||
while (false) {
|
||||
uint8_t received = 0;
|
||||
|
||||
while (!serial1.peek())
|
||||
while (!serial.peek())
|
||||
;
|
||||
|
||||
{
|
||||
serial1 << F("Peeked: ");
|
||||
serial1.txByte(received);
|
||||
serial1 << F("\r\n");
|
||||
serial << F("Peeked: ");
|
||||
serial.txByte(received);
|
||||
serial << F("\r\n");
|
||||
}
|
||||
|
||||
if (serial1.rxByte(received)) {
|
||||
serial1 << F("Received: ");
|
||||
serial1.txByte(received);
|
||||
serial1 << F("\r\n");
|
||||
if (serial.rxByte(received)) {
|
||||
serial << F("Received: ");
|
||||
serial.txByte(received);
|
||||
serial << F("\r\n");
|
||||
}
|
||||
}
|
||||
|
||||
serial1.flushTx();
|
||||
serial.flushTx();
|
||||
}
|
||||
|
||||
void newUartUsage2()
|
||||
{
|
||||
using namespace uart;
|
||||
|
||||
Uart<Hardware1<Config<115200>, Driven::INTERRUPT>> serial1;
|
||||
uart1_interface_t serial1;
|
||||
|
||||
auto ramString = "Hello World from RAM. ";
|
||||
auto flashString = F("Hello World from flash\r\n");
|
||||
@@ -61,7 +84,7 @@ void newUartUsage2()
|
||||
void newUartStreamOverloads()
|
||||
{
|
||||
using namespace uart;
|
||||
Uart<Hardware1<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
|
||||
Uart<Hardware0<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
|
||||
serial.init();
|
||||
|
||||
bool bVal = true;
|
||||
@@ -191,17 +214,18 @@ void spiTest()
|
||||
|
||||
static inline void initUart(const uint32_t baudRate)
|
||||
{
|
||||
UBRR1 = static_cast<uint16_t>((F_CPU + 8 * baudRate) / (16 * baudRate) - 1);
|
||||
UCSR1C = (1 << UCSZ11) | (1 << UCSZ10);
|
||||
UCSR1B = (1 << RXEN1) | (1 << TXEN1);
|
||||
UBRR0 = static_cast<uint16_t>((F_CPU + 8 * baudRate) / (16 * baudRate) - 1);
|
||||
UCSR0A = 0;
|
||||
UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
|
||||
UCSR0B = (1 << RXEN0) | (1 << TXEN0);
|
||||
}
|
||||
|
||||
static inline void txUart(uint8_t byte)
|
||||
{
|
||||
while (!(UCSR1A & (1 << UDRE1)))
|
||||
while (!(UCSR0A & (1 << UDRE0)))
|
||||
;
|
||||
|
||||
UDR1 = byte;
|
||||
UDR0 = byte;
|
||||
}
|
||||
|
||||
static inline void txString(const char *str)
|
||||
@@ -220,11 +244,11 @@ static inline void txString(const detail::FlashString *str)
|
||||
|
||||
static inline void flushTx()
|
||||
{
|
||||
while (!(UCSR1A & (1 << UDRE1)))
|
||||
while (!(UCSR0A & (1 << UDRE0)))
|
||||
;
|
||||
while (!(UCSR1A & (1 << TXC1)))
|
||||
while (!(UCSR0A & (1 << TXC0)))
|
||||
;
|
||||
UCSR1A |= (1 << TXC1);
|
||||
UCSR0A |= (1 << TXC0);
|
||||
}
|
||||
|
||||
void optimalUartTest()
|
||||
@@ -244,6 +268,8 @@ int main()
|
||||
{
|
||||
sei();
|
||||
|
||||
doubleSpeedTest();
|
||||
|
||||
newUartUsage2();
|
||||
optimalUartTest();
|
||||
newUartStreamOverloads();
|
||||
|
||||
Submodule uart/uart updated: cb436b11a8...119de32445
@@ -28,9 +28,10 @@
|
||||
<ResetRule>0</ResetRule>
|
||||
<eraseonlaunchrule>0</eraseonlaunchrule>
|
||||
<EraseKey />
|
||||
<avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>
|
||||
<avrtool>
|
||||
</avrtool>
|
||||
<avrtoolserialnumber>J41800099437</avrtoolserialnumber>
|
||||
<avrdeviceexpectedsignature>0x1E9705</avrdeviceexpectedsignature>
|
||||
<avrdeviceexpectedsignature>0x1E950F</avrdeviceexpectedsignature>
|
||||
<com_atmel_avrdbg_tool_jtagicemkii>
|
||||
<ToolOptions>
|
||||
<InterfaceProperties>
|
||||
@@ -43,7 +44,7 @@
|
||||
<ToolName>JTAGICE mkII</ToolName>
|
||||
</com_atmel_avrdbg_tool_jtagicemkii>
|
||||
<avrtoolinterface>ISP</avrtoolinterface>
|
||||
<avrtoolinterfaceclock>5000000</avrtoolinterfaceclock>
|
||||
<avrtoolinterfaceclock>125000</avrtoolinterfaceclock>
|
||||
<AAFDebugger>
|
||||
<AAFDebugFiles>
|
||||
<DebugFile>
|
||||
@@ -87,7 +88,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.Device>-mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p"</avrgcc.common.Device>
|
||||
<avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
@@ -145,7 +146,7 @@
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
<ToolchainSettings>
|
||||
<AvrGccCpp>
|
||||
<avrgcc.common.Device>-mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\atmega1284p"</avrgcc.common.Device>
|
||||
<avrgcc.common.Device>-mmcu=atmega1284p</avrgcc.common.Device>
|
||||
<avrgcc.common.optimization.RelaxBranches>True</avrgcc.common.optimization.RelaxBranches>
|
||||
<avrgcc.common.outputfiles.hex>True</avrgcc.common.outputfiles.hex>
|
||||
<avrgcc.common.outputfiles.lss>True</avrgcc.common.outputfiles.lss>
|
||||
@@ -233,13 +234,20 @@
|
||||
<Compile Include="uart\uart.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="uart\utils.hpp">
|
||||
<Compile Include="util\func.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="util\type.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
<Compile Include="util\util.hpp">
|
||||
<SubType>compile</SubType>
|
||||
</Compile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Folder Include="io" />
|
||||
<Folder Include="flash" />
|
||||
<Folder Include="util" />
|
||||
<Folder Include="uart" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(AVRSTUDIO_EXE_PATH)\\Vs\\Compiler.targets" />
|
||||
|
||||
1
uart/util
Submodule
1
uart/util
Submodule
Submodule uart/util added at 81b3ae244c
Reference in New Issue
Block a user