Implement uploading custom waveform lut

This commit is contained in:
BlackMark 2022-06-03 11:07:49 +02:00
parent 6218cdfc51
commit 8d8369440c

View File

@ -21,6 +21,9 @@ template <std::uint16_t Width, std::uint16_t Height, typename Spi, io::P RstPin,
class Eink { class Eink {
using word_t = typename Spi::word_t; using word_t = typename Spi::word_t;
struct original_lut_tag {
};
static io::Pin<RstPin> m_rst; static io::Pin<RstPin> m_rst;
static io::Pin<BusyPin> m_busy; static io::Pin<BusyPin> m_busy;
@ -37,6 +40,7 @@ class Eink {
WRITE_RAM_RED = 0x26, WRITE_RAM_RED = 0x26,
READ_RAM = 0x27, READ_RAM = 0x27,
LOAD_OTP_TO_RAM = 0x31, LOAD_OTP_TO_RAM = 0x31,
WRITE_LUT = 0x32,
BORDER_WAVEFORM_CONTROL = 0x3C, BORDER_WAVEFORM_CONTROL = 0x3C,
READ_RAM_CHANNEL = 0x41, READ_RAM_CHANNEL = 0x41,
SET_RAM_X_ADDR_POSITIONS = 0x44, SET_RAM_X_ADDR_POSITIONS = 0x44,
@ -141,6 +145,17 @@ class Eink {
template <typename RleImage> template <typename RleImage>
static void draw(const RleImage &rleImage) static void draw(const RleImage &rleImage)
{ {
draw(rleImage, original_lut_tag{});
}
template <typename RleImage, typename Lut = original_lut_tag>
static void draw(const RleImage &rleImage, const Lut &lut)
{
constexpr auto USE_ORIGINAL_LUT = std::is_same_v<Lut, original_lut_tag>;
if constexpr (!USE_ORIGINAL_LUT) {
writeLut(lut);
}
constexpr auto sendImageChannel = [](const auto command, const auto &image) { constexpr auto sendImageChannel = [](const auto command, const auto &image) {
sendCommand(command); sendCommand(command);
for (auto j = std::size_t{0}; j < image.size(); ++j) { 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)); sendImageChannel(Cmd::WRITE_RAM_RED, std::get<1>(rleImage));
sendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2); sendCommand(Cmd::DISPLAY_UPDATE_CONTROL_2);
sendData(0xF7); sendData(USE_ORIGINAL_LUT ? 0xF7 : 0xC7);
sendCommand(Cmd::UPDATE_DISPLAY); sendCommand(Cmd::UPDATE_DISPLAY);
waitUntilIdle(); waitUntilIdle();
} }
@ -195,6 +210,17 @@ class Eink {
waitUntilIdle(); waitUntilIdle();
} }
static void writeLut(const Waveform &lut)
{
const auto flashLutPtr = reinterpret_cast<const std::byte *>(&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<word_t>(lutByte));
}
}
static void autoPatternFill() static void autoPatternFill()
{ {
constexpr auto RED_PATTERN_FILL_CMD = static_cast<Cmd>(0x46); constexpr auto RED_PATTERN_FILL_CMD = static_cast<Cmd>(0x46);