Changed example to use rx as well
This commit is contained in:
parent
e891e1019f
commit
408ab83afb
@ -13,9 +13,17 @@
|
||||
void newUartUsage()
|
||||
{
|
||||
using namespace uart;
|
||||
Uart1<> serial1;
|
||||
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<>, Driven::INTERRUPT>> serial1;
|
||||
sei();
|
||||
|
||||
serial1 << "Hello World from RAM. " << F("Hello World from flash\r\n");
|
||||
serial1 << F("Hello World from RAM. ") << F("Hello World from flash\r\n");
|
||||
|
||||
while (true) {
|
||||
uint8_t received = 0;
|
||||
|
||||
if (serial1.rxByte(received))
|
||||
serial1.txByte(received);
|
||||
}
|
||||
|
||||
_delay_ms(1000);
|
||||
}
|
||||
@ -25,7 +33,7 @@ void newUartUsage2()
|
||||
using namespace uart;
|
||||
|
||||
using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>;
|
||||
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::INTERRUPT>;
|
||||
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::BLOCKING>;
|
||||
using softuart = Software<io::P::B1, io::P::B2, config>;
|
||||
|
||||
Uart<uart0> serial;
|
||||
@ -47,37 +55,37 @@ void oldUsartUsage()
|
||||
|
||||
_delay_ms(1000);
|
||||
}
|
||||
|
||||
/*
|
||||
namespace spi {
|
||||
|
||||
enum class Cpol {
|
||||
MODE_0,
|
||||
MODE_1,
|
||||
MODE_0,
|
||||
MODE_1,
|
||||
};
|
||||
|
||||
enum class Cpha {
|
||||
MODE_0,
|
||||
MODE_1,
|
||||
MODE_0,
|
||||
MODE_1,
|
||||
};
|
||||
|
||||
enum class DataOrder {
|
||||
MSB,
|
||||
LSB,
|
||||
MSB,
|
||||
LSB,
|
||||
};
|
||||
|
||||
template <Cpol cpol, Cpha cpha, DataOrder dataOrder>
|
||||
struct Config {
|
||||
static constexpr auto CPOL_MODE = cpol;
|
||||
static constexpr auto CPHA_MODE = cpha;
|
||||
static constexpr auto DATA_ORDER = dataOrder;
|
||||
static constexpr auto CPOL_MODE = cpol;
|
||||
static constexpr auto CPHA_MODE = cpha;
|
||||
static constexpr auto DATA_ORDER = dataOrder;
|
||||
};
|
||||
|
||||
template <class Driver>
|
||||
struct spi {
|
||||
spi()
|
||||
{
|
||||
Driver::init();
|
||||
}
|
||||
spi()
|
||||
{
|
||||
Driver::init();
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace spi
|
||||
@ -87,42 +95,42 @@ namespace uart {
|
||||
template <class Config>
|
||||
class Hardware0<Mode::SPI, Config> {
|
||||
public:
|
||||
static void init()
|
||||
{
|
||||
UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00);
|
||||
static void init()
|
||||
{
|
||||
UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00);
|
||||
|
||||
if (DATA_ORDER == spi::DataOrder::MSB)
|
||||
UCSR0C &= ~(1 << UCSZ01);
|
||||
else
|
||||
UCSR0C |= (1 << UCSZ01);
|
||||
if (DATA_ORDER == spi::DataOrder::MSB)
|
||||
UCSR0C &= ~(1 << UCSZ01);
|
||||
else
|
||||
UCSR0C |= (1 << UCSZ01);
|
||||
|
||||
if (CPOL_MODE == spi::Cpol::MODE_0)
|
||||
UCSR0C &= ~(1 << UCPOL0);
|
||||
else
|
||||
UCSR0C |= (1 << UCPOL0);
|
||||
if (CPOL_MODE == spi::Cpol::MODE_0)
|
||||
UCSR0C &= ~(1 << UCPOL0);
|
||||
else
|
||||
UCSR0C |= (1 << UCPOL0);
|
||||
|
||||
if (CPHA_MODE == spi::Cpha::MODE_0)
|
||||
UCSR0C &= ~(1 << UCSZ00);
|
||||
else
|
||||
UCSR0C |= (1 << UCSZ00);
|
||||
}
|
||||
if (CPHA_MODE == spi::Cpha::MODE_0)
|
||||
UCSR0C &= ~(1 << UCSZ00);
|
||||
else
|
||||
UCSR0C |= (1 << UCSZ00);
|
||||
}
|
||||
|
||||
private:
|
||||
static constexpr auto CPOL_MODE = Config::CPOL_MODE;
|
||||
static constexpr auto CPHA_MODE = Config::CPHA_MODE;
|
||||
static constexpr auto DATA_ORDER = Config::DATA_ORDER;
|
||||
static constexpr auto CPOL_MODE = Config::CPOL_MODE;
|
||||
static constexpr auto CPHA_MODE = Config::CPHA_MODE;
|
||||
static constexpr auto DATA_ORDER = Config::DATA_ORDER;
|
||||
};
|
||||
|
||||
} // namespace uart
|
||||
|
||||
void spiTest()
|
||||
{
|
||||
using config = spi::Config<spi::Cpol::MODE_0, spi::Cpha::MODE_0, spi::DataOrder::MSB>;
|
||||
using uartspi = uart::Hardware0<uart::Mode::SPI, config>;
|
||||
using config = spi::Config<spi::Cpol::MODE_0, spi::Cpha::MODE_0, spi::DataOrder::MSB>;
|
||||
using uartspi = uart::Hardware0<uart::Mode::SPI, config>;
|
||||
|
||||
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);
|
||||
@ -170,11 +178,11 @@ void cUartLibTest()
|
||||
auto ramString = "Hello World from RAM. ";
|
||||
auto flashString = F("Hello World from flash\r\n");
|
||||
|
||||
uart_init(UART_BAUD_SELECT(9600, F_CPU));
|
||||
uart1_init(UART_BAUD_SELECT(9600, F_CPU));
|
||||
sei();
|
||||
|
||||
uart_puts(ramString);
|
||||
uart_puts_p(reinterpret_cast<const char *>(flashString));
|
||||
uart1_puts(ramString);
|
||||
uart1_puts_p(reinterpret_cast<const char *>(flashString));
|
||||
|
||||
_delay_ms(1000);
|
||||
}
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit 92c96bbc72e8784f10d38e85073c5bd010ab877e
|
||||
Subproject commit 0bfd303a26a8aad77607e9cefb1039997952af09
|
@ -86,58 +86,58 @@
|
||||
<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.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>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.directories.IncludePaths>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
||||
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++17</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
<avrgcccpp.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.assembler.general.IncludePaths>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
|
||||
</AvrGccCpp>
|
||||
<avrgcc.common.Device>-mmcu=atmega1284p -B "%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\gcc\dev\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>
|
||||
<avrgcc.common.outputfiles.eep>True</avrgcc.common.outputfiles.eep>
|
||||
<avrgcc.common.outputfiles.srec>True</avrgcc.common.outputfiles.srec>
|
||||
<avrgcc.common.outputfiles.usersignatures>False</avrgcc.common.outputfiles.usersignatures>
|
||||
<avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcc.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcc.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcc.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.symbols.DefSymbols>
|
||||
<avrgcc.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcc.compiler.directories.IncludePaths>
|
||||
<avrgcc.compiler.optimization.level>Optimize for size (-Os)</avrgcc.compiler.optimization.level>
|
||||
<avrgcc.compiler.optimization.PackStructureMembers>True</avrgcc.compiler.optimization.PackStructureMembers>
|
||||
<avrgcc.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcc.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcc.compiler.warnings.AllWarnings>True</avrgcc.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultCharTypeUnsigned>
|
||||
<avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>True</avrgcccpp.compiler.general.ChangeDefaultBitFieldUnsigned>
|
||||
<avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<ListValues>
|
||||
<Value>NDEBUG</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.symbols.DefSymbols>
|
||||
<avrgcccpp.compiler.directories.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.compiler.directories.IncludePaths>
|
||||
<avrgcccpp.compiler.optimization.level>Optimize for size (-Os)</avrgcccpp.compiler.optimization.level>
|
||||
<avrgcccpp.compiler.optimization.PackStructureMembers>True</avrgcccpp.compiler.optimization.PackStructureMembers>
|
||||
<avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>True</avrgcccpp.compiler.optimization.AllocateBytesNeededForEnum>
|
||||
<avrgcccpp.compiler.warnings.AllWarnings>True</avrgcccpp.compiler.warnings.AllWarnings>
|
||||
<avrgcccpp.compiler.warnings.Pedantic>True</avrgcccpp.compiler.warnings.Pedantic>
|
||||
<avrgcccpp.compiler.miscellaneous.OtherFlags>-Wextra -std=c++17</avrgcccpp.compiler.miscellaneous.OtherFlags>
|
||||
<avrgcccpp.linker.libraries.Libraries>
|
||||
<ListValues>
|
||||
<Value>libm</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.linker.libraries.Libraries>
|
||||
<avrgcccpp.assembler.general.IncludePaths>
|
||||
<ListValues>
|
||||
<Value>%24(PackRepoDir)\Atmel\ATmega_DFP\1.3.300\include</Value>
|
||||
</ListValues>
|
||||
</avrgcccpp.assembler.general.IncludePaths>
|
||||
</AvrGccCpp>
|
||||
</ToolchainSettings>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
|
||||
|
Loading…
Reference in New Issue
Block a user