From 3d45d2a4b393724f3eb618d49936adc7ee168d1b Mon Sep 17 00:00:00 2001 From: BlackMark Date: Fri, 3 Jun 2022 16:55:01 +0200 Subject: [PATCH] Allow image and LUT to be located either in ram or flash --- eink.hpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/eink.hpp b/eink.hpp index 5cc417b..fb9dbb8 100644 --- a/eink.hpp +++ b/eink.hpp @@ -157,9 +157,11 @@ class Eink { } constexpr auto sendImageChannel = [](const auto command, const auto &image) { + using image_t = std::remove_cvref_t; + sendCommand(command); - for (auto j = std::size_t{0}; j < image.size(); ++j) { - const auto [count, data] = flash::load(image[j]); + for (auto j = std::size_t{0}; j < std::tuple_size_v; ++j) { + const auto [count, data] = flash::loadLike(image[j]); for (auto i = std::uint16_t{0}; i < count; ++i) { if (command == Cmd::WRITE_RAM_BLACK) { sendData(data); @@ -170,8 +172,8 @@ class Eink { } }; - sendImageChannel(Cmd::WRITE_RAM_BLACK, std::get<0>(rleImage)); - sendImageChannel(Cmd::WRITE_RAM_RED, std::get<1>(rleImage)); + sendImageChannel(Cmd::WRITE_RAM_BLACK, std::get<0>(rleImage.value)); + sendImageChannel(Cmd::WRITE_RAM_RED, std::get<1>(rleImage.value)); sendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2); sendData(USE_ORIGINAL_LUT ? 0xF7 : 0xC7); @@ -210,13 +212,15 @@ class Eink { waitUntilIdle(); } - static void writeLut(const Waveform &lut) + template + static void writeLut(const Lut &lut) { - const auto flashLutPtr = reinterpret_cast(&lut); + static_assert(sizeof(lut) == sizeof(Waveform), "Invalid LUT size"); sendCommand(Cmd::WRITE_LUT); for (auto i = std::size_t{0}; i < sizeof(lut); ++i) { - const auto lutByte = flash::load(flashLutPtr[i]); + const auto lutByte = lut[i]; + static_assert(std::is_same_v>, "Invalid LUT value type"); sendData(static_cast(lutByte)); } }