cancel
Showing results for 
Search instead for 
Did you mean: 

TouchGFX gray 4 to RGB565

KRega.1
Associate II

I'm using TouchGfx in Gray 4 mode. I have read the GFX documentation and I can't find the answer. I can't figure out how the data is stored in RAM. Consequently, I need to convert this Gray 4 to RGB565 to my FMC 16bit 8080 TFT-LCD. Any ideas how to do this? or additional references I should be reading? I'm using a 480 x 854 LCD.

Here is a failed attempt..

void TouchGFXHAL::copyFrameBufferBlockToLCD(const Rect rect)
{
    __IO uint16_t* ptr;
    int16_t row;
 
    // For Gray4 only 4 bits per pixel
    for (row = 0; row < (rect.width) ; row++)
    {
        ptr = getClientFrameBuffer() + rect.y + (row+ rect.x)  * 120;    // 480 x 854 LCD
        LCD_IO_WriteMultipleDataGrey4((uint16_t*)ptr, 120);
    }   
}
 
 
  void LCD_IO_WriteMultipleDataGrey4(uint16_t* pData, uint32_t Size)
    {
        uint32_t  i;
 
        for (i = 0; i < Size; i++)
        { //			R 5bits					G 6bits                    B 5 bits
           FMC_BANK1_WriteData( ((pData[i]&0xF000)<<0) | ((pData[i]&0xF000)>>5) | ((pData[i]&0xF000)>>12) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x0F00)<<4) | ((pData[i]&0x0F00)>>0) | ((pData[i]&0x0F00)>>8) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x00F0)<<8) | ((pData[i]&0x00F0)<<5) | ((pData[i]&0x00F0)>>4) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x000F)<<12) | ((pData[i]&0x000F)<<10) | ((pData[i]&0x000F)>>0) );
        }
    }

3 REPLIES 3
MM..1
Chief II

Your shifting nums >> << isnt right, check 😁

        for (i = 0; i < Size; i++)
        { //							R 5bits					G 6bits                    B 5 bits
           FMC_BANK1_WriteData( ((pData[i]&0xF000)<<0) | ((pData[i]&0xF000)>>5) | ((pData[i]&0xF000)>>11) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x0F00)<<4) | ((pData[i]&0x0F00)>>1) | ((pData[i]&0x0F00)>>7) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x00F0)<<8) | ((pData[i]&0x00F0)<<3) | ((pData[i]&0x00F0)>>3) );
 
           FMC_BANK1_WriteData( ((pData[i]&0x000F)<<12) | ((pData[i]&0x000F)<<7) | ((pData[i]&0x000F)<<1) );
           
        }

ok this is correct now, right?

Thanks, Kevin

Seems right now, and too exist second choice use DMA2D L4 CLUT conversion for offload MCU. This enable choice some colors not only gray...