13#include <idfxx/epaper/color>
14#include <idfxx/epaper/panel>
63#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
95 [[nodiscard]]
size_t width() const noexcept {
return _width; }
98 [[nodiscard]]
size_t height() const noexcept {
return _height; }
108 [[nodiscard]]
size_t stride_bytes() const noexcept {
return (_width + 7) / 8; }
120 if (x >= _width || y >= _height) {
124 const uint8_t mask =
static_cast<uint8_t
>(1u << (7 - x % 8));
125 const auto bits = std::to_underlying(level);
126 _set_plane_bit(_data[index], mask, (bits & 0x01) != 0);
127 _set_plane_bit(_data[_plane_size() + index], mask, (bits & 0x02) != 0);
139 if (x >= _width || y >= _height) {
143 const uint8_t mask =
static_cast<uint8_t
>(1u << (7 - x % 8));
145 if ((_data[index] & mask) != 0) {
148 if ((_data[_plane_size() + index] & mask) != 0) {
151 return static_cast<gray4>(bits);
159 const auto bits = std::to_underlying(level);
160 auto plane0 = std::span<uint8_t>(_data).first(_plane_size());
161 auto plane1 = std::span<uint8_t>(_data).last(_plane_size());
162 std::ranges::fill(plane0, (bits & 0x01) != 0 ? uint8_t{0xFF} : uint8_t{0x00});
163 std::ranges::fill(plane1, (bits & 0x02) != 0 ? uint8_t{0xFF} : uint8_t{0x00});
182 [[nodiscard]] std::span<const uint8_t>
plane(
size_t index)
const noexcept {
183 return std::span<const uint8_t>(_data).subspan(index * _plane_size(), _plane_size());
196 [[nodiscard]] std::span<const uint8_t>
plane_row(
size_t index,
size_t y)
const noexcept {
200#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
271 , _data(std::move(data)) {}
273 [[nodiscard]]
size_t _plane_size() const noexcept {
return stride_bytes() * _height; }
275 static void _set_plane_bit(uint8_t&
byte, uint8_t mask,
bool on)
noexcept {
279 byte &=
static_cast<uint8_t
>(~mask);
285 std::vector<uint8_t> _data;
In-memory framebuffer for 4-level grayscale ePaper displays.
void fill(gray4 level) noexcept
Sets every pixel to the given gray level.
size_t height() const noexcept
Returns the height in pixels.
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 width() const noexcept
Returns the width in pixels.
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.
void flush(panel &panel, size_t x=0, size_t y=0) const
Uploads the full framebuffer to a panel's RAM.
gray4_framebuffer(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels white.
std::span< const uint8_t > plane(size_t index) const noexcept
Returns the raw pixel data of one plane.
gray4 get_pixel(size_t x, size_t y) const noexcept
Returns the gray level of a single pixel.
size_t stride_bytes() const noexcept
Returns the number of bytes per row within each plane.
std::span< const uint8_t > plane_row(size_t index, size_t y) const noexcept
Returns the raw bytes of a single row of one plane.
static result< gray4_framebuffer > make(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels white.
void clear() noexcept
Blanks every pixel to white (equivalent to fill(gray4::white)).
result< void > try_flush(panel &panel, size_t x=0, size_t y=0) const
Uploads the full framebuffer to a panel's RAM.
void set_pixel(size_t x, size_t y, gray4 level) noexcept
Sets a single pixel to the given gray level.
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.
gray4
A 4-level grayscale pixel value.
@ white
Blank paper (no ink).
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.