idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::lcd::mono_framebuffer Class Reference

In-memory framebuffer for monochrome (1 bit per pixel) displays. More...

Public Types

using pixel_type = bool
 The value type written by set_pixel.
 

Public Member Functions

 mono_framebuffer (size_t width, size_t height)
 Creates a framebuffer of the given dimensions, with all pixels off.
 
size_t width () const noexcept
 Returns the width in pixels.
 
size_t height () const noexcept
 Returns the height in pixels.
 
void set_pixel (size_t x, size_t y, bool on) noexcept
 Sets or clears a single pixel.
 
bool get_pixel (size_t x, size_t y) const noexcept
 Returns the state of a single pixel.
 
void fill (bool on) noexcept
 Sets every pixel to the given state.
 
void clear () noexcept
 Clears every pixel (equivalent to fill(false)).
 
std::span< const uint8_t > data () const noexcept
 Returns the raw page-packed pixel data.
 
void flush (panel &panel) const
 Draws the full framebuffer to a panel.
 
void flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Draws a horizontal band of the framebuffer to a panel.
 
void flush_region (panel &panel, size_t x_start, size_t y_start, size_t x_end, size_t y_end) const
 Draws a rectangular region of the framebuffer to a panel.
 
result< void > try_flush (panel &panel) const
 Draws the full framebuffer to a panel.
 
result< void > try_flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Draws a horizontal band of the framebuffer to a panel.
 
result< void > try_flush_region (panel &panel, size_t x_start, size_t y_start, size_t x_end, size_t y_end) const
 Draws a rectangular region of the framebuffer to a panel.
 

Static Public Member Functions

static result< mono_framebuffermake (size_t width, size_t height)
 Creates a framebuffer of the given dimensions, with all pixels off.
 

Detailed Description

In-memory framebuffer for monochrome (1 bit per pixel) displays.

Pixels are stored page-packed, the native format of SSD1306-style monochrome OLED controllers: each byte holds 8 vertically adjacent pixels (bit 0 is the topmost), and pages (rows of 8 pixels) are laid out top-to-bottom, each page spanning the full display width. The byte for pixel (x, y) is at index (y / 8) * width() + x, bit y % 8.

Draw into the framebuffer with set_pixel and friends, then push it to a panel with flush (full frame) or flush_rows (a horizontal band). This is a plain value type: copyable, movable, and independent of any panel.

idfxx::lcd::mono_framebuffer fb(display.width(), display.height());
fb.set_pixel(10, 20, true);
fb.flush(display);
In-memory framebuffer for monochrome (1 bit per pixel) displays.

Definition at line 49 of file mono_framebuffer.hpp.

Member Typedef Documentation

◆ pixel_type

The value type written by set_pixel.

Definition at line 52 of file mono_framebuffer.hpp.

Constructor & Destructor Documentation

◆ mono_framebuffer()

idfxx::lcd::mono_framebuffer::mono_framebuffer ( size_t  width,
size_t  height 
)
inline

Creates a framebuffer of the given dimensions, with all pixels off.

Parameters
widthWidth in pixels; must be non-zero.
heightHeight in pixels; must be non-zero and a multiple of 8.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. invalid dimensions).

Definition at line 64 of file mono_framebuffer.hpp.

Member Function Documentation

◆ clear()

void idfxx::lcd::mono_framebuffer::clear ( )
inlinenoexcept

Clears every pixel (equivalent to fill(false)).

Definition at line 133 of file mono_framebuffer.hpp.

References fill().

◆ data()

std::span< const uint8_t > idfxx::lcd::mono_framebuffer::data ( ) const
inlinenoexcept

Returns the raw page-packed pixel data.

The span holds width() * height() / 8 bytes in the layout described in the class documentation, suitable for passing directly to a monochrome panel's draw_bitmap.

Returns
A read-only view of the pixel data.

Definition at line 144 of file mono_framebuffer.hpp.

◆ fill()

void idfxx::lcd::mono_framebuffer::fill ( bool  on)
inlinenoexcept

Sets every pixel to the given state.

Parameters
ontrue to set all pixels, false to clear them.

Definition at line 130 of file mono_framebuffer.hpp.

Referenced by clear().

◆ flush()

void idfxx::lcd::mono_framebuffer::flush ( panel panel) const
inline

Draws the full framebuffer to a panel.

The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error.

Definition at line 157 of file mono_framebuffer.hpp.

References try_flush(), and idfxx::unwrap().

◆ flush_region()

void idfxx::lcd::mono_framebuffer::flush_region ( panel panel,
size_t  x_start,
size_t  y_start,
size_t  x_end,
size_t  y_end 
) const
inline

Draws a rectangular region of the framebuffer to a panel.

The region spans columns [x_start, x_end) and rows [y_start, y_end), with the rows expanded outward to page boundaries (multiples of 8) to match the page-packed layout. Full-width regions transfer in a single draw; narrower regions transfer one draw per page. The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
x_startFirst column of the region, inclusive.
y_startFirst row of the region, inclusive.
x_endEnd column, exclusive; must satisfy x_start < x_end <= width().
y_endEnd row, exclusive; must satisfy y_start < y_end <= height().
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. an invalid region).

