48class mono_framebuffer;
49class gray4_framebuffer;
128 [[nodiscard]]
size_t width() const noexcept {
return _width; }
131 [[nodiscard]]
size_t height() const noexcept {
return _height; }
152 [[nodiscard]]
bool asleep() const noexcept {
return _asleep; }
158#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
374 _has_baseline =
false;
382#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
431 template<
typename Rep,
typename Period>
468 _has_baseline =
true;
496 template<
typename Rep,
typename Period>
498 return do_wait(std::chrono::ceil<std::chrono::milliseconds>(
timeout));
505#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
540 if (mode == _color_mode) {
547 _has_baseline =
false;
555#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
627 _has_baseline =
false;
673 , _busy_level(busy_level)
687 [[nodiscard]] std::chrono::milliseconds
busy_timeout() const noexcept {
return _busy_timeout; }
801 template<
typename FB>
803 _try_write_rows(
const FB& fb,
enum color_mode expected,
size_t row_start,
size_t row_end,
size_t x,
size_t y);
809 std::chrono::milliseconds _busy_timeout{15'000};
812 bool _asleep =
false;
815 bool _has_baseline =
false;
In-memory framebuffer for 4-level grayscale ePaper displays.
In-memory framebuffer for monochrome (1 bit per pixel) ePaper displays.
Abstract base class for ePaper display panels.
result< void > try_set_color_mode(enum color_mode mode)
Switches the panel between monochrome and grayscale operation.
result< void > try_clear()
Clears the controller's RAM to white, without a framebuffer.
void write_rows(const gray4_framebuffer &fb, size_t row_start, size_t row_end, size_t x=0, size_t y=0)
Uploads a horizontal band of a grayscale framebuffer.
bool asleep() const noexcept
Returns whether the panel is in deep sleep.
virtual result< void > do_set_color_mode(enum color_mode mode)
Hook for try_set_color_mode.
void sleep()
Puts the panel controller into deep sleep.
result< void > hardware_reset()
Pulses the reset line and waits for the controller to settle.
std::chrono::milliseconds busy_timeout() const noexcept
Returns the default BUSY timeout.
result< void > try_sleep()
Puts the panel controller into deep sleep.
result< void > wait_busy(std::optional< std::chrono::milliseconds > timeout=std::nullopt)
Polls the BUSY line until it releases.
void write(const gray4_framebuffer &fb, size_t x=0, size_t y=0)
Uploads a grayscale framebuffer to the controller's RAM.
result< void > try_wake()
Wakes the panel controller from deep sleep.
void wait_for(const std::chrono::duration< Rep, Period > &timeout)
Waits for the controller's BUSY line to release, with a timeout.
virtual result< void > do_clear()=0
Hook for try_clear.
virtual result< void > do_sleep()=0
Hook for try_sleep. Called only while the panel is awake.
void wait()
Waits for the controller's BUSY line to release.
void write_rows(const mono_framebuffer &fb, size_t row_start, size_t row_end, size_t x=0, size_t y=0)
Uploads a horizontal band of a monochrome framebuffer.
result< void > try_write(const gray4_framebuffer &fb, size_t x=0, size_t y=0)
Uploads a grayscale framebuffer to the controller's RAM.
size_t height() const noexcept
Returns the panel height in pixels.
static result< void > configure_control_lines(gpio busy_gpio, gpio reset_gpio)
Configures the direction of the BUSY and reset pins.
result< void > try_write(const mono_framebuffer &fb, size_t x=0, size_t y=0)
Uploads a monochrome framebuffer to the controller's RAM.
virtual result< void > do_write(const mono_framebuffer &fb, size_t row_start, size_t row_end, size_t x, size_t y)=0
Hook for try_write / try_write_rows (monochrome).
result< void > try_refresh(refresh_mode mode=refresh_mode::full)
Refreshes the panel from the controller's RAM.
panel(panel &&) noexcept=default
gpio reset_gpio() const noexcept
Returns the reset output pin (may be unconnected).
result< void > try_wait_for(const std::chrono::duration< Rep, Period > &timeout)
Waits for the controller's BUSY line to release, with a timeout.
virtual result< void > do_wait(std::optional< std::chrono::milliseconds > timeout)
Hook for try_wait / try_wait_for.
void set_color_mode(enum color_mode mode)
Switches the panel between monochrome and grayscale operation.
result< void > try_write_rows(const gray4_framebuffer &fb, size_t row_start, size_t row_end, size_t x=0, size_t y=0)
Uploads a horizontal band of a grayscale framebuffer.
virtual result< void > do_wake()=0
Hook for try_wake.
panel(const panel &)=delete
result< void > try_write_rows(const mono_framebuffer &fb, size_t row_start, size_t row_end, size_t x=0, size_t y=0)
Uploads a horizontal band of a monochrome framebuffer.
panel(size_t width, size_t height, gpio busy_gpio, enum gpio::level busy_level, std::chrono::milliseconds busy_timeout, gpio reset_gpio) noexcept
Constructs the panel base with the given dimensions and control lines.
gpio busy_gpio() const noexcept
Returns the BUSY input pin (may be unconnected).
result< void > try_wait()
Waits for the controller's BUSY line to release.
enum color_mode color_mode() const noexcept
Returns the panel's current pixel format.
virtual result< void > do_refresh(refresh_mode mode)=0
Hook for try_refresh.
panel(size_t width, size_t height) noexcept
Constructs the panel base with the given dimensions and no control lines.
panel & operator=(const panel &)=delete
void write(const mono_framebuffer &fb, size_t x=0, size_t y=0)
Uploads a monochrome framebuffer to the controller's RAM.
void wake()
Wakes the panel controller from deep sleep.
virtual result< void > do_write(const gray4_framebuffer &fb, size_t row_start, size_t row_end, size_t x, size_t y)
Hook for try_write / try_write_rows (grayscale).
size_t width() const noexcept
Returns the panel width in pixels.
void clear()
Clears the controller's RAM to white, without a framebuffer.
void refresh(refresh_mode mode=refresh_mode::full)
Refreshes the panel from the controller's RAM.
static constexpr gpio nc()
Returns a GPIO representing "not connected".
level
GPIO output/input level.
ePaper display driver classes.
refresh_mode
Refresh style for panel::refresh.
@ 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 ...
color_mode
Pixel format the panel is operating in.
@ mono
1 bit per pixel black-and-white (mono_framebuffer).
gray4
A 4-level grayscale pixel value.
constexpr std::unexpected< std::error_code > error(E e) noexcept
Creates an unexpected error from an error code enum.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ invalid_state
Invalid state.
@ timeout
Operation timed out.
@ not_supported
Operation or feature not supported.
std::expected< T, std::error_code > result
result type wrapping a value or error code.