Remove last remaining legacy usage of the library

This commit is contained in:
mrfaptastic 2021-08-17 15:13:11 +01:00
parent a7483a8b7d
commit 3ac0fa6f83
11 changed files with 137 additions and 113 deletions

View file

@ -124,19 +124,7 @@ Various people have created PCBs for which one can simply connect an ESP32 to a
Please contact or order these products from the respective authors. Please contact or order these products from the respective authors.
## 3. Run a Test Sketch ## 3. Run a Test Sketch
Below is a bare minimum sketch to draw a single white dot in the top left. You must call .begin() before you call ANY pixel-drawing (fonts, lines, colours etc.) function of the MatrixPanel_I2S_DMA class. Below is a bare minimum sketch to draw a single white dot in the top left. You must call begin() before you call ANY pixel-drawing (fonts, lines, colours etc.) function of the MatrixPanel_I2S_DMA class.
No .begin() before other functions = Crash
```
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
MatrixPanel_I2S_DMA matrix;
void setup(){
// MUST DO THIS FIRST!
matrix.begin(); // Use default values for matrix dimentions and pins supplied within ESP32-HUB75-MatrixPanel-I2S-DMA.h
// Draw a single white pixel
matrix.drawPixel(0,0, matrix.color565(255,255,255)); // can do this after .begin() only
}
void loop(){ }
```
Once this is working, refer to the [PIO Test Patterns](/examples/PIO_TestPatterns) example. This sketch draws simple colors/lines/gradients over the entire matrix and it could help to troubleshoot various issues with ghosting, flickering, etc... Once this is working, refer to the [PIO Test Patterns](/examples/PIO_TestPatterns) example. This sketch draws simple colors/lines/gradients over the entire matrix and it could help to troubleshoot various issues with ghosting, flickering, etc...
>Note: Requires the use of [PlatformIO](https://platformio.org/), which you should probably use if you aren't already. >Note: Requires the use of [PlatformIO](https://platformio.org/), which you should probably use if you aren't already.
@ -177,11 +165,9 @@ Example:
``` ```
void setup() { void setup() {
Serial.begin(115200); Serial.begin(115200);
matrix.begin(); // setup the LED matrix dma_display->begin(); // setup the LED matrix
matrix.setPanelBrightness(16); // Set the brightness. 32 or lower ideal for a single 64x32 LED Matrix Panel. dma_display->setBrightness8(90); //0-255
dma_display->clearScreen();
// or another way
matrix.setBrightness8(192); // Set the brightness to about 3/4 or 75% (192/256) of maximum.
} }
``` ```
@ -195,7 +181,7 @@ If you are facing issues with image ghosting when pixels has clones with horizon
An example: An example:
``` ```
matrix.setLatBlanking(2); dma_display->setLatBlanking(2);
``` ```
## Power, Power and Power! ## Power, Power and Power!

View file

@ -1,38 +1,55 @@
/* ------------------------- CUSTOM GPIO PIN MAPPING ------------------------- */
#define R1_PIN 18
#define G1_PIN 25
#define B1_PIN 5
#define R2_PIN 17
#define G2_PIN 26
#define B2_PIN 16
#define A_PIN 14
#define B_PIN 27
#define C_PIN 12
#define D_PIN 4
#define E_PIN -1
#define LAT_PIN 13
#define OE_PIN 15
#define CLK_PIN 2
/* -------------------------- Display Config Initialisation -------------------- */
// MATRIX_WIDTH and MATRIX_HEIGHT *must* be changed in ESP32-HUB75-MatrixPanel-I2S-DMA.h
// If you are using Platform IO (you should), pass MATRIX_WIDTH and MATRIX_HEIGHT as a compile time option.
// Refer to: https://github.com/mrfaptastic/ESP32-HUB75-MatrixPanel-I2S-DMA/issues/48#issuecomment-749402379
/* -------------------------- Class Initialisation -------------------------- */
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h> #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
/*--------------------- MATRIX GPIO CONFIG -------------------------*/
#define R1_PIN 25
#define G1_PIN 26
#define B1_PIN 27
#define R2_PIN 14
#define G2_PIN 12
#define B2_PIN 13
#define A_PIN 23
#define B_PIN 19 // Changed from library default
#define C_PIN 5
#define D_PIN 17
#define E_PIN -1
#define LAT_PIN 4
#define OE_PIN 15
#define CLK_PIN 16
/*--------------------- MATRIX PANEL CONFIG -------------------------*/
#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
#define PANEL_CHAIN 1 // Total number of panels chained one to another
/* /*
* Below is an is the 'legacy' way of initialising the MatrixPanel_I2S_DMA class. //Another way of creating config structure
* i.e. MATRIX_WIDTH and MATRIX_HEIGHT are modified by compile-time directives. //Custom pin mapping for all pins
* By default the library assumes a single 64x32 pixel panel is connected. HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK};
* HUB75_I2S_CFG mxconfig(
* Refer to the example '2_PatternPlasma' on the new / correct way to setup this library 64, // width
* for different resolutions / panel chain lengths within the sketch 'setup()'. 64, // height
* 4, // chain length
_pins, // pin mapping
HUB75_I2S_CFG::FM6126A // driver chip
);
*/ */
MatrixPanel_I2S_DMA matrix; MatrixPanel_I2S_DMA *dma_display = nullptr;
// Module configuration
HUB75_I2S_CFG mxconfig(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // Chain length
);
//mxconfig.gpio.e = -1; // Assign a pin if you have a 64x64 panel
//mxconfig.clkphase = false; // Change this if you have issues with ghosting.
//mxconfig.driver = HUB75_I2S_CFG::FM6126A; // Change this according to your pane.
#include <FastLED.h> #include <FastLED.h>
@ -54,26 +71,25 @@ unsigned long last_frame=0, ms_previous=0;
void setup() void setup()
{ {
// Setup serial interface /************** SERIAL **************/
Serial.begin(115200); Serial.begin(115200);
delay(250); delay(250);
matrix.begin(R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN ); // setup the LED matrix
/**
* this demos runs pretty fine in fast-mode which gives much better fps on large matrixes (>128x64)
* see comments in the lib header on what does that means
*/
//dma_display.setFastMode(true);
// SETS THE BRIGHTNESS HERE. MAX value is MATRIX_WIDTH, 2/3 OR LOWER IDEAL, default is about 50% /************** DISPLAY **************/
// dma_display.setPanelBrightness(30); Serial.println("...Starting Display");
/* another way to change brightness is to use dma_display = new MatrixPanel_I2S_DMA(mxconfig);
* dma_display.setPanelBrightness8(uint8_t brt); // were brt is within range 0-255 dma_display->begin();
* it will recalculate to consider matrix width automatically dma_display->setBrightness8(90); //0-255
*/
//dma_display.setPanelBrightness8(180);
dma_display->fillScreenRGB888(128,0,0);
delay(1000);
dma_display->fillScreenRGB888(0,0,128);
delay(1000);
dma_display->clearScreen();
delay(1000);
Serial.println("**************** Starting Aurora Effects Demo ****************"); Serial.println("**************** Starting Aurora Effects Demo ****************");
// setup the effects generator // setup the effects generator
effects.Setup(); effects.Setup();

View file

@ -318,7 +318,7 @@ class Boid {
//vertex(r, r*2); //vertex(r, r*2);
//endShape(); //endShape();
//popMatrix(); //popMatrix();
//matrix.drawBackgroundPixelRGB888(location.x, location.y, CRGB::Blue); //dma_display->drawBackgroundPixelRGB888(location.x, location.y, CRGB::Blue);
} }
}; };

