Minor cleanup
Minor cleanup to the contribution made by @vortigont . Move some of the special constants into specific #defined constants.
This commit is contained in:
parent
09dabb2e35
commit
c425b9caa7
2 changed files with 42 additions and 25 deletions
|
@ -503,14 +503,14 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t y_coord
|
||||||
|
|
||||||
if (painting_top_frame)
|
if (painting_top_frame)
|
||||||
{ // Need to copy what the RGB status is for the bottom pixels
|
{ // 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
|
// Set the color of the pixel of interest
|
||||||
if (green & mask) { v|=BIT_G1; }
|
if (green & mask) { v|=BIT_G1; }
|
||||||
if (blue & mask) { v|=BIT_B1; }
|
if (blue & mask) { v|=BIT_B1; }
|
||||||
if (red & mask) { v|=BIT_R1; }
|
if (red & mask) { v|=BIT_R1; }
|
||||||
|
|
||||||
} else { // Do it the other way around
|
} else { // Do it the other way around
|
||||||
v &= BITSMASK_RGB2; // reset R2G2B2 bits
|
v &= BITMASK_RGB2_CLEAR; // reset R2G2B2 bits
|
||||||
// Color to set
|
// Color to set
|
||||||
if (red & mask) { v|=BIT_R2; }
|
if (red & mask) { v|=BIT_R2; }
|
||||||
if (green & mask) { v|=BIT_G2; }
|
if (green & mask) { v|=BIT_G2; }
|
||||||
|
@ -521,9 +521,10 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(int16_t x_coord, int16_t y_coord
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// update address/control bits
|
// 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;
|
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
|
// drive latch while shifting out last bit of RGB data
|
||||||
if((x_coord) == PIXELS_PER_ROW-1) v|=BIT_LAT;
|
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_idx<PIXEL_COLOR_DEPTH_BITS; color_depth_idx++) // color depth - 8 iterations
|
for(uint8_t color_depth_idx=0; color_depth_idx<PIXEL_COLOR_DEPTH_BITS; color_depth_idx++) // color depth - 8 iterations
|
||||||
{
|
{
|
||||||
// let's precalculate RGB1 and RGB2 bits than flood it over the entire DMA buffer
|
// let's precalculate RGB1 and RGB2 bits than flood it over the entire DMA buffer
|
||||||
uint16_t RGBbitfield = 0;
|
uint16_t RGB_output_bits = 0;
|
||||||
uint8_t mask = (1 << color_depth_idx); // 24 bit color
|
uint8_t mask = (1 << color_depth_idx); // 24 bit color
|
||||||
|
|
||||||
RGBbitfield |= (bool)(blue & mask);
|
/* Per the .h file, the order of the output RGB bits is:
|
||||||
RGBbitfield <<= 1;
|
* BIT_B2, BIT_G2, BIT_R2, BIT_B1, BIT_G1, BIT_R1 */
|
||||||
RGBbitfield |= (bool)(green & mask);
|
RGB_output_bits |= (bool)(blue & mask); // --B
|
||||||
RGBbitfield <<= 1;
|
RGB_output_bits <<= 1;
|
||||||
RGBbitfield |= (bool)(red & mask);
|
RGB_output_bits |= (bool)(green & mask); // -BG
|
||||||
RGBbitfield |= RGBbitfield << 3; // now we should have 6 bits of RGB suitable for DMA buffer
|
RGB_output_bits <<= 1;
|
||||||
//Serial.printf("Fill with: 0x%#06x\n", RGBbitfield);
|
RGB_output_bits |= (bool)(red & mask); // BGR
|
||||||
|
|
||||||
|
// Duplicate and shift across so we have have 6 populated bits of RGB1 and RGB2 pin values suitable for DMA buffer
|
||||||
|
RGB_output_bits |= RGB_output_bits << BITS_RGB2_OFFSET; //BGRBGR
|
||||||
|
|
||||||
|
//Serial.printf("Fill with: 0x%#06x\n", RGB_output_bits);
|
||||||
|
|
||||||
// iterate rows
|
// iterate rows
|
||||||
for (uint16_t matrix_frame_parallel_row = 0; matrix_frame_parallel_row < ROWS_PER_FRAME; matrix_frame_parallel_row++) // half height - 16 iterations
|
for (uint16_t matrix_frame_parallel_row = 0; matrix_frame_parallel_row < ROWS_PER_FRAME; matrix_frame_parallel_row++) // half height - 16 iterations
|
||||||
|
@ -594,19 +600,27 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint8_t red, uint8_t green, uint
|
||||||
|
|
||||||
// iterate pixels in a row
|
// iterate pixels in a row
|
||||||
if (fastmode){
|
if (fastmode){
|
||||||
for(uint16_t x_coord=0; x_coord < MATRIX_WIDTH; x_coord++){
|
|
||||||
|
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)]; // take reference to bit vector
|
uint16_t &v = p->data[(x_coord % 2) ? (x_coord-1):(x_coord+1)]; // take reference to bit vector
|
||||||
v &= BITSMASK_RGB12; // reset color bits
|
v &= BITMASK_RGB12_CLEAR; // reset color bits
|
||||||
v |= RGBbitfield; // set new color bits
|
v |= RGB_output_bits; // set new color bits
|
||||||
}
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
// Set ABCDE address bits vector
|
// Set ABCDE address bits vector
|
||||||
uint16_t _y = color_depth_idx ? matrix_frame_parallel_row : matrix_frame_parallel_row -1;
|
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++){
|
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
|
// 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
|
v|=_y; // set ABCDE address bits for current row
|
||||||
|
|
||||||
// drive latch while shifting out last bit of RGB data
|
// drive latch while shifting out last bit of RGB data
|
||||||
|
|
|
@ -84,11 +84,13 @@
|
||||||
/* Do not change. */
|
/* Do not change. */
|
||||||
|
|
||||||
// Panel Upper half RGB (numbering according to order in DMA gpio_bus configuration)
|
// 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_R1 (1<<0)
|
||||||
#define BIT_G1 (1<<1)
|
#define BIT_G1 (1<<1)
|
||||||
#define BIT_B1 (1<<2)
|
#define BIT_B1 (1<<2)
|
||||||
|
|
||||||
// Panel Lower half RGB
|
// Panel Lower half RGB
|
||||||
|
#define BITS_RGB2_OFFSET 3 // Start point of RGB_X2 bits
|
||||||
#define BIT_R2 (1<<3)
|
#define BIT_R2 (1<<3)
|
||||||
#define BIT_G2 (1<<4)
|
#define BIT_G2 (1<<4)
|
||||||
#define BIT_B2 (1<<5)
|
#define BIT_B2 (1<<5)
|
||||||
|
@ -98,16 +100,17 @@
|
||||||
#define BIT_OE (1<<7)
|
#define BIT_OE (1<<7)
|
||||||
|
|
||||||
// Panel GPIO Pin Addresses (A, B, C, D etc..)
|
// 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_A (1<<8)
|
||||||
#define BIT_B (1<<9)
|
#define BIT_B (1<<9)
|
||||||
#define BIT_C (1<<10)
|
#define BIT_C (1<<10)
|
||||||
#define BIT_D (1<<11)
|
#define BIT_D (1<<11)
|
||||||
#define BIT_E (1<<12)
|
#define BIT_E (1<<12)
|
||||||
|
|
||||||
#define BITSMASK_RGB1 (0xfff8) // inverted bitmask for R1G1B1 bit in pixel vector
|
#define BITMASK_RGB1_CLEAR (0xfff8) // inverted bitmask for R1G1B1 bit in pixel vector
|
||||||
#define BITSMASK_RGB2 (0xffc7) // inverted bitmask for R2G2B2 bit in pixel vector
|
#define BITMASK_RGB2_CLEAR (0xffc7) // inverted bitmask for R2G2B2 bit in pixel vector
|
||||||
#define BITSMASK_RGB12 (0xffc0) // inverted bitmask for R1G1B1R2G2B2 bit in pixel vector
|
#define BITMASK_RGB12_CLEAR (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_CTRL_CLEAR (0xe03f) // inverted bitmask for control bits ABCDE,LAT,OE in pixel vector
|
||||||
|
|
||||||
// RGB Panel Constants / Calculated Values
|
// RGB Panel Constants / Calculated Values
|
||||||
#define COLOR_CHANNELS_PER_PIXEL 3
|
#define COLOR_CHANNELS_PER_PIXEL 3
|
||||||
|
|
Loading…
Reference in a new issue