示例#1
0
/**
*
* This function changes the column, row position in the Instance structure
* of driver. It is used to correct the position for the next character to
* be written if column and row position cross limits.
*
* @param	InstancePtr is a pointer to the XTft instance.
* @param	ColVal is the column number to which ColVal member of
*		Instance structure is updated. If ColVal crosses
*		(XTFT_DISPLAY_WIDTH - 1) -  XTFT_CHAR_WIDTH, position is
*		moved to next line. The valid values are 0 to
*		(XTFT_DISPLAY_WIDTH - 1).
* @param	RowVal is the row number to which RowVal member of
*		Instance structure is updated. If RowVal crosses
*		(XTFT_DISPLAY_HEIGHT - 1)- XTFT_CHAR_HEIGHT, the first line
*		will be deleted. The valid values are 0 to
*		(XTFT_DISPLAY_HEIGHT - 1).
*
* @return	None.
*
* @note		This function differs from the function XTft_SetPos because
*		you cannot move to any position on the screen as we have
*		to check for enough space for a character to be written.
*
****************************************************************************/
void XTft_SetPosChar(XTft *InstancePtr, u32 ColVal, u32 RowVal)
{
	/*
	 * Assert validates the input arguments.
	 */
	Xil_AssertVoid(InstancePtr != NULL);
	Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY);
	Xil_AssertVoid(ColVal <= (XTFT_DISPLAY_WIDTH - 1));
	Xil_AssertVoid(RowVal <= (XTFT_DISPLAY_HEIGHT - 1));

	/*
	 * If there is no space in the current line for the next char
	 * go to next line.
	 */
	if (ColVal > (XTFT_DISPLAY_WIDTH - 1) - XTFT_CHAR_WIDTH) {
		ColVal = XTFT_DEF_COLVAL;
		RowVal += XTFT_CHAR_HEIGHT;
	}

	/*
	 * If there is no space in the current line for the next char
	 * go to next line by deleting the first line.
	 */
	while (RowVal > (XTFT_DISPLAY_HEIGHT - 1) - XTFT_CHAR_HEIGHT) {
		XTft_Scroll(InstancePtr);
		RowVal -= XTFT_CHAR_HEIGHT;
	}

	/*
	 * Update the column, row position values.
	 */
	InstancePtr->ColVal = ColVal;
	InstancePtr->RowVal = RowVal;

}
示例#2
0
 XStatus XTft_SetPos(XTft *InstancePtr, Xuint32 x, Xuint32 y)
 {
   XASSERT_NONVOID(InstancePtr != XNULL);
   XASSERT_NONVOID(InstancePtr->IsReady == XCOMPONENT_IS_READY);

   if (x > XTFT_DISPLAY_WIDTH - XTFT_CHAR_WIDTH)
   {
     x = 0;
     y += XTFT_CHAR_HEIGHT;
   }
   while (y > XTFT_DISPLAY_HEIGHT - XTFT_CHAR_HEIGHT)
   {
     XTft_Scroll(InstancePtr);
     y = y - XTFT_CHAR_HEIGHT;
   }

   InstancePtr->X = x;
   InstancePtr->Y = y;

   return XST_SUCCESS;
 }
示例#3
0
/**
*
* This is the example function which performs the following operations on
* the TFT device -
* - Set the color values of foreground and background
* - Write two characters (S) one after another
* - Write a string of characters
* - Draw a line and scroll the screen once
* - Disable the display (The screen goes blank)
* - Scroll the screen once and draw a line
* - Enable the TFT display
*
* @param	TftDeviceId is the unique Id of the device.
*
* @return
*		- XST_SUCCESS if successful.
*		- XST_FAILURE if unsuccessful.
*
* @note		None.
*
******************************************************************************/
int TftExample(u32 TftDeviceId)
{
	int Status;
	u8 VarChar;
	XTft_Config *TftConfigPtr;

	/*
	 * Get address of the XTft_Config structure for the given device id.
	 */
	TftConfigPtr = XTft_LookupConfig(TftDeviceId);
	if (TftConfigPtr == (XTft_Config *)NULL) {
		return XST_FAILURE;
	}

	/*
	 * Initialize all the TftInstance members and fills the screen with
	 * default background color.
	 */
	Status = XTft_CfgInitialize(&TftInstance, TftConfigPtr,
				 	TftConfigPtr->BaseAddress);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Wait till Vsync(Video address latch) status bit is set before writing
	 * the frame address into the Address Register. This ensures that the
	 * current frame has been displayed and we can display a new frame of
	 * data. Checking the Vsync state ensures that there is no data flicker
	 * when displaying frames in real time though there is some delay due to
	 * polling.
	 */
	while (XTft_GetVsyncStatus(&TftInstance) !=
					XTFT_IESR_VADDRLATCH_STATUS_MASK);

	/*
	 * Change the Video Memory Base Address from default value to
	 * a valid Memory Address and clear the screen.
	 */
	XTft_SetFrameBaseAddr(&TftInstance, TFT_FRAME_ADDR);
	XTft_ClearScreen(&TftInstance);

	/*
	 * Initialize the variable VarChar to the value to be displayed on the
	 * screen.
	 * Set the foreground and background colors.
	 */
	VarChar = 'S';
	XTft_SetColor(&TftInstance, FGCOLOR_VALUE, BGCOLOR_VALUE);

	/*
	 * Write the character two times starting from top left corner
	 * (i.e. origin) of screen.
	 */
	XTft_Write(&TftInstance, VarChar);
	XTft_Write(&TftInstance, VarChar);

	/*
	 * Write a string which is displayed next to the two characters
	 * written previously.
	 */
	Status = TftWriteString(&TftInstance, (u8*)"TFT CONTROLLER\n");
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Draw a line between the coordinates (X1,Y1) and (X2,Y2) which
	 * displays a vertical line in white color.
	 * Scroll the screen, so the two characters and string will be
	 * erased on screen.
	 */
	Status = TftDrawLine(&TftInstance, X1POS, Y1POS, X2POS, Y2POS,
				WHITECOLOR_VALUE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}
	XTft_Scroll(&TftInstance);

	/*
	 * Disable the display, the screen will be turned off.
	 */
	XTft_DisableDisplay(&TftInstance);

	/*
	 * Even though the screen is turned off, we can still do operations on
	 * video memory.
	 * Scroll the screen.
	 * Draw a line between the coordinates (X1 + 10,Y1) and (X2,Y2) which
	 * is displayed at different position as X1 has some offset.
	 */
	XTft_Scroll(&TftInstance);
	Status = TftDrawLine(&TftInstance, X1POS + 10, Y1POS, X2POS + 10,
				 Y2POS, WHITECOLOR_VALUE);
	if (Status != XST_SUCCESS) {
		return XST_FAILURE;
	}

	/*
	 * Enable the display. Screen will display two lines in white color.
	 * The first line from the left of screen is slightly above the
	 * second one indicating the scroll was successful.
	 */
	XTft_EnableDisplay(&TftInstance);

	return XST_SUCCESS;
}