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
42class panel_io {
43public:
50 typedef std::move_only_function<bool(esp_lcd_panel_io_event_data_t* edata)> color_transfer_done_callback;
51
55 struct spi_config {
59 freq::hertz pclk_freq;
62 nullptr;
66 0;
68 0;
69 struct {
70 unsigned int dc_high_on_cmd : 1 = 0;
71 unsigned int dc_low_on_data : 1 = 0;
72 unsigned int dc_low_on_param : 1 = 0;
73 unsigned int octal_mode : 1 =
74 0;
75 unsigned int quad_mode : 1 = 0;
77 unsigned int sio_mode : 1 = 0;
78 unsigned int lsb_first : 1 = 0;
79 unsigned int cs_high_active : 1 = 0;
80 } flags = {};
81 };
82
91 [[nodiscard]] static result<std::unique_ptr<panel_io>>
92 make(std::shared_ptr<idfxx::spi::master_bus> spi_bus, spi_config config);
93
94#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
104 [[nodiscard]] explicit panel_io(std::shared_ptr<idfxx::spi::master_bus> spi_bus, spi_config config);
105#endif
106
108
109 panel_io(const panel_io&) = delete;
110 panel_io& operator=(const panel_io&) = delete;
111 panel_io(panel_io&&) = delete;
113
115 [[nodiscard]] esp_lcd_panel_io_handle_t idf_handle() const { return _handle; }
116
117private:
118 explicit panel_io() = default;
119
121 static bool
122 on_color_transfer_done(esp_lcd_panel_io_handle_t handle, esp_lcd_panel_io_event_data_t* edata, void* user_ctx);
123
124 std::shared_ptr<idfxx::spi::master_bus> _spi_bus;
125 esp_lcd_panel_io_handle_t _handle;
126 color_transfer_done_callback _on_color_transfer_done;
127};
128
// end of idfxx_lcd
130
131} // namespace idfxx::lcd
Type-safe set of flags from a scoped enum.
Definition flags.hpp:88
A GPIO pin.
Definition gpio.hpp:58
SPI-based panel I/O interface.
Definition panel_io.hpp:42
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
panel_io & operator=(panel_io &&)=delete
esp_lcd_panel_io_handle_t idf_handle() const
Returns the underlying ESP-IDF handle.
Definition panel_io.hpp:115
static result< std::unique_ptr< panel_io > > make(std::shared_ptr< idfxx::spi::master_bus > spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io(const panel_io &)=delete
panel_io(std::shared_ptr< idfxx::spi::master_bus > spi_bus, spi_config config)
Creates a new panel I/O interface.
panel_io(panel_io &&)=delete
panel_io & operator=(const panel_io &)=delete
host_device
General purpose SPI Host Controller ID.
Definition master.hpp:40
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:118
SPI-based panel I/O configuration.
Definition panel_io.hpp:55
unsigned int octal_mode
transmit with octal mode (8 data lines), this mode is used to simulate Intel 8080 timing
Definition panel_io.hpp:74
size_t trans_queue_depth
Size of internal transaction queue.
Definition panel_io.hpp:60
uint8_t cs_enable_pretrans
Amount of SPI bit-cycles the cs should be activated before the transmission (0-16)
Definition panel_io.hpp:65
unsigned int dc_low_on_data
If enabled, DC level = 0 indicates color data transfer.
Definition panel_io.hpp:71
int spi_mode
Traditional SPI mode (0~3)
Definition panel_io.hpp:58
int lcd_param_bits
Bit-width of LCD parameter.
Definition panel_io.hpp:64
int lcd_cmd_bits
Bit-width of LCD command.
Definition panel_io.hpp:63
unsigned int cs_high_active
CS line is high active.
Definition panel_io.hpp:79
gpio cs_gpio
GPIO used for CS line.
Definition panel_io.hpp:56
freq::hertz pclk_freq
Frequency of pixel clock.
Definition panel_io.hpp:59
unsigned int dc_low_on_param
If enabled, DC level = 0 indicates parameter transfer.
Definition panel_io.hpp:72
unsigned int dc_high_on_cmd
If enabled, DC level = 1 indicates command transfer.
Definition panel_io.hpp:70
color_transfer_done_callback on_color_transfer_done
Callback invoked when color data transfer has finished.
Definition panel_io.hpp:61
gpio dc_gpio
GPIO used to select the D/C line, set this to -1 if the D/C line is not used.
Definition panel_io.hpp:57
uint8_t cs_enable_posttrans
Amount of SPI bit-cycles the cs should stay active after the transmission (0-16)
Definition panel_io.hpp:67
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:75
unsigned int sio_mode
Read and write through a single data line (MOSI)
Definition panel_io.hpp:77
unsigned int lsb_first
transmit LSB bit first
Definition panel_io.hpp:78