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
22#include <idfxx/spi/master>
23
24#include <esp_lcd_panel_io.h>
25#include <frequency/frequency>
26#include <functional>
27#include <memory>
28
33namespace idfxx::lcd {
34
44class panel_io {
45public:
53
60 struct spi_config {
63 int spi_mode = 0;
64 freq::hertz pclk_freq{0};
65 size_t trans_queue_depth = 0;
67 nullptr;
68 int lcd_cmd_bits = 0;
71 0;
73 0;
74 struct {
75 unsigned int dc_high_on_cmd : 1 = 0;
76 unsigned int dc_low_on_data : 1 = 0;
77 unsigned int dc_low_on_param : 1 = 0;
78 unsigned int octal_mode : 1 =
79 0;
80 unsigned int quad_mode : 1 = 0;
82 unsigned int sio_mode : 1 = 0;
83 unsigned int lsb_first : 1 = 0;
84 unsigned int cs_high_active : 1 = 0;
85 } flags = {};
86 };
87
88#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
102#endif
103
116
118
119 panel_io(const panel_io&) = delete;
120 panel_io& operator=(const panel_io&) = delete;
121 panel_io(panel_io&& other) noexcept;
122 panel_io& operator=(panel_io&& other) noexcept;
123
125 [[nodiscard]] esp_lcd_panel_io_handle_t idf_handle() const { return _handle; }
126
127private:
128 panel_io() = default;
129
130 struct callback_state {
131 color_transfer_done_callback on_color_transfer_done;
132 };
133
134 panel_io(esp_lcd_panel_io_handle_t handle, std::unique_ptr<callback_state> callbacks);
135
136 static bool
137 on_color_transfer_done(esp_lcd_panel_io_handle_t handle, esp_lcd_panel_io_event_data_t* edata, void* user_ctx);
138
139 esp_lcd_panel_io_handle_t _handle = nullptr;
140 std::unique_ptr<callback_state> _callbacks; // heap-stable state for ESP-IDF callbacks
141};
142
// end of idfxx_lcd
144
145} // namespace idfxx::lcd
Type-safe set of flags from a scoped enum.
Definition flags.hpp:88
A GPIO pin.
Definition gpio.hpp:61
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:254
SPI-based panel I/O interface.
Definition panel_io.hpp:44
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:52
panel_io(idfxx::spi::master_bus &spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io(panel_io &&other) noexcept
esp_lcd_panel_io_handle_t idf_handle() const
Returns the underlying ESP-IDF handle.
Definition panel_io.hpp:125
static result< panel_io > make(idfxx::spi::master_bus &spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io & operator=(panel_io &&other) noexcept
panel_io(const panel_io &)=delete
panel_io & operator=(const panel_io &)=delete
A SPI master bus.
Definition master.hpp:158
LCD driver classes.
Definition color.hpp:19
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
SPI-based panel I/O configuration.
Definition panel_io.hpp:60
unsigned int octal_mode
transmit with octal mode (8 data lines), this mode is used to simulate Intel 8080 timing
Definition panel_io.hpp:79
size_t trans_queue_depth
Size of internal transaction queue.
Definition panel_io.hpp:65
uint8_t cs_enable_pretrans
Amount of SPI bit-cycles the cs should be activated before the transmission (0-16)
Definition panel_io.hpp:70
unsigned int dc_low_on_data
If enabled, DC level = 0 indicates color data transfer.
Definition panel_io.hpp:76
int spi_mode
Traditional SPI mode (0~3)
Definition panel_io.hpp:63
int lcd_param_bits
Bit-width of LCD parameter.
Definition panel_io.hpp:69
int lcd_cmd_bits
Bit-width of LCD command.
Definition panel_io.hpp:68
unsigned int cs_high_active
CS line is high active.
Definition panel_io.hpp:84
gpio cs_gpio
GPIO used for CS line.
Definition panel_io.hpp:61
freq::hertz pclk_freq
Frequency of pixel clock.
Definition panel_io.hpp:64
unsigned int dc_low_on_param
If enabled, DC level = 0 indicates parameter transfer.
Definition panel_io.hpp:77
unsigned int dc_high_on_cmd
If enabled, DC level = 1 indicates command transfer.
Definition panel_io.hpp:75
color_transfer_done_callback on_color_transfer_done
Callback invoked when color data transfer has finished.
Definition panel_io.hpp:66
gpio dc_gpio
GPIO used to select the D/C line, set to gpio::nc() if not used.
Definition panel_io.hpp:62
uint8_t cs_enable_posttrans
Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
Definition panel_io.hpp:72
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:80
unsigned int sio_mode
Read and write through a single data line (MOSI)
Definition panel_io.hpp:82
unsigned int lsb_first
transmit LSB bit first
Definition panel_io.hpp:83