13#include <idfxx/epaper/panel>
59#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
90 [[nodiscard]]
size_t width() const noexcept {
return _width; }
93 [[nodiscard]]
size_t height() const noexcept {
return _height; }
103 [[nodiscard]]
size_t stride_bytes() const noexcept {
return (_width + 7) / 8; }
115 if (x >= _width || y >= _height) {
119 uint8_t mask =
static_cast<uint8_t
>(1u << (7 - x % 8));
122 byte &=
static_cast<uint8_t
>(~mask);
136 [[nodiscard]]
bool get_pixel(
size_t x,
size_t y)
const noexcept {
137 if (x >= _width || y >= _height) {
140 return (_data[y *
stride_bytes() + x / 8] & (1u << (7 - x % 8))) == 0;
147 void fill(
bool ink)
noexcept { std::ranges::fill(_data, ink ? uint8_t{0x00} : uint8_t{0xFF}); }
161 [[nodiscard]] std::span<const uint8_t>
data() const noexcept {
return _data; }
172 [[nodiscard]] std::span<const uint8_t>
row(
size_t y)
const noexcept {
176#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
243 , _data(std::move(
data)) {}
247 std::vector<uint8_t> _data;
In-memory framebuffer for monochrome (1 bit per pixel) ePaper displays.
void fill(bool ink) noexcept
Sets every pixel to the given state.
result< void > try_flush_rows(panel &panel, size_t y_start, size_t y_end) const
Uploads a horizontal band of the framebuffer to a panel's RAM.
size_t stride_bytes() const noexcept
Returns the number of bytes per row.
std::span< const uint8_t > data() const noexcept
Returns the raw row-major pixel data.
static result< mono_framebuffer > make(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels white.
std::span< const uint8_t > row(size_t y) const noexcept
Returns the raw bytes of a single row.
void flush(panel &panel, size_t x=0, size_t y=0) const
Uploads the full framebuffer to a panel's RAM.
void flush_rows(panel &panel, size_t y_start, size_t y_end) const
Uploads a horizontal band of the framebuffer to a panel's RAM.
bool pixel_type
The value type written by set_pixel — true is black ink.
result< void > try_flush(panel &panel, size_t x=0, size_t y=0) const
Uploads the full framebuffer to a panel's RAM.
size_t width() const noexcept
Returns the width in pixels.
void set_pixel(size_t x, size_t y, bool ink) noexcept
Inks or blanks a single pixel.
size_t height() const noexcept
Returns the height in pixels.
bool get_pixel(size_t x, size_t y) const noexcept
Returns the state of a single pixel.
void clear() noexcept
Blanks every pixel to white (equivalent to fill(false)).
mono_framebuffer(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels white.
Abstract base class for ePaper display panels.
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.
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.
ePaper display driver classes.
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_arg
Invalid argument.
std::expected< T, std::error_code > result
result type wrapping a value or error code.