Skip to content

Please factor out matrix definition in all example code in external matrix_defines.h file (or equivalent) #887

@marcmerlin

Description

@marcmerlin

Virtually all the hardware libs I've worked with, including this one, duplicate panel config in every code example, and they're usually not in sync.
It's also annoying because once you modify them you can't git pull updates unless you git stash your local panel changes.
It's also a bit unnecessary to have everyone duplicate the effort of figuring it pin definitions for standard boards.

My own lib that includes all the other ones, uses a pretty big neomatrix_config.h that you set once, and everything uses it. You only change one file and everything else follows and just works.
It's a bit "big" because of how many hardware config it supports, but for example:
https://github.com/marcmerlin/FastLED_NeoMatrix_SmartMatrix_LEDMatrix_GFX_Demos/blob/master/neomatrix_config.h

In the case of this lib, I propose you simply factor out something like this and then make all demo code include this new file. This will make everyone's lives (including yours :) ) simpler. My new personal config now also supports setting up ifdefs when using make(1) builds so you can define all your configs in that common .h, and activate the one you're trying to use at build time without having to change the definition file. You don't need to actually do this, but by factoring out the config, the end user can do those ifdefs in that new file, getting to as complex a level as they need.

// Step 1) Provide the size of each individual physical panel LED Matrix panel that is chained (or not) together
#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. 
#define PANEL_RES_Y 64 // Number of pixels tall of each INDIVIDUAL panel module.

// Step 2) Provide details of the physical panel chaining that is in place.
#define NUM_ROWS 1 // Number of rows of chained INDIVIDUAL PANELS
#define NUM_COLS 1 // Number of INDIVIDUAL PANELS per ROW
#define PANEL_CHAIN NUM_ROWS*NUM_COLS    // total number of panels chained one to another

// Step 3) How are the panels chained together?
#define PANEL_CHAIN_TYPE CHAIN_TOP_RIGHT_DOWN

// Refer to: https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/tree/master/examples/VirtualMatrixPanel
//      and: https://github.com/mrcodetastic/ESP32-HUB75-MatrixPanel-DMA/blob/master/doc/VirtualMatrixPanel.pdf

// Virtual Panel dimensions - our combined panel would be a square 4x4 modules with a combined resolution of 128x128 pixels
#define VPANEL_W PANEL_RES_X*NUM_COLS 
#define VPANEL_H PANEL_RES_Y*NUM_ROWS
#define MATRIX_WIDTH VPANEL_W
#define MATRIX_HEIGHT VPANEL_H

#ifdef mapping1
    // custom pin mapping (this one is Adafruit Matrixportal ESP32S3)
    #define R1 42
    #define G1 41
    #define B1 40
    #define R2 38
    #define G2 39
    #define B2 37
    #define CH_A 45
    #define CH_B 36
    #define CH_C 48
    #define CH_D 35
    #define CH_E 21
    #define CLK 2
    #define LAT 47
    #define OE  14
#elif defined(mapping2)
(...)
#endif

My own config also factors out the matrix building in setup in that same file since it's always the same code, but that one I'll leave up to you whether it makes sense to you, or not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions