idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
uc8179.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
13#include <idfxx/epaper/panel>
14#include <idfxx/error>
15#include <idfxx/gpio>
16#include <idfxx/panel_io>
17
18#include <chrono>
19#include <cstddef>
20#include <cstdint>
21#include <frequency/frequency>
22#include <initializer_list>
23#include <span>
24
29namespace idfxx::epaper {
30
66class uc8179 final : public panel {
67public:
72 struct config {
76 size_t width = 800;
78 size_t height = 480;
91 std::chrono::milliseconds busy_timeout{30'000};
92 };
93
113 [[nodiscard]] static panel_io::spi_config
114 spi_io_config(gpio cs, gpio dc, freq::hertz pclk = freq::hertz{10'000'000}) noexcept;
115
116#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
136 [[nodiscard]] explicit uc8179(idfxx::panel_io& panel_io, config config);
137#endif
138
162
163 ~uc8179() override;
164
165 uc8179(const uc8179&) = delete;
166 uc8179& operator=(const uc8179&) = delete;
167 uc8179(uc8179&& other) noexcept;
168 uc8179& operator=(uc8179&& other) noexcept;
169
170private:
171 // Waveform configuration currently loaded into the controller. The
172 // UC8179 selects its update waveform at initialization (OTP banks or
173 // register-written LUTs), not per refresh command, so the driver
174 // re-initializes when a refresh needs a different waveform.
175 enum class waveform : uint8_t { full, fast, partial, gray };
176
177 // A rectangular pixel region of the panel, for partial-window
178 // programming.
179 struct region {
180 size_t x;
181 size_t y;
182 size_t width;
183 size_t height;
184 };
185
186 // Tag distinguishing the non-initializing constructor make() uses from
187 // the public throwing constructor with the same argument list.
188 struct raw_tag {};
189
190 explicit uc8179(raw_tag, idfxx::panel_io& panel_io, config config)
191 : panel(config.width, config.height, config.busy_gpio, gpio::level::low, config.busy_timeout, config.reset_gpio)
192 , _io(&panel_io) {}
193
194 // epaper::panel customization hooks.
195 [[nodiscard]] result<void>
196 do_write(const mono_framebuffer& fb, size_t row_start, size_t row_end, size_t x, size_t y) override;
197 [[nodiscard]] result<void>
198 do_write(const gray4_framebuffer& fb, size_t row_start, size_t row_end, size_t x, size_t y) override;
199 [[nodiscard]] result<void> do_clear() override;
200 [[nodiscard]] result<void> do_refresh(refresh_mode mode) override;
201 [[nodiscard]] result<void> do_set_color_mode(enum color_mode mode) override;
202 [[nodiscard]] result<void> do_sleep() override;
203 [[nodiscard]] result<void> do_wake() override;
204
205 // Command sequencing helpers (see src/uc8179.cpp).
206 [[nodiscard]] result<void> _cmd(uint8_t cmd);
207 [[nodiscard]] result<void> _cmd(uint8_t cmd, std::initializer_list<uint8_t> params);
208 [[nodiscard]] result<void> _cmd(uint8_t cmd, std::span<const uint8_t> params);
209 [[nodiscard]] result<void> _stream(int cmd, std::span<const uint8_t> data);
210 [[nodiscard]] result<void> _power_on();
211 [[nodiscard]] result<void> _set_resolution();
212 [[nodiscard]] result<void> _load_luts(
213 std::span<const uint8_t> vcom,
214 std::span<const uint8_t> ww,
215 std::span<const uint8_t> kw,
216 std::span<const uint8_t> wk,
217 std::span<const uint8_t> kk
218 );
219 [[nodiscard]] result<void> _init_full();
220 [[nodiscard]] result<void> _init_fast();
221 [[nodiscard]] result<void> _init_partial();
222 [[nodiscard]] result<void> _init_gray();
223 [[nodiscard]] result<void> _ensure_waveform(waveform target);
224 [[nodiscard]] result<void> _window_begin(region r);
225 [[nodiscard]] result<void> _window_end();
226 [[nodiscard]] result<void> _clear_ram(bool include_old_plane);
227 [[nodiscard]] result<void> _update();
228 [[nodiscard]] result<void> _enter_deep_sleep();
229
230 idfxx::panel_io* _io = nullptr; // nullptr after move
231 waveform _waveform = waveform::full;
232};
233
234} // namespace idfxx::epaper
Abstract base class for ePaper display panels.
Definition panel.hpp:116
std::chrono::milliseconds busy_timeout() const noexcept
Returns the default BUSY timeout.
Definition panel.hpp:687
size_t height() const noexcept
Returns the panel height in pixels.
Definition panel.hpp:131
gpio reset_gpio() const noexcept
Returns the reset output pin (may be unconnected).
Definition panel.hpp:684
gpio busy_gpio() const noexcept
Returns the BUSY input pin (may be unconnected).
Definition panel.hpp:681
enum color_mode color_mode() const noexcept
Returns the panel's current pixel format.
Definition panel.hpp:141
size_t width() const noexcept
Returns the panel width in pixels.
Definition panel.hpp:128
UC8179 ePaper display controller driver.
Definition uc8179.hpp:66
static result< uc8179 > make(idfxx::panel_io &panel_io, config config)
Creates a new UC8179 panel driver.
uc8179 & operator=(uc8179 &&other) noexcept
uc8179(idfxx::panel_io &panel_io, config config)
Creates a new UC8179 panel driver.
uc8179(const uc8179 &)=delete
static panel_io::spi_config spi_io_config(gpio cs, gpio dc, freq::hertz pclk=freq::hertz{10 '000 '000}) noexcept
Returns a panel I/O configuration for communicating with a UC8179 over SPI.
uc8179 & operator=(const uc8179 &)=delete
uc8179(uc8179 &&other) noexcept
A GPIO pin.
Definition gpio.hpp:62
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:255
Panel I/O interface for SPI- and I2C-connected displays.
Definition panel_io.hpp:42
ePaper display driver classes.
Definition color.hpp:19
refresh_mode
Refresh style for panel::refresh.
Definition panel.hpp:58
@ partial
Differential update: only pixels that changed since the previous refresh flip, without the full-refre...
@ fast
Full-screen update with a shortened waveform: much faster than refresh_mode::full and still updates e...
@ full
Full update with the controller's highest-quality waveform: the panel flashes through inverse images ...
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
Configuration structure for UC8179 panels.
Definition uc8179.hpp:72
std::chrono::milliseconds busy_timeout
Maximum time to wait for the BUSY line to release.
Definition uc8179.hpp:91
gpio reset_gpio
GPIO wired to the panel's reset line, or gpio::nc() if not wired.
Definition uc8179.hpp:84
size_t width
Panel width in pixels (sources).
Definition uc8179.hpp:76
size_t height
Panel height in pixels (gates). The controller drives up to 600.
Definition uc8179.hpp:78
gpio busy_gpio
GPIO wired to the panel's BUSY output (required).
Definition uc8179.hpp:87
SPI-based panel I/O configuration.
Definition panel_io.hpp:58