View file

@ -38,7 +38,7 @@ public:
// a single frame should be drawn as fast as possible, without any delay or blocking // a single frame should be drawn as fast as possible, without any delay or blocking
// return how many millisecond delay is requested before the next call to drawFrame() // return how many millisecond delay is requested before the next call to drawFrame()
virtual unsigned int drawFrame() { virtual unsigned int drawFrame() {
matrix.fillScreen(0); dma_display->fillScreen(0);
//backgroundLayer.fillScreen({ 0, 0, 0 }); //backgroundLayer.fillScreen({ 0, 0, 0 });
return 0; return 0;
}; };

View file

@ -127,7 +127,7 @@ public:
} }
ClearFrame(); ClearFrame();
matrix.clearScreen(); //dma_display->clearScreen();
} }
~Effects(){ ~Effects(){
free(leds); free(leds);
@ -147,13 +147,13 @@ public:
void drawBackgroundFastLEDPixelCRGB(int16_t x, int16_t y, CRGB color) void drawBackgroundFastLEDPixelCRGB(int16_t x, int16_t y, CRGB color)
{ {
leds[XY(x, y)] = color; leds[XY(x, y)] = color;
//matrix.drawPixelRGB888(x, y, color.r, color.g, color.b); //dma_display->drawPixelRGB888(x, y, color.r, color.g, color.b);
} }
// write one pixel with the specified color from the current palette to coordinates // write one pixel with the specified color from the current palette to coordinates
void Pixel(int x, int y, uint8_t colorIndex) { void Pixel(int x, int y, uint8_t colorIndex) {
leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex); leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex);
//matrix.drawPixelRGB888(x, y, temp.r, temp.g, temp.b); // now draw it? //dma_display->drawPixelRGB888(x, y, temp.r, temp.g, temp.b); // now draw it?
} }
void PrepareFrame() { void PrepareFrame() {
@ -175,7 +175,7 @@ public:
for (int x=0; x<MATRIX_WIDTH; ++x){ for (int x=0; x<MATRIX_WIDTH; ++x){
//Serial.printf("Flushing x, y coord %d, %d\n", x, y); //Serial.printf("Flushing x, y coord %d, %d\n", x, y);
uint16_t _pixel = XY16(x,y); uint16_t _pixel = XY16(x,y);
matrix.drawPixelRGB888( x, y, leds[_pixel].r, leds[_pixel].g, leds[_pixel].b); dma_display->drawPixelRGB888( x, y, leds[_pixel].r, leds[_pixel].g, leds[_pixel].b);
} // end loop to copy fast led to the dma matrix } // end loop to copy fast led to the dma matrix
} }
} }
@ -734,13 +734,6 @@ public:
} }
} }
// write one pixel with the specified color from the current palette to coordinates
/*
void Pixel(int x, int y, uint8_t colorIndex) {
leds[XY(x, y)] = ColorFromCurrentPalette(colorIndex);
matrix.drawBackgroundPixelRGB888(x,y, leds[XY(x, y)]); // now draw it?
}
*/
CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) { CRGB ColorFromCurrentPalette(uint8_t index = 0, uint8_t brightness = 255, TBlendType blendType = LINEARBLEND) {
return ColorFromPalette(currentPalette, index, brightness, currentBlendType); return ColorFromPalette(currentPalette, index, brightness, currentBlendType);

View file

@ -188,7 +188,7 @@ class PatternCube : public Drawable {
{ {
e = edge + i; e = edge + i;
if (!e->visible) { if (!e->visible) {
matrix.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color); dma_display->drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
} }
} }
@ -200,7 +200,7 @@ class PatternCube : public Drawable {
e = edge + i; e = edge + i;
if (e->visible) if (e->visible)
{ {
matrix.drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color); dma_display->drawLine(screen[e->x].x, screen[e->x].y, screen[e->y].x, screen[e->y].y, color);
} }
} }

