idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
panel.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/error>
24#include <idfxx/gpio>
25#include <idfxx/lcd/color>
26
27#include <cstddef>
28
29struct esp_lcd_panel_t;
30typedef struct esp_lcd_panel_t* esp_lcd_panel_handle_t;
31
36namespace idfxx::lcd {
37
47class panel {
48public:
61
62 virtual ~panel() = default;
63
64 panel(const panel&) = delete;
65 panel& operator=(const panel&) = delete;
66
71 [[nodiscard]] esp_lcd_panel_handle_t idf_handle() const { return do_idf_handle(); }
72
81 [[nodiscard]] size_t width() const noexcept { return _width; }
82
91 [[nodiscard]] size_t height() const noexcept { return _height; }
92
93#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
110 void draw_bitmap(int x_start, int y_start, int x_end, int y_end, const void* color_data) {
111 unwrap(try_draw_bitmap(x_start, y_start, x_end, y_end, color_data));
112 }
113
120 void invert_color(bool invert) { unwrap(try_invert_color(invert)); }
121
128 void swap_xy(bool swap) { unwrap(try_swap_xy(swap)); }
129
137 void mirror(bool mirror_x, bool mirror_y) { unwrap(try_mirror(mirror_x, mirror_y)); }
138
145 void display_on(bool on) { unwrap(try_display_on(on)); }
146#endif
147
163 [[nodiscard]] result<void> try_draw_bitmap(int x_start, int y_start, int x_end, int y_end, const void* color_data) {
164 return do_draw_bitmap(x_start, y_start, x_end, y_end, color_data);
165 }
166
172 [[nodiscard]] result<void> try_invert_color(bool invert) { return do_invert_color(invert); }
173
179 [[nodiscard]] result<void> try_swap_xy(bool swap) { return do_swap_xy(swap); }
180
187 [[nodiscard]] result<void> try_mirror(bool mirror_x, bool mirror_y) { return do_mirror(mirror_x, mirror_y); }
188
194 [[nodiscard]] result<void> try_display_on(bool on) { return do_display_on(on); }
195
196protected:
197 panel() = default;
199 panel(size_t width, size_t height) noexcept
200 : _width(width)
201 , _height(height) {}
202 panel(panel&&) noexcept = default;
203 panel& operator=(panel&&) noexcept = default;
204
205 // =========================================================================
206 // Customization hooks
207 //
208 // Concrete drivers override these (typically privately). Each hook
209 // implements the correspondingly named public method.
210 // =========================================================================
211
213 [[nodiscard]] virtual esp_lcd_panel_handle_t do_idf_handle() const = 0;
216 [[nodiscard]] virtual result<void>
217 do_draw_bitmap(int x_start, int y_start, int x_end, int y_end, const void* color_data);
220 [[nodiscard]] virtual result<void> do_invert_color(bool invert);
223 [[nodiscard]] virtual result<void> do_swap_xy(bool swap);
226 [[nodiscard]] virtual result<void> do_mirror(bool mirror_x, bool mirror_y);
229 [[nodiscard]] virtual result<void> do_display_on(bool on);
230
231private:
232 size_t _width = 0;
233 size_t _height = 0;
234};
235
// end of idfxx_lcd
237
238} // 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 width() const noexcept
Returns the panel's native width in pixels.
Definition panel.hpp:81
result< void > try_display_on(bool on)
Turns the display on or off.
Definition panel.hpp:194
void swap_xy(bool swap)
Swaps the X and Y axes.
Definition panel.hpp:128
virtual result< void > do_display_on(bool on)
Hook for try_display_on.
panel(size_t width, size_t height) noexcept
Constructs a panel reporting the given native dimensions.
Definition panel.hpp:199
void display_on(bool on)
Turns the display on or off.
Definition panel.hpp:145
panel & operator=(const panel &)=delete
void invert_color(bool invert)
Inverts the color of the display.
Definition panel.hpp:120
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.
void mirror(bool mirror_x, bool mirror_y)
Mirrors the display.
Definition panel.hpp:137
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.
Definition panel.hpp:110
size_t height() const noexcept
Returns the panel's native height in pixels.
Definition panel.hpp:91
result< void > try_mirror(bool mirror_x, bool mirror_y)
Mirrors the display.
Definition panel.hpp:187
panel(const panel &)=delete
virtual esp_lcd_panel_handle_t do_idf_handle() const =0
Hook for idf_handle.
virtual result< void > do_invert_color(bool invert)
Hook for try_invert_color.
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.
Definition panel.hpp:163
result< void > try_swap_xy(bool swap)
Swaps the X and Y axes.
Definition panel.hpp:179
virtual result< void > do_mirror(bool mirror_x, bool mirror_y)
Hook for try_mirror.
panel(panel &&) noexcept=default
esp_lcd_panel_handle_t idf_handle() const
Returns the underlying ESP-IDF handle.
Definition panel.hpp:71
virtual ~panel()=default
result< void > try_invert_color(bool invert)
Inverts the color of the display.
Definition panel.hpp:172
virtual result< void > do_swap_xy(bool swap)
Hook for try_swap_xy.
struct esp_lcd_panel_t * esp_lcd_panel_handle_t
Definition panel.hpp:30
LCD driver classes.
Definition color.hpp:21
rgb_element_order
RGB element order for LCD panels.
Definition color.hpp:27
@ rgb
RGB element order.
rgb_data_endian
RGB data endian for LCD panels.
Definition color.hpp:36
@ big
RGB data endian: MSB first.
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 LCD panels.
Definition panel.hpp:53
gpio reset_gpio
GPIO number for hardware reset, or idfxx::gpio::nc() if not used.
Definition panel.hpp:54
uint32_t bits_per_pixel
Color depth, in bpp.
Definition panel.hpp:57
void * vendor_config
vendor specific configuration, optional, left as NULL if not used
Definition panel.hpp:59
rgb_data_endian data_endian
Set the data endian for color data larger than 1 byte.
Definition panel.hpp:56
gpio::level reset_active_level
Active level for the panel reset signal.
Definition panel.hpp:58