idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
panel_io.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
23#include <idfxx/i2c/master>
24#include <idfxx/spi/master>
25
26#include <esp_lcd_panel_io.h>
27#include <frequency/frequency>
28#include <functional>
29#include <memory>
30
31namespace idfxx {
32
42class panel_io {
43public:
50 typedef std::move_only_function<bool(esp_lcd_panel_io_event_data_t* edata)> color_transfer_done_callback;
51
58 struct spi_config {
61 int spi_mode = 0;
62 freq::hertz pclk_freq{0};
63 size_t trans_queue_depth = 0;
65 nullptr;
66 int lcd_cmd_bits = 0;
69 0;
71 0;
72 struct {
73 unsigned int dc_high_on_cmd : 1 = 0;
74 unsigned int dc_low_on_data : 1 = 0;
75 unsigned int dc_low_on_param : 1 = 0;
76 unsigned int octal_mode : 1 =
77 0;
78 unsigned int quad_mode : 1 = 0;
80 unsigned int sio_mode : 1 = 0;
81 unsigned int lsb_first : 1 = 0;
82 unsigned int cs_high_active : 1 = 0;
83 } flags = {};
84 };
85
94 struct i2c_config {
95 uint16_t device_address = 0;
96 freq::hertz scl_speed{0};
98 nullptr;
101 unsigned int dc_bit_offset = 0;
102 int lcd_cmd_bits = 0;
104 struct {
105 unsigned int dc_low_on_data : 1 = 0;
107 unsigned int disable_control_phase : 1 = 0;
108 } flags = {};
109 };
110
111#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
124 [[nodiscard]] explicit panel_io(idfxx::spi::master_bus& spi_bus, spi_config config);
125#endif
126
138 [[nodiscard]] static result<panel_io> make(idfxx::spi::master_bus& spi_bus, spi_config config);
139
140#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
153 [[nodiscard]] explicit panel_io(idfxx::i2c::master_bus& i2c_bus, i2c_config config);
154#endif
155
167 [[nodiscard]] static result<panel_io> make(idfxx::i2c::master_bus& i2c_bus, i2c_config config);
168
170
171 panel_io(const panel_io&) = delete;
172 panel_io& operator=(const panel_io&) = delete;
173 panel_io(panel_io&& other) noexcept;
174 panel_io& operator=(panel_io&& other) noexcept;
175
177 [[nodiscard]] esp_lcd_panel_io_handle_t idf_handle() const { return _handle; }
178
179private:
180 panel_io() = default;
181
182 struct callback_state {
183 color_transfer_done_callback on_color_transfer_done;
184 };
185
186 panel_io(esp_lcd_panel_io_handle_t handle, std::unique_ptr<callback_state> callbacks);
187
188 static bool
189 on_color_transfer_done(esp_lcd_panel_io_handle_t handle, esp_lcd_panel_io_event_data_t* edata, void* user_ctx);
190
191 esp_lcd_panel_io_handle_t _handle = nullptr;
192 std::unique_ptr<callback_state> _callbacks; // heap-stable state for ESP-IDF callbacks
193};
194
// end of idfxx_panel_io
196
197} // namespace idfxx
Type-safe set of flags from a scoped enum.
Definition flags.hpp:88
A GPIO pin.
Definition gpio.hpp:62
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:255
I2C master bus controller with thread-safe device access.
Definition master.hpp:152
Panel I/O interface for SPI- and I2C-connected displays.
Definition panel_io.hpp:42
panel_io(const panel_io &)=delete
esp_lcd_panel_io_handle_t idf_handle() const
Returns the underlying ESP-IDF handle.
Definition panel_io.hpp:177
std::move_only_function< bool(esp_lcd_panel_io_event_data_t *edata)> color_transfer_done_callback
Callback type invoked when color data transfer has finished.
Definition panel_io.hpp:50
static result< panel_io > make(idfxx::spi::master_bus &spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io(panel_io &&other) noexcept
panel_io(idfxx::i2c::master_bus &i2c_bus, i2c_config config)
Creates a new panel I/O interface.
panel_io & operator=(const panel_io &)=delete
panel_io(idfxx::spi::master_bus &spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io & operator=(panel_io &&other) noexcept
static result< panel_io > make(idfxx::i2c::master_bus &i2c_bus, i2c_config config)
Creates a new panel I/O interface.
A SPI master bus.
Definition master.hpp:256
Definition adc.hpp:48
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
I2C-based panel I/O configuration.
Definition panel_io.hpp:94
unsigned int disable_control_phase
If enabled, the control phase isn't used.
Definition panel_io.hpp:107
size_t control_phase_bytes
Number of bytes the panel encodes control information (e.g.
Definition panel_io.hpp:99
int lcd_param_bits
Bit-width of LCD parameter.
Definition panel_io.hpp:103
uint16_t device_address
7-bit I2C device address (e.g. 0x3C for a typical SSD1306)
Definition panel_io.hpp:95
int lcd_cmd_bits
Bit-width of LCD command.
Definition panel_io.hpp:102
unsigned int dc_bit_offset
Offset of the D/C selection bit in the control phase.
Definition panel_io.hpp:101
freq::hertz scl_speed
I2C SCL frequency.
Definition panel_io.hpp:96
color_transfer_done_callback on_color_transfer_done
Callback invoked when color data transfer has finished.
Definition panel_io.hpp:97
unsigned int dc_low_on_data
If enabled, DC bit = 0 indicates data transfer and DC bit = 1 indicates command transfer; vice versa ...
Definition panel_io.hpp:105
SPI-based panel I/O configuration.
Definition panel_io.hpp:58
int lcd_cmd_bits
Bit-width of LCD command.
Definition panel_io.hpp:66
unsigned int dc_low_on_param
If enabled, DC level = 0 indicates parameter transfer.
Definition panel_io.hpp:75
unsigned int quad_mode
transmit with quad mode (4 data lines), this mode is useful when transmitting LCD parameters (Only us...
Definition panel_io.hpp:78
int lcd_param_bits
Bit-width of LCD parameter.
Definition panel_io.hpp:67
gpio dc_gpio
GPIO used to select the D/C line, set to gpio::nc() if not used.
Definition panel_io.hpp:60
unsigned int dc_low_on_data
If enabled, DC level = 0 indicates color data transfer.
Definition panel_io.hpp:74
uint8_t cs_enable_posttrans
Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
Definition panel_io.hpp:70
unsigned int cs_high_active
CS line is high active.
Definition panel_io.hpp:82
int spi_mode
Traditional SPI mode (0~3)
Definition panel_io.hpp:61
uint8_t cs_enable_pretrans
Amount of SPI bit-cycles the cs should be activated before the transmission (0-16)
Definition panel_io.hpp:68
size_t trans_queue_depth
Size of internal transaction queue.
Definition panel_io.hpp:63
gpio cs_gpio
GPIO used for CS line.
Definition panel_io.hpp:59
unsigned int dc_high_on_cmd
If enabled, DC level = 1 indicates command transfer.
Definition panel_io.hpp:73
unsigned int sio_mode
Read and write through a single data line (MOSI)
Definition panel_io.hpp:80
unsigned int lsb_first
transmit LSB bit first
Definition panel_io.hpp:81
color_transfer_done_callback on_color_transfer_done
Callback invoked when color data transfer has finished.
Definition panel_io.hpp:64
freq::hertz pclk_freq
Frequency of pixel clock.
Definition panel_io.hpp:62
unsigned int octal_mode
transmit with octal mode (8 data lines), this mode is used to simulate Intel 8080 timing
Definition panel_io.hpp:77