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