Added config and hardware templates

This commit is contained in:
BlackMark 2020-02-21 17:10:49 +01:00
parent 8e6c3738f8
commit e0fd37dbb0
3 changed files with 44 additions and 22 deletions

30
config.hpp Normal file
View File

@ -0,0 +1,30 @@
#pragma once
namespace spi {
enum class ClockDiv {
DIV_4 = 0,
DIV_16 = 1,
DIV_64 = 2,
DIV_128 = 3,
DIV_2X_2 = 4,
DIV_2X_8 = 5,
DIV_2X_32 = 6,
DIV_2X_64 = 7,
};
enum class Mode {
MODE_0 = 0,
MODE_1 = 1,
MODE_2 = 2,
MODE_3 = 3,
};
template <ClockDiv freq, Mode mode>
struct Config {
static constexpr auto FREQ = freq;
static constexpr auto MODE = mode;
};
} // namespace spi

9
hardware.hpp Normal file
View File

@ -0,0 +1,9 @@
#pragma once
namespace spi {
template <class Cfg>
class Hardware {
};
} // namespace spi

27
spi.hpp
View File

@ -1,32 +1,15 @@
#pragma once
#include "config.hpp"
#include "hardware.hpp"
#include "../io/io.hpp"
#include <avr/io.h>
namespace spi {
template <class Driver>
class Spi {
public:
enum class ClockDiv {
CLKDIV_4 = 0,
CLKDIV_16 = 1,
CLKDIV_64 = 2,
CLKDIV_128 = 3,
CLKDIV_2X_2 = 4,
CLKDIV_2X_8 = 5,
CLKDIV_2X_32 = 6,
CLKDIV_2X_64 = 7,
};
enum class Mode {
MODE_0 = 0,
MODE_1 = 1,
MODE_2 = 2,
MODE_3 = 3,
};
private:
static void setCPOL(bool bCPOL)
{
@ -51,7 +34,7 @@ class Spi {
static io::Pin<io::P::B2> sm_cSS;
public:
static void init(ClockDiv enmClockDiv = ClockDiv::CLKDIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true,
static void init(ClockDiv enmClockDiv = ClockDiv::DIV_128, Mode enmMode = Mode::MODE_0, bool bMaster = true,
bool bLSBFirst = false, bool bMISOPullup = false)
{
if (bMaster) {