-
Notifications
You must be signed in to change notification settings - Fork 1
/
neomatrix_config.h
1476 lines (1315 loc) · 63.7 KB
/
neomatrix_config.h
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
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#ifndef neomatrix_config_h
#define neomatrix_config_h
/* There are 2 major backends
1) SmartMatrix (via SmartMatrix::GFX)
2) Not SmartMatrix (via FastLED::NeoMatrix or FastLED_SPITFT::GFX)
All backends end up using the same Framebuffer::GFX as the base class
but SmartMatrix is sufficiently different to need its own exceptions and handling
(for one, with SmartMatrix, the buffer is actually handled by SmartMatrix whereas
the other libraries define their own FastLED CRGB buffer (RGB888) ).
Backends you should choose from (define 1):
- SMARTMATRIX (if you are using the old SMARTMATRIX3, also define SMARTMATRIXV3)
- ILI9341
- ST7735_128b160
- ST7735_128b128
- SSD1331 (96x64 TFT)
- Everything below is NeoMatrix in different patterns:
M24BY24 M32BY8X3 M16BY16T4 M64BY64 are 4 examples of NEOMATRIX defines
(3 tiled 32x8, 4 tiled 16x16, and a single zigzag 64x64 array)
- ARDUINOONPC is auto defined by https://github.com/marcmerlin/ArduinoOnPc-FastLED-GFX-LEDMatrix
- On ARM, we assume rPi and define RPIRGBPANEL
- Elsewhere, we assume rendering on linux/X11
- LINUX_RENDERER_X11 is the default with ArduinoOnPc-FastLED-GFX-LEDMatrix
- LINUX_RENDERER_SDL can be defined in ArduinoOnPc-FastLED-GFX-LEDMatrix's Makefile
LEDMATRIX is a separate define you'd set before including this file and
adds the LEDMatrix API if you need it.
The TL;DR is you shouldn't bother with it if you already have the GFX
and FastLED APIs, unless you can use fancy wavy scrolling colored fonts or the
sprite support in LEDMatrix.
You should not need to modify this file at all unless you are adding new matrix
definitions and/or changing pin mappings for TFT screens. To choose which backend
to use, set the define before you include the file.
*/
// vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
// README README README README README README README README README README README README README README
// If you have never used FastLED::NeoMatrix before, please try these 2 examples first
// https://github.com/marcmerlin/FastLED_NeoMatrix/tree/master/examples/matrixtest
// https://github.com/marcmerlin/FastLED_NeoMatrix/tree/master/examples/MatrixGFXDemo
// Then just uncomment this line below (define M24BY24) and fix the matrix definition
// or use one of the other ones if they are closer ot your setup (M32BY8X3 M16BY16T4 M64BY64)
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//#define M24BY24
// For TFTs, there is original support from adafruit, but https://github.com/moononournation/Arduino_GFX/
// has better and faster support for many TFTs.
// define ADAFRUIT_TFT if you'd rather have the Adafruit drivers
#if !defined(M24BY24) && !defined(M32BY8X3) && !defined(M16BY16T4) && !defined(M64BY64) && !defined(SMARTMATRIX) && !defined(SSD1331) && !defined(ST7735_128b128) && !defined(ST7735_128b160) && !defined(ILI9341) && !defined(ARDUINOONPC)
#ifdef ESP8266
//#define SSD1331
//#define SSD1331_ROTATE 1
// ESP8266 shirt with neopixel strips
#define M32BY8X3
//#define M16BY16T4
#endif
#ifdef ESP32
//#define ILI9341
//#define ST7735_128b160
//#define ST7735_128b128
//#define SSD1331
//#define SSD1331_ROTATE 1
#define SMARTMATRIX
//#define M64BY64
#endif
// Teensy 3.6
#ifdef __MK66FX1M0__
#define ILI9341
// If instead you are using the old SmartMatrix V3, define those 2
//#define SMARTMATRIX3
// And with SmartMatrix (v4), only this define is needed.
//#define SMARTMATRIX
#endif
// Teensy v.4
#ifdef __IMXRT1062__
//#define SMARTMATRIX3
#define SMARTMATRIX
#endif
#endif
#if defined(ARDUINOONPC)
// Those defines (including RPIRGBPANEL) come from makeNativeArduino.mk
#if defined(RPI4)
#pragma message "Detected ARDUINOONPC on rPi4, RPIRGBPANEL defined and will use FastLED_RPIRGBPanel_GFX"
#elif defined(RPI3)
#pragma message "Detected ARDUINOONPC on rPi3, RPIRGBPANEL defined and will use FastLED_RPIRGBPanel_GFX"
#elif defined(RPILT3)
#pragma message "Detected ARDUINOONPC on pre-rPi3, RPIRGBPANEL defined and will use FastLED_RPIRGBPanel_GFX"
#else
#ifndef LINUX_RENDERER_SDL
#pragma message "Detected ARDUINOONPC. Using LINUX_RENDERER_X11 FastLED_TFTWrapper_GFX Rendering"
#define LINUX_RENDERER_X11
#else
#pragma message "Detected ARDUINOONPC. Using LINUX_RENDERER_SDL FastLED_NeoMatrix Rendering."
#pragma message "Comment out LINUX_RENDERER_SDL for X11 rendering instead of SDL. Use + for brighter."
#endif
#endif
#endif
#include <Adafruit_GFX.h>
bool init_done = 0;
uint32_t tft_spi_speed;
#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
// min/max are complicated. Arduino and ESP32 layers try to be helpful by using
// templates that take specific kinds of arguments, but those do not always work
// with mixed types:
// error: no matching function for call to 'max(byte&, int16_t&)'
// These defines get around this problem.
#define mmin(a,b) ((a<b)?(a):(b))
#define mmax(a,b) ((a>b)?(a):(b))
// The ESP32 FastLED defines below must be defined before FastLED.h is loaded
// They are not relevant if you don't actually use FastLED pixel output but cause
// no harm if we only include FastLED for its CRGB struct.
#ifdef ESP32
// Allow infrared for old FastLED versions
#define FASTLED_ALLOW_INTERRUPTS 1
// Newer Samguyver ESP32 FastLED has a new I2S implementation that can be
// better (or worse) than then default RMT which only supports 8 channels.
#define FASTLED_ESP32_I2S
#pragma message "Please use https://github.com/samguyer/FastLED.git if stock FastLED is unstable with ESP32"
#endif
#include <FastLED.h>
#ifdef LEDMATRIX
// Please use https://github.com/marcmerlin/LEDMatrix/ at lesat as recent as
// https://github.com/marcmerlin/LEDMatrix/commit/597ce703e924d45b2e676d6558c4c74a8ebc6991
// or https://github.com/Jorgen-VikingGod/LEDMatrix/commit/a11e74c8cd5b933021b6e15eb067280a52691449
// zero copy/no malloc code to work.
#include <LEDMatrix.h>
#endif
//============================================================================
// Ok, if you're doing matrices of displays, there is also a reasonable chance
// you'll be using SPIFFS or FATFS on flash, or an sdcard, so let's define it
// here (NeoMatrix-FastLED-IR actually also uses this to read a config file)
//============================================================================
// control if we decode in 32x32 or 64x64, or something else
#ifdef ESP8266
#define gif_size 32
#else
#define gif_size 64
#endif
// Note, you can use an sdcard on ESP32 or ESP8266 if you really want,
// but if your data fits in built in flash, why not use it?
// Use built in flash via SPIFFS/FATFS
// esp8266com/esp8266/libraries/SD/src/File.cpp
// ESP8266: http://esp8266.github.io/Arduino/versions/2.3.0/doc/filesystem.html#uploading-files-to-file-system
// ESP32: https://github.com/me-no-dev/arduino-esp32fs-plugin
// https://github.com/marcmerlin/esp32_fatfsimage/blob/master/README.md
#if defined(ESP8266)
#define FS_PREFIX ""
#include <FS.h>
#define FSO SPIFFS
#define FSOSPIFFS
#if gif_size == 64
#define GIF_DIRECTORY FS_PREFIX "/gifs64/"
#else
#define GIF_DIRECTORY FS_PREFIX "/gifs/"
#endif
extern "C" {
#include "user_interface.h"
}
#elif defined(ESP32)
#define FS_PREFIX ""
//#include <SPIFFS.h>
//#define FSOSPIFFS
//#define FSO SPIFFS
#include "FFat.h"
#define FSO FFat
#define FSOFAT
// Do NOT add a trailing slash, or things will fail
#if gif_size == 64
#define GIF_DIRECTORY FS_PREFIX "/gifs64"
#else
#define GIF_DIRECTORY FS_PREFIX "/gifs"
#endif
#elif defined(ARDUINOONPC)
#define UNIXFS
#define FS_PREFIX "/root/NM/"
#define GIF_DIRECTORY FS_PREFIX "gifs/"
#else
#define FS_PREFIX ""
#define FSO SD
#define FSOSD
#if defined (ARDUINO)
#include <SD.h>
#endif
// Chip select for SD card on the SmartMatrix Shield or Photon
// Teensy 3.5/3.6
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
#define SD_CS BUILTIN_SDCARD
#elif defined(ESP32)
#define SD_CS 5
#elif defined (ARDUINO)
#define SD_CS 15
//#define SD_CS BUILTIN_SDCARD
#elif defined (SPARK)
#define SD_CS SS
#endif
// Teensy SD Library requires a trailing slash in the directory name
#if gif_size == 64
#define GIF_DIRECTORY FS_PREFIX "/gifs64/"
#else
#define GIF_DIRECTORY FS_PREFIX "/gifs/"
#endif
#endif
//============================================================================
// Matrix defines (SMARTMATRIX vs NEOMATRIX and size)
// You should #define one and only one of them and if you need to edit it,
// edit both the block below and the 2nd block in setup() at the bottom of this file
//============================================================================
//
#if defined(M24BY24)
#include <FastLED_NeoMatrix.h>
#define FASTLED_NEOMATRIX
const uint8_t MATRIXPIN = 13;
uint8_t matrix_brightness = 64;
// Used by LEDMatrix
const uint16_t MATRIX_TILE_WIDTH = 24; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 24; // height of each matrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
CRGB *matrixleds;
#ifdef LEDMATRIX
// cLEDMatrix defines
// Unfortunately LEDMatrix has its own matrix definition that isn't as well documented
// and easy to use. Look for examples if you need to setup a matrix of matrices.
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
// MATRIX DECLARATION:
// Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display)
// Parameter 2 = height of each matrix
// Parameter 3 = number of matrices arranged horizontally
// Parameter 4 = number of matrices arranged vertically
// Parameter 5 = pin number (most are valid)
// Parameter 6 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are
// arranged in horizontal rows or in vertical columns, respectively;
// pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN
// EACH MATRIX proceed in the same order, or alternate lines reverse
// direction; pick one.
// NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT:
// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick
// two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner.
// NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY
// are arranged in horizontal rows or in vertical columns, respectively;
// pick one or the other.
// NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES
// (tiles) in the OVERALL DISPLAY proceed in the same order for every
// line, or alternate lines reverse direction; pick one. When using
// zig-zag order, the orientation of the matrices in alternate rows
// will be rotated 180 degrees (this is normal -- simplifies wiring).
// See example below for these values in action.
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG );
//----------------------------------------------------------------------------
#elif defined(M32BY8X3)
#include <FastLED_NeoMatrix.h>
#define FASTLED_NEOMATRIX
uint8_t matrix_brightness = 64;
// Used by LEDMatrix
const uint16_t MATRIX_TILE_WIDTH = 8; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 32; // height of each matrix
const uint8_t MATRIX_TILE_H = 3; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<-MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_ZIGZAG_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
// MATRIX DECLARATION:
// Parameter 1 = width of EACH NEOPIXEL MATRIX (not total display)
// Parameter 2 = height of each matrix
// Parameter 3 = number of matrices arranged horizontally
// Parameter 4 = number of matrices arranged vertically
// Parameter 5 = pin number (most are valid)
// Parameter 6 = matrix layout flags, add together as needed:
// NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
// Position of the FIRST LED in the FIRST MATRIX; pick two, e.g.
// NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
// NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs WITHIN EACH MATRIX are
// arranged in horizontal rows or in vertical columns, respectively;
// pick one or the other.
// NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns WITHIN
// EACH MATRIX proceed in the same order, or alternate lines reverse
// direction; pick one.
// NEO_TILE_TOP, NEO_TILE_BOTTOM, NEO_TILE_LEFT, NEO_TILE_RIGHT:
// Position of the FIRST MATRIX (tile) in the OVERALL DISPLAY; pick
// two, e.g. NEO_TILE_TOP + NEO_TILE_LEFT for the top-left corner.
// NEO_TILE_ROWS, NEO_TILE_COLUMNS: the matrices in the OVERALL DISPLAY
// are arranged in horizontal rows or in vertical columns, respectively;
// pick one or the other.
// NEO_TILE_PROGRESSIVE, NEO_TILE_ZIGZAG: the ROWS/COLUMS OF MATRICES
// (tiles) in the OVERALL DISPLAY proceed in the same order for every
// line, or alternate lines reverse direction; pick one. When using
// zig-zag order, the orientation of the matrices in alternate rows
// will be rotated 180 degrees (this is normal -- simplifies wiring).
// See example below for these values in action.
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, MATRIX_TILE_H, MATRIX_TILE_V,
NEO_MATRIX_TOP + NEO_MATRIX_RIGHT +
NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG +
NEO_TILE_TOP + NEO_TILE_LEFT + NEO_TILE_PROGRESSIVE);
//----------------------------------------------------------------------------
#elif defined(M16BY16T4)
#include <FastLED_NeoMatrix.h>
#define FASTLED_NEOMATRIX
uint8_t matrix_brightness = 64;
const uint16_t MATRIX_TILE_WIDTH = 16; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 16; // height of each matrix
const uint8_t MATRIX_TILE_H = 2; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 2; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<-MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_ZIGZAG_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, VERTICAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, MATRIX_TILE_H, MATRIX_TILE_V,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG +
NEO_TILE_TOP + NEO_TILE_RIGHT + NEO_TILE_PROGRESSIVE);
const uint8_t MATRIXPIN = 13;
//----------------------------------------------------------------------------
#elif defined(M64BY64) // 64x64 straight connection (no matrices)
#include <FastLED_NeoMatrix.h>
#define FASTLED_NEOMATRIX
// http://marc.merlins.org/perso/arduino/post_2018-07-30_Building-a-64x64-Neopixel-Neomatrix-_4096-pixels_-running-NeoMatrix-FastLED-IR.html
uint8_t matrix_brightness = 128;
//
// Used by LEDMatrix
const uint16_t MATRIX_TILE_WIDTH = 64; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 64; // height of each matrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#define NUM_STRIPS 16
#define NUM_LEDS_PER_STRIP 256
CRGB *matrixleds;
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, VERTICAL_ZIGZAG_MATRIX> ledmatrix(false);
#endif
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT,
NEO_MATRIX_BOTTOM + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG );
//----------------------------------------------------------------------------
#elif defined(SMARTMATRIX)
// CHANGEME for ESP32, see MatrixHardware_ESP32_V0.h in SmartMatrix/src
#define GPIOPINOUT 8
// This is defined by you before including this file if you are using the old SmartMatrixv3
#ifdef SMARTMATRIXV3
#include <SmartLEDShieldV4.h>
#include <SmartMatrix3.h>
#else // As of 2020/11, SmartMatrix v4 has a new interface
// https://community.pixelmatix.com/t/smartmatrix-library-4-0-changes-to-matrixhardware-includes/709/9
#ifdef ESP32
// This saves RAM but could make your code unstable if you do Flash + Wifi + PSRAM
//#define SMARTMATRIX_USE_PSRAM
#include <MatrixHardware_ESP32_V0.h> // ESP32
#elif __IMXRT1062__ // Teensy 4.0/4.1
#include <MatrixHardware_Teensy4_ShieldV4Adapter.h> // Teensy 4 Adapter attached to SmartLED Shield for Teensy 3 (V4)
//#include <MatrixHardware_Teensy4_ShieldV5.h> // SmartLED Shield for Teensy 4 (V5)
#else
#include <MatrixHardware_Teensy3_ShieldV4.h> // SmartLED Shield for Teensy 3 (V4)
//#include <MatrixHardware_Teensy3_ShieldV1toV3.h> // SmartMatrix Shield for Teensy 3 V1-V3
#endif
#include <SmartMatrix.h>
#endif
#include <SmartMatrix_GFX.h>
uint8_t matrix_brightness = 255;
#ifdef ESP32
#pragma message "SmartMatrix for ESP32 with 64x32 16 scan panel and 64x96 resolution"
const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint16_t MATRIX_TILE_WIDTH = 64; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 96; // height of each matrix
#elif defined(__MK66FX1M0__) // my teensy 3.6 is connected to a 64x64 panel
#pragma message "SmartMatrix for Teensy with 64x64 32 scan panel"
//const uint8_t kPanelType = SMARTMATRIX_HUB75_32ROW_MOD16SCAN; // use SMARTMATRIX_HUB75_16ROW_MOD8SCAN for common 16x32 panels
const uint8_t kPanelType = SMARTMATRIX_HUB75_64ROW_MOD32SCAN;
const uint16_t MATRIX_TILE_WIDTH = 64; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 64; // height of each matrix
#elif defined(__IMXRT1062__) // teensy v.4
const uint8_t kPanelType = SMARTMATRIX_HUB75_64ROW_MOD32SCAN;
const uint16_t MATRIX_TILE_WIDTH = 64; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 64; // height of each matrix
#else
#error Unknown architecture (not ESP32 or teensy 3.5/6 or teensy 4.0, please write a panel config)
#endif
// Used by LEDMatrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
/// SmartMatrix Defines
#define COLOR_DEPTH 24 // known working: 24, 48 - If the sketch uses type `rgb24` directly, COLOR_DEPTH must be 24
const uint8_t kMatrixWidth = MATRIX_TILE_WIDTH * MATRIX_TILE_H;
const uint8_t kMatrixHeight = MATRIX_TILE_HEIGHT * MATRIX_TILE_V;
const uint8_t kRefreshDepth = 24; // known working: 24, 36, 48
const uint8_t kDmaBufferRows = 2; // known working: 2-4, use 2 to save memory, more to keep from dropping frames and automatically lowering refresh rate
const uint8_t kMatrixOptions = (SMARTMATRIX_OPTIONS_FM6126A_RESET_AT_START); // see http://docs.pixelmatix.com/SmartMatrix for options
//const uint8_t kMatrixOptions = 0;
const uint8_t kBackgroundLayerOptions = (SM_BACKGROUND_OPTIONS_NONE);
SMARTMATRIX_ALLOCATE_BUFFERS(matrixLayer, kMatrixWidth, kMatrixHeight, kRefreshDepth, kDmaBufferRows, kPanelType, kMatrixOptions);
SMARTMATRIX_ALLOCATE_BACKGROUND_LAYER(backgroundLayer, kMatrixWidth, kMatrixHeight, COLOR_DEPTH, kBackgroundLayerOptions);
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, -MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
void show_callback();
SmartMatrix_GFX *matrix = new SmartMatrix_GFX(matrixleds, kMatrixWidth, kMatrixHeight, show_callback);
// Sadly this callback function must be copied around with this init code
void show_callback() {
// memcpy(backgroundLayer.backBuffer(), matrixleds, kMatrixHeight*kMatrixWidth*3);
// backgroundLayer.swapBuffers(false);
backgroundLayer.swapBuffers(true);
//matrixleds = (CRGB *)backgroundLayer.getRealBackBuffer());
matrixleds = (CRGB *)backgroundLayer.backBuffer();
matrix->newLedsPtr(matrixleds);
#ifdef LEDMATRIX
ledmatrix.SetLEDArray(matrixleds);
#endif
matrix->showfps();
}
//----------------------------------------------------------------------------
#elif defined(M5STACK)
#define HAS_TFT
#include <M5Stack.h>
#include <FastLED_SPITFT_GFX.h>
uint8_t matrix_brightness = 255;
const uint16_t MATRIX_TILE_WIDTH = 320;
const uint16_t MATRIX_TILE_HEIGHT= 240;
//
// Used by LEDMatrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
// M5 gets defined in M5Stack
FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, mw, mh, &M5.lcd, 100);
//----------------------------------------------------------------------------
#elif defined(ILI9341)
#define HAS_TFT
#ifdef ADAFRUIT_TFT
#include "Adafruit_ILI9341.h"
#include <FastLED_SPITFT_GFX.h>
#else
#include <FastLED_ArduinoGFX_TFT.h>
#endif
/* https://pinout.xyz/pinout/spi
SD1331 Pin Arduino ESP8266 ESP32 ESP32 rPi rPi
1 GND VSPI HSPI SPI0 SPI1
2 VCC
3 SCL/SCK/CLK/D0 13 GPIO14/D5 18 14 BC11/22 BC21/40
4 SDA/SDI/MOSI/D1 11 GPIO13/D7 23 13 BC10/19 BC20/38
---- 2 pins above and MISO are HWSPI, pins below are anything
---- RST is not part of SPI, it's an out of band signal to reset a TFT
---- This could be wired to the ESP32 EN(reset) pin
5 RES/RST 9 GPIO15/D8 26 26 BC24
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI
---- data is actually a command, or pixel data.
6 DC/A0/RS (data) 8 GPIO05/D1 25 25 BC23
---- Cable select chooses which SPI device we're talking to, if there is only
---- one, it can be tied to ground. Any pin is fine
7 CS/SS => GND 10 GPIO04/D2 0 2 BC08
CS2: 2 => if you have 2 different screens, need 2 CS pins
---- MISO is not used to talk to TFTs, but is one of the 3 SPI hardware pins
MISO 12 GPIO12/D6 19 12 BM11/23 BC19/35
*/
// this is the TFT reset pin. Some boards may have an auto-reset
// circuitry on the breakout so this pin might not required but it can
// be helpful sometimes to reset the TFT if your setup is not always
// resetting cleanly. Connect to ground to reset the TFT
#define TFT_RST 26 // Grey
//#define TFT_RST -1 // Grey, can be wired to ESP32 EN to save a pin
#define TFT_DC 25 // Purple
//#define TFT_CS -1 // for display without CS pin
#define TFT_CS 0 // White can be wired to ground
#define TFT_CS2 2 // Orange can be wired to ground
#define TFT_MOSI 23 // Blue
#define TFT_CLK 18 // Green
#define TFT_MISO 19 // Yellow
#define TFT_BL 15
#define TFT_SCK TFT_CLK
#ifdef ADAFRUIT_TFT
//Adafruit_ILI9341 *tft = new Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
Adafruit_ILI9341 *tft = new Adafruit_ILI9341((int8_t) TFT_CS, TFT_DC, TFT_RST);
#else
#ifdef ESP32
// Arduino_ESP32SPI_DMA is faster than Arduino_ESP32SPI, but makes framebuffer::gfx slower at 80Mhz
Arduino_DataBus *bus2 = new Arduino_ESP32SPI_DMA(TFT_DC, TFT_CS2, TFT_SCK, TFT_MOSI, TFT_MISO, VSPI);//60fps ILI9341 at 80Mhz
// Arduino_DataBus *bus2 = new Arduino_ESP32SPI(TFT_DC, TFT_CS2, TFT_SCK, TFT_MOSI, TFT_MISO, VSPI); // 53fps ILI9341 at 80Mhz
#else
Arduino_DataBus *bus2 = new Arduino_HWSPI(TFT_DC, TFT_CS2); // 42fps ILI9341 at 80Mhz
#endif
Arduino_ILI9341 *tft = new Arduino_ILI9341(bus2, TFT_RST, 1 /* rotation */);
#endif
// It would be great if we could do this, but many programs use size related variables to
// define static arrays, which required constants
//uint16_t tftw = tft->width();
//uint16_t tfth = tft->height();
const uint16_t tftw = 320;
const uint16_t tfth = 240;
const uint16_t mw = tftw;
// if you are using ILI9341 on ESP32, the framebuffer does not fit in memory (224KB)
// If PSRAM is available, it will get used. If not, you need to make the framebuffer
// smaller than the TFT. One simple way is to have the framebuffer be half the screen
// size, render what you need in one half, display it, render the other half and then
// render that.
// Before you ask "why would I do this, in that case I can just render to the TFT directly"
// the answer is "yes, you can as long as you are using GFX directly, you can indeed skip
// the framebuffer, but if you use FastLED/LEDMatrix code that requires a CRGB 24bpp buffer
// and does transformations like reading the framebuffer and flipping parts of it, you do
// need the framebuffer and therefore it could make sense to split the screen in two and
// render each half separately.
// In my case, I can use LEDText for fancy font rendering not supported by Adafruit's GFX
// and then display the 24bpp framebuffer on the 16bpp TFT
#ifdef ESP32
#ifdef BOARD_HAS_PSRAM
#pragma message "Compiling for ILI9341 on ESP32 with PSRAM"
const uint16_t mh = tfth;
#else
#pragma message "Compiling for ILI9341 on ESP32 without PSRAM, framebuffer will only be half height"
const uint16_t mh = tfth/2;
#endif
#else
#pragma message "Compiling for ILI9341. Most chips except teensy 3.6 and better, won't have enough RAM"
const uint16_t mh = tfth;
#endif
// Used by LEDMatrix
// templates prevents being able to get the screen size at runtime. This is why templates must die
const uint16_t MATRIX_TILE_WIDTH = mw;
const uint16_t MATRIX_TILE_HEIGHT = mh;
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX, MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
// matrixleds is malloced at runtime as there is more memory available once setup runs
CRGB *matrixleds;
uint8_t matrix_brightness = 255;
// create the matrix object, and reset the matrixleds pointer in matrix_setup
#ifdef ADAFRUIT_TFT
FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, mw, mh, tft, 0);
#else
FastLED_ArduinoGFX_TFT *matrix = new FastLED_ArduinoGFX_TFT(matrixleds, mw, mh, tft);;
#endif
//----------------------------------------------------------------------------
#elif defined(ST7735_128b128) || defined(ST7735_128b160)
#define HAS_TFT
#include <Adafruit_ST7735.h>
#include <FastLED_SPITFT_GFX.h>
uint8_t matrix_brightness = 255;
const uint16_t mw = 128;
#ifdef ST7735_128b128
const uint16_t mh = 128;
#else
const uint16_t mh = 160;
#endif
// Used by LEDMatrix
// templates prevents being able to get the screen size at runtime. This is why templates must die
const uint16_t MATRIX_TILE_WIDTH = mw;
const uint16_t MATRIX_TILE_HEIGHT = mh;
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
/* https://pinout.xyz/pinout/spi
SD1331 Pin Arduino ESP8266 ESP32 ESP32 rPi rPi
1 GND VSPI HSPI SPI0 SPI1
2 VCC
3 SCL/SCK/CLK/D0 13 GPIO14/D5 18 14 BC11/22 BC21/40
4 SDA/SDI/MOSI/D1 11 GPIO13/D7 23 13 BC10/19 BC20/38
---- 2 pins above and MISO are HWSPI, pins below are anything
---- RST is not part of SPI, it's an out of band signal to reset a TFT
---- This could be wired to the ESP32 EN(reset) pin
5 RES/RST 9 GPIO15/D8 26 26 BC24
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI
---- data is actually a command, or pixel data.
6 DC/A0/RS (data) 8 GPIO05/D1 25 25 BC23
---- Cable select chooses which SPI device we're talking to, if there is only
---- one, it can be tied to ground. Any pin is fine
7 CS/SS => GND 10 GPIO04/D2 0 2 BC08
CS2: 2 => if you have 2 different screens, need 2 CS pins
---- MISO is not used to talk to TFTs, but is one of the 3 SPI hardware pins
MISO 12 GPIO12/D6 19 12 BM11/23 BC19/35
*/
#ifdef ESP32
#define TFT_RST 26 // Grey
#define TFT_DC 25 // Purple
#define TFT_CS 0 // White with 2 devices
#define TFT_CS2 2 // Orange with 2 deices
#elif defined(ESP8266)
#define TFT_RST 15
#define TFT_DC 5
#define TFT_CS 4 // this can be wired to ground if you have one device
#define TFT_CS2 4
#else
#define TFT_RST 9 // Or set to -1 and connect to Arduino RESET pin
#define TFT_DC 8
#define TFT_CS 4 // this can be wired to ground if you have one device
#define TFT_CS2 4
#endif
#ifdef ADAFRUIT_TFT
Adafruit_ST7735 *tft = new Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, mw, mh, tft, 0);
#else
#ifdef ESP32
// Arduino_ESP32SPI_DMA is faster than Arduino_ESP32SPI, but makes framebuffer::gfx slower at 80Mhz
Arduino_DataBus *bus2 = new Arduino_ESP32SPI_DMA(TFT_DC, TFT_CS2, TFT_SCK, TFT_MOSI, TFT_MISO, VSPI);//60fps ILI9341 at 80Mhz
// Arduino_DataBus *bus2 = new Arduino_ESP32SPI(TFT_DC, TFT_CS2, TFT_SCK, TFT_MOSI, TFT_MISO, VSPI); // 53fps ILI9341 at 80Mhz
#else
Arduino_DataBus *bus2 = new Arduino_HWSPI(TFT_DC, TFT_CS2); // 42fps ILI9341 at 80Mhz
#endif
Arduino_ILI9341 *gfx = new Arduino_ILI9341(bus2, TFT_RST, 0 /* rotation */);
#endif
//----------------------------------------------------------------------------
#elif defined(SSD1331)
#define HAS_TFT
#include <Adafruit_SSD1331.h>
#include <FastLED_SPITFT_GFX.h>
uint8_t matrix_brightness = 255;
#if SSD1331_ROTATE == 0
const uint16_t mw = 96;
const uint16_t mh = 64;
#else
const uint16_t mw = 64;
const uint16_t mh = 96;
#endif
// Used by LEDMatrix
// templates prevents being able to get the screen size at runtime. This is why templates must die
const uint16_t MATRIX_TILE_WIDTH = mw;
const uint16_t MATRIX_TILE_HEIGHT = mh;
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
/* https://pinout.xyz/pinout/spi
SD1331 Pin Arduino ESP8266 ESP32 ESP32 rPi rPi
1 GND VSPI HSPI SPI0 SPI1
2 VCC
3 SCL/SCK/CLK/D0 13 GPIO14/D5 18 14 BC11/22 BC21/40
4 SDA/SDI/MOSI/D1 11 GPIO13/D7 23 13 BC10/19 BC20/38
---- 2 pins above and MISO are HWSPI, pins below are anything
---- RST is not part of SPI, it's an out of band signal to reset a TFT
---- This could be wired to the ESP32 EN(reset) pin
5 RES/RST 9 GPIO15/D8 26 26 BC24
---- Data/Command pin is not part of SPI but used to tell the TFT if incoming SPI
---- data is actually a command, or pixel data.
6 DC/A0/RS (data) 8 GPIO05/D1 25 25 BC23
---- Cable select chooses which SPI device we're talking to, if there is only
---- one, it can be tied to ground. Any pin is fine
7 CS/SS => GND 10 GPIO04/D2 0 2 BC08
CS2: 2 => if you have 2 different screens, need 2 CS pins
---- MISO is not used to talk to TFTs, but is one of the 3 SPI hardware pins
MISO 12 GPIO12/D6 19 12 BM11/23 BC19/35
*/
#ifdef ESP32
#define TFT_RST 26 // Grey
#define TFT_DC 25 // Purple
#define TFT_CS 0 // White can be wired to ground
#define TFT_MOSI 23 // Blue
#define TFT_MISO 19 // Green
#define TFT_CLK 18 // Yellow
// Option 1: use any pins but a little slower
#pragma message "Using SWSPI"
Adafruit_SSD1331 *tft = new Adafruit_SSD1331(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST);
// HWSPI hangs on ESP32 the moment it is run
// https://github.com/adafruit/Adafruit-SSD1331-OLED-Driver-Library-for-Arduino/issues/27
//Adafruit_SSD1331 *tft = new Adafruit_SSD1331(TFT_CS, TFT_DC, TFT_RST);
#else
// ESP8266 + Teensy?
#define TFT_RST 15
#define TFT_DC 5
#define TFT_CS 4
// You can use any (4 or) 5 pins
// hwspi hardcodes those pins, no need to redefine them
#define TFT_MOSI 13
#define TFT_CLK 14
#pragma message "Using HWSPI"
Adafruit_SSD1331 *tft = new Adafruit_SSD1331(&SPI, TFT_CS, TFT_DC, TFT_RST);
#endif
#if SSD1331_ROTATE == 0
FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, 96, 64, tft, 0);
#else
FastLED_SPITFT_GFX *matrix = new FastLED_SPITFT_GFX(matrixleds, mw, mh, 96, 64, tft, 1);
#endif
//----------------------------------------------------------------------------
#elif defined(LINUX_RENDERER_X11)
#include "TFT_LinuxWrapper.h"
#include <FastLED_TFTWrapper_GFX.h>
uint8_t matrix_brightness = 255;
const uint16_t MATRIX_TILE_WIDTH = 64;
const uint16_t MATRIX_TILE_HEIGHT= 96;
//
// Used by LEDMatrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
TFT_LinuxWrapper *tft = new TFT_LinuxWrapper(MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT);
FastLED_TFTWrapper_GFX *matrix = new FastLED_TFTWrapper_GFX(matrixleds, mw, mh, tft);
//----------------------------------------------------------------------------
#elif defined(LINUX_RENDERER_SDL)
#include <FastLED_NeoMatrix.h>
uint8_t matrix_brightness = 128;
//
// Used by LEDMatrix
// All running 1D neopixel code
#ifdef NEOPIXEL_STRIP
#pragma message "Neopixel 1D code"
const uint16_t MATRIX_TILE_WIDTH = 64; // width of EACH NEOPIXEL MATRIX (not total display)
const uint16_t MATRIX_TILE_HEIGHT= 1; // height of each matrix
#else
#undef gif_size
#define gif_size 192
#ifdef GFXDISPLAY_M384BY256
#pragma message "M384BY256 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 384;
const uint16_t MATRIX_TILE_HEIGHT= 256;
#elif GFXDISPLAY_M192BY160
#pragma message "M192BY160 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 192;
const uint16_t MATRIX_TILE_HEIGHT= 160;
#elif GFXDISPLAY_M128BY192
#pragma message "M128BY192 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 128;
const uint16_t MATRIX_TILE_HEIGHT= 192;
#elif GFXDISPLAY_M64BY96
#pragma message "M64Y96 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 64;
const uint16_t MATRIX_TILE_HEIGHT= 96;
#else
#pragma message "Please write M384BY256 or equivalent to /root/NM/gfxdisplay (see ../../makeNativeArduino.mk)"
const uint16_t MATRIX_TILE_WIDTH = 128;
const uint16_t MATRIX_TILE_HEIGHT= 192;
#endif
#endif
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
CRGB *matrixleds;
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, -MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
FastLED_NeoMatrix *matrix = new FastLED_NeoMatrix(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS );
//----------------------------------------------------------------------------
#elif defined(RPIRGBPANEL)
#include <FastLED_RPIRGBPanel_GFX.h>
// https://github.com/hzeller/rpi-rgb-led-matrix
// Arduino min/max conflict with g++ math min/max
#undef min
#undef max
#define min(a,b) ((a<b)?(a):(b))
#define max(a,b) ((a>b)?(a):(b))
#include <led-matrix.h>
#undef gif_size
#define gif_size 192
uint8_t matrix_brightness = 255;
#ifdef GFXDISPLAY_M384BY256
#pragma message "M384BY256 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 384;
const uint16_t MATRIX_TILE_HEIGHT= 256;
#elif GFXDISPLAY_M192BY160
#pragma message "M192BY160 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 192;
const uint16_t MATRIX_TILE_HEIGHT= 160;
#elif GFXDISPLAY_M128BY192
#pragma message "M128BY192 read from /root/NM/gfxdisplay"
const uint16_t MATRIX_TILE_WIDTH = 128;
const uint16_t MATRIX_TILE_HEIGHT= 192;
#else
#pragma message "Please write M384BY256 or equivalent to /root/NM/gfxdisplay (see ../../makeNativeArduino.mk)"
const uint16_t MATRIX_TILE_WIDTH = 128;
const uint16_t MATRIX_TILE_HEIGHT= 192;
#endif
// Used by LEDMatrix
const uint8_t MATRIX_TILE_H = 1; // number of matrices arranged horizontally
const uint8_t MATRIX_TILE_V = 1; // number of matrices arranged vertically
#ifdef LEDMATRIX
// cLEDMatrix defines
cLEDMatrix<MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT, HORIZONTAL_MATRIX,
MATRIX_TILE_H, MATRIX_TILE_V, HORIZONTAL_BLOCKS> ledmatrix(false);
#endif
CRGB *matrixleds;
FastLED_RPIRGBPanel_GFX *matrix = new FastLED_RPIRGBPanel_GFX(matrixleds, MATRIX_TILE_WIDTH, MATRIX_TILE_HEIGHT);
//============================================================================
#else
#error "Please write a matrix config or choose one of the definitions above. If you have a FastLED matrix, define M24BY24 at the top of this file"
#endif
//============================================================================
// End Matrix defines (SMARTMATRIX vs NEOMATRIX and size)
//============================================================================
// Compat for some other demos
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
const uint16_t MATRIX_WIDTH = MATRIX_TILE_WIDTH * MATRIX_TILE_H;
const uint16_t MATRIX_HEIGHT = MATRIX_TILE_HEIGHT * MATRIX_TILE_V;
// If the actual display is bigger than the framebuffer (this is needed
// for TFTs which require more FB RAM than you can get on chips like ESP32)
#ifdef HAS_TFT
uint8_t gfx_scale = (tftw*tfth)/(mw*mh);
#else
// Used by NeoMatrix
const uint16_t mw = MATRIX_WIDTH;
const uint16_t mh = MATRIX_HEIGHT;
#endif
// Used by some demos
const uint32_t NUMMATRIX = mw*mh;
const uint32_t NUM_LEDS = NUMMATRIX;
// Compat with SmartMatrix code that uses those variables
// (but don't redefine for SmartMatrix backend)
#ifndef SMARTMATRIX
const uint16_t kMatrixWidth = mw;
const uint16_t kMatrixHeight = mh;
#endif
#pragma GCC diagnostic pop
#ifdef ESP8266
// Turn off Wifi in setup()
// https://www.hackster.io/rayburne/esp8266-turn-off-wifi-reduce-current-big-time-1df8ae
//
#include "ESP8266WiFi.h"
extern "C" {
#include "user_interface.h"
}
#endif // ESP8266
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
uint16_t speed = 255;
float matrix_gamma = 1; // higher number is darker, needed for Neomatrix more than SmartMatrix
// Like XY, but for a mirror image from the top (used by misconfigured code)
int XY2( int x, int y, bool wrap=false) {
wrap = wrap; // squelch compiler warning
return matrix->XY(x,MATRIX_HEIGHT-1-y);
}
// FastLED::colorutils needs a signature with uint8_t
uint16_t XY( uint8_t x, uint8_t y) {
return matrix->XY(x,y);
}
// but x/y can be bigger than 256
uint16_t XY16( uint16_t x, uint16_t y) {
return matrix->XY(x,y);
}
int wrapX(int x) {
if (x < 0 ) return 0;
if (x >= MATRIX_WIDTH) return (MATRIX_WIDTH-1);
return x;
}
void show_free_mem(const char *pre=NULL) {
Framebuffer_GFX::show_free_mem(pre);
}
void die(const char *mesg) {
Serial.println(mesg);
while(1) delay((uint32_t)1); // while 1 loop only triggers watchdog on ESP chips
}
void *mallocordie(const char *varname, uint32_t req, bool psram=true) {
// If varname starts with @, show debug for the allocation
void *mem;
#ifndef BOARD_HAS_PSRAM
psram = false;
#endif
if (varname[0] == '@') {