From 8d8369440c2a3ea25c7c5ca31c16e790746eede0 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 3 Jun 2022 11:07:49 +0200 Subject: [PATCH] Implement uploading custom waveform lut --- eink.hpp | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/eink.hpp b/eink.hpp index 47b4c0c..5cc417b 100644 --- a/eink.hpp +++ b/eink.hpp @@ -21,6 +21,9 @@ template m_rst; static io::Pin m_busy; @@ -37,6 +40,7 @@ class Eink { WRITE_RAM_RED = 0x26, READ_RAM = 0x27, LOAD_OTP_TO_RAM = 0x31, + WRITE_LUT = 0x32, BORDER_WAVEFORM_CONTROL = 0x3C, READ_RAM_CHANNEL = 0x41, SET_RAM_X_ADDR_POSITIONS = 0x44, @@ -141,6 +145,17 @@ class Eink { template static void draw(const RleImage &rleImage) { + draw(rleImage, original_lut_tag{}); + } + + template + static void draw(const RleImage &rleImage, const Lut &lut) + { + constexpr auto USE_ORIGINAL_LUT = std::is_same_v; + if constexpr (!USE_ORIGINAL_LUT) { + writeLut(lut); + } + constexpr auto sendImageChannel = [](const auto command, const auto &image) { sendCommand(command); for (auto j = std::size_t{0}; j < image.size(); ++j) { @@ -159,7 +174,7 @@ class Eink { sendImageChannel(Cmd::WRITE_RAM_RED, std::get<1>(rleImage)); sendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2); - sendData(0xF7); + sendData(USE_ORIGINAL_LUT ? 0xF7 : 0xC7); sendCommand(Cmd::UPDATE_DISPLAY); waitUntilIdle(); } @@ -195,6 +210,17 @@ class Eink { waitUntilIdle(); } + static void writeLut(const Waveform &lut) + { + const auto flashLutPtr = reinterpret_cast(&lut); + + sendCommand(Cmd::WRITE_LUT); + for (auto i = std::size_t{0}; i < sizeof(lut); ++i) { + const auto lutByte = flash::load(flashLutPtr[i]); + sendData(static_cast(lutByte)); + } + } + static void autoPatternFill() { constexpr auto RED_PATTERN_FILL_CMD = static_cast(0x46);