TinyGPU
Loading...
Searching...
No Matches
DeviceOutput.h
Go to the documentation of this file.
1
2#pragma once
3
4#include <stdint.h>
5
6#include "TinyGPU/Surface/ISurface.h"
7#include "TinyGPU/Drivers/DisplayDriver.h"
8
9namespace tinygpu {
10
11/**
12 * @brief Hardware abstraction for writing framebuffers to SPI-based color
13 * displays.
14 *
15 * DeviceOutput provides a unified interface for sending RGB565 framebuffer data
16 * to common embedded display controllers (ST7735, ST7789, ILI9341, HX8357)
17 * using the Arduino SPI API.
18 *
19 * Features:
20 * - Handles X/Y offsets for displays that require them (via driver)
21 * - Supports configurable color order (RGB/BGR) via RGB565
22 * - Initialization sequence and address window logic delegated to driver
23 * - Optional hardware reset pin (via driver)
24 * - Efficient bulk framebuffer transfer
25 *
26 * Usage:
27 * DeviceOutput out(new ILI9341Driver(spi, cs, dc, rst), 240, 320);
28 * out.writeData(framebuffer);
29 *
30 * @note For color order, set RGB565::setColorOrderBGR(true/false) as needed for
31 * your display, before creating any data.
32 */
33template <typename RGB_T = RGB565>
35 public:
36 /**
37 * @brief Construct a DeviceOutput with a display driver.
38 * @param driver Pointer to a display driver (ownership not taken)
39 * @param width Display width in pixels
40 * @param height Display height in pixels
41 */
43 : driver_(&driver) {}
44
45 /// Initializes the display and prepares it for receiving data.
46 bool begin() {
47 if (driver_) {
48 return driver_->begin();
49 }
50 return false;
51 }
52
53 void end() {
54 if (driver_) {
55 driver_->end();
56 }
57 }
58
59 /// Write a framebuffer to the display (w x h, RGB565, 2 bytes per pixel).
60 bool writeData(ISurface<RGB_T>& surface) {
61 if (driver_) {
62 // write as is
63 driver_->writeData(surface);
64 return true;
65 }
66 return false;
67 }
68
69 private:
70 DisplayDriver<RGB_T>* driver_ = nullptr;
71 bool is_active = false;
72};
73
74} // namespace tinygpu
Hardware abstraction for writing framebuffers to SPI-based color displays.
Definition: DeviceOutput.h:34
bool begin()
Initializes the display and prepares it for receiving data.
Definition: DeviceOutput.h:46
bool writeData(ISurface< RGB_T > &surface)
Write a framebuffer to the display (w x h, RGB565, 2 bytes per pixel).
Definition: DeviceOutput.h:60
void end()
Definition: DeviceOutput.h:53
DeviceOutput(DisplayDriver< RGB_T > &driver)
Construct a DeviceOutput with a display driver.
Definition: DeviceOutput.h:42
Definition: DisplayDriver.h:49
RGB color stored in 16-bit RGB565 format, byte-swapped from the conventional bit layout.
Definition: RGB565.h:24
Definition: DSIBusESP32.h:19