View file

@ -36,7 +36,7 @@ class PatternInvadersSmall : public Drawable {
} }
void start() { void start() {
matrix.fillScreen(0); dma_display->fillScreen(0);
} }
unsigned int drawFrame() { unsigned int drawFrame() {
@ -80,7 +80,7 @@ class PatternInvadersMedium : public Drawable {
} }
void start() { void start() {
matrix.fillScreen(0); dma_display->fillScreen(0);
} }
unsigned int drawFrame() { unsigned int drawFrame() {
@ -92,10 +92,10 @@ class PatternInvadersMedium : public Drawable {
if (random(0, 2) == 1) color = color1; if (random(0, 2) == 1) color = color1;
matrix.fillRect(x + (i * 2), y + (j * 2), x + (i * 2 + 1), y + (j * 2 + 1), color); dma_display->fillRect(x + (i * 2), y + (j * 2), x + (i * 2 + 1), y + (j * 2 + 1), color);
if (i < 2) if (i < 2)
matrix.fillRect(x + (8 - i * 2), y + (j * 2), x + (9 - i * 2), y + (j * 2 + 1), color); dma_display->fillRect(x + (8 - i * 2), y + (j * 2), x + (9 - i * 2), y + (j * 2 + 1), color);
} }
} }
@ -122,11 +122,11 @@ class PatternInvadersLarge : public Drawable {
} }
void start() { void start() {
matrix.fillScreen(0); dma_display->fillScreen(0);
} }
unsigned int drawFrame() { unsigned int drawFrame() {
matrix.fillScreen(0); dma_display->fillScreen(0);
CRGB color1 = effects.ColorFromCurrentPalette(random(0, 255)); CRGB color1 = effects.ColorFromCurrentPalette(random(0, 255));
@ -138,10 +138,10 @@ class PatternInvadersLarge : public Drawable {
color = color1; color = color1;
} }
matrix.fillRect(1 + x * 6, 1 + y * 6, 5 + x * 6, 5 + y * 6, color); dma_display->fillRect(1 + x * 6, 1 + y * 6, 5 + x * 6, 5 + y * 6, color);
if (x < 2) if (x < 2)
matrix.fillRect(1 + (4 - x) * 6, 1 + y * 6, 5 + (4 - x) * 6, 5 + y * 6, color); dma_display->fillRect(1 + (4 - x) * 6, 1 + y * 6, 5 + (4 - x) * 6, 5 + y * 6, color);
} }
} }

