Skip to main content
KRega.1
Associate III
June 8, 2021
Question

TouchGFX gray 4 to RGB565

  • June 8, 2021
  • 3 replies
  • 1023 views

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) );
 }
 }

This topic has been closed for replies.

3 replies

MM..1
Super User
June 9, 2021

Your shifting nums >> << isnt right, check :beaming_face_with_smiling_eyes:

KRega.1
KRega.1Author
Associate III
June 9, 2021
 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

MM..1
Super User
June 10, 2021

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