This section is to explain how you may access LT768x SDRAM, and retrieve the pixel data of a designated location.
Following is the related function:
/*---------------------------------------------------------------------------------------*/
/* Function: MPU8_Memory_Read_Pixel */
/* */
/* Parameters: */
/* x: x coordinate */
/* y: y coordinate */
/* Returns: One pixel data */
/* Description: MCU read a pixel data from the designated location of LT768x SDRAM */
/*---------------------------------------------------------------------------------------*/
u16 MPU8_Memory_Read_Pixel
(
unsigned short x
,unsigned short y
)
{
int pixelData; // The pixel data to be read
// Setup the designated location -> Modify these settings to a different location by needs
Canvas_Image_Start_address(0);
Active_Window_XY(0,0);
Active_Window_WH(LCD_XSIZE_TFT,LCD_YSIZE_TFT);
Goto_Pixel_XY(x,y);
LCD_CmdWrite(0x04); // Memory Read/Write Data Port (MRWDP)
LCD_DataRead(); // Send a dummy cycle
while((LCD_StatusRead()&0x20) == 0x00) { /* Check if Memory Read FIFO is ready */ }
pixelData = LCD_DataRead(); // Read the first byte - lower byte
pixelData = pixelData | LCD_DataRead() << 8; //(1) The first byte read is the lower byte
//(2) The second byte read is the higher byte
return pixelData;
}
The above function allows developers to retrieve one pixel data from LT768x SDRAM.
To do so, there are several steps that need to be proceeded:
(1) Specify the target position
Canvas_Image_Start_address(0) -> Set the canvas start address to 0, which is the left top position of the canvas.
Active_Window_XY(0,0) -> Set the start coordinate of the Active window
Active_Window_WH(LCD_XSIZE_TFT, LCD_YSIZE_TFT) -> Set the size of the active window.
Goto_Pixel_XY(x, y) -> Set the coordinate of the target pixel.
(2) Get the LT768x SDRAM ready for access
LCD_CmdWrite(0x04) -> Setup Memory Read/Write Data Port
LCD_DataRead -> Send a dummy cycle
If Memory Read FIFO is ready, then start read process
(3) Read one pixel data (16bits, R5G6B5) from the designated location.
LCD_ReadData() -> Read one byte at a time.
-> The first read byte is the lower byte, and the second one is the higher byte.
The below demo function will read a full picture (800x480) from LT768x SDRAM, then invert the retrieved data, and then write them back to LT768x SDRAM.
/*----------------------------------------------------------------------------------------*/
/* Function: MCU_Read_Memory */
/* */
/* Parameters: None */
/* Returns: None */
/* Description: (1) MCU read designated pixel data from LT768x SDRAM memory */
/* (2) Invert the pixel data and display it onto the LCD display */
/*----------------------------------------------------------------------------------------*/
void MCU_Read_Memory(void)
{
Select_Main_Window_16bpp(); // Set main window color depth
Main_Image_Start_Address(LAYER_0); // Set main window start address - Display layer
Main_Image_Width(LCD_XSIZE_TFT); // Set main window width
Main_Window_Start_XY(0,0); // Set main window start coordinate
Canvas_Image_Start_address(LAYER_0); // Set canvas start address
Canvas_image_width(LCD_XSIZE_TFT); // Set canvas width
Active_Window_XY(0,0); // Set active window start coordinate
Active_Window_WH(LCD_XSIZE_TFT,LCD_YSIZE_TFT); // Set active window area
// Retrieve the flash data and display it onto the panel
LT768_DMA_24bit_Block(1,0,0,0,LCD_XSIZE_TFT, LCD_YSIZE_TFT, LCD_XSIZE_TFT,0);
u16 temp; // The pixel(RGB, 16bits) read from the designated SDRAM coordinate
u8 pBuf[1600] = {0}; // data buffer for writing SDRAM -> 800 pixels = 1600 bytes
u16 index; // index for pBuf;
for (int i = 0; i < LCD_YSIZE_TFT; i++) // Y direction: 480 pixels
{
index = 0; // Reset index
for (int j = 0; j < LCD_XSIZE_TFT; j++) // X direction: 800 pixels -> Read 800 pixels in the loop
{
// Read SDRAM memory - one pixel at a time
temp = MPU8_Memory_Read_Pixel(j, i);
pBuf[index] = ~(temp & 0x00FF); // Lower byte -> Get the negation result
pBuf[++index] = ~(temp & 0xFF00) >> 8; // Higher byte -> Get the negation result
index++; // increment here to move to the next pBuf position
}
MPU8_16bpp_Memory_Write_Continuous(0, i, LCD_XSIZE_TFT, 1, pBuf); // MCU writes the new pixel data back to SDRAM
}
}
The running result is as shown below: