idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
ssd1306.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright 2026 Chris Leishman
3
4#pragma once
5
13#include <idfxx/lcd/panel>
14#include <idfxx/panel_io>
15
16#include <cstddef>
17#include <cstdint>
18
23namespace idfxx::lcd {
24
39class ssd1306 : public panel {
40public:
50
69 [[nodiscard]] static panel_io::i2c_config
70 i2c_io_config(uint16_t device_address = 0x3C, freq::hertz scl_speed = freq::hertz{400000}) noexcept;
71
72#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
85 [[nodiscard]] explicit ssd1306(idfxx::panel_io& panel_io, config config);
86#endif
87
101
102#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
114 void set_contrast(uint8_t level) { unwrap(try_set_contrast(level)); }
115#endif
116
128 [[nodiscard]] result<void> try_set_contrast(uint8_t level);
129
131
132 ssd1306(const ssd1306&) = delete;
133 ssd1306& operator=(const ssd1306&) = delete;
134 ssd1306(ssd1306&& other) noexcept;
135 ssd1306& operator=(ssd1306&& other) noexcept;
136
137private:
138 explicit ssd1306(esp_lcd_panel_io_handle_t io_handle, esp_lcd_panel_handle_t handle, size_t height)
139 : panel(128, height)
140 , _io_handle(io_handle)
141 , _handle(handle) {}
142
143 // lcd::panel customization hooks.
144 [[nodiscard]] esp_lcd_panel_handle_t do_idf_handle() const override;
145
146 esp_lcd_panel_io_handle_t _io_handle = nullptr;
147 esp_lcd_panel_handle_t _handle = nullptr;
148};
149
150} // namespace idfxx::lcd
A GPIO pin.
Definition gpio.hpp:62
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:255
level
GPIO output/input level.
Definition gpio.hpp:68
@ low
Logic low (0)
Abstract base class for LCD panels.
Definition panel.hpp:47
size_t height() const noexcept
Returns the panel's native height in pixels.
Definition panel.hpp:91
SSD1306 monochrome OLED display controller driver.
Definition ssd1306.hpp:39
void set_contrast(uint8_t level)
Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).
Definition ssd1306.hpp:114
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.
result< void > try_set_contrast(uint8_t level)
Sets the display contrast (SSD1306 "Set Contrast Control", command 0x81).
ssd1306(idfxx::panel_io &panel_io, config config)
Creates a new ssd1306 panel.
ssd1306 & operator=(const ssd1306 &)=delete
ssd1306(const ssd1306 &)=delete
ssd1306 & operator=(ssd1306 &&other) noexcept
ssd1306(ssd1306 &&other) noexcept
static result< ssd1306 > make(idfxx::panel_io &panel_io, config config)
Creates a new ssd1306 panel.
Panel I/O interface for SPI- and I2C-connected displays.
Definition panel_io.hpp:42
struct esp_lcd_panel_t * esp_lcd_panel_handle_t
Definition panel.hpp:30
LCD driver classes.
Definition color.hpp:21
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
Definition error.hpp:307
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
Configuration structure for SSD1306 panels.
Definition ssd1306.hpp:45
gpio::level reset_active_level
Active level for the panel reset signal.
Definition ssd1306.hpp:48
uint32_t height
Display height in pixels (64 or 32)
Definition ssd1306.hpp:47
gpio reset_gpio
GPIO number for hardware reset, or idfxx::gpio::nc() if not used.
Definition ssd1306.hpp:46
I2C-based panel I/O configuration.
Definition panel_io.hpp:94