From c66b592e9fcde0767aa8dc912100c25433c8c5db Mon Sep 17 00:00:00 2001 From: mrfaptastic <12006953+mrfaptastic@users.noreply.github.com> Date: Sat, 28 Jan 2023 21:54:09 +0000 Subject: It's 'COLOR' --- src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp | 131 +++++++++++++++----------------- 1 file changed, 62 insertions(+), 69 deletions(-) (limited to 'src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp') diff --git a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp index 4778c5b..b8fcf55 100644 --- a/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp +++ b/src/ESP32-HUB75-MatrixPanel-I2S-DMA.cpp @@ -23,29 +23,29 @@ #endif /* This library is designed to take an 8 bit / 1 byte value (0-255) for each R G B colour sub-pixel. - * The PIXEL_COLOUR_DEPTH_BITS should always be '8' as a result. + * The PIXEL_COLOR_DEPTH_BITS should always be '8' as a result. * However, if the library is to be used with lower colour depth (i.e. 6 bit colour), then we need to ensure the 8-bit value passed to the colour masking * is adjusted accordingly to ensure the LSB's are shifted left to MSB, by the difference. Otherwise the colours will be all screwed up. */ -#if PIXEL_COLOUR_DEPTH_BITS > 8 - #error "Color depth bits cannot be greater than 8." -#elif PIXEL_COLOUR_DEPTH_BITS < 2 +#if PIXEL_COLOR_DEPTH_BITS > 8 + #error "Colour depth bits cannot be greater than 8." +#elif PIXEL_COLOR_DEPTH_BITS < 2 #error "Colour depth bits cannot be less than 2." #endif -#if PIXEL_COLOUR_DEPTH_BITS != 8 - #define MASK_OFFSET (8 - PIXEL_COLOUR_DEPTH_BITS) +#if PIXEL_COLOR_DEPTH_BITS != 8 + #define MASK_OFFSET (8 - PIXEL_COLOR_DEPTH_BITS) #define PIXEL_COLOUR_MASK_BIT(colour_depth_index) (1 << (colour_depth_index + MASK_OFFSET)) - //static constexpr uint8_t const MASK_OFFSET = 8-PIXEL_COLOUR_DEPTH_BITS; + //static constexpr uint8_t const MASK_OFFSET = 8-PIXEL_COLOR_DEPTH_BITS; #else #define PIXEL_COLOUR_MASK_BIT(colour_depth_index) (1 << (colour_depth_index)) #endif /* - #if PIXEL_COLOUR_DEPTH_BITS < 8 + #if PIXEL_COLOR_DEPTH_BITS < 8 uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit colour (8 bits per RGB subpixel) #else - uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit color (8 bits per RGB subpixel) + uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit colour (8 bits per RGB subpixel) #endif */ @@ -65,11 +65,11 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory() size_t allocated_fb_memory = 0; for (int malloc_num =0; malloc_num < ROWS_PER_FRAME; ++malloc_num) { - auto ptr = std::make_shared(PIXELS_PER_ROW, PIXEL_COLOUR_DEPTH_BITS, m_cfg.double_buff); + auto ptr = std::make_shared(PIXELS_PER_ROW, PIXEL_COLOR_DEPTH_BITS, m_cfg.double_buff); if (ptr->data == nullptr) { - ESP_LOGE("I2S-DMA", "CRITICAL ERROR: Not enough memory for requested colour depth! Please reduce PIXEL_COLOUR_DEPTH_BITS value.\r\n"); + ESP_LOGE("I2S-DMA", "CRITICAL ERROR: Not enough memory for requested colour depth! Please reduce PIXEL_COLOR_DEPTH_BITS value.\r\n"); ESP_LOGE("I2S-DMA", "Could not allocate rowBitStruct %d!.\r\n", malloc_num); return false; @@ -83,7 +83,7 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory() ESP_LOGI("I2S-DMA", "Allocating %d bytes memory for DMA BCM framebuffer(s).", allocated_fb_memory); // calculate the lowest LSBMSB_TRANSITION_BIT value that will fit in memory that will meet or exceed the configured refresh rate -#if !defined(FORCE_COLOUR_DEPTH) +#if !defined(FORCE_COLOR_DEPTH) ESP_LOGI("I2S-DMA", "Minimum visual refresh rate (scan rate from panel top to bottom) requested: %d Hz", m_cfg.min_refresh_rate); @@ -92,11 +92,11 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory() int nsPerLatch = ((PIXELS_PER_ROW + CLKS_DURING_LATCH) * psPerClock) / 1000; // add time to shift out LSBs + LSB-MSB transition bit - this ignores fractions... - int nsPerRow = PIXEL_COLOUR_DEPTH_BITS * nsPerLatch; + int nsPerRow = PIXEL_COLOR_DEPTH_BITS * nsPerLatch; // add time to shift out MSBs - for(int i=lsbMsbTransitionBit + 1; i m_cfg.min_refresh_rate) break; - if(lsbMsbTransitionBit < PIXEL_COLOUR_DEPTH_BITS - 1) + if(lsbMsbTransitionBit < PIXEL_COLOR_DEPTH_BITS - 1) lsbMsbTransitionBit++; else break; @@ -126,7 +126,7 @@ bool MatrixPanel_I2S_DMA::allocateDMAmemory() * memory allocation of the DMA linked list memory structure. */ int numDMAdescriptorsPerRow = 1; - for(int i=lsbMsbTransitionBit + 1; isize() > DMA_MAX ) { - ESP_LOGW("I2S-DMA", "rowColorDepthStruct struct is too large, split DMA payload required. Adding %d DMA descriptors\n", PIXEL_COLOUR_DEPTH_BITS-1); + ESP_LOGW("I2S-DMA", "rowBits struct is too large to fit in one DMA transfer payload, splitting required. Adding %d DMA descriptors\n", PIXEL_COLOR_DEPTH_BITS-1); - numDMAdescriptorsPerRow += PIXEL_COLOUR_DEPTH_BITS-1; + numDMAdescriptorsPerRow += PIXEL_COLOR_DEPTH_BITS-1; // Note: If numDMAdescriptorsPerRow is even just one descriptor too large, DMA linked list will not correctly loop. } @@ -173,7 +173,7 @@ void MatrixPanel_I2S_DMA::configureDMA(const HUB75_I2S_CFG& _cfg) int current_dmadescriptor_offset = 0; // HACK: If we need to split the payload in 1/2 so that it doesn't breach DMA_MAX, lets do it by the colour_depth. - int num_dma_payload_colour_depths = PIXEL_COLOUR_DEPTH_BITS; + int num_dma_payload_colour_depths = PIXEL_COLOR_DEPTH_BITS; if ( dma_buff.rowBits[0]->size() > DMA_MAX ) { num_dma_payload_colour_depths = 1; } @@ -199,7 +199,7 @@ void MatrixPanel_I2S_DMA::configureDMA(const HUB75_I2S_CFG& _cfg) if ( dma_buff.rowBits[0]->size() > DMA_MAX ) { - for (int cd = 1; cd < PIXEL_COLOUR_DEPTH_BITS; cd++) + for (int cd = 1; cd < PIXEL_COLOR_DEPTH_BITS; cd++) { dma_bus.create_dma_desc_link(dma_buff.rowBits[row]->getDataPtr(cd, 0), dma_buff.rowBits[row]->size(num_dma_payload_colour_depths), false); @@ -213,7 +213,7 @@ void MatrixPanel_I2S_DMA::configureDMA(const HUB75_I2S_CFG& _cfg) } // row depth struct - for(int i=lsbMsbTransitionBit + 1; igetDataPtr(i, 0), dma_buff.rowBits[row]->size(PIXEL_COLOUR_DEPTH_BITS - i), false); + dma_bus.create_dma_desc_link(dma_buff.rowBits[row]->getDataPtr(i, 0), dma_buff.rowBits[row]->size(PIXEL_COLOR_DEPTH_BITS - i), false); if (m_cfg.double_buff) { - dma_bus.create_dma_desc_link(dma_buff.rowBits[row]->getDataPtr(i, 1), dma_buff.rowBits[row]->size(PIXEL_COLOUR_DEPTH_BITS - i), true ); + dma_bus.create_dma_desc_link(dma_buff.rowBits[row]->getDataPtr(i, 1), dma_buff.rowBits[row]->size(PIXEL_COLOR_DEPTH_BITS - i), true ); } current_dmadescriptor_offset++; @@ -311,7 +311,7 @@ void IRAM_ATTR MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint16_t x_coord, uint /* LED Brightness Compensation. Because if we do a basic "red & mask" for example, * we'll NEVER send the dimmest possible colour, due to binary skew. - * i.e. It's almost impossible for colour_depth_idx of 0 to be sent out to the MATRIX unless the 'value' of a color is exactly '1' + * i.e. It's almost impossible for colour_depth_idx of 0 to be sent out to the MATRIX unless the 'value' of a colour is exactly '1' * https://ledshield.wordpress.com/2012/11/13/led-brightness-to-your-eye-gamma-correction-no/ */ #ifndef NO_CIE1931 @@ -351,17 +351,10 @@ void IRAM_ATTR MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint16_t x_coord, uint } // Iterating through colour depth bits, which we assume are 8 bits per RGB subpixel (24bpp) - uint8_t colour_depth_idx = PIXEL_COLOUR_DEPTH_BITS; + uint8_t colour_depth_idx = PIXEL_COLOR_DEPTH_BITS; do { --colour_depth_idx; -/* -// uint8_t mask = (1 << (colour_depth_idx COLOR_DEPTH_LESS_THAN_8BIT_ADJUST)); // expect 24 bit colour (8 bits per RGB subpixel) - #if PIXEL_COLOUR_DEPTH_BITS < 8 - uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit colour (8 bits per RGB subpixel) - #else - uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit color (8 bits per RGB subpixel) - #endif -*/ + uint8_t mask = PIXEL_COLOUR_MASK_BIT(colour_depth_idx); uint16_t RGB_output_bits = 0; @@ -376,7 +369,7 @@ void IRAM_ATTR MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint16_t x_coord, uint // Get the contents at this address, - // it would represent a vector pointing to the full row of pixels for the specified color depth bit at Y coordinate + // it would represent a vector pointing to the full row of pixels for the specified colour depth bit at Y coordinate ESP32_I2S_DMA_STORAGE_TYPE *p = getRowDataPtr(y_coord, colour_depth_idx, back_buffer_id); @@ -404,13 +397,13 @@ void MatrixPanel_I2S_DMA::updateMatrixDMABuffer(uint8_t red, uint8_t green, uint blue = lumConvTab[blue]; #endif - for(uint8_t colour_depth_idx=0; colour_depth_idxcolour_depth; do { --colouridx; - // switch pointer to a row for a specific color index + // switch pointer to a row for a specific colour index row = dma_buff.rowBits[row_idx]->getDataPtr(colouridx, _buff_id); /* @@ -617,12 +610,12 @@ void MatrixPanel_I2S_DMA::brtCtrlOE(int brt, const bool _buff_id){ do { --row_idx; - // let's set OE control bits for specific pixels in each color_index subrows + // let's set OE control bits for specific pixels in each colour_index subrows uint8_t colouridx = dma_buff.rowBits[row_idx]->colour_depth; do { --colouridx; - // switch pointer to a row for a specific color index + // switch pointer to a row for a specific colour index ESP32_I2S_DMA_STORAGE_TYPE* row = dma_buff.rowBits[row_idx]->getDataPtr(colouridx, _buff_id); int x_coord = dma_buff.rowBits[row_idx]->width; @@ -668,7 +661,7 @@ void MatrixPanel_I2S_DMA::brtCtrlOE(int brt, const bool _buff_id){ } while(colouridx); - // switch pointer to a row for a specific color index + // switch pointer to a row for a specific colour index #if defined(SPIRAM_DMA_BUFFER) ESP32_I2S_DMA_STORAGE_TYPE* row_hack = dma_buff.rowBits[row_idx]->getDataPtr(colouridx, _buff_id); Cache_WriteBack_Addr((uint32_t)row_hack, sizeof(ESP32_I2S_DMA_STORAGE_TYPE) * ((dma_buff.rowBits[row_idx]->width * dma_buff.rowBits[row_idx]->colour_depth)-1)) ; @@ -698,10 +691,10 @@ void MatrixPanel_I2S_DMA::brtCtrlOEv2(uint8_t brt, const int _buff_id) { do { --row_idx; - // let's set OE control bits for specific pixels in each color_index subrows + // let's set OE control bits for specific pixels in each colour_index subrows uint8_t colouridx = dma_buff.rowBits[row_idx]->colour_depth; do { - // Multiply brightness according to index of bitplane (color index subrow) + // Multiply brightness according to index of bitplane (colour index subrow) // in respect of accumulating LED intensities with Binary-Coded Modulation: // bitplane 0 is 1/1 of total brightness; bitplane 1 is 1/2; bitplane 2 is 1/4, etc // accumulating all of them together means we will get only ~1/4 of the total brightness. @@ -717,7 +710,7 @@ void MatrixPanel_I2S_DMA::brtCtrlOEv2(uint8_t brt, const int _buff_id) { int brightness_in_x_pixels = (PIXELS_PER_ROW * brt) >> (8 + rightshift); --colouridx; - // switch pointer to a row for a specific color index + // switch pointer to a row for a specific colour index ESP32_I2S_DMA_STORAGE_TYPE* row = dma_buff.rowBits[row_idx]->getDataPtr(colouridx, _buff_id); int x_coord = dma_buff.rowBits[row_idx]->width; @@ -769,7 +762,7 @@ void MatrixPanel_I2S_DMA::brtCtrlOEv2(uint8_t brt, const int _buff_id) { } while(colouridx); - // switch pointer to a row for a specific color index + // switch pointer to a row for a specific colour index #if defined(SPIRAM_DMA_BUFFER) ESP32_I2S_DMA_STORAGE_TYPE* row_hack = dma_buff.rowBits[row_idx]->getDataPtr(colouridx, _buff_id); Cache_WriteBack_Addr((uint32_t)row_hack, sizeof(ESP32_I2S_DMA_STORAGE_TYPE) * ((dma_buff.rowBits[row_idx]->width * dma_buff.rowBits[row_idx]->colour_depth)-1)) ; @@ -828,7 +821,7 @@ uint8_t MatrixPanel_I2S_DMA::setLatBlanking(uint8_t pulses){ * @param x_coord - line start coordinate x * @param y_coord - line start coordinate y * @param l - line length - * @param r,g,b, - RGB888 color + * @param r,g,b, - RGB888 colour */ void MatrixPanel_I2S_DMA::hlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, uint8_t red, uint8_t green, uint8_t blue){ if ( !initialized ) @@ -858,18 +851,18 @@ void MatrixPanel_I2S_DMA::hlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, y_coord -= ROWS_PER_FRAME; } - // Iterating through color depth bits (8 iterations) - uint8_t colour_depth_idx = PIXEL_COLOUR_DEPTH_BITS; + // Iterating through colour depth bits (8 iterations) + uint8_t colour_depth_idx = PIXEL_COLOR_DEPTH_BITS; do { --colour_depth_idx; // let's precalculate RGB1 and RGB2 bits than flood it over the entire DMA buffer uint16_t RGB_output_bits = 0; // uint8_t mask = (1 << colour_depth_idx COLOR_DEPTH_LESS_THAN_8BIT_ADJUST); - // #if PIXEL_COLOUR_DEPTH_BITS < 8 - // uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit color (8 bits per RGB subpixel) + // #if PIXEL_COLOR_DEPTH_BITS < 8 + // uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit colour (8 bits per RGB subpixel) // #else - // uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit color (8 bits per RGB subpixel) + // uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit colour (8 bits per RGB subpixel) // #endif uint8_t mask = PIXEL_COLOUR_MASK_BIT(colour_depth_idx); @@ -880,10 +873,10 @@ void MatrixPanel_I2S_DMA::hlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, RGB_output_bits |= (bool)(green & mask); // -BG RGB_output_bits <<= 1; RGB_output_bits |= (bool)(red & mask); // BGR - RGB_output_bits <<= _colourbitoffset; // shift color bits to the required position + RGB_output_bits <<= _colourbitoffset; // shift colour bits to the required position // Get the contents at this address, - // it would represent a vector pointing to the full row of pixels for the specified color depth bit at Y coordinate + // it would represent a vector pointing to the full row of pixels for the specified colour depth bit at Y coordinate ESP32_I2S_DMA_STORAGE_TYPE *p = dma_buff.rowBits[y_coord]->getDataPtr(colour_depth_idx, back_buffer_id); // inlined version works slower here, dunno why :( // ESP32_I2S_DMA_STORAGE_TYPE *p = getRowDataPtr(y_coord, colour_depth_idx, back_buffer_id); @@ -903,10 +896,10 @@ void MatrixPanel_I2S_DMA::hlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, */ uint16_t &v = p[ESP32_TX_FIFO_POSITION_ADJUST(_x)]; - v &= _colourbitclear; // reset color bits - v |= RGB_output_bits; // set new color bits + v &= _colourbitclear; // reset colour bits + v |= RGB_output_bits; // set new colour bits } while(_l); // iterate pixels in a row - } while(colour_depth_idx); // end of color depth loop (8) + } while(colour_depth_idx); // end of colour depth loop (8) } // hlineDMA() @@ -915,7 +908,7 @@ void MatrixPanel_I2S_DMA::hlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, * @param x_coord - line start coordinate x * @param y_coord - line start coordinate y * @param l - line length - * @param r,g,b, - RGB888 color + * @param r,g,b, - RGB888 colour */ void MatrixPanel_I2S_DMA::vlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, uint8_t red, uint8_t green, uint8_t blue){ if ( !initialized ) @@ -944,16 +937,16 @@ void MatrixPanel_I2S_DMA::vlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, */ x_coord = ESP32_TX_FIFO_POSITION_ADJUST(x_coord); - uint8_t colour_depth_idx = PIXEL_COLOUR_DEPTH_BITS; - do { // Iterating through color depth bits (8 iterations) + uint8_t colour_depth_idx = PIXEL_COLOR_DEPTH_BITS; + do { // Iterating through colour depth bits (8 iterations) --colour_depth_idx; // let's precalculate RGB1 and RGB2 bits than flood it over the entire DMA buffer // uint8_t mask = (1 << colour_depth_idx COLOR_DEPTH_LESS_THAN_8BIT_ADJUST); - // #if PIXEL_COLOUR_DEPTH_BITS < 8 - // uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit color (8 bits per RGB subpixel) + // #if PIXEL_COLOR_DEPTH_BITS < 8 + // uint8_t mask = (1 << (colour_depth_idx+MASK_OFFSET)); // expect 24 bit colour (8 bits per RGB subpixel) // #else - // uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit color (8 bits per RGB subpixel) + // uint8_t mask = (1 << (colour_depth_idx)); // expect 24 bit colour (8 bits per RGB subpixel) // #endif uint8_t mask = PIXEL_COLOUR_MASK_BIT(colour_depth_idx); @@ -978,7 +971,7 @@ void MatrixPanel_I2S_DMA::vlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, } // Get the contents at this address, - // it would represent a vector pointing to the full row of pixels for the specified color depth bit at Y coordinate + // it would represent a vector pointing to the full row of pixels for the specified colour depth bit at Y coordinate //ESP32_I2S_DMA_STORAGE_TYPE *p = getRowDataPtr(_y, colour_depth_idx, back_buffer_id); ESP32_I2S_DMA_STORAGE_TYPE *p = dma_buff.rowBits[_y]->getDataPtr(colour_depth_idx, back_buffer_id); @@ -986,7 +979,7 @@ void MatrixPanel_I2S_DMA::vlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, p[x_coord] |= RGB_output_bits; // set new RGB bits ++_y; } while(++_l!=l); // iterate pixels in a col - } while(colour_depth_idx); // end of color depth loop (8) + } while(colour_depth_idx); // end of colour depth loop (8) } // vlineDMA() @@ -995,9 +988,9 @@ void MatrixPanel_I2S_DMA::vlineDMA(int16_t x_coord, int16_t y_coord, int16_t l, * this works much faster than multiple consecutive per-pixel calls to updateMatrixDMABuffer() * @param int16_t x, int16_t y - coordinates of a top-left corner * @param int16_t w, int16_t h - width and height of a rectangular, min is 1 px - * @param uint8_t r - RGB888 color - * @param uint8_t g - RGB888 color - * @param uint8_t b - RGB888 color + * @param uint8_t r - RGB888 colour + * @param uint8_t g - RGB888 colour + * @param uint8_t b - RGB888 colour */ void MatrixPanel_I2S_DMA::fillRectDMA(int16_t x, int16_t y, int16_t w, int16_t h, uint8_t r, uint8_t g, uint8_t b){ -- cgit v1.3.1