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() void newUartUsage()
{ {
using settings = uart::settings<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>; using config = uart::config<9600, uart::DataBits::EIGHT, uart::Parity::NONE, uart::StopBits::ONE>;
using uart0 = uart::detail::hardware0<settings, uart::Mode::ASYNCHRONOUS>; 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<uart0> serial;
uart::uart<softuart> softSerial;
serial << "Hello World using finalized interface!" << F("\r\nAlso works from progmem\r\n"); 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() void oldUsartUsage()
@ -226,11 +229,88 @@ void oldUsartUsage()
_delay_ms(1000); _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() int main()
{ {
usartTestUsage(); usartTestUsage();
newUartUsage(); newUartUsage();
oldUsartUsage(); oldUsartUsage();
spiTest();
return 0; return 0;
} }

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

View File

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