forked from SerumColor/ColorizingDMD
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathZeDMD.h
More file actions
469 lines (413 loc) · 13.5 KB
/
ZeDMD.h
File metadata and controls
469 lines (413 loc) · 13.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
/** @file ZeDMD.h
* @brief ZeDMD client library.
*
* Connecting ZeDMD devices.
*/
#pragma once
#define ZEDMD_VERSION_MAJOR 0 // X Digits
#define ZEDMD_VERSION_MINOR 9 // Max 2 Digits
#define ZEDMD_VERSION_PATCH 1 // Max 2 Digits
#define _ZEDMD_STR(x) #x
#define ZEDMD_STR(x) _ZEDMD_STR(x)
#define ZEDMD_VERSION \
ZEDMD_STR(ZEDMD_VERSION_MAJOR) \
"." ZEDMD_STR(ZEDMD_VERSION_MINOR) "." ZEDMD_STR(ZEDMD_VERSION_PATCH)
#define ZEDMD_MINOR_VERSION ZEDMD_STR(ZEDMD_VERSION_MAJOR) "." ZEDMD_STR(ZEDMD_VERSION_MINOR)
#define ZEDMD_MAX_WIDTH 256
#define ZEDMD_MAX_HEIGHT 64
#ifdef _MSC_VER
#define ZEDMDAPI __declspec(dllexport)
#define ZEDMDCALLBACK __stdcall
#else
#define ZEDMDAPI __attribute__((visibility("default")))
#define ZEDMDCALLBACK
#endif
#include <inttypes.h>
#include <stdarg.h>
#include <cstdio>
typedef void(ZEDMDCALLBACK* ZeDMD_LogCallback)(const char* format, va_list args, const void* userData);
class ZeDMDComm;
class ZeDMDWiFi;
class ZEDMDAPI ZeDMD
{
public:
ZeDMD();
~ZeDMD();
/** @brief Set the log callback
*
* Set the log callback.
*
* @param callback
* @param userData
*/
void SetLogCallback(ZeDMD_LogCallback callback, const void* userData);
/** @brief Ignore a serial device when searching for ZeDMD
*
* While searching for a ZeDMD any serial ports are tested.
* This could cause trouble with other devices attached via
* USB or serial ports.
* Using this mfunction, a serial device could be excluded
* from the scan.
* This function could be called multiple times to ignore
* multiple devices.
* Another option to limit the searching is to use SetDevice().
* @see SetDevice()
* @see Open()
*
* @param ignore_device the device to ignore
*/
void IgnoreDevice(const char* const ignore_device);
/** @brief Use a specific serial device for ZeDMD
*
* Instead of serching through all serial devices for a ZeDMD,
* just use this device.
* @see Open()
*
* @param device the device
*/
void SetDevice(const char* const device);
/** @brief Open the connection to ZeDMD
*
* Open a cennection to ZeDMD. Therefore all serial ports will be
* scanned. Use IgnoreDevice() to exclude one or more specific
* serial devices during that scan. Use SetDevice() to omit the
* the scan and to use a specific seriel device instead.
* @see IgnoreDevice()
* @see SetDevice()
*/
bool Open();
/** @brief Open the connection to ZeDMD
*
* Backward compatibiility version of Open() which additionally
* sets the frame size. Use Open() and SetFrameSize() instead.
* @see Open()
* @see SetFrameSize()
*
* @deprecated
*
* @param width the frame width
* @param height the frame height
*/
bool Open(uint16_t width, uint16_t height);
/** @brief Open a WiFi connection to ZeDMD
*
* ZeDMD could be connected via WiFi instead of USB.
* The WiFi settings need to be stored in ZeDMD's EEPROM
* first using a USB connection or via the web interface.
* @see Open()
* @see SetWiFiSSID()
* @see SetWiFiPassword()
* @see SetWiFiPort()
* @see SaveSettings()
*
* @param ip the IPv4 address of the ZeDMD device
*/
bool OpenWiFi(const char* ip);
/** @brief Open default WiFi connection to ZeDMD.
*
* ZeDMD could be connected via WiFi instead of USB.
* The WiFi settings need to be stored in ZeDMD's EEPROM.
* Connect to http://zedmd-wifi.local to configure the device.
* For the first time configuration, establish a connection to
* this network:
* SSID: ZeDMD-WiFi
* Password: zedmd1234
*/
bool OpenDefaultWiFi();
/** @brief Close connection to ZeDMD
*
* Close connection to ZeDMD.
*/
void Close();
/** @brief Reset ZeDMD
*
* Reset ZeDMD.
*/
void Reset();
/** @brief Set the frame size
*
* Set the frame size of the content that will be displayed
* next on the ZeDMD device. Depending on the settings and
* the physical dimensions of the LED panels, the content
* will by centered and scaled correctly.
* @see EnableUpscaling()
* @see DisableUpscaling()
*
* @param width the frame width
* @param height the frame height
*/
void SetFrameSize(uint16_t width, uint16_t height);
/** @brief Get the physical panel width
*
* Get the width of the physical dimensions of the LED panels.
*
* @return width
*/
uint16_t const GetWidth();
/** @brief Get the physical panel height
*
* Get the height of the physical dimensions of the LED panels.
*
* @return height
*/
uint16_t const GetHeight();
/** @brief Does ZeDMD run on an ESP32 S3?
*
* On an ESP32 S3 a native USB connection is used to increase
* the bandwidth. Furthermore double buffering is active.
*
* @return true if an ESP32 S3 is used.
*/
bool const IsS3();
/** @brief Get the libezedmd version
*
* Get the version of the library.
*
* @return version string
*/
const char* GetVersion();
/** @brief Get the ZeDMD firmware version
*
* Get the version of the ZeDMD firmware.
*
* @return version string
*/
const char* GetFirmwareVersion();
/** @brief Test the panels attached to ZeDMD
*
* Renders a sequence of full red, full green and full blue frames.
*/
void LedTest();
/** @brief Enable debug mode
*
* ZeDMD will display various debug information as overlay to
* the displayed frame.
* @see https://github.com/PPUC/ZeDMD
*/
void EnableDebug();
/** @brief Disable debug mode
*
* @see EnableDebug()
*/
void DisableDebug();
/** @brief Set the RGB order
*
* ZeDMD supports different LED panels.
* Depending on the panel, the RGB order needs to be adjusted.
* @see https://github.com/PPUC/ZeDMD
*
* @param rgbOrder a value between 0 and 5
*/
void SetRGBOrder(uint8_t rgbOrder);
/** @brief Set the brightness
*
* Set the brightness of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param brightness a value between 0 and 15
*/
void SetBrightness(uint8_t brightness);
/** @brief Set the WiFi SSID
*
* Set the WiFi SSID ZeDMD should connect with.
* @see https://github.com/PPUC/ZeDMD
*
* @param brightness a value between 0 and 15
*/
void SetWiFiSSID(const char* const ssid);
/** @brief Set the WiFi Password
*
* Set the WiFi Password ZeDMD should use to connect.
* @see https://github.com/PPUC/ZeDMD
*
* @param password the password
*/
void SetWiFiPassword(const char* const password);
/** @brief Set the WiFi Port
*
* Set the Port ZeDMD should listen at over WiFi.
* @see https://github.com/PPUC/ZeDMD
*
* @param port the port
*/
void SetWiFiPort(int port);
/** @brief Set the panel clock phase
*
* Set the clock phase of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param clockPhase a value between 0 and 1
*/
void SetPanelClockPhase(uint8_t clockPhase);
/** @brief Set the panel i2s speed
*
* Set the i2s speed of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param i2sspeed a value of 8, 16 or 20
*/
void SetPanelI2sSpeed(uint8_t i2sSpeed);
/** @brief Set the panel latch blanking
*
* Set the latch blanking of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param clkphase a value between 0 and 4
*/
void SetPanelLatchBlanking(uint8_t latchBlanking);
/** @brief Set the panel minimla refresh rate
*
* Set the minimal refresh rate of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param minRefreshRate a value between 0 and 1
*/
void SetPanelMinRefreshRate(uint8_t minRefreshRate);
/** @brief Set the panel driver
*
* Set the driver of the LED panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param driver a value between 0 and 6; 0(SHIFTREG), 1(FM6124), 2(FM6126A), 3(ICN2038S), 4(MBI5124), 5(SM5266P),
* 6(DP3246_SM5368)
*/
void SetPanelDriver(uint8_t driver);
/** @brief Set the transport
*
* Set the transport of ZeDMD. Note, this is just to change ZeDMD's settings, not for connecting.
* @see https://github.com/PPUC/ZeDMD
*
* @param transport a value between 0 and 3; 0(USB), 1(UDP), 2(TCP), 3(SPI)
*/
void SetTransport(uint8_t transport);
/** @brief Set the UDP delay
*
* Set the UDP Delay.
* @see https://github.com/PPUC/ZeDMD
*
* @param udpDelay a value between 0 and 9
*/
void SetUdpDelay(uint8_t udpDelay);
/** @brief Set the USB package size
*
* Set the USB package size.
* @see https://github.com/PPUC/ZeDMD
*
* @param usbPackageSize a value between 32 and 1920, but only multiple of 32
*/
void SetUsbPackageSize(uint16_t usbPackageSize);
/** @brief Set the Y-offset of 128x64 panels
*
* Set the Y-offset of 128x64 panels.
* @see https://github.com/PPUC/ZeDMD
*
* @param yOffset a value between 0 and 32
*/
void SetYOffset(uint8_t yOffset);
/** @brief Save the current setting
*
* Saves all current setting within ZeDMD's EEPROM to be used
* as defualt at its next start.
* @see https://github.com/PPUC/ZeDMD
* @see SetRGBOrder()
* @see SetBrightness()
* @see SetWiFiSSID()
* @see SetWiFiPassword()
* @see SetWiFiPort()
*
* @param brightness a value between 0 and 15
*/
void SaveSettings();
/** @brief Enable upscaling on the client side
*
* If enabled, the content will centered and scaled up to
* fit into the physical dimensions of the ZeDMD panels,
* before the content gets send to ZeDMD, if required.
*/
void EnableUpscaling();
/** @brief Disable upscaling on the client side
*
* @see EnableUpscaling()
*/
void DisableUpscaling();
/** @brief Clear the screen
*
* Turn off all pixels of ZeDMD, so a blank black screen will be shown.
*/
void ClearScreen();
/** @brief Render a RGB24 frame
*
* Renders a true color RGB frame. By default the zone streaming mode is
* used. The encoding is RGB888.
* @see DisableRGB24Streaming()
*
* @param frame the RGB frame
*/
void RenderRgb888(uint8_t* frame);
/** @brief Render a RGB565 frame
*
* Renders a true color RGB565 frame. Only zone streaming mode is supported.
*
* @param frame the RGB565 frame
*/
void RenderRgb565(uint16_t* frame);
private:
bool UpdateFrameBuffer888(uint8_t* pFrame);
bool UpdateFrameBuffer565(uint16_t* pFrame);
uint8_t GetScaleMode(uint16_t frameWidth, uint16_t frameHeight, uint8_t* pXOffset, uint8_t* pYOffset);
int Scale888(uint8_t* pScaledFrame, uint8_t* pFrame, uint8_t bytes);
int Scale565(uint8_t* pScaledFrame, uint16_t* pFrame, bool bigEndian);
ZeDMDComm* m_pZeDMDComm;
ZeDMDWiFi* m_pZeDMDWiFi;
uint16_t m_romWidth;
uint16_t m_romHeight;
bool m_usb = false;
bool m_wifi = false;
bool m_hd = false;
bool m_upscaling = false;
uint8_t* m_pFrameBuffer;
uint8_t* m_pScaledFrameBuffer;
uint8_t* m_pRgb565Buffer;
};
#ifdef __cplusplus
extern "C"
{
#endif
extern ZEDMDAPI ZeDMD* ZeDMD_GetInstance();
extern ZEDMDAPI const char* ZeDMD_GetVersion();
extern ZEDMDAPI const char* ZeDMD_GetFirmwareVersion(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_IgnoreDevice(ZeDMD* pZeDMD, const char* const ignore_device);
extern ZEDMDAPI void ZeDMD_SetDevice(ZeDMD* pZeDMD, const char* const device);
extern ZEDMDAPI bool ZeDMD_Open(ZeDMD* pZeDMD);
extern ZEDMDAPI bool ZeDMD_OpenWiFi(ZeDMD* pZeDMD, const char* ip);
extern ZEDMDAPI bool ZeDMD_OpenDefaultWiFi(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_Close(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_SetLogCallback(ZeDMD* pZeDMD, ZeDMD_LogCallback callback, const void* userData);
extern ZEDMDAPI void ZeDMD_SetFrameSize(ZeDMD* pZeDMD, uint16_t width, uint16_t height);
extern ZEDMDAPI void ZeDMD_SetDefaultPalette(ZeDMD* pZeDMD, uint8_t bitDepth);
extern ZEDMDAPI void ZeDMD_LedTest(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_EnableDebug(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_DisableDebug(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_SetRGBOrder(ZeDMD* pZeDMD, uint8_t rgbOrder);
extern ZEDMDAPI void ZeDMD_SetBrightness(ZeDMD* pZeDMD, uint8_t brightness);
extern ZEDMDAPI void ZeDMD_SaveSettings(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_EnableUpscaling(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_DisableUpscaling(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_SetWiFiSSID(ZeDMD* pZeDMD, const char* const ssid);
extern ZEDMDAPI void ZeDMD_SetWiFiPassword(ZeDMD* pZeDMD, const char* const password);
extern ZEDMDAPI void ZeDMD_SetWiFiPort(ZeDMD* pZeDMD, int port);
extern ZEDMDAPI void ZeDMD_SetPanelClockPhase(ZeDMD* pZeDMD, uint8_t clockPhase);
extern ZEDMDAPI void ZeDMD_SetPanelI2sSpeed(ZeDMD* pZeDMD, uint8_t i2sSpeed);
extern ZEDMDAPI void ZeDMD_SetPanelLatchBlanking(ZeDMD* pZeDMD, uint8_t latchBlanking);
extern ZEDMDAPI void ZeDMD_SetPanelMinRefreshRate(ZeDMD* pZeDMD, uint8_t minRefreshRate);
extern ZEDMDAPI void ZeDMD_SetPanelDriver(ZeDMD* pZeDMD, uint8_t driver);
extern ZEDMDAPI void ZeDMD_SetTransport(ZeDMD* pZeDMD, uint8_t transport);
extern ZEDMDAPI void ZeDMD_SetUdpDelay(ZeDMD* pZeDMD, uint8_t udpDelay);
extern ZEDMDAPI void ZeDMD_SetUsbPackageSize(ZeDMD* pZeDMD, uint16_t usbPackageSize);
extern ZEDMDAPI void ZeDMD_SetYOffset(ZeDMD* pZeDMD, uint8_t yOffset);
extern ZEDMDAPI void ZeDMD_ClearScreen(ZeDMD* pZeDMD);
extern ZEDMDAPI void ZeDMD_RenderRgb888(ZeDMD* pZeDMD, uint8_t* frame);
extern ZEDMDAPI void ZeDMD_RenderRgb565(ZeDMD* pZeDMD, uint16_t* frame);
#ifdef __cplusplus
}
#endif