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

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