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

SSD1306 monochrome OLED display controller driver. More...

Inheritance diagram for idfxx::lcd::ssd1306:
idfxx::lcd::panel

Classes

struct  config
 Configuration structure for SSD1306 panels. More...
 

Public Member Functions

 ssd1306 (idfxx::panel_io &panel_io, config config)
 Creates a new ssd1306 panel.
 
void set_contrast (uint8_t level)
 Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).
 
result< void > try_set_contrast (uint8_t level)
 Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).
 
 ~ssd1306 ()
 
 ssd1306 (const ssd1306 &)=delete
 
ssd1306operator= (const ssd1306 &)=delete
 
 ssd1306 (ssd1306 &&other) noexcept
 
ssd1306operator= (ssd1306 &&other) noexcept
 
- Public Member Functions inherited from idfxx::lcd::panel
virtual ~panel ()=default
 
 panel (const panel &)=delete
 
paneloperator= (const panel &)=delete
 
esp_lcd_panel_handle_t idf_handle () const
 Returns the underlying ESP-IDF handle.
 
size_t width () const noexcept
 Returns the panel's native width in pixels.
 
size_t height () const noexcept
 Returns the panel's native height in pixels.
 
void draw_bitmap (int x_start, int y_start, int x_end, int y_end, const void *color_data)
 Draws bitmap data to a region of the display.
 
void invert_color (bool invert)
 Inverts the color of the display.
 
void swap_xy (bool swap)
 Swaps the X and Y axes.
 
void mirror (bool mirror_x, bool mirror_y)
 Mirrors the display.
 
void display_on (bool on)
 Turns the display on or off.
 
result< void > try_draw_bitmap (int x_start, int y_start, int x_end, int y_end, const void *color_data)
 Draws bitmap data to a region of the display.
 
result< void > try_invert_color (bool invert)
 Inverts the color of the display.
 
result< void > try_swap_xy (bool swap)
 Swaps the X and Y axes.
 
result< void > try_mirror (bool mirror_x, bool mirror_y)
 Mirrors the display.
 
result< void > try_display_on (bool on)
 Turns the display on or off.
 

Static Public Member Functions

static panel_io::i2c_config i2c_io_config (uint16_t device_address=0x3C, freq::hertz scl_speed=freq::hertz{400000}) noexcept
 Returns a panel I/O configuration for communicating with an SSD1306 over I2C.
 
static result< ssd1306make (idfxx::panel_io &panel_io, config config)
 Creates a new ssd1306 panel.
 

Additional Inherited Members

- Protected Member Functions inherited from idfxx::lcd::panel
 panel ()=default
 
 panel (size_t width, size_t height) noexcept
 Constructs a panel reporting the given native dimensions.
 
 panel (panel &&) noexcept=default
 
paneloperator= (panel &&) noexcept=default
 
virtual result< void > do_draw_bitmap (int x_start, int y_start, int x_end, int y_end, const void *color_data)
 Hook for try_draw_bitmap.
 
virtual result< void > do_invert_color (bool invert)
 Hook for try_invert_color.
 
virtual result< void > do_swap_xy (bool swap)
 Hook for try_swap_xy.
 
virtual result< void > do_mirror (bool mirror_x, bool mirror_y)
 Hook for try_mirror.
 
virtual result< void > do_display_on (bool on)
 Hook for try_display_on.
 

Detailed Description

SSD1306 monochrome OLED display controller driver.

Driver for SSD1306-based OLED displays (128x64 or 128x32, 1 bit per pixel). The display starts off; call display_on(true) after construction to make output visible.

Pixel data for draw_bitmap must be page-packed: each byte holds 8 vertically adjacent pixels (bit 0 topmost), and pages (rows of 8 pixels) are laid out top-to-bottom. Row coordinates passed to draw_bitmap must be page-aligned (multiples of 8). idfxx::lcd::mono_framebuffer produces this layout directly.

Definition at line 39 of file ssd1306.hpp.

Constructor & Destructor Documentation

◆ ssd1306() [1/3]

idfxx::lcd::ssd1306::ssd1306 ( idfxx::panel_io panel_io,
config  config 
)
explicit

Creates a new ssd1306 panel.

Does not take ownership of panel_io. It is the caller's responsibility to ensure that this panel does not outlive the panel I/O interface.

Parameters
panel_ioThe panel I/O interface.
configpanel configuration.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error.

◆ ~ssd1306()

idfxx::lcd::ssd1306::~ssd1306 ( )

◆ ssd1306() [2/3]

idfxx::lcd::ssd1306::ssd1306 ( const ssd1306 )
delete

◆ ssd1306() [3/3]

idfxx::lcd::ssd1306::ssd1306 ( ssd1306 &&  other)
noexcept

Member Function Documentation

◆ i2c_io_config()

static panel_io::i2c_config idfxx::lcd::ssd1306::i2c_io_config ( uint16_t  device_address = 0x3C,
freq::hertz  scl_speed = freq::hertz{400000} 
)
staticnoexcept

Returns a panel I/O configuration for communicating with an SSD1306 over I2C.

Fills in the I2C framing the SSD1306 controller requires (a one-byte control phase with the D/C selection in bit 6, and 8-bit commands and parameters), so only the wiring-specific values are parameters.

Parameters
device_addressThe panel's 7-bit I2C address. Most modules use 0x3C; some are strapped to 0x3D.
scl_speedThe I2C SCL frequency. The SSD1306 supports up to 400 kHz.
Returns
A panel_io::i2c_config ready to construct a panel_io.
idfxx::lcd::ssd1306 display(io, {.height = 64});
SSD1306 monochrome OLED display controller driver.
Definition ssd1306.hpp:39
static panel_io::i2c_config i2c_io_config(uint16_t device_address=0x3C, freq::hertz scl_speed=freq::hertz{400000}) noexcept
Returns a panel I/O configuration for communicating with an SSD1306 over I2C.
Panel I/O interface for SPI- and I2C-connected displays.
Definition panel_io.hpp:42

◆ make()

static result< ssd1306 > idfxx::lcd::ssd1306::make ( idfxx::panel_io panel_io,
config  config 
)
static

Creates a new ssd1306 panel.

Does not take ownership of panel_io. It is the caller's responsibility to ensure that this panel does not outlive the panel I/O interface.

Parameters
panel_ioThe panel I/O interface.
configpanel configuration.
Returns
The new ssd1306, or an error.
Return values
idfxx::errc::invalid_argif the configured height is not 64 or 32.

◆ operator=() [1/2]

ssd1306 & idfxx::lcd::ssd1306::operator= ( const ssd1306 )
delete

◆ operator=() [2/2]

ssd1306 & idfxx::lcd::ssd1306::operator= ( ssd1306 &&  other)
noexcept

◆ set_contrast()

void idfxx::lcd::ssd1306::set_contrast ( uint8_t  level)
inline

Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).

The controller powers on with contrast 0x7F. Lower values dim the panel; dimming also slows OLED burn-in on mostly-static content.

Parameters
levelContrast level, 0x00 (dimmest) to 0xFF (brightest).
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error.

Definition at line 114 of file ssd1306.hpp.

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

◆ try_set_contrast()

result< void > idfxx::lcd::ssd1306::try_set_contrast ( uint8_t  level)

Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).

The controller powers on with contrast 0x7F. Lower values dim the panel; dimming also slows OLED burn-in on mostly-static content.

Parameters
levelContrast level, 0x00 (dimmest) to 0xFF (brightest).
Returns
Nothing, or an error.
Return values
idfxx::errc::invalid_stateif the panel has been moved from.

Referenced by set_contrast().


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