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