Added proof of concept for using hardware0 in SPI mode

This commit is contained in:
BlackMark 2019-07-28 12:16:09 +02:00
parent ab1d55ee6f
commit 5cd2b963fa
3 changed files with 93 additions and 13 deletions

View File

@ -207,12 +207,15 @@ void usartTestUsage()
void newUartUsage()
{
using settings = uart::settings<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>;
using uart0 = uart::detail::hardware0<settings, uart::Mode::ASYNCHRONOUS>;
using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>;
using uart0 = uart::hardware0<uart::Mode::ASYNCHRONOUS, config>;
using softuart = uart::software<io::P::B1, io::P::B2, config>;
uart::uart<uart0> serial;
uart::uart<softuart> softSerial;
serial << "Hello World using finalized interface!" << F("\r\nAlso works from progmem\r\n");
// softSerial << "Hello World using finalized software interface!" << F("\r\nAlso greetz from progmem\r\n");
}
void oldUsartUsage()
@ -226,11 +229,88 @@ void oldUsartUsage()
_delay_ms(1000);
}
namespace spi {
enum class Cpol {
MODE_0,
MODE_1,
};
enum class Cpha {
MODE_0,
MODE_1,
};
enum class DataOrder {
MSB,
LSB,
};
template <const Cpol cpol, const Cpha cpha, const DataOrder dataOrder>
struct config {
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();
}
};
} // namespace spi
namespace uart {
template <class config>
class hardware0<Mode::SPI, config> {
public:
static void init()
{
UCSR0C |= (1 << UMSEL01) | (1 << UMSEL00);
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 (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;
};
} // 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>;
spi::spi<uartspi> uartSpi;
}
int main()
{
usartTestUsage();
newUartUsage();
oldUsartUsage();
spiTest();
return 0;
}

@ -1 +1 @@
Subproject commit f08f607265cd316714d0db6fde5807e1c6320a72
Subproject commit 29b4d85ce3e2a5467dc378f029b94fa35cb6c793

View File

@ -69,7 +69,7 @@
<dependencies>
<content-extension eid="atmel.asf" uuidref="Atmel.ASF" version="3.46.0" />
</dependencies>
</framework-data>
</framework-data>
</AsfFrameworkConfig>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Release' ">
@ -211,7 +211,7 @@
<Compile Include="uart\hardware1.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\settings.hpp">
<Compile Include="uart\config.hpp">
<SubType>compile</SubType>
</Compile>
<Compile Include="uart\software.hpp">