spi/config.hpp

64 lines
1.4 KiB
C++
Raw Permalink Normal View History

2020-02-21 17:10:49 +01:00
#pragma once
2022-05-29 16:14:42 +02:00
#include <cstdint>
2022-05-26 14:58:47 +02:00
#include "../io/io.hpp"
2020-02-21 17:10:49 +01:00
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,
};
2020-02-21 17:26:14 +01:00
enum class Side {
MASTER,
SLAVE,
};
enum class BitOrder {
LSB_FIRST,
MSB_FIRST,
};
template <ClockDiv freq = ClockDiv::DIV_128, Mode mode = Mode::MODE_0, Side side = Side::MASTER,
2022-05-26 14:58:47 +02:00
BitOrder bitOrder = BitOrder::MSB_FIRST, io::P ssPin = io::P::B2, bool pullup = false>
2022-05-28 15:43:42 +02:00
struct HardwareConfig {
2020-02-21 17:10:49 +01:00
static constexpr auto FREQ = freq;
static constexpr auto MODE = mode;
2020-02-21 17:26:14 +01:00
static constexpr auto SIDE = side;
static constexpr auto BIT_ORDER = bitOrder;
2022-05-26 14:58:47 +02:00
static constexpr auto SS_PIN = ssPin;
2020-02-21 17:26:14 +01:00
static constexpr auto PULLUP = pullup;
2020-02-21 17:10:49 +01:00
};
2022-05-29 16:14:42 +02:00
template <io::P sckPin, io::P misoPin, io::P mosiPin, io::P ssPin, std::uint32_t freq = 100'000,
Mode mode = Mode::MODE_0, BitOrder bitOrder = BitOrder::MSB_FIRST, std::uint8_t bits = 8, bool pullup = false>
2022-05-28 15:43:42 +02:00
struct SoftwareConfig {
static constexpr auto SCK_PIN = sckPin;
static constexpr auto MISO_PIN = misoPin;
static constexpr auto MOSI_PIN = mosiPin;
static constexpr auto SS_PIN = ssPin;
static constexpr auto FREQ = freq;
static constexpr auto MODE = mode;
static constexpr auto BIT_ORDER = bitOrder;
static constexpr auto BITS = bits;
static constexpr auto PULLUP = pullup;
};
2020-02-21 17:10:49 +01:00
} // namespace spi