Compare commits
2 Commits
9a4193ee75
...
2e417a0f3a
| Author | SHA1 | Date | |
|---|---|---|---|
| 2e417a0f3a | |||
| d1419b2d23 |
47
eink.hpp
47
eink.hpp
@@ -12,26 +12,31 @@ 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 {
|
||||||
struct Cmd {
|
using word_t = typename Spi::word_t;
|
||||||
static constexpr auto SW_RESET = uint8_t{0x12};
|
|
||||||
static constexpr auto DRIVER_OUTPUT_CONTROL = uint8_t{0x01};
|
enum class Cmd : uint8_t {
|
||||||
static constexpr auto DATA_ENTRY_MODE = uint8_t{0x11};
|
DRIVER_OUTPUT_CONTROL = 0x01,
|
||||||
static constexpr auto SET_RAM_X_ADDR_POSITIONS = uint8_t{0x44};
|
DEEP_SLEEP_MODE = 0x10,
|
||||||
static constexpr auto SET_RAM_Y_ADDR_POSITIONS = uint8_t{0x45};
|
DATA_ENTRY_MODE = 0x11,
|
||||||
static constexpr auto BORDER_WAVEFORM_CONTROL = uint8_t{0x3C};
|
SW_RESET = 0x12,
|
||||||
static constexpr auto READ_TEMPERATURE_SENSOR = uint8_t{0x18};
|
READ_TEMPERATURE_SENSOR = 0x18,
|
||||||
static constexpr auto SET_RAM_X_ADDR = uint8_t{0x4E};
|
UPDATE_DISPLAY = 0x20,
|
||||||
static constexpr auto SET_RAM_Y_ADDR = uint8_t{0x4F};
|
DISPLAY_UPDATE_CONTROL_2 = 0x22,
|
||||||
static constexpr auto WRITE_RAM_BLACK = uint8_t{0x24};
|
WRITE_RAM_BLACK = 0x24,
|
||||||
static constexpr auto WRITE_RAM_RED = uint8_t{0x26};
|
WRITE_RAM_RED = 0x26,
|
||||||
static constexpr auto DISPLAY_UPDATE_CONTROL_2 = uint8_t{0x22};
|
BORDER_WAVEFORM_CONTROL = 0x3C,
|
||||||
static constexpr auto UPDATE_DISPLAY = uint8_t{0x20};
|
SET_RAM_X_ADDR_POSITIONS = 0x44,
|
||||||
static constexpr auto DEEP_SLEEP_MODE = uint8_t{0x10};
|
SET_RAM_Y_ADDR_POSITIONS = 0x45,
|
||||||
|
SET_RAM_X_ADDR = 0x4E,
|
||||||
|
SET_RAM_Y_ADDR = 0x4F,
|
||||||
};
|
};
|
||||||
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -106,14 +111,18 @@ class Eink {
|
|||||||
waitUntilIdle();
|
waitUntilIdle();
|
||||||
}
|
}
|
||||||
|
|
||||||
static void sendCommand(const uint8_t command)
|
static void sendCommand(const Cmd command)
|
||||||
{
|
{
|
||||||
m_dc = false;
|
m_dc = false;
|
||||||
spiTransfer(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);
|
||||||
|
|||||||
Reference in New Issue
Block a user