Adapted interface to move more often used template parameters to the front

This commit is contained in:
BlackMark 2019-08-05 20:06:42 +02:00
parent c74f1afcac
commit 0354bc3020
2 changed files with 41 additions and 43 deletions

View File

@ -11,7 +11,7 @@
void newUartUsage() void newUartUsage()
{ {
using namespace uart; using namespace uart;
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<115200>, Driven::INTERRUPT>> serial1; Uart<Hardware1<Config<115200>, Driven::INTERRUPT, Mode::ASYNCHRONOUS>> serial1;
serial1.init(); serial1.init();
serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n"); serial1 << "New uart hi from RAM. " << F("New uart hi from flash\r\n");
@ -43,7 +43,7 @@ void newUartUsage2()
using namespace uart; using namespace uart;
using config = Config<115200, DataBits::EIGHT, Parity::NONE, StopBits::ONE>; using config = Config<115200, DataBits::EIGHT, Parity::NONE, StopBits::ONE>;
using uart0 = Hardware0<Mode::ASYNCHRONOUS, config, Driven::INTERRUPT>; using uart0 = Hardware0<config, Driven::INTERRUPT, Mode::ASYNCHRONOUS>;
Uart<uart0> serial; Uart<uart0> serial;
serial.init(); serial.init();
@ -56,7 +56,7 @@ void newUartUsage2()
void newUartStreamOverloads() void newUartStreamOverloads()
{ {
using namespace uart; using namespace uart;
Uart<Hardware1<Mode::ASYNCHRONOUS, Config<115200>, Driven::BLOCKING>> serial; Uart<Hardware1<Config<115200>, Driven::BLOCKING, Mode::ASYNCHRONOUS>> serial;
serial.init(); serial.init();
bool bVal = true; bool bVal = true;
@ -109,37 +109,36 @@ void newUartStreamOverloads()
serial.flushTx(); serial.flushTx();
} }
/*
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
@ -147,44 +146,43 @@ struct spi {
namespace uart { namespace uart {
template <class Config> template <class Config>
class Hardware0<Mode::SPI, Config> { class Hardware0<Config, Driven::INTERRUPT, Mode::SPI> {
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<config, uart::Driven::INTERRUPT, uart::Mode::SPI>;
spi::spi<uartspi> uartSpi; spi::spi<uartspi> uartSpi;
} }
*/
static inline void initUart(const uint32_t baudRate) static inline void initUart(const uint32_t baudRate)
{ {
@ -247,7 +245,7 @@ int main()
txString(F("\r\n")); txString(F("\r\n"));
flushTx(); flushTx();
// spiTest(); spiTest();
return 0; return 0;
} }

@ -1 +1 @@
Subproject commit 87e693605143d019f1f6eb7b5ca40d914765c2e0 Subproject commit c4f38cbcdf722c2c41325617066f5910c4a8cfea