Add three wire spi support

This commit is contained in:
BlackMark 2022-05-28 17:02:00 +02:00
parent d1419b2d23
commit 2e417a0f3a

View File

@ -12,6 +12,8 @@ namespace eink {
template <uint16_t Width, uint16_t Height, typename Spi, io::P RstPin, io::P DcPin, io::P BusyPin> template <uint16_t Width, uint16_t Height, typename Spi, io::P RstPin, io::P DcPin, io::P BusyPin>
class Eink { class Eink {
using word_t = typename Spi::word_t;
enum class Cmd : uint8_t { enum class Cmd : uint8_t {
DRIVER_OUTPUT_CONTROL = 0x01, DRIVER_OUTPUT_CONTROL = 0x01,
DEEP_SLEEP_MODE = 0x10, DEEP_SLEEP_MODE = 0x10,
@ -32,6 +34,9 @@ class Eink {
static io::Pin<RstPin> m_rst; static io::Pin<RstPin> m_rst;
static io::Pin<DcPin> m_dc; static io::Pin<DcPin> m_dc;
static io::Pin<BusyPin> m_bsy; static io::Pin<BusyPin> 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; static constexpr auto BLOCK_SIZE = 5;
@ -109,11 +114,15 @@ class Eink {
static void sendCommand(const Cmd command) static void sendCommand(const Cmd command)
{ {
m_dc = false; m_dc = false;
spiTransfer(static_cast<uint8_t>(command)); spiTransfer(static_cast<word_t>(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; m_dc = true;
spiTransfer(data); spiTransfer(data);
} }
@ -201,7 +210,7 @@ class Eink {
_delay_ms(100); _delay_ms(100);
} }
static void spiTransfer(const uint8_t data) static void spiTransfer(const word_t data)
{ {
Spi::select(true); Spi::select(true);
Spi::transfer(data); Spi::transfer(data);