RGB matrix Panel
RGBmatrixPanel.h
Go to the documentation of this file.
1 
19 #ifndef RGBMATRIXPANEL_H
20 #define RGBMATRIXPANEL_H
21 
22 #if ARDUINO >= 100
23 #include "Arduino.h"
24 #else
25 #include "WProgram.h"
26 #include "pins_arduino.h"
27 #endif
28 #include "Adafruit_GFX.h"
29 
30 #if defined(__AVR__)
31 typedef uint8_t PortType;
32 #elif defined(__arm__) || defined(__xtensa__)
33 typedef uint32_t PortType; // Formerly 'RwReg' but interfered w/CMCIS header
34 #endif
35 
39 class RGBmatrixPanel : public Adafruit_GFX {
40 
41 public:
55  RGBmatrixPanel(uint8_t a, uint8_t b, uint8_t c, uint8_t clk, uint8_t lat,
56  uint8_t oe, boolean dbuf
57 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP32)
58  ,
59  uint8_t *pinlist = NULL
60 #endif
61  );
62 
79  RGBmatrixPanel(uint8_t a, uint8_t b, uint8_t c, uint8_t d, uint8_t clk,
80  uint8_t lat, uint8_t oe, boolean dbuf, uint8_t width = 32
81 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP32)
82  ,
83  uint8_t *pinlist = NULL
84 #endif
85  );
86 
90  void begin(void);
91 
101  void drawPixel(int16_t x, int16_t y, uint16_t c);
102 
110  void fillScreen(uint16_t c);
111 
115  void updateDisplay(void);
116 
120  void swapBuffers(boolean);
121 
130  void dumpMatrix(void);
131 
140  uint8_t *backBuffer(void);
141 
153  uint16_t Color333(uint8_t r, uint8_t g, uint8_t b);
154 
165  uint16_t Color444(uint8_t r, uint8_t g, uint8_t b);
166 
178  uint16_t Color888(uint8_t r, uint8_t g, uint8_t b);
179 
192  uint16_t Color888(uint8_t r, uint8_t g, uint8_t b, boolean gflag);
193 
206  uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, boolean gflag);
207 
208 private:
209  uint8_t *matrixbuff[2];
210  uint8_t nRows;
211  volatile uint8_t backindex;
212  volatile boolean swapflag;
213 
214  // Init/alloc code common to both constructors:
215  void init(uint8_t rows, uint8_t a, uint8_t b, uint8_t c, uint8_t clk,
216  uint8_t lat, uint8_t oe, boolean dbuf, uint8_t width
217 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP32)
218  ,
219  uint8_t *rgbpins
220 #endif
221  );
222 
223  uint8_t _clk;
224  uint8_t _lat;
225  uint8_t _oe;
226  uint8_t _a;
227  uint8_t _b;
228  uint8_t _c;
229  uint8_t _d;
230  PortType clkmask;
231  PortType latmask;
232  PortType oemask;
233  PortType addramask;
234  PortType addrbmask;
235  PortType addrcmask;
236  PortType addrdmask;
237  // PORT register pointers (CLKPORT is hardcoded on AVR)
238  volatile PortType *latport;
239  volatile PortType *oeport;
240  volatile PortType *addraport;
241  volatile PortType *addrbport;
242  volatile PortType *addrcport;
243  volatile PortType *addrdport;
244 
245 #if defined(ARDUINO_ARCH_SAMD) || defined(ARDUINO_ARCH_ESP32)
246  uint8_t rgbpins[6];
247  volatile PortType *outsetreg;
248  volatile PortType *outclrreg;
249  PortType rgbclkmask;
250  PortType expand[256];
251 #endif
252 
253  volatile uint8_t row;
254  volatile uint8_t plane;
255  volatile uint8_t *buffptr;
256 };
257 
258 #endif // RGBMATRIXPANEL_H
void updateDisplay(void)
Refresh matrix contents following one or more drawing calls.
Definition: RGBmatrixPanel.cpp:829
uint8_t * backBuffer(void)
Get address of back buffer – can then load/store data directly. Format is very strangely interleaved...
Definition: RGBmatrixPanel.cpp:687
void drawPixel(int16_t x, int16_t y, uint16_t c)
Lowest-level pixel drawing function required by Adafruit_GFX. Does not have an immediate effect – mu...
Definition: RGBmatrixPanel.cpp:589
uint16_t ColorHSV(long hue, uint8_t sat, uint8_t val, boolean gflag)
Convert hue, saturation, value (used in some existing graphics code in other projects and languages) ...
Definition: RGBmatrixPanel.cpp:519
void begin(void)
Start RGB matrix. Initializes timers and interrupts.
Definition: RGBmatrixPanel.cpp:248
Class encapsulating RGB LED matrix functionality.
Definition: RGBmatrixPanel.h:39
void swapBuffers(boolean)
If using double buffering, swap the front and back buffers.
Definition: RGBmatrixPanel.cpp:695
uint16_t Color888(uint8_t r, uint8_t g, uint8_t b)
Decimate 8-bits R,G,B (used in a lot of existing graphics code in other projects and languages) to th...
Definition: RGBmatrixPanel.cpp:501
void fillScreen(uint16_t c)
Fill entire matrix a single color. Does not have an immediate effect – must call updateDisplay() aft...
Definition: RGBmatrixPanel.cpp:674
uint16_t Color444(uint8_t r, uint8_t g, uint8_t b)
Promote 4-bits R,G,B (handled by the current version of this library) to the '565' color format used ...
Definition: RGBmatrixPanel.cpp:493
RGBmatrixPanel(uint8_t a, uint8_t b, uint8_t c, uint8_t clk, uint8_t lat, uint8_t oe, boolean dbuf)
Constructor for 16x32 panel.
Definition: RGBmatrixPanel.cpp:199
void dumpMatrix(void)
Dump display contents to the Serial Monitor, adding some formatting to simplify copy-and-paste of dat...
Definition: RGBmatrixPanel.cpp:713
uint16_t Color333(uint8_t r, uint8_t g, uint8_t b)
Promote 3-bits R,G,B (used by earlier versions of this library) to the '565' color format used in Ada...
Definition: RGBmatrixPanel.cpp:486