From c425b9caa703c92f6181ae6d4b315ca2f803eb68 Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Tue, 8 Dec 2020 08:10:35 +0000 Subject: [PATCH] Minor cleanup Minor cleanup to the contribution made by @vortigont . Move some of the special constants into specific #defined constants. --- ESP32-HUB75-MatrixPanel-I2S-DMA.cpp | 56 ++++++++++++++++++----------- ESP32-HUB75-MatrixPanel-I2S-DMA.h | 11 +++--- 2 files changed, 42 insertions(+), 25 deletions(-) diff --git a/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp b/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp index 97a9386..3bb51df 100644 --- a/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp +++ b/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp @@ -503,14 +503,14 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t y_coord if (painting_top_frame) { // Need to copy what the RGB status is for the bottom pixels - v &= BITSMASK_RGB1; // reset R1G1B1 bits + v &= BITMASK_RGB1_CLEAR; // reset R1G1B1 bits // Set the color of the pixel of interest if (green & mask) { v|=BIT_G1; } if (blue & mask) { v|=BIT_B1; } if (red & mask) { v|=BIT_R1; } } else { // Do it the other way around - v &= BITSMASK_RGB2; // reset R2G2B2 bits + v &= BITMASK_RGB2_CLEAR; // reset R2G2B2 bits // Color to set if (red & mask) { v|=BIT_R2; } if (green & mask) { v|=BIT_G2; } @@ -521,9 +521,10 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t y_coord continue; // update address/control bits - v &= BITSMASK_CTRL; // reset ABCDE,EO,LAT address bits + v &= BITMASK_CTRL_CLEAR; // reset ABCDE,EO,LAT address bits + uint16_t _y = color_depth_idx ? y_coord : y_coord -1; - v|=_y<<8; // shift row coord to match ABCDE bits from 8 to 12 and set bitvector + v|=_y << BITS_ADDR_OFFSET; // shift row coord to match ABCDE bits from bit positions 8 to 12 and set bitvector // drive latch while shifting out last bit of RGB data if((x_coord) == PIXELS_PER_ROW-1) v|=BIT_LAT; @@ -572,16 +573,21 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint8_t red, uint8_t green, uint for(uint8_t color_depth_idx=0; color_depth_idxdata[(x_coord % 2) ? (x_coord-1):(x_coord+1)]; // take reference to bit vector - v &= BITSMASK_RGB12; // reset color bits - v |= RGBbitfield; // set new color bits + v &= BITMASK_RGB12_CLEAR; // reset color bits + v |= RGB_output_bits; // set new color bits } + } else { + // Set ABCDE address bits vector uint16_t _y = color_depth_idx ? matrix_frame_parallel_row : matrix_frame_parallel_row -1; - _y <<=8; // shift row y-coord to match ABCDE bits in vector from 8 to 12 + _y <<= BITS_ADDR_OFFSET; // shift row y-coord to match ABCDE bits in vector from 8 to 12 - for(uint16_t x_coord=0; x_coord < MATRIX_WIDTH; x_coord++){ - uint16_t &v = p->data[(x_coord % 2) ? (x_coord-1):(x_coord+1)]; // persist what we already have - v = RGBbitfield; // set colot bits and reset all others - v|=_y; // set ABCDE address bits for current row + for(uint16_t x_coord=0; x_coord < MATRIX_WIDTH; x_coord++) { + + // We need to update the correct uint16_t in the rowBitStruct array, that gets sent out in parallel + // 16 bit parallel mode - Save the calculated value to the bitplane memory in reverse order to account for I2S Tx FIFO mode1 ordering + uint16_t rowBitStruct_x_coord_uint16_t_position = (x_coord % 2) ? (x_coord-1):(x_coord+1); + + uint16_t &v = p->data[rowBitStruct_x_coord_uint16_t_position]; // persist what we already have + v = RGB_output_bits; // set colot bits and reset all others + v|=_y; // set ABCDE address bits for current row // drive latch while shifting out last bit of RGB data if((x_coord) == PIXELS_PER_ROW-1) v|=BIT_LAT; diff --git a/ESP32-HUB75-MatrixPanel-I2S-DMA.h b/ESP32-HUB75-MatrixPanel-I2S-DMA.h index ccb517c..31a65f8 100644 --- a/ESP32-HUB75-MatrixPanel-I2S-DMA.h +++ b/ESP32-HUB75-MatrixPanel-I2S-DMA.h @@ -84,11 +84,13 @@ /* Do not change. */ // Panel Upper half RGB (numbering according to order in DMA gpio_bus configuration) +#define BITS_RGB1_OFFSET 0 // Start point of RGB_X1 bits #define BIT_R1 (1<<0) #define BIT_G1 (1<<1) #define BIT_B1 (1<<2) // Panel Lower half RGB +#define BITS_RGB2_OFFSET 3 // Start point of RGB_X2 bits #define BIT_R2 (1<<3) #define BIT_G2 (1<<4) #define BIT_B2 (1<<5) @@ -98,16 +100,17 @@ #define BIT_OE (1<<7) // Panel GPIO Pin Addresses (A, B, C, D etc..) +#define BITS_ADDR_OFFSET 8 // Start point of address bits #define BIT_A (1<<8) #define BIT_B (1<<9) #define BIT_C (1<<10) #define BIT_D (1<<11) #define BIT_E (1<<12) -#define BITSMASK_RGB1 (0xfff8) // inverted bitmask for R1G1B1 bit in pixel vector -#define BITSMASK_RGB2 (0xffc7) // inverted bitmask for R2G2B2 bit in pixel vector -#define BITSMASK_RGB12 (0xffc0) // inverted bitmask for R1G1B1R2G2B2 bit in pixel vector -#define BITSMASK_CTRL (0xe03f) // inverted bitmask for control bits ABCDE,LAT,OE in pixel vector +#define BITMASK_RGB1_CLEAR (0xfff8) // inverted bitmask for R1G1B1 bit in pixel vector +#define BITMASK_RGB2_CLEAR (0xffc7) // inverted bitmask for R2G2B2 bit in pixel vector +#define BITMASK_RGB12_CLEAR (0xffc0) // inverted bitmask for R1G1B1R2G2B2 bit in pixel vector +#define BITMASK_CTRL_CLEAR (0xe03f) // inverted bitmask for control bits ABCDE,LAT,OE in pixel vector // RGB Panel Constants / Calculated Values #define COLOR_CHANNELS_PER_PIXEL 3