Definition at line 193 of file mono_framebuffer.hpp.

References try_flush_region(), and idfxx::unwrap().

◆ flush_rows()

void idfxx::lcd::mono_framebuffer::flush_rows ( panel panel,
size_t  y_start,
size_t  y_end 
) const
inline

Draws a horizontal band of the framebuffer to a panel.

The band spans rows [y_start, y_end) across the full width, and is expanded outward to page boundaries (multiples of 8 rows) to match the page-packed layout. The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
y_startFirst row of the band, inclusive.
y_endEnd row of the band, exclusive; must satisfy y_start < y_end <= height().
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. an invalid row range).

Definition at line 173 of file mono_framebuffer.hpp.

References try_flush_rows(), and idfxx::unwrap().

◆ get_pixel()

bool idfxx::lcd::mono_framebuffer::get_pixel ( size_t  x,
size_t  y 
) const
inlinenoexcept

Returns the state of a single pixel.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
Returns
true if the pixel is set; false if it is clear or the coordinates are out of range.

Definition at line 119 of file mono_framebuffer.hpp.

◆ height()

size_t idfxx::lcd::mono_framebuffer::height ( ) const
inlinenoexcept

Returns the height in pixels.

Definition at line 88 of file mono_framebuffer.hpp.

Referenced by make().

◆ make()

static result< mono_framebuffer > idfxx::lcd::mono_framebuffer::make ( size_t  width,
size_t  height 
)
inlinestatic

Creates a framebuffer of the given dimensions, with all pixels off.

Parameters
widthWidth in pixels; must be non-zero.
heightHeight in pixels; must be non-zero and a multiple of 8.
Returns
The new mono_framebuffer, or an error.
Return values
idfxx::errc::invalid_argif width is zero, or height is zero or not a multiple of 8.

Definition at line 77 of file mono_framebuffer.hpp.

References idfxx::error(), height(), idfxx::invalid_arg, and width().

◆ set_pixel()

void idfxx::lcd::mono_framebuffer::set_pixel ( size_t  x,
size_t  y,
bool  on 
)
inlinenoexcept

Sets or clears a single pixel.

Out-of-range coordinates are ignored.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
ontrue to set the pixel, false to clear it.

Definition at line 99 of file mono_framebuffer.hpp.

◆ try_flush()

result< void > idfxx::lcd::mono_framebuffer::try_flush ( panel panel) const
inline

Draws the full framebuffer to a panel.

The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
Returns
Success, or an error.

Definition at line 207 of file mono_framebuffer.hpp.

References idfxx::lcd::panel::try_draw_bitmap().

Referenced by flush().

◆ try_flush_region()

result< void > idfxx::lcd::mono_framebuffer::try_flush_region ( panel panel,
size_t  x_start,
size_t  y_start,
size_t  x_end,
size_t  y_end 
) const
inline

Draws a rectangular region of the framebuffer to a panel.

The region spans columns [x_start, x_end) and rows [y_start, y_end), with the rows expanded outward to page boundaries (multiples of 8) to match the page-packed layout. Full-width regions transfer in a single draw; narrower regions transfer one draw per page. The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
x_startFirst column of the region, inclusive.
y_startFirst row of the region, inclusive.
x_endEnd column, exclusive; must satisfy x_start < x_end <= width().
y_endEnd row, exclusive; must satisfy y_start < y_end <= height().
Returns
Success, or an error.
Return values
idfxx::errc::invalid_argif the region is invalid.

Definition at line 248 of file mono_framebuffer.hpp.

References idfxx::error(), idfxx::invalid_arg, and idfxx::lcd::panel::try_draw_bitmap().

Referenced by flush_region(), and try_flush_rows().

◆ try_flush_rows()

result< void > idfxx::lcd::mono_framebuffer::try_flush_rows ( panel panel,
size_t  y_start,
size_t  y_end 
) const
inline

Draws a horizontal band of the framebuffer to a panel.

The band spans rows [y_start, y_end) across the full width, and is expanded outward to page boundaries (multiples of 8 rows) to match the page-packed layout. The panel must use the page-packed 1-bpp format (e.g. an SSD1306) and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
y_startFirst row of the band, inclusive.
y_endEnd row of the band, exclusive; must satisfy y_start < y_end <= height().
Returns
Success, or an error.
Return values
idfxx::errc::invalid_argif the row range is invalid.

Definition at line 225 of file mono_framebuffer.hpp.

References try_flush_region().

Referenced by flush_rows().

◆ width()

size_t idfxx::lcd::mono_framebuffer::width ( ) const
inlinenoexcept

Returns the width in pixels.

Definition at line 85 of file mono_framebuffer.hpp.

Referenced by make().


The documentation for this class was generated from the following file: