diff --git a/eink.hpp b/eink.hpp index ce1ca0b..c6c1a5d 100644 --- a/eink.hpp +++ b/eink.hpp @@ -12,6 +12,8 @@ namespace eink { template class Eink { + using word_t = typename Spi::word_t; + enum class Cmd : uint8_t { DRIVER_OUTPUT_CONTROL = 0x01, DEEP_SLEEP_MODE = 0x10, @@ -32,6 +34,9 @@ class Eink { static io::Pin m_rst; static io::Pin m_dc; static io::Pin m_bsy; + static constexpr auto THREE_WIRE_SPI = (DcPin == io::P::NONE ? true : false); + static_assert((THREE_WIRE_SPI && sizeof(word_t) > 1) || !THREE_WIRE_SPI, + "Three wire SPI requires SPI word size of at least 9 bits"); static constexpr auto BLOCK_SIZE = 5; @@ -109,11 +114,15 @@ class Eink { static void sendCommand(const Cmd command) { m_dc = false; - spiTransfer(static_cast(command)); + spiTransfer(static_cast(command)); } - static void sendData(const uint8_t data) + static void sendData(word_t data) { + if constexpr (THREE_WIRE_SPI) { + data |= 1 << 8; + } + m_dc = true; spiTransfer(data); } @@ -201,7 +210,7 @@ class Eink { _delay_ms(100); } - static void spiTransfer(const uint8_t data) + static void spiTransfer(const word_t data) { Spi::select(true); Spi::transfer(data);