arduino-audio-tools
Loading...
Searching...
No Matches
OutputTinyGPU.h
Go to the documentation of this file.
1#pragma once
2#include <TinyGPU.h> // https://github.com/pschatzmann/TinyGPU
3#include <TinyGPU/DisplayDriverSPI.h> // ILI9341Driver
4#include <TinyGPU/SurfaceWithExternalBuffer.h> // zero-copy write() path
5
7
8namespace audio_tools {
9
26class OutputTinyGPU : public VideoOutput {
27 public:
32 OutputTinyGPU(ILI9341Driver<RGB565>& driver, int width, int height,
33 int pinBacklight, int bandHeight = 40)
34 : tftDriver(driver),
35 width(width),
37 kPinBacklight(pinBacklight),
38 kBandHeight(bandHeight) {}
39
40 bool begin() {
41 if (kPinBacklight >= 0) {
44 }
45 tftDriver.begin();
47
48 return true;
49 }
50
52 void setVideoInfoSource(VideoInfoSource& source) { p_info = &source; }
53
55 void setVideoInfo(VideoInfo info) { info_ = info; }
56
57 size_t write(const uint8_t* data, size_t len) override {
58 if (p_info != nullptr) {
60 }
61
62 if (info_.width == 0 || info_.height == 0) {
63 LOGE("OutputTinyGPU: invalid video size: %d x %d", (int)info_.width,
64 (int)info_.height);
65 return 0;
66 }
67
68 size_t needed = (size_t)info_.width * info_.height * sizeof(RGB565);
69 if (len < needed) {
70 LOGE("OutputTinyGPU: frame too small: %d < %d bytes", (int)len,
71 (int)needed);
72 return 0;
73 }
74
75 // View directly over the caller's buffer - no allocation, no copy.
76 SurfaceWithExternalBuffer<RGB565> frame;
77 frame.setExternalBuffer(const_cast<uint8_t*>(data), len);
78 frame.resize(info_.width, info_.height);
79 tftDriver.writeData(frame, 0, 0);
80
81 return len;
82 }
83
84 void clearScreen() {
85 SurfaceRGB565 band(width, kBandHeight, FontRGB565);
86 band.begin();
87 band.clear(RGB565(0, 0, 0));
88 for (int y = 0; y < height; y += kBandHeight) {
89 tftDriver.writeData(band, 0, y);
90 }
91 band.end();
92 }
93
94 protected:
95 int width = 320;
96 int height = 240;
101 ILI9341Driver<RGB565>& tftDriver;
102};
103
104} // namespace audio_tools
#define HIGH
Definition Arduino.h:46
#define OUTPUT
Definition Arduino.h:38
#define LOGE(...)
Definition AudioLoggerIDF.h:30
Bridges VideoDecoder's write() calls to a TinyGPU ILI9341Driver - VideoDecoder always hands over one ...
Definition OutputTinyGPU.h:26
int width
Definition OutputTinyGPU.h:95
VideoInfoSource * p_info
Definition OutputTinyGPU.h:99
int kBandHeight
Definition OutputTinyGPU.h:98
VideoInfo info_
Definition OutputTinyGPU.h:100
int kPinBacklight
Definition OutputTinyGPU.h:97
bool begin()
Definition OutputTinyGPU.h:40
ILI9341Driver< RGB565 > & tftDriver
Definition OutputTinyGPU.h:101
size_t write(const uint8_t *data, size_t len) override
Definition OutputTinyGPU.h:57
void clearScreen()
Definition OutputTinyGPU.h:84
OutputTinyGPU(ILI9341Driver< RGB565 > &driver, int width, int height, int pinBacklight, int bandHeight=40)
Definition OutputTinyGPU.h:32
void setVideoInfoSource(VideoInfoSource &source)
Defines the source of the video information (width, height, fps, format)
Definition OutputTinyGPU.h:52
void setVideoInfo(VideoInfo info)
Defines the video format and dimensions - call before begin() if you.
Definition OutputTinyGPU.h:55
int height
Definition OutputTinyGPU.h:96
Definition Video.h:176
virtual VideoInfo videoInfo()=0
Abstract class for video playback. This class is used to assemble a complete video frame in memory....
Definition Video.h:192
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
void digitalWrite(digital_pin_t pin, bool value)
Definition Arduino.h:317
void pinMode(digital_pin_t pin, int mode)
Definition Arduino.h:286
Basic video information (width/height/codec/frame size), analogous to AudioInfo - common to both Demu...
Definition Video.h:102
uint16_t height
Frame height in pixels.
Definition Video.h:106
uint16_t width
Frame width in pixels.
Definition Video.h:104