Refactored code to use capital letters for classes and added using namespace inside functions

This commit is contained in:
BlackMark 2019-07-28 18:00:15 +02:00
parent 9809b34bca
commit d952794c55
2 changed files with 28 additions and 16 deletions

View File

@ -18,7 +18,7 @@ enum class Parity { DISABLED = 0, ODD = 1, EVEN = 2 };
enum class StopBit { ONE = 1, TWO = 2 };
template <uint32_t baudRate, uint8_t dataBits, Parity parity, StopBit stopBit, Mode mode>
class hardware0 {
class Hardware0 {
static constexpr auto calcBaud()
{
uint16_t ui16UBRR = ((F_CPU / (16 * baudRate)) - 1);
@ -185,7 +185,7 @@ class uart {
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>;
/*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()
{
using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>;
using uart0 = uart::hardware0<uart::Mode::ASYNCHRONOUS, config, uart::Driven::INTERRUPT>;
using softuart = uart::software<io::P::B1, io::P::B2, config>;
using namespace uart;
Uart0<Config<9600>> serial;
uart::uart<uart0> serial;
uart::uart<softuart> softSerial;
serial << "Hello World from RAM. " << F("Hello World from flash\r\n");
_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");
// 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>
struct config {
struct Config {
static constexpr auto CPOL_MODE = cpol;
static constexpr auto CPHA_MODE = cpha;
static constexpr auto DATA_ORDER = dataOrder;
@ -267,8 +279,8 @@ struct spi {
namespace uart {
template <class config>
class hardware0<Mode::SPI, config> {
template <class Config>
class Hardware0<Mode::SPI, Config> {
public:
static void init()
{
@ -291,17 +303,17 @@ class hardware0<Mode::SPI, config> {
}
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;
}

@ -1 +1 @@
Subproject commit 8e0ba5a46347beec2ba26e03e2956574577096bf
Subproject commit 00cb9ad13c9f66b3be99689e181cf650cffcd1e9