1#ifndef ISF15ACP4_HEADER_INCLUDED
2#error "isf15acp4.ipp must be included from isf15acp4.hpp"
8template <
typename SpiType>
13template <
typename SpiType>
18template <
typename SpiType>
23template <
typename SpiType>
28template <
typename SpiType>
35template <
typename SpiType>
37 : bus_(bus), config_(config), variant_(config.variant), geometry_(
GetGeometry(config.variant)) {
38 window_ = {0, 0,
static_cast<uint8_t
>(geometry_.width - 1),
static_cast<uint8_t
>(geometry_.height - 1)};
41template <
typename SpiType>
45template <
typename SpiType>
48 error_flags_ |=
static_cast<uint16_t
>(e);
51template <
typename SpiType>
61template <
typename SpiType>
63 if (!bus_->BeginCommand()) {
68 if (!bus_->WriteBytes(&cmd, 1)) {
69 bus_->EndTransaction();
74 if (len > 0 && data !=
nullptr) {
75 if (!bus_->WriteBytes(data, len)) {
76 bus_->EndTransaction();
82 bus_->EndTransaction();
86template <
typename SpiType>
88 return sendCommand(cmd, &data, 1);
91template <
typename SpiType>
93 return sendCommand(cmd,
nullptr, 0);
96template <
typename SpiType>
98 std::size_t count = 0;
101 for (std::size_t i = 0; i < count; ++i) {
102 if (!sendCommand(table[i].command, table[i].data, table[i].data_len)) {
109template <
typename SpiType>
111 if (bus_ ==
nullptr) {
116 if (!bus_->EnsureInitialized()) {
132 if (!runInitTable()) {
136 if (!SetFullWindow()) {
144template <
typename SpiType>
146 initialized_ =
false;
147 return Initialize(enable_vcc);
150template <
typename SpiType>
155template <
typename SpiType>
160template <
typename SpiType>
162 return sendCommandOnly(0xAC);
165template <
typename SpiType>
174template <
typename SpiType>
176 if (rect.x1 < rect.x0 || rect.y1 < rect.y0 || rect.x1 >= geometry_.width ||
177 rect.y1 >= geometry_.height) {
184 const Rect ram = toRam(rect);
185 const uint8_t col_data[2] = {ram.
x0, ram.
x1};
186 const uint8_t row_data[2] = {ram.
y0, ram.
y1};
199template <
typename SpiType>
201 return SetWindow({0, 0,
static_cast<uint8_t
>(geometry_.width - 1),
static_cast<uint8_t
>(geometry_.height - 1)});
204template <
typename SpiType>
206 return {
static_cast<uint8_t
>(rect.x0 + geometry_.column_start),
static_cast<uint8_t
>(rect.y0 + geometry_.row_start),
207 static_cast<uint8_t
>(rect.x1 + geometry_.column_start),
static_cast<uint8_t
>(rect.y1 + geometry_.row_start)};
210template <
typename SpiType>
216 if (data ==
nullptr || byte_len == 0 || (byte_len % 2) != 0) {
221 if (!bus_->BeginData()) {
226 if (!bus_->WriteBytes(data, byte_len)) {
227 bus_->EndTransaction();
232 bus_->EndTransaction();
236template <
typename SpiType>
242 if (colors ==
nullptr || count == 0) {
247 if (!bus_->BeginData()) {
256 constexpr std::size_t kChunkPixels = 64;
257 uint8_t chunk[kChunkPixels * 2];
258 std::size_t done = 0;
259 while (done < count) {
260 const std::size_t n = (count - done) < kChunkPixels ? (count - done) : kChunkPixels;
261 for (std::size_t i = 0; i < n; ++i) {
263 chunk[2 * i] =
static_cast<uint8_t
>(c >> 8);
264 chunk[2 * i + 1] =
static_cast<uint8_t
>(c & 0xFF);
266 if (!bus_->WriteBytes(chunk, n * 2)) {
267 bus_->EndTransaction();
274 bus_->EndTransaction();
278template <
typename SpiType>
280 if (canvas.Width() != geometry_.width || canvas.Height() != geometry_.height) {
284 if (!SetFullWindow()) {
287 return WriteColors(canvas.Data(), canvas.ByteSize() /
sizeof(
Color565));
290template <
typename SpiType>
295template <
typename SpiType>
299 ConfigurePresenter(gfx);
304template <
typename SpiType>
313 gfx.BindPresenter(presenter);
316template <
typename SpiType>
321 return DrawCanvas(gfx.CanvasBuffer());
324template <
typename SpiType>
326 if (!SetWindow({x, y, x, y})) {
329 return WriteColors(&color, 1);
332template <
typename SpiType>
336 return DrawCanvas(canvas);
339template <
typename SpiType>
342 out[0] =
static_cast<uint8_t
>((color >> 11) & 0x1F);
343 out[1] =
static_cast<uint8_t
>((color >> 5) & 0x3F);
344 out[2] =
static_cast<uint8_t
>(color & 0x1F);
347template <
typename SpiType>
350 colorToSsd1331(color, rgb);
351 const Rect ram = toRam({start.x, start.y, end.x, end.y});
352 const uint8_t data[7] = {ram.
x0, ram.
y0, ram.
x1, ram.
y1,
353 static_cast<uint8_t
>(rgb[2] << 1), rgb[1],
354 static_cast<uint8_t
>(rgb[0] << 1)};
358template <
typename SpiType>
361 const uint8_t fill_cfg[2] = {0x01, 0x00};
368 colorToSsd1331(color, rgb);
369 const Rect ram = toRam(rect);
370 const uint8_t data[10] = {ram.
x0, ram.
y0, ram.
x1, ram.
y1,
371 static_cast<uint8_t
>(rgb[2] << 1), rgb[1],
372 static_cast<uint8_t
>(rgb[0] << 1),
373 static_cast<uint8_t
>(rgb[2] << 1), rgb[1],
374 static_cast<uint8_t
>(rgb[0] << 1)};
379 const uint8_t disable[2] = {0x00, 0x00};
385template <
typename SpiType>
387 const Rect ram = toRam(rect);
388 const uint8_t data[4] = {ram.
x0, ram.
y0, ram.
x1, ram.
y1};
392template <
typename SpiType>
397template <
typename SpiType>
399 uint8_t v_offset, uint8_t interval_code,
400 bool activate)
noexcept {
406 const uint8_t data[5] = {h_offset, start_row, scroll_rows, v_offset,
407 static_cast<uint8_t
>(interval_code & 0x03)};
417template <
typename SpiType>
422template <
typename SpiType>
CPU-side RGB565 framebuffer with basic drawing operations.
Definition isf15acp4_canvas.hpp:22
void Clear(Color565 color) noexcept
Clear the framebuffer to a solid color.
Definition isf15acp4_canvas.ipp:13
Owns the active graphics backend selected at construction time.
Definition isf15acp4_graphics_context.hpp:42
High-level driver for NKK SSD1331-based SmartDisplay modules.
Definition isf15acp4.hpp:31
bool ClearWindow(const Rect &rect) noexcept
Clear a rectangular window via controller command 25H, in display coordinates.
Definition isf15acp4.ipp:386
void setError(Error e) noexcept
Definition isf15acp4.ipp:46
bool sendCommand(uint8_t cmd, const uint8_t *data, uint8_t len) noexcept
Definition isf15acp4.ipp:62
bool StopScroll() noexcept
Stop hardware scrolling (2EH).
Definition isf15acp4.ipp:418
bool DrawLine(const Point &start, const Point &end, Color565 color) noexcept
Draw a hardware-accelerated line (command 21H), in display coordinates.
Definition isf15acp4.ipp:348
bool IsPressed() const noexcept
Read momentary switch state when wired to SpiInterface::CtrlPin::Switch.
Definition isf15acp4.ipp:393
bool runInitTable() noexcept
Definition isf15acp4.ipp:97
void ConfigurePresenter(GraphicsContext &gfx) noexcept
Register presenter hooks for HardwareDirect backend (bind this display to gfx).
Definition isf15acp4.ipp:305
bool DrawRectangle(const Rect &rect, Color565 color, bool filled=false) noexcept
Draw a hardware rectangle outline (command 22H), in display coordinates.
Definition isf15acp4.ipp:359
Rect toRam(const Rect &rect) const noexcept
Definition isf15acp4.ipp:205
bool DisplayOn() noexcept
Turn display on (normal mode, command AFH).
Definition isf15acp4.ipp:151
SmartDisplay(SpiType *bus, const SmartDisplayConfig &config) noexcept
Construct with explicit configuration (variant + graphics backend).
Definition isf15acp4.ipp:36
bool SetWindow(const Rect &rect) noexcept
Configure the active GRAM download window.
Definition isf15acp4.ipp:175
bool DisplayDim() noexcept
Enter dim mode (command ACH).
Definition isf15acp4.ipp:161
bool DisplayOff() noexcept
Turn display off / sleep (command AEH).
Definition isf15acp4.ipp:156
bool SetMasterCurrent(uint8_t level) noexcept
Set master current while display is off (command 87H).
Definition isf15acp4.ipp:166
bool DrawCanvas(const Canvas &canvas) noexcept
Upload an entire canvas framebuffer.
Definition isf15acp4.ipp:279
void pulseReset() noexcept
Definition isf15acp4.ipp:52
bool DrawPixel(uint8_t x, uint8_t y, Color565 color) noexcept
Draw one RGB565 pixel at (x,y).
Definition isf15acp4.ipp:325
bool ConfigureScroll(uint8_t h_offset, uint8_t start_row, uint8_t scroll_rows, uint8_t v_offset, uint8_t interval_code, bool activate) noexcept
Set up hardware scrolling and optionally start it.
Definition isf15acp4.ipp:398
bool FillScreen(Color565 color) noexcept
Fill the panel with a solid color.
Definition isf15acp4.ipp:333
bool sendCommandByte(uint8_t cmd, uint8_t data) noexcept
Definition isf15acp4.ipp:87
bool Reset(bool enable_vcc=true) noexcept
Hardware reset pulse and full re-initialization.
Definition isf15acp4.ipp:145
bool sendCommandOnly(uint8_t cmd) noexcept
Definition isf15acp4.ipp:92
bool WritePixels(const uint8_t *data, std::size_t byte_len) noexcept
Stream raw pixel bytes to the controller GRAM, unchanged.
Definition isf15acp4.ipp:211
bool Initialize(bool enable_vcc=true) noexcept
Perform power-up, reset, and SSD1331 initialization.
Definition isf15acp4.ipp:110
bool Present(const GraphicsContext &gfx) noexcept
Present any graphics backend to the panel.
Definition isf15acp4.ipp:317
static void colorToSsd1331(Color565 color, uint8_t out[3]) noexcept
Definition isf15acp4.ipp:340
bool SetFullWindow() noexcept
Configure full-panel memory window for the active variant.
Definition isf15acp4.ipp:200
GraphicsContext CreateGraphicsContext() noexcept
Create a graphics context matching this display configuration.
Definition isf15acp4.ipp:296
SmartDisplay(SpiType *bus, ProductVariant variant=ProductVariant::Isf15acp4) noexcept
Construct a SmartDisplay driver (defaults to ISF15ACP4 + BuiltinCanvas).
Definition isf15acp4.ipp:42
bool WriteColors(const Color565 *colors, std::size_t count) noexcept
Stream Color565 pixels to the controller GRAM in the SSD1331 65k-colour byte order.
Definition isf15acp4.ipp:237
bool presenterFillScreen(void *ctx, Color565 color) noexcept
Definition isf15acp4.ipp:24
bool presenterFlushCanvas(void *ctx, const Color565 *data, std::size_t bytes) noexcept
Definition isf15acp4.ipp:29
bool presenterDrawPixel(void *ctx, uint8_t x, uint8_t y, Color565 color) noexcept
Definition isf15acp4.ipp:9
bool presenterDrawLine(void *ctx, Point a, Point b, Color565 color) noexcept
Definition isf15acp4.ipp:14
bool presenterDrawRect(void *ctx, Rect r, Color565 color, bool filled) noexcept
Definition isf15acp4.ipp:19
constexpr uint16_t ToPanelPixel(Color565 color) noexcept
Convert an RGB565 colour to the 16-bit pixel word the NKK panels expect in display RAM.
Definition isf15acp4_ssd1331.hpp:151
constexpr uint32_t kResetRecoveryUs
Wait after releasing RES# before the first command.
Definition isf15acp4_ssd1331.hpp:73
const InitStep * GetInitTable(ProductVariant variant, std::size_t &count) noexcept
Resolve initialization table for a product variant.
Definition isf15acp4_ssd1331.hpp:158
constexpr uint32_t kResetPulseMinUs
Minimum RES# low pulse width (SSD1331 rev 1.2 Table 18; NKK power ON sequence).
Definition isf15acp4_ssd1331.hpp:66
Definition isf15acp4.hpp:19
Error
Driver error flags (bitmask).
Definition isf15acp4_types.hpp:28
ProductVariant
Supported NKK SmartDisplay OLED product variants.
Definition isf15acp4_types.hpp:19
uint16_t Color565
16-bit RGB565 color value (R5G6B5).
Definition isf15acp4_types.hpp:50
constexpr const DisplayGeometry & GetGeometry(ProductVariant variant) noexcept
Get geometry metadata for a product variant.
Definition isf15acp4_types.hpp:77
@ ChipSelect
SS / slave select (active-low on device)
@ Reset
RES# reset input: Active = held in reset (pin low), Inactive = running (pin high)
@ VccEnable
Optional charge-pump / 16V rail enable.
@ Switch
Optional momentary switch sense input.
@ DataCommand
D/C: command (inactive) vs data (active)
Type-erased presenter used by HardwareDirect backend.
Definition isf15acp4_graphics_context.hpp:22
void * context
Definition isf15acp4_graphics_context.hpp:28
2D point in display coordinates.
Definition isf15acp4_types.hpp:90
Axis-aligned rectangle in display coordinates (inclusive bounds).
Definition isf15acp4_types.hpp:96
uint8_t y1
Definition isf15acp4_types.hpp:100
uint8_t x0
Definition isf15acp4_types.hpp:97
uint8_t x1
Definition isf15acp4_types.hpp:99
uint8_t y0
Definition isf15acp4_types.hpp:98
Configuration for SmartDisplay construction.
Definition isf15acp4_button_ui.hpp:17
ProductVariant variant
Definition isf15acp4_button_ui.hpp:18
One initialization command with optional trailing data bytes.
Definition isf15acp4_ssd1331.hpp:59