diff --git a/config.hpp b/config.hpp new file mode 100644 index 0000000..8dc8a1b --- /dev/null +++ b/config.hpp @@ -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 +struct Config { + static constexpr auto FREQ = freq; + static constexpr auto MODE = mode; +}; + +} // namespace spi diff --git a/hardware.hpp b/hardware.hpp new file mode 100644 index 0000000..c5dc164 --- /dev/null +++ b/hardware.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace spi { + +template +class Hardware { +}; + +} // namespace spi diff --git a/spi.hpp b/spi.hpp index 3b71fdf..3343324 100644 --- a/spi.hpp +++ b/spi.hpp @@ -1,32 +1,15 @@ #pragma once +#include "config.hpp" +#include "hardware.hpp" + #include "../io/io.hpp" -#include - namespace spi { +template 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 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) {