idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
ssd1680.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/epaper/panel>
14#include <idfxx/error>
15#include <idfxx/gpio>
16#include <idfxx/memory>
17#include <idfxx/panel_io>
18
19#include <chrono>
20#include <cstddef>
21#include <cstdint>
22#include <frequency/frequency>
23#include <initializer_list>
24#include <span>
25#include <vector>
26
31namespace idfxx::epaper {
32
65class ssd1680 final : public panel {
66public:
71 struct config {
74 size_t width = 122;
76 size_t height = 250;
86 std::chrono::milliseconds busy_timeout{15'000};
91 bool mirror_x = false;
94 bool mirror_y = false;
95 };
96
116 [[nodiscard]] static panel_io::spi_config
117 spi_io_config(gpio cs, gpio dc, freq::hertz pclk = freq::hertz{10'000'000}) noexcept;
118
119#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
138 [[nodiscard]] explicit ssd1680(idfxx::panel_io& panel_io, config config);
139#endif
140
162
163 ~ssd1680() override;
164
165 ssd1680(const ssd1680&) = delete;
166 ssd1680& operator=(const ssd1680&) = delete;
167 ssd1680(ssd1680&& other) noexcept;
168 ssd1680& operator=(ssd1680&& other) noexcept;
169
170private:
171 // A rectangular pixel region of the panel, for RAM window programming.
172 struct region {
173 size_t x;
174 size_t y;
175 size_t width;
176 size_t height;
177 };
178
179 explicit ssd1680(idfxx::panel_io& panel_io, config config, std::vector<uint8_t, dram_allocator<uint8_t>> shadow)
180 : panel(
181 config.width,
182 config.height,
183 config.busy_gpio,
184 gpio::level::high,
185 config.busy_timeout,
186 config.reset_gpio
187 )
188 , _io(&panel_io)
189 , _mirror_x(config.mirror_x)
190 , _mirror_y(config.mirror_y)
191 , _shadow(std::move(shadow)) {}
192
193 // epaper::panel customization hooks.
194 [[nodiscard]] result<void>
195 do_write(const mono_framebuffer& fb, size_t row_start, size_t row_end, size_t x, size_t y) override;
196 [[nodiscard]] result<void>
197 do_write(const gray4_framebuffer& fb, size_t row_start, size_t row_end, size_t x, size_t y) override;
198 [[nodiscard]] result<void> do_clear() override;
199 [[nodiscard]] result<void> do_refresh(refresh_mode mode) override;
200 [[nodiscard]] result<void> do_set_color_mode(enum color_mode mode) override;
201 [[nodiscard]] result<void> do_sleep() override;
202 [[nodiscard]] result<void> do_wake() override;
203
204 // Command sequencing helpers (see src/ssd1680.cpp).
205 [[nodiscard]] result<void> _cmd(uint8_t cmd);
206 [[nodiscard]] result<void> _cmd(uint8_t cmd, std::initializer_list<uint8_t> params);
207 [[nodiscard]] result<void> _cmd(uint8_t cmd, std::span<const uint8_t> params);
208 [[nodiscard]] result<void> _stream(uint8_t cmd, std::span<const uint8_t> data);
209 [[nodiscard]] result<void> _drain();
210 [[nodiscard]] result<void> _init();
211 [[nodiscard]] result<void> _init_gray();
212 [[nodiscard]] result<void> _init_scan();
213 [[nodiscard]] result<void> _set_ram_window(region r);
214 [[nodiscard]] result<void>
215 _write_planes(region window, std::span<const uint8_t> new_plane, std::span<const uint8_t> old_plane);
216 [[nodiscard]] result<void> _sync_old_plane();
217 [[nodiscard]] size_t _stride() const noexcept { return (width() + 7) / 8; }
218
219 idfxx::panel_io* _io = nullptr; // nullptr after move
220 bool _mirror_x = false;
221 bool _mirror_y = false;
222 // Shadow of the last-written new-plane RAM bytes; re-sent to the
223 // controller's old-image plane after each refresh so partial updates
224 // diff against the frame actually on the glass.
225 std::vector<uint8_t, dram_allocator<uint8_t>> _shadow;
226};
227
228} // namespace idfxx::epaper
Abstract base class for ePaper display panels.
Definition panel.hpp:116
std::chrono::milliseconds busy_timeout() const noexcept
Returns the default BUSY timeout.
Definition panel.hpp:687
size_t height() const noexcept
Returns the panel height in pixels.
Definition panel.hpp:131
gpio reset_gpio() const noexcept
Returns the reset output pin (may be unconnected).
Definition panel.hpp:684
gpio busy_gpio() const noexcept
Returns the BUSY input pin (may be unconnected).
Definition panel.hpp:681
enum color_mode color_mode() const noexcept
Returns the panel's current pixel format.
Definition panel.hpp:141
size_t width() const noexcept
Returns the panel width in pixels.
Definition panel.hpp:128
SSD1680 ePaper display controller driver.
Definition ssd1680.hpp:65
static result< ssd1680 > make(idfxx::panel_io &panel_io, config config)
Creates a new SSD1680 panel driver.
ssd1680(ssd1680 &&other) noexcept
ssd1680(const ssd1680 &)=delete
ssd1680(idfxx::panel_io &panel_io, config config)
Creates a new SSD1680 panel driver.
static panel_io::spi_config spi_io_config(gpio cs, gpio dc, freq::hertz pclk=freq::hertz{10 '000 '000}) noexcept
Returns a panel I/O configuration for communicating with an SSD1680 over SPI.
ssd1680 & operator=(ssd1680 &&other) noexcept
ssd1680 & operator=(const ssd1680 &)=delete
A GPIO pin.
Definition gpio.hpp:62
static constexpr gpio nc()
Returns a GPIO representing "not connected".
Definition gpio.hpp:255
Panel I/O interface for SPI- and I2C-connected displays.
Definition panel_io.hpp:42
ePaper display driver classes.
Definition color.hpp:19
refresh_mode
Refresh style for panel::refresh.
Definition panel.hpp:58
std::expected< T, std::error_code > result
result type wrapping a value or error code.
Definition error.hpp:120
STL-compatible allocator for capability-based memory regions.
Definition memory.hpp:368
Configuration structure for SSD1680 panels.
Definition ssd1680.hpp:71
size_t height
Panel height in pixels (gates). The controller drives up to 296.
Definition ssd1680.hpp:76
bool mirror_x
Mirror the image horizontally (reverses the source scan via the controller's address decrement mode)....
Definition ssd1680.hpp:91
bool mirror_y
Mirror the image vertically (reverses the gate scan via the controller's address decrement mode).
Definition ssd1680.hpp:94
gpio reset_gpio
GPIO wired to the panel's reset line, or gpio::nc() if not wired.
Definition ssd1680.hpp:80
std::chrono::milliseconds busy_timeout
Maximum time to wait for the BUSY line to release.
Definition ssd1680.hpp:86
gpio busy_gpio
GPIO wired to the panel's BUSY output (required).
Definition ssd1680.hpp:83
size_t width
Panel width in pixels (sources).
Definition ssd1680.hpp:74
SPI-based panel I/O configuration.
Definition panel_io.hpp:58