Some words about FM612X setup performance with ESP32

It’s just a reminder.

If matrix panels drived by FM612X chip, the library has slow setup process because of SMARTMATRIX_OPTIONS_FM6126A_RESET_AT_START. In my case with 14 panels (32x16, 4 scan mode), begin() calling costs 7000+ms.

Look into the function
void SmartMatrix3RefreshMultiplexed<refreshDepth, matrixWidth, matrixHeight, panelType, optionFlags>::begin(uint32_t dmaRamToKeepFreeBytes)

where there are many delay(1) calling in two loops., such as:

        // Send Data to control register 11
        for(int i=0; i<PIXELS_PER_LATCH; i++) {
            int y=i%16;
            gpio_set_level(R1_PIN, 0);
            gpio_set_level(G1_PIN, 0);
            gpio_set_level(B1_PIN, 0);
            gpio_set_level(R2_PIN, 0);
            gpio_set_level(G2_PIN, 0);
            gpio_set_level(B2_PIN, 0);

            if(C12[y] == 1) {
                gpio_set_level(R1_PIN, 1);
                gpio_set_level(G1_PIN, 1);
                gpio_set_level(B1_PIN, 1);
                gpio_set_level(R2_PIN, 1);
                gpio_set_level(G2_PIN, 1);
                gpio_set_level(B2_PIN, 1);                
            }

            delay(1);

            if(i > PIXELS_PER_LATCH-12)
                gpio_set_level(LAT_PIN, 1);
            else
                gpio_set_level(LAT_PIN, 0);

            delay(1);

#ifdef CLK_MANUAL_PIN        
            gpio_set_level(CLK_MANUAL_PIN, 1);
            gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
            gpio_set_level(CLK_PIN, 1);
            delay(1);
            gpio_set_level(CLK_PIN, 0);
            delay(1);
        }

So, when you have a bigger matrix, you suffer a long loop for PIXELS_PER_LATCH for this macro.

#define PIXELS_PER_LATCH ((matrixWidth * matrixHeight) / MATRIX_PANEL_HEIGHT * PHYSICAL_ROWS_PER_REFRESH_ROW)

That is, to comment out delay(1); will improve performance at the beginning.

The macro

#define PIXELS_PER_LATCH ((matrixWidth * matrixHeight) / MATRIX_PANEL_HEIGHT * PHYSICAL_ROWS_PER_REFRESH_ROW)

will evaluate as 32 * 14 * 2 = 896 in case of your 14 (32x16) panels. So it’s unlikely that it gives 7000ms latency.
But I agree that delay 1ms after each register writing is too long, I would recommend to use delayMicroseconds(x) instead where x = 1…10

@b707 In my case, PIXELS_PER_LATCH is 1792 because panel is in 4-scan mode.

As codes say, for fm612x case, two registers (C12 and C13) need to be set. The following is to set C13:

        for(int i=0; i<PIXELS_PER_LATCH; i++) {
            int y=i%16;
            gpio_set_level(R1_PIN, 0);
            gpio_set_level(G1_PIN, 0);
            gpio_set_level(B1_PIN, 0);
            gpio_set_level(R2_PIN, 0);
            gpio_set_level(G2_PIN, 0);
            gpio_set_level(B2_PIN, 0);

            if(C13[y] == 1) {
                gpio_set_level(R1_PIN, 1);
                gpio_set_level(G1_PIN, 1);
                gpio_set_level(B1_PIN, 1);
                gpio_set_level(R2_PIN, 1);
                gpio_set_level(G2_PIN, 1);
                gpio_set_level(B2_PIN, 1);                
            }

            delay(1);

            if(i > PIXELS_PER_LATCH-13)
                gpio_set_level(LAT_PIN, 1);
            else
                gpio_set_level(LAT_PIN, 0);

            delay(1);

#ifdef CLK_MANUAL_PIN        
            gpio_set_level(CLK_MANUAL_PIN, 1);
            gpio_set_level(CLK_MANUAL_PIN, 0);
#endif
            gpio_set_level(CLK_PIN, 1);
            delay(1);
            gpio_set_level(CLK_PIN, 0);
            delay(1);
        }

delay(1) is called 4 times in a loop. So 7000ms delay is expected.

Your recommendation to use delayMicroseconds is an good option.