libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
Namespaces | Classes | Concepts | Typedefs | Enumerations | Functions | Variables
epaper Namespace Reference

Namespaces

namespace  colors
 
namespace  DisplayOps
 Display operation constants.
 
namespace  Grayscale
 Bit manipulation constants for grayscale processing.
 
namespace  hal
 
namespace  internal
 
namespace  PanelConfig
 Panel configuration constants.
 
namespace  pixel_constants
 
namespace  PowerOptimization
 Power optimization register settings.
 
namespace  Resolution
 Resolution setting constants.
 
namespace  Timing
 Timing constants for EPD27 operations (in milliseconds).
 

Classes

struct  BoosterConfig
 Booster soft start configuration. More...
 
class  CircleBuilder
 
struct  CircleCommand
 Command for drawing a circle. More...
 
class  ColorManager
 
class  Device
 
struct  DeviceColor
 Device-specific color representation (generic template). More...
 
struct  DeviceColor< DisplayMode::BlackWhite >
 
struct  DeviceColor< DisplayMode::BWR >
 Specialization for Black/White/Red displays. More...
 
struct  DeviceColor< DisplayMode::BWY >
 Specialization for Black/White/Yellow displays. More...
 
struct  DeviceColor< DisplayMode::Grayscale4 >
 
struct  DeviceColor< DisplayMode::Spectra6 >
 Specialization for Spectra 6 (6-color) displays. More...
 
struct  DeviceConfig
 
class  Display
 
struct  driver_traits
 Driver capabilities trait template. More...
 
struct  driver_traits< EPD27 >
 
struct  driver_traits< MockDriver >
 
class  EPD27
 2.7 inch e-paper display driver (176x264 pixels). More...
 
struct  EPD27PinConfig
 Pin configuration for standard Raspberry Pi HATs. More...
 
struct  Error
 
class  Font
 
struct  FontMetrics
 Font dimension metrics. More...
 
class  Graphics
 
class  ImageIO
 Utilities for loading/saving images and converting formats. More...
 
class  LineBuilder
 
struct  LineCommand
 Command for drawing a line between two points. More...
 
struct  LineStyleSpec
 
class  MockDriver
 
class  MonoFramebuffer
 
class  MultiPlaneFramebuffer
 
class  Pin
 
struct  PinConfig
 Pin configuration tracking (internal use). More...
 
struct  Point
 
class  PointBuilder
 
struct  PointCommand
 Command for drawing a point (pixel or multi-pixel dot). More...
 
struct  PowerConfig
 Power configuration settings for EPD27. More...
 
class  RectangleBuilder
 
struct  RectangleCommand
 Command for drawing a rectangle. More...
 
struct  RGB
 
struct  RGBA
 
struct  ShapeStyleSpec
 
struct  Size
 
class  TextBuilder
 
struct  TextCommand
 Command for drawing text. More...
 
struct  TextStyleSpec
 

Concepts

concept  FramebufferLike
 
concept  DriverTraits
 Concept to check if a type is a valid driver with capabilities.
 
concept  Driver
 

Typedefs

using TwoPlaneFramebuffer = MultiPlaneFramebuffer< internal::PlaneCount::Two >
 Convenience alias for a two-plane color framebuffer.
 

Enumerations

enum class  TriColor : std::uint8_t { Black = 0 , White = 1 , Third = 2 }
 Color values for 3-color displays (Black/White/Red or Black/White/Yellow). More...
 
enum class  Spectra6Color : std::uint8_t {
  Black = 0 , White = 1 , Red = 2 , Yellow = 3 ,
  Blue = 4 , Green = 5
}
 Color values for Spectra 6 displays. More...
 
enum class  ErrorCode {
  DeviceNotInitialized , DeviceInitFailed , GPIOInitFailed , GPIORequestFailed ,
  SPIInitFailed , SPIDeviceOpenFailed , SPIConfigFailed , InvalidPin ,
  TransferFailed , DriverNotInitialized , DriverInitFailed , InvalidMode ,
  Timeout , DisplayNotReady , RefreshFailed , FileNotFound ,
  InvalidFormat , LoadFailed , InvalidDimensions
}
 Unified error codes for all libepaper operations. More...
 
enum class  Color : std::uint8_t {
  White = 0xFF , Black = 0x00 , Gray1 = 0x80 , Gray2 = 0x40 ,
  Red = 0x01 , Yellow = 0x02 , Blue = 0x03 , Green = 0x04
}
 
enum class  Orientation : std::uint8_t { Portrait0 = 0 , Landscape90 = 1 , Portrait180 = 2 , Landscape270 = 3 }
 
enum class  DotPixel : std::uint8_t {
  Pixel1x1 = 1 , Pixel2x2 = 2 , Pixel3x3 = 3 , Pixel4x4 = 4 ,
  Pixel5x5 = 5 , Pixel6x6 = 6 , Pixel7x7 = 7 , Pixel8x8 = 8
}
 
enum class  LineStyle { Solid , Dotted }
 
enum class  DrawFill { Empty , Full }
 
enum class  TextContent { String , Number , Decimal }
 Content type for text rendering. More...
 
enum class  DisplayMode : std::uint8_t {
  BlackWhite , Grayscale4 , BWR , BWY ,
  Spectra6
}
 
enum class  Command : std::uint8_t {
  BOOSTER_SOFT_START = 0x06 , DATA_START_TRANSMISSION_1 = 0x10 , DISPLAY_REFRESH = 0x12 , DATA_START_TRANSMISSION_2 = 0x13 ,
  PARTIAL_DISPLAY_REFRESH = 0x16 , LUT_VCOM = 0x20 , LUT_WW = 0x21 , LUT_BW = 0x22 ,
  LUT_WB = 0x23 , LUT_BB = 0x24 , LUT_WW2 = 0x25 , PLL_CONTROL = 0x30 ,
  VCOM_DATA_INTERVAL = 0x50 , RESOLUTION_SETTING = 0x61 , GET_STATUS = 0x71 , VCM_DC_SETTING = 0x82 ,
  POWER_OPTIMIZATION = 0xF8 , PANEL_SETTING = 0x00 , POWER_SETTING = 0x01 , POWER_OFF = 0x02 ,
  POWER_ON = 0x04 , DEEP_SLEEP = 0x07
}
 E-paper display command codes for EPD27. More...
 

Functions

template<typename DriverType >
requires Driver<DriverType> && DriverTraits<DriverType>
auto create_display (Device &device, DisplayMode mode, Orientation orientation=Orientation::Portrait0, bool auto_sleep=true) -> std::expected< Display< DriverType, MonoFramebuffer >, Error >
 Convenience factory for mono-plane displays.
 
template<typename DriverType , FramebufferLike FramebufferT>
requires Driver<DriverType> && DriverTraits<DriverType>
auto create_display (Device &device, DisplayMode mode, Orientation orientation=Orientation::Portrait0, bool auto_sleep=true) -> std::expected< Display< DriverType, FramebufferT >, Error >
 Primary factory function for creating displays with explicit framebuffer type.
 
constexpr auto to_string (ErrorCode code) -> std::string_view
 Convert error code to string representation.
 
auto make_error (ErrorCode code, std::string_view context={}) -> Error
 
template<typename Driver >
requires DriverTraits<Driver>
constexpr auto supports_display_mode (DisplayMode mode) noexcept -> bool
 
constexpr auto bits_per_pixel (DisplayMode mode) noexcept -> std::uint8_t
 Get bits per pixel for a display mode.
 
constexpr auto is_color_mode (DisplayMode mode) noexcept -> bool
 Check if mode supports color (non-grayscale).
 
constexpr auto num_planes (DisplayMode mode) noexcept -> std::size_t
 Get number of color planes required for a display mode.
 
constexpr auto spectra6_color_to_value (Color color) noexcept -> std::uint8_t
 Convert a Color to its 3-bit Spectra6 value.
 
constexpr auto spectra6_value_to_color (std::uint8_t value) noexcept -> Color
 Convert a 3-bit Spectra6 value to Color.
 
constexpr auto color_to_rgb (Color color) noexcept -> RGB
 Convert a Color enum to RGB values.
 
constexpr auto rgb_to_grayscale (std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept -> std::uint8_t
 Convert RGB values to grayscale using standard luminance formula.
 
constexpr auto rgb_to_color_bw (std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept -> Color
 Convert RGB to Color for black/white mode.
 
constexpr auto rgb_to_color_grayscale4 (std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept -> Color
 Convert RGB to Color for 4-level grayscale mode.
 
constexpr auto rgb_to_color (DisplayMode mode, std::uint8_t r, std::uint8_t g, std::uint8_t b) noexcept -> Color
 Convert RGB to Color based on display mode.
 
constexpr auto calculate_bw_position (std::size_t width, std::size_t x, std::size_t y) noexcept -> std::pair< std::size_t, std::uint8_t >
 Calculate byte index and bit mask for B/W mode pixel.
 
constexpr auto calculate_gray_position (std::size_t width, std::size_t x, std::size_t y) noexcept -> std::pair< std::size_t, std::uint8_t >
 Calculate byte index and pixel shift for Grayscale4 mode pixel.
 
constexpr auto calculate_spectra6_position (std::size_t width, std::size_t x, std::size_t y) noexcept -> std::pair< std::size_t, std::size_t >
 Calculate byte index and bit offset for Spectra6 (3-bit) mode pixel.
 
auto get_pixel_bw (std::span< const std::byte > buffer, std::size_t width, std::size_t x, std::size_t y) noexcept -> Color
 Read a pixel from a B/W mode buffer.
 
auto get_pixel_grayscale4 (std::span< const std::byte > buffer, std::size_t width, std::size_t x, std::size_t y) noexcept -> Color
 Read a pixel from a Grayscale4 mode buffer.
 
auto get_pixel_bwr_bwy (std::span< const std::byte > buffer, std::size_t width, std::size_t height, std::size_t x, std::size_t y, bool is_bwr) noexcept -> Color
 Read a pixel from a BWR or BWY mode buffer.
 
auto get_pixel_spectra6 (std::span< const std::byte > buffer, std::size_t width, std::size_t x, std::size_t y) noexcept -> Color
 Read a pixel from a Spectra6 mode buffer.
 
auto get_pixel_from_buffer (DisplayMode mode, std::span< const std::byte > buffer, std::size_t width, std::size_t height, std::size_t x, std::size_t y) noexcept -> Color
 Read a pixel from a buffer based on display mode.
 
auto set_pixel_bw (std::span< std::byte > buffer, std::size_t width, std::size_t x, std::size_t y, Color color) noexcept -> void
 Write a pixel to a B/W mode buffer.
 
auto set_pixel_grayscale4 (std::span< std::byte > buffer, std::size_t width, std::size_t x, std::size_t y, Color color) noexcept -> void
 Write a pixel to a Grayscale4 mode buffer.
 
auto set_pixel_bwr_bwy (std::span< std::byte > buffer, std::size_t width, std::size_t height, std::size_t x, std::size_t y, Color color, bool is_bwr) noexcept -> void
 Write a pixel to a BWR or BWY mode buffer.
 
auto set_pixel_spectra6 (std::span< std::byte > buffer, std::size_t width, std::size_t x, std::size_t y, Color color) noexcept -> void
 Write a pixel to a Spectra6 mode buffer.
 
auto set_pixel_in_buffer (DisplayMode mode, std::span< std::byte > buffer, std::size_t width, std::size_t height, std::size_t x, std::size_t y, Color color) noexcept -> void
 Write a pixel to a buffer based on display mode.
 

Variables

constexpr PowerConfig POWER_CONFIG_BW
 Power configuration for black/white mode.
 
constexpr PowerConfig POWER_CONFIG_GRAYSCALE
 Power configuration for grayscale mode.
 
constexpr BoosterConfig BOOSTER_CONFIG = {.phase1 = 0x07, .phase2 = 0x07, .phase3 = 0x17}
 Standard booster soft start configuration.
 
constexpr std::array< Color, 8 > SPECTRA6_VALUE_TO_COLOR
 Mapping from 3-bit Spectra6 value to Color enum.
 

Typedef Documentation

◆ TwoPlaneFramebuffer

Convenience alias for a two-plane color framebuffer.

Examples
/mnt/nas/libepaper/include/epaper/core/framebuffer.hpp.

Enumeration Type Documentation

◆ Color

enum class epaper::Color : std::uint8_t
strong
Enumerator
White 

White (or lightest gray in grayscale modes)

Black 

Black (or darkest gray in grayscale modes)

Gray1 

First gray level - lighter (Grayscale4 mode only)

Gray2 

Second gray level - darker (Grayscale4 mode only)

Red 

Red (BWR and Spectra6 modes)

Yellow 

Yellow (BWY and Spectra6 modes)

Blue 

Blue (Spectra6 mode only)

Green 

Green (Spectra6 mode only)

Examples
/mnt/nas/libepaper/include/epaper/color/color_manager.hpp, /mnt/nas/libepaper/include/epaper/core/display.hpp, /mnt/nas/libepaper/include/epaper/core/framebuffer.hpp, /mnt/nas/libepaper/include/epaper/core/framebuffer_concepts.hpp, /mnt/nas/libepaper/include/epaper/core/types.hpp, /mnt/nas/libepaper/include/epaper/draw/builders.hpp, /mnt/nas/libepaper/include/epaper/draw/commands.hpp, /mnt/nas/libepaper/include/epaper/draw/styles.hpp, /mnt/nas/libepaper/include/epaper/graphics/graphics.hpp, and /mnt/nas/libepaper/include/epaper/io/image_io.hpp.

◆ Command

enum class epaper::Command : std::uint8_t
strong

E-paper display command codes for EPD27.

Enumerator
BOOSTER_SOFT_START 

Booster soft start control.

DATA_START_TRANSMISSION_1 

Start data transmission (old data)

DISPLAY_REFRESH 

Refresh display.

DATA_START_TRANSMISSION_2 

Start data transmission (new data)

PARTIAL_DISPLAY_REFRESH 

Partial display refresh control.

LUT_VCOM 

VCOM LUT register.

LUT_WW 

White-to-White LUT register.

LUT_BW 

Black-to-White LUT register.

LUT_WB 

White-to-Black LUT register.

LUT_BB 

Black-to-Black LUT register.

LUT_WW2 

Additional White-to-White LUT register.

PLL_CONTROL 

PLL control (frame rate)

VCOM_DATA_INTERVAL 

VCOM and data interval setting.

RESOLUTION_SETTING 

Resolution setting.

GET_STATUS 

Get display status.

VCM_DC_SETTING 

VCM DC setting.

POWER_OPTIMIZATION 

Power optimization register.

PANEL_SETTING 

Panel setting register.

POWER_SETTING 

Power setting.

POWER_OFF 

Power off command.

POWER_ON 

Power on command.

DEEP_SLEEP 

Deep sleep mode.

◆ DisplayMode

enum class epaper::DisplayMode : std::uint8_t
strong

◆ DotPixel

enum class epaper::DotPixel : std::uint8_t
strong
Enumerator
Pixel1x1 

Single pixel (finest resolution)

Pixel2x2 

2x2 pixel block

Pixel3x3 

3x3 pixel block

Pixel4x4 

4x4 pixel block

Pixel5x5 

5x5 pixel block

Pixel6x6 

6x6 pixel block

Pixel7x7 

7x7 pixel block

Pixel8x8 

8x8 pixel block (thickest)

Examples
/mnt/nas/libepaper/include/epaper/core/types.hpp, /mnt/nas/libepaper/include/epaper/draw/builders.hpp, /mnt/nas/libepaper/include/epaper/draw/commands.hpp, and /mnt/nas/libepaper/include/epaper/draw/styles.hpp.

◆ DrawFill

enum class epaper::DrawFill
strong

◆ ErrorCode

enum class epaper::ErrorCode
strong

Unified error codes for all libepaper operations.

This enum consolidates all error types across the library, providing a consistent error handling interface.

Enumerator
DeviceNotInitialized 

Device has not been initialized.

DeviceInitFailed 

Device initialization failed.

GPIOInitFailed 

GPIO initialization failed (libgpiod)

GPIORequestFailed 

GPIO line request failed.

SPIInitFailed 

SPI initialization failed.

SPIDeviceOpenFailed 

SPI device open failed.

SPIConfigFailed 

SPI configuration failed.

InvalidPin 

Invalid GPIO pin number.

TransferFailed 

SPI/data transfer failed.

DriverNotInitialized 

Driver has not been initialized.

DriverInitFailed 

Driver initialization failed.

InvalidMode 

Invalid display mode specified.

Timeout 

Operation timed out.

DisplayNotReady 

Display is not ready for operation.

RefreshFailed 

Display refresh operation failed.

FileNotFound 

Image file not found.

InvalidFormat 

Invalid or unsupported image format.

LoadFailed 

Failed to load image data.

InvalidDimensions 

Invalid image dimensions.

Examples
/mnt/nas/libepaper/include/epaper/core/errors.hpp.

◆ LineStyle

enum class epaper::LineStyle
strong

◆ Orientation

enum class epaper::Orientation : std::uint8_t
strong
Enumerator
Portrait0 

Default portrait orientation (0° rotation)

Landscape90 

90° clockwise rotation (landscape mode)

Portrait180 

180° rotation (upside down portrait)

Landscape270 

270° clockwise / 90° counter-clockwise (landscape mode)

Examples
/mnt/nas/libepaper/include/epaper/core/display.hpp, /mnt/nas/libepaper/include/epaper/core/framebuffer.hpp, /mnt/nas/libepaper/include/epaper/core/framebuffer_concepts.hpp, /mnt/nas/libepaper/include/epaper/core/types.hpp, /mnt/nas/libepaper/include/epaper/graphics/graphics.hpp, and /mnt/nas/libepaper/include/epaper/internal/internal.hpp.

◆ Spectra6Color

enum class epaper::Spectra6Color : std::uint8_t
strong

Color values for Spectra 6 displays.

6-Color Palette:

  • Supports full primary and secondary colors in RGB space
  • Each color encoded as 3-bit value (0-5, values 6-7 unused)
  • Pixels packed tightly in framebuffer (may span byte boundaries)

Bit Encoding:

Color | Value | Binary | RGB Equivalent
-------|-------|--------|---------------
Black | 0 | 000 | (0, 0, 0)
White | 1 | 001 | (255, 255, 255)
Red | 2 | 010 | (255, 0, 0)
Yellow | 3 | 011 | (255, 255, 0)
Blue | 4 | 100 | (0, 0, 255)
Green | 5 | 101 | (0, 255, 0)
Color
Definition types.hpp:32
Definition color.hpp:50
Note
Spectra6 uses single-plane 3bpp encoding, unlike BWR/BWY dual-plane.
Enumerator
Black 
White 
Red 
Yellow 
Blue 
Green 
Examples
/mnt/nas/libepaper/include/epaper/color/device_color.hpp.

◆ TextContent

enum class epaper::TextContent
strong

Content type for text rendering.

Discriminant for TextCommand's internal union-like behavior. Determines which fields are active and how text is populated.

Enumerator
String 

Direct string content (text field used as-is)

Number 

Integer number (number field converted to text via sprintf)

Decimal 

Decimal number (decimal field formatted with decimal_places precision)

Examples
/mnt/nas/libepaper/include/epaper/draw/builders.hpp, and /mnt/nas/libepaper/include/epaper/draw/commands.hpp.

◆ TriColor

enum class epaper::TriColor : std::uint8_t
strong

Color values for 3-color displays (Black/White/Red or Black/White/Yellow).

Used by BWR and BWY display modes which employ dual-plane architecture:

  • Plane 0: Black/White data (1 bpp)
  • Plane 1: Accent color data (1 bpp)

Dual-Plane Encoding:

Color | Plane 0 | Plane 1 | TriColor Value
--------|---------|---------|---------------
Black | 1 | 1 | Black (0)
White | 0 | 1 | White (1)
Red/Yel | 0 | 0 | Third (2)
TriColor
Color values for 3-color displays (Black/White/Red or Black/White/Yellow).
Definition device_color.hpp:144
@ Third
Red for BWR, Yellow for BWY.
Note
The Third value represents Red for BWR mode and Yellow for BWY mode.
Enumerator
Black 
White 
Third 

Red for BWR, Yellow for BWY.

Examples
/mnt/nas/libepaper/include/epaper/color/device_color.hpp.

Function Documentation

◆ bits_per_pixel()

constexpr auto epaper::bits_per_pixel ( DisplayMode  mode) -> std::uint8_t
constexprnoexcept

Get bits per pixel for a display mode.

Parameters
modeDisplay mode
Returns
Bits per pixel required for this mode
Examples
/mnt/nas/libepaper/include/epaper/drivers/driver.hpp, and /mnt/nas/libepaper/include/epaper/drivers/mock_driver.hpp.
Here is the caller graph for this function:

◆ calculate_bw_position()

constexpr auto epaper::calculate_bw_position ( std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> std::pair<std::size_t, std::uint8_t>
constexprnoexcept

Calculate byte index and bit mask for B/W mode pixel.

Encoding:

  • 8 pixels per byte, MSB-first (leftmost pixel = bit 7)
  • Row-major layout: pixels packed left-to-right, top-to-bottom
  • Partial bytes: right-padded with zeros if width not multiple of 8

Example (width=10):

Pixels: [0][1][2][3][4][5][6][7] | [8][9][pad][pad]...
Byte 0: b7 b6 b5 b4 b3 b2 b1 b0 | Byte 1: b7 b6 ...
Parameters
widthDisplay width in pixels
xX coordinate (0-based, left edge = 0)
yY coordinate (0-based, top edge = 0)
Returns
Pair of (byte_index, bit_mask) where bit_mask has single bit set
Here is the caller graph for this function:

◆ calculate_gray_position()

constexpr auto epaper::calculate_gray_position ( std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> std::pair<std::size_t, std::uint8_t>
constexprnoexcept

Calculate byte index and pixel shift for Grayscale4 mode pixel.

Encoding:

  • 2 bits per pixel, 4 pixels per byte
  • Packed MSB-first: pixel 0 in bits [7:6], pixel 1 in bits [5:4], etc.
  • 4 gray levels: 00=Black, 01=Gray2 (dark), 10=Gray1 (light), 11=White

Example (width=6):

Pixels: [0][1][2][3] | [4][5][pad][pad]
Byte 0: [76][54][32][10] | Byte 1: [76][54][--][--]

Pixel shift values:

  • x % 4 == 0: shift = 0 (bits [7:6])
  • x % 4 == 1: shift = 2 (bits [5:4])
  • x % 4 == 2: shift = 4 (bits [3:2])
  • x % 4 == 3: shift = 6 (bits [1:0])
Parameters
widthDisplay width in pixels
xX coordinate
yY coordinate
Returns
Pair of (byte_index, pixel_shift)
Here is the caller graph for this function:

◆ calculate_spectra6_position()

constexpr auto epaper::calculate_spectra6_position ( std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> std::pair<std::size_t, std::size_t>
constexprnoexcept

Calculate byte index and bit offset for Spectra6 (3-bit) mode pixel.

Encoding:

  • 3 bits per pixel (values 0-5 for 6 colors, 6-7 unused)
  • Pixels packed sequentially across byte boundaries
  • No alignment - pixel N starts at bit (N * 3) from buffer start

Example (first 3 pixels = 9 bits):

Pixel: [ 0 ][ 1 ][ 2 ]
Bits: 210 210 210
Byte 0: [76543210] (contains p0 + p1_b2)
Byte 1: [76543210] (contains p1_b1b0 + p2)

Cross-byte handling:

  • bit_offset ≤ 5: pixel fits in single byte
  • bit_offset > 5: pixel spans two bytes (need to merge bits)
Parameters
widthDisplay width in pixels
xX coordinate
yY coordinate
Returns
Pair of (byte_index, bit_offset within byte)
Here is the caller graph for this function:

◆ color_to_rgb()

constexpr auto epaper::color_to_rgb ( Color  color) -> RGB
constexprnoexcept

Convert a Color enum to RGB values.

Parameters
colorThe e-paper color
Returns
RGB struct with red, green, blue components
Examples
/mnt/nas/libepaper/include/epaper/drivers/mock_driver.hpp.

◆ create_display() [1/2]

template<typename DriverType , FramebufferLike FramebufferT>
requires Driver<DriverType> && DriverTraits<DriverType>
auto epaper::create_display ( Device device,
DisplayMode  mode,
Orientation  orientation = Orientation::Portrait0,
bool  auto_sleep = true 
) -> std::expected<Display<DriverType, FramebufferT>, Error>

Primary factory function for creating displays with explicit framebuffer type.

Template Parameters
DriverTypeThe driver type to use
FramebufferTFramebuffer type to use
Parameters
deviceInitialized device
modeDisplay mode
orientationDisplay orientation
auto_sleepEnable auto-sleep after refresh
Returns
Display with the requested framebuffer type on success, Error on failure

◆ create_display() [2/2]

template<typename DriverType >
requires Driver<DriverType> && DriverTraits<DriverType>
auto epaper::create_display ( Device device,
DisplayMode  mode,
Orientation  orientation = Orientation::Portrait0,
bool  auto_sleep = true 
) -> std::expected<Display<DriverType, MonoFramebuffer>, Error>

Convenience factory for mono-plane displays.

Defaults to MonoFramebuffer and validates that the requested mode is single-plane.

Template Parameters
DriverTypeThe driver type to use
Parameters
deviceInitialized device
modeDisplay mode
orientationDisplay orientation
auto_sleepEnable auto-sleep after refresh
Returns
Display with a MonoFramebuffer on success, Error on failure
Examples
/mnt/nas/libepaper/include/epaper/core/display.hpp.

◆ get_pixel_bw()

auto epaper::get_pixel_bw ( std::span< const std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> Color
inlinenoexcept

Read a pixel from a B/W mode buffer.

Bit Transformation:

  1. Calculate byte index and bit mask (MSB-first)
  2. Read byte from buffer
  3. AND byte with bit_mask
  4. Non-zero result = White (1), zero result = Black (0)

Safety:

  • Returns Color::White if byte_index out of bounds
  • No undefined behavior on invalid coordinates
Parameters
bufferFramebuffer data (read-only)
widthDisplay width
xX coordinate
yY coordinate
Returns
Color::White or Color::Black
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pixel_bwr_bwy()

auto epaper::get_pixel_bwr_bwy ( std::span< const std::byte >  buffer,
std::size_t  width,
std::size_t  height,
std::size_t  x,
std::size_t  y,
bool  is_bwr 
) -> Color
inlinenoexcept

Read a pixel from a BWR or BWY mode buffer.

Dual-Plane Encoding:

  • Buffer layout: [BW plane (plane_size bytes)][Color plane (plane_size bytes)]
  • Each plane: 1bpp, same layout as BlackWhite mode

Bit Transformation:

  1. Read BW plane bit: 1 = candidate for white/color, 0 = candidate for black/color
  2. Read Color plane bit: 0 = use color ink (active-low), 1 = no color ink
  3. Decode combination:
    • (BW=1, Color=1) → White (no ink on either plane)
    • (BW=0, Color=1) → Black (BW ink only)
    • (BW=x, Color=0) → Red/Yellow (color ink overwrites BW)

Active-Low Color Plane: E-paper color planes typically use inverted logic where 0 = "apply color ink". This allows white to be the default (all 1s).

Safety:

  • Returns Color::White if out of bounds
  • Validates both plane accesses
Parameters
bufferFramebuffer data (two planes: B/W + color)
widthDisplay width
heightDisplay height (needed to calculate plane_size)
xX coordinate
yY coordinate
is_bwrTrue for BWR mode (Red), false for BWY mode (Yellow)
Returns
Color::White, Color::Black, Color::Red, or Color::Yellow
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pixel_from_buffer()

auto epaper::get_pixel_from_buffer ( DisplayMode  mode,
std::span< const std::byte >  buffer,
std::size_t  width,
std::size_t  height,
std::size_t  x,
std::size_t  y 
) -> Color
inlinenoexcept

Read a pixel from a buffer based on display mode.

Dispatches to the appropriate mode-specific function.

Parameters
modeDisplay mode
bufferFramebuffer data
widthDisplay width
heightDisplay height (needed for multi-plane modes)
xX coordinate
yY coordinate
Returns
Pixel color
Examples
/mnt/nas/libepaper/include/epaper/drivers/mock_driver.hpp.
Here is the call graph for this function:

◆ get_pixel_grayscale4()

auto epaper::get_pixel_grayscale4 ( std::span< const std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> Color
inlinenoexcept

Read a pixel from a Grayscale4 mode buffer.

Bit Transformation:

  1. Calculate byte index and pixel shift (2 bits per pixel)
  2. Read byte from buffer
  3. Right-shift by (6 - pixel_shift) to align 2-bit field to LSBs
  4. Mask with 0x03 to extract 2-bit value
  5. Map 2-bit value to Color:
    • 0b00 (0) → Black
    • 0b01 (1) → Gray2 (dark gray)
    • 0b10 (2) → Gray1 (light gray)
    • 0b11 (3) → White

Safety:

Parameters
bufferFramebuffer data (read-only)
widthDisplay width
xX coordinate
yY coordinate
Returns
One of the four grayscale Color values
Here is the call graph for this function:
Here is the caller graph for this function:

◆ get_pixel_spectra6()

auto epaper::get_pixel_spectra6 ( std::span< const std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y 
) -> Color
inlinenoexcept

Read a pixel from a Spectra6 mode buffer.

3-Bit Cross-Byte Decoding:

  • Pixel N spans bits [(N*3) : (N*3 + 2)] in buffer
  • May require reading 1 or 2 bytes depending on alignment

Case 1: Single-byte (bit_offset ≤ 5):

Byte: [76543210]
^^^ 3-bit pixel fits in one byte
Shift right by (5 - bit_offset), mask with 0x07

Case 2: Cross-byte (bit_offset = 6 or 7):

Byte N: [......10] (high_bits = 2 or 1)
Byte N+1: [1.......] (low_bits = 1 or 2)
Merge: (high_byte & mask) << low_bits | (low_byte >> shift) & mask

Color Mapping: 0=Black, 1=White, 2=Red, 3=Yellow, 4=Blue, 5=Green, 6-7=Fallback to Black

Safety:

  • Returns Color::White if byte_index out of bounds
  • Handles partial second byte gracefully
Parameters
bufferFramebuffer data (read-only)
widthDisplay width
xX coordinate
yY coordinate
Returns
One of the six Spectra6 colors
Here is the call graph for this function:
Here is the caller graph for this function:

◆ is_color_mode()

constexpr auto epaper::is_color_mode ( DisplayMode  mode) -> bool
constexprnoexcept

Check if mode supports color (non-grayscale).

Parameters
modeDisplay mode
Returns
true if mode supports color
Examples
/mnt/nas/libepaper/include/epaper/core/display.hpp, and /mnt/nas/libepaper/include/epaper/drivers/driver.hpp.
Here is the caller graph for this function:

◆ make_error()

auto epaper::make_error ( ErrorCode  code,
std::string_view  context = {} 
) -> Error
inline

◆ num_planes()

constexpr auto epaper::num_planes ( DisplayMode  mode) -> std::size_t
constexprnoexcept

Get number of color planes required for a display mode.

Parameters
modeDisplay mode
Returns
Number of planes (1 for monochrome/grayscale, 2+ for color)
Examples
/mnt/nas/libepaper/include/epaper/core/display.hpp, /mnt/nas/libepaper/include/epaper/core/framebuffer.hpp, and /mnt/nas/libepaper/include/epaper/drivers/driver.hpp.
Here is the caller graph for this function:

◆ rgb_to_color()

constexpr auto epaper::rgb_to_color ( DisplayMode  mode,
std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
) -> Color
constexprnoexcept

Convert RGB to Color based on display mode.

Parameters
modeCurrent display mode
rRed component
gGreen component
bBlue component
Returns
Appropriate Color for the display mode
Here is the call graph for this function:

◆ rgb_to_color_bw()

constexpr auto epaper::rgb_to_color_bw ( std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
) -> Color
constexprnoexcept

Convert RGB to Color for black/white mode.

Uses threshold of 128 for binarization.

Parameters
rRed component
gGreen component
bBlue component
Returns
Color::White or Color::Black
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rgb_to_color_grayscale4()

constexpr auto epaper::rgb_to_color_grayscale4 ( std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
) -> Color
constexprnoexcept

Convert RGB to Color for 4-level grayscale mode.

Quantizes to 4 levels: White, Gray1, Gray2, Black.

Parameters
rRed component
gGreen component
bBlue component
Returns
One of the four grayscale Color values
Here is the call graph for this function:
Here is the caller graph for this function:

◆ rgb_to_grayscale()

constexpr auto epaper::rgb_to_grayscale ( std::uint8_t  r,
std::uint8_t  g,
std::uint8_t  b 
) -> std::uint8_t
constexprnoexcept

Convert RGB values to grayscale using standard luminance formula.

Uses the ITU-R BT.601 luma formula: Y = 0.299R + 0.587G + 0.114B

Parameters
rRed component (0-255)
gGreen component (0-255)
bBlue component (0-255)
Returns
Grayscale value (0-255)
Here is the caller graph for this function:

◆ set_pixel_bw()

auto epaper::set_pixel_bw ( std::span< std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y,
Color  color 
) -> void
inlinenoexcept

Write a pixel to a B/W mode buffer.

Bit Transformation:

  1. Calculate byte index and bit mask (single bit set)
  2. Read current byte value
  3. For White: OR byte with bit_mask (set bit to 1)
  4. For Black: AND byte with ~bit_mask (clear bit to 0)
  5. Write modified byte back

Read-Modify-Write: Must preserve other 7 bits in the byte. Using bitwise operations ensures atomic semantics on single-threaded systems.

Safety:

  • No-op if byte_index out of bounds (silent fail)
  • Treats all non-White colors as Black
Parameters
bufferFramebuffer data (mutable)
widthDisplay width
xX coordinate
yY coordinate
colorPixel color (White or Black)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pixel_bwr_bwy()

auto epaper::set_pixel_bwr_bwy ( std::span< std::byte >  buffer,
std::size_t  width,
std::size_t  height,
std::size_t  x,
std::size_t  y,
Color  color,
bool  is_bwr 
) -> void
inlinenoexcept

Write a pixel to a BWR or BWY mode buffer.

Dual-Plane Encoding Logic:

Input Color → (BW plane bit, Color plane bit)
White → (1, 1) # No ink on either plane
Black → (0, 1) # BW ink only
Red/Yellow → (0, 0) # Color ink (active-low)

Bit Transformation:

  1. Calculate byte index and bit mask (same for both planes)
  2. Decode input color to (is_bw_white, is_color) flags
  3. Write BW plane: set bit if is_bw_white, clear otherwise
  4. Write Color plane: clear bit if is_color (active-low!), set otherwise

Active-Low Color Logic: The Color plane bit is INVERTED:

  • 0 = "apply color ink" (Red/Yellow pixel)
  • 1 = "no color ink" (allows BW plane to show through)

Safety:

  • No-op if either plane access out of bounds
  • Validates buffer size includes both planes
Parameters
bufferFramebuffer data (mutable, two planes)
widthDisplay width
heightDisplay height (for plane_size calculation)
xX coordinate
yY coordinate
colorPixel color
is_bwrTrue for BWR mode (Red), false for BWY mode (Yellow)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pixel_grayscale4()

auto epaper::set_pixel_grayscale4 ( std::span< std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y,
Color  color 
) -> void
inlinenoexcept

Write a pixel to a Grayscale4 mode buffer.

Bit Transformation:

  1. Calculate byte index and pixel shift (2 bits per pixel)
  2. Extract 2-bit color value from Color enum (bits [7:6])
  3. Shift color value right by pixel_shift to align with target position
  4. Create mask for 2-bit field: 0xC0 >> pixel_shift
  5. Clear target field: byte & ~mask
  6. Set new value: (byte & ~mask) | (color_bits & mask)

Color Encoding:

  • Color enum already has correct bit patterns in [7:6]:
    • Black = 0b00xx_xxxx → 0b00
    • Gray2 = 0b01xx_xxxx → 0b01
    • Gray1 = 0b10xx_xxxx → 0b10
    • White = 0b11xx_xxxx → 0b11

Safety:

  • No-op if byte_index out of bounds
  • Preserves other 3 pixels in the byte
Parameters
bufferFramebuffer data (mutable)
widthDisplay width
xX coordinate
yY coordinate
colorPixel color (one of 4 grayscale levels)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ set_pixel_in_buffer()

auto epaper::set_pixel_in_buffer ( DisplayMode  mode,
std::span< std::byte >  buffer,
std::size_t  width,
std::size_t  height,
std::size_t  x,
std::size_t  y,
Color  color 
) -> void
inlinenoexcept

Write a pixel to a buffer based on display mode.

Dispatches to the appropriate mode-specific function.

Parameters
modeDisplay mode
bufferFramebuffer data (mutable)
widthDisplay width
heightDisplay height (needed for multi-plane modes)
xX coordinate
yY coordinate
colorPixel color
Here is the call graph for this function:

◆ set_pixel_spectra6()

auto epaper::set_pixel_spectra6 ( std::span< std::byte >  buffer,
std::size_t  width,
std::size_t  x,
std::size_t  y,
Color  color 
) -> void
inlinenoexcept

Write a pixel to a Spectra6 mode buffer.

Parameters
bufferFramebuffer data (mutable)
widthDisplay width
xX coordinate
yY coordinate
colorPixel color
Here is the call graph for this function:
Here is the caller graph for this function:

◆ spectra6_color_to_value()

constexpr auto epaper::spectra6_color_to_value ( Color  color) -> std::uint8_t
constexprnoexcept

Convert a Color to its 3-bit Spectra6 value.

Parameters
colorThe color to convert
Returns
3-bit value (0-5) for Spectra6 encoding
Here is the caller graph for this function:

◆ spectra6_value_to_color()

constexpr auto epaper::spectra6_value_to_color ( std::uint8_t  value) -> Color
constexprnoexcept

Convert a 3-bit Spectra6 value to Color.

Parameters
value3-bit value (0-7)
Returns
Corresponding Color enum value
Here is the caller graph for this function:

◆ supports_display_mode()

template<typename Driver >
requires DriverTraits<Driver>
constexpr auto epaper::supports_display_mode ( DisplayMode  mode) -> bool
constexprnoexcept

◆ to_string()

constexpr auto epaper::to_string ( ErrorCode  code) -> std::string_view
constexpr

Convert error code to string representation.

Parameters
codeError code to convert
Returns
String view describing the error
Examples
/mnt/nas/libepaper/include/epaper/core/errors.hpp.
Here is the caller graph for this function:

Variable Documentation

◆ BOOSTER_CONFIG

constexpr BoosterConfig epaper::BOOSTER_CONFIG = {.phase1 = 0x07, .phase2 = 0x07, .phase3 = 0x17}
constexpr

Standard booster soft start configuration.

◆ POWER_CONFIG_BW

constexpr PowerConfig epaper::POWER_CONFIG_BW
constexpr
Initial value:
= {
.vds_en_vdg_en = 0x03, .vcom_hv_vghl_lv = 0x00, .vdh = 0x2B, .vdl = 0x2B, .vdhr = 0x09}

Power configuration for black/white mode.

◆ POWER_CONFIG_GRAYSCALE

constexpr PowerConfig epaper::POWER_CONFIG_GRAYSCALE
constexpr
Initial value:
= {
.vds_en_vdg_en = 0x03,
.vcom_hv_vghl_lv = 0x00,
.vdh = 0x2B,
.vdl = 0x2B,
.vdhr = 0x00
}

Power configuration for grayscale mode.

◆ SPECTRA6_VALUE_TO_COLOR

constexpr std::array<Color, 8> epaper::SPECTRA6_VALUE_TO_COLOR
constexpr
Initial value:
= {{
Color::Black,
Color::White,
Color::Red,
Color::Yellow,
Color::Blue,
Color::Green,
Color::Black,
Color::Black
}}

Mapping from 3-bit Spectra6 value to Color enum.