Refactored code to use capital letters for classes and added using namespace inside functions
This commit is contained in:
parent
9809b34bca
commit
d952794c55
@ -18,7 +18,7 @@ enum class Parity { DISABLED = 0, ODD = 1, EVEN = 2 };
|
|||||||
enum class StopBit { ONE = 1, TWO = 2 };
|
enum class StopBit { ONE = 1, TWO = 2 };
|
||||||
|
|
||||||
template <uint32_t baudRate, uint8_t dataBits, Parity parity, StopBit stopBit, Mode mode>
|
template <uint32_t baudRate, uint8_t dataBits, Parity parity, StopBit stopBit, Mode mode>
|
||||||
class hardware0 {
|
class Hardware0 {
|
||||||
static constexpr auto calcBaud()
|
static constexpr auto calcBaud()
|
||||||
{
|
{
|
||||||
uint16_t ui16UBRR = ((F_CPU / (16 * baudRate)) - 1);
|
uint16_t ui16UBRR = ((F_CPU / (16 * baudRate)) - 1);
|
||||||
@ -185,7 +185,7 @@ class uart {
|
|||||||
|
|
||||||
void usartTestUsage()
|
void usartTestUsage()
|
||||||
{
|
{
|
||||||
using uart0 = uart_test::hardware0<9600, 8, uart_test::Parity::DISABLED, uart_test::StopBit::ONE,
|
using uart0 = uart_test::Hardware0<9600, 8, uart_test::Parity::DISABLED, uart_test::StopBit::ONE,
|
||||||
uart_test::Mode::ASYNCHRONOUS>;
|
uart_test::Mode::ASYNCHRONOUS>;
|
||||||
|
|
||||||
/*using softuart = uart::Device<uart::software<io::P::B0, io::P::B1>, 9600, 8, uart::Parity::DISABLED,
|
/*using softuart = uart::Device<uart::software<io::P::B0, io::P::B1>, 9600, 8, uart::Parity::DISABLED,
|
||||||
@ -207,12 +207,24 @@ void usartTestUsage()
|
|||||||
|
|
||||||
void newUartUsage()
|
void newUartUsage()
|
||||||
{
|
{
|
||||||
using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>;
|
using namespace uart;
|
||||||
using uart0 = uart::hardware0<uart::Mode::ASYNCHRONOUS, config, uart::Driven::INTERRUPT>;
|
Uart0<Config<9600>> serial;
|
||||||
using softuart = uart::software<io::P::B1, io::P::B2, config>;
|
|
||||||
|
|
||||||
uart::uart<uart0> serial;
|
serial << "Hello World from RAM. " << F("Hello World from flash\r\n");
|
||||||
uart::uart<softuart> softSerial;
|
|
||||||
|
_delay_ms(1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
void newUartUsage2()
|
||||||
|
{
|
||||||
|
using namespace uart;
|
||||||
|
|
||||||
|
using config = Config<9600, DataBits::EIGHT, Parity::NONE, StopBits::ONE>;
|
||||||
|
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::INTERRUPT>;
|
||||||
|
using softuart = Software<io::P::B1, io::P::B2, config>;
|
||||||
|
|
||||||
|
Uart<uart0> serial;
|
||||||
|
Uart<softuart> softSerial;
|
||||||
|
|
||||||
serial << "Hello World from RAM. " << F("Hello World from flash\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");
|
||||||
@ -249,7 +261,7 @@ enum class DataOrder {
|
|||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
@ -267,8 +279,8 @@ struct spi {
|
|||||||
|
|
||||||
namespace uart {
|
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()
|
||||||
{
|
{
|
||||||
@ -291,17 +303,17 @@ class hardware0<Mode::SPI, config> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
@ -1 +1 @@
|
|||||||
Subproject commit 8e0ba5a46347beec2ba26e03e2956574577096bf
|
Subproject commit 00cb9ad13c9f66b3be99689e181cf650cffcd1e9
|
Loading…
Reference in New Issue
Block a user