View file

@ -52,17 +52,17 @@ class PatternPulse : public Drawable {
} }
if (step == 0) { if (step == 0) {
matrix.drawCircle(centerX, centerY, step, effects.ColorFromCurrentPalette(hue)); dma_display->drawCircle(centerX, centerY, step, effects.ColorFromCurrentPalette(hue));
step++; step++;
} }
else { else {
if (step < maxSteps) { if (step < maxSteps) {
// initial pulse // initial pulse
matrix.drawCircle(centerX, centerY, step, effects.ColorFromCurrentPalette(hue, pow(fadeRate, step - 2) * 255)); dma_display->drawCircle(centerX, centerY, step, effects.ColorFromCurrentPalette(hue, pow(fadeRate, step - 2) * 255));
// secondary pulse // secondary pulse
if (step > 3) { if (step > 3) {
matrix.drawCircle(centerX, centerY, step - 3, effects.ColorFromCurrentPalette(hue, pow(fadeRate, step - 2) * 255)); dma_display->drawCircle(centerX, centerY, step - 3, effects.ColorFromCurrentPalette(hue, pow(fadeRate, step - 2) * 255));
} }
step++; step++;
} }

View file

@ -12,7 +12,7 @@ class PatternTest : public Drawable {
unsigned int drawFrame() { unsigned int drawFrame() {
matrix.fillScreen(matrix.color565(128, 0, 0)); dma_display->fillScreen(dma_display->color565(128, 0, 0));
return 1000; return 1000;
} }
}; };

View file

@ -27,16 +27,39 @@
#define CLK_PIN 16 #define CLK_PIN 16
/*--------------------- MATRIX LILBRARY CONFIG -------------------------*/
#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module.
#define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
#define PANEL_CHAIN 1 // Total number of panels chained one to another
MatrixPanel_I2S_DMA *dma_display = nullptr;
// Module configuration
HUB75_I2S_CFG mxconfig(
PANEL_RES_X, // module width
PANEL_RES_Y, // module height
PANEL_CHAIN // Chain length
);
/* /*
* Below is an is the 'legacy' way of initialising the MatrixPanel_I2S_DMA class. //Another way of creating config structure
* i.e. MATRIX_WIDTH and MATRIX_HEIGHT are modified by compile-time directives. //Custom pin mapping for all pins
* By default the library assumes a single 64x32 pixel panel is connected. HUB75_I2S_CFG::i2s_pins _pins={R1, G1, BL1, R2, G2, BL2, CH_A, CH_B, CH_C, CH_D, CH_E, LAT, OE, CLK};
* HUB75_I2S_CFG mxconfig(
* Refer to the example '2_PatternPlasma' on the new / correct way to setup this library 64, // width
* for different resolutions / panel chain lengths within the sketch 'setup()'. 64, // height
* 4, // chain length
_pins, // pin mapping
HUB75_I2S_CFG::FM6126A // driver chip
);
*/ */
MatrixPanel_I2S_DMA display; // RGB Panel
//mxconfig.gpio.e = -1; // Assign a pin if you have a 64x64 panel
//mxconfig.clkphase = false; // Change this if you have issues with ghosting.
//mxconfig.driver = HUB75_I2S_CFG::FM6126A; // Change this according to your pane.
/* /*
* Wifi Logo, generated with the following steps: * Wifi Logo, generated with the following steps:
@ -81,7 +104,7 @@ void drawXbm565(int x, int y, int width, int height, const char *xbm, uint16_t c
int targetX = (i * 8 + j) % width + x; int targetX = (i * 8 + j) % width + x;
int targetY = (8 * i / (width)) + y; int targetY = (8 * i / (width)) + y;
if (bitRead(charColumn, j)) { if (bitRead(charColumn, j)) {
display.drawPixel(targetX, targetY, color); dma_display->drawPixel(targetX, targetY, color);
} }
} }
} }
@ -148,19 +171,22 @@ void setup() {
/************** DISPLAY **************/ /************** DISPLAY **************/
Sprintln("...Starting Display"); Sprintln("...Starting Display");
display.begin(R1_PIN, G1_PIN, B1_PIN, R2_PIN, G2_PIN, B2_PIN, A_PIN, B_PIN, C_PIN, D_PIN, E_PIN, LAT_PIN, OE_PIN, CLK_PIN ); dma_display = new MatrixPanel_I2S_DMA(mxconfig);
dma_display->begin();
dma_display->setBrightness8(90); //0-255
dma_display->clearScreen();
display.fillScreen(display.color444(0, 1, 0)); dma_display->fillScreen(dma_display->color444(0, 1, 0));
// Fade a Red Wifi Logo In // Fade a Red Wifi Logo In
for (int r=0; r < 255; r++ ) for (int r=0; r < 255; r++ )
{ {
drawXbm565(0,0,64,32, wifi_image1bit, display.color565(r,0,0)); drawXbm565(0,0,64,32, wifi_image1bit, dma_display->color565(r,0,0));
delay(10); delay(10);
} }
delay(2000); delay(2000);
display.clearScreen(); dma_display->clearScreen();
} }
@ -173,6 +199,6 @@ void loop() {
current_icon = (current_icon +1 ) % num_icons; current_icon = (current_icon +1 ) % num_icons;
delay(2000); delay(2000);
display.clearScreen(); dma_display->clearScreen();
} }

View file

@ -20,6 +20,9 @@
* *
**************************************************************************/ **************************************************************************/
// PLEASE NOTE THIS EXAMPLE NO LONGER WORKS AS OF AUGUST 2021
// IT NEEDS TO BE UPDATED TO THE NEW WAY OF USING THE LIBRARY
// uncomment to use custom pins, then provide below // uncomment to use custom pins, then provide below
#define USE_CUSTOM_PINS #define USE_CUSTOM_PINS