/** * * This function fills the screen with the range defined by the start and end * values of column and row with the color passed as argument. * * @param InstancePtr is a pointer to the XTft instance. * @param ColStartVal is the value of the starting column. The valid * values are 0 to (XTFT_DISPLAY_WIDTH - 1). * @param RowStartVal is the value of the starting row. The valid * values are 0 to (XTFT_DISPLAY_HEIGHT - 1). * @param ColEndVal is the value of the ending column. The valid * values are 0 to (XTFT_DISPLAY_WIDTH - 1). * @param RowEndVal is the value of the ending row. The valid * values are 0 to (XTFT_DISPLAY_HEIGHT - 1). * @param PixelVal represents the color with which it will be * filled on screen. * * @return None. * * @note It must be taken care to pass values such that column start * position should not exceed column end position, same is the * case with row position. * ****************************************************************************/ void XTft_FillScreen(XTft* InstancePtr, u32 ColStartVal, u32 RowStartVal, u32 ColEndVal, u32 RowEndVal, u32 PixelVal) { u32 ColIndex; u32 RowIndex; /* * Assert validates the input arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(ColStartVal <= (XTFT_DISPLAY_WIDTH - 1)); Xil_AssertVoid(RowStartVal <= (XTFT_DISPLAY_HEIGHT - 1)); Xil_AssertVoid(ColEndVal <= (XTFT_DISPLAY_WIDTH - 1)); Xil_AssertVoid(RowEndVal <= (XTFT_DISPLAY_HEIGHT - 1)); /* * Fills each pixel on the screen with the value of PixelVal. */ for (ColIndex = ColStartVal; ColIndex <= ColEndVal; ColIndex++) { for (RowIndex = RowStartVal; RowIndex <= RowEndVal; RowIndex++) { XTft_SetPixel(InstancePtr, ColIndex, RowIndex, PixelVal); } } }
/** * * This function writes a particular character onto the screen using * the character bitmap values. * * @param InstancePtr is a pointer to the XTft instance. * @param CharValue is the value of the ASCII character. * @param ColStartVal is the value of the starting column. The valid * values are 0 to (XTFT_DISPLAY_WIDTH - 1). * @param RowStartVal is the value of the starting row. The valid * values are 0 to (XTFT_DISPLAY_HEIGHT - 1). * @param FgColor is the value with which the pixels will be filled * to highlight the character. * @param BgColor is the value with which the pixels will be filled * with a different color from foreground. * * @return None. * * @note It must be taken care that the ASCII character which is to * be written has value greater than 31 as character bitmap * array starts with space as its first character. * ****************************************************************************/ static void XTft_WriteChar(XTft* InstancePtr, u8 CharValue, u32 ColStartVal, u32 RowStartVal, u32 FgColor, u32 BgColor) { u32 PixelVal; u32 ColIndex; u32 RowIndex; u8 BitMapVal; /* * Assert validates the input arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); Xil_AssertVoid(ColStartVal <= (XTFT_DISPLAY_WIDTH - 1)); Xil_AssertVoid(RowStartVal <= (XTFT_DISPLAY_HEIGHT - 1)); /* * Checks whether the given character value is more than or equal to * space character value, as our character array starts with space. */ Xil_AssertVoid((u32) CharValue >= XTFT_ASCIICHAR_OFFSET); /* * Gets the 12 bit value from the character array defined in * charcode.c file and regenerates the bitmap of that character. * It draws that character on screen by setting the pixel either * with the foreground or background color depending on * whether value is 1 or 0. */ for (RowIndex = 0; RowIndex < XTFT_CHAR_HEIGHT; RowIndex++) { BitMapVal = XTft_VidChars[(u32) CharValue - XTFT_ASCIICHAR_OFFSET][RowIndex]; for (ColIndex = 0; ColIndex < XTFT_CHAR_WIDTH; ColIndex++) { if (BitMapVal & (1 << (XTFT_CHAR_WIDTH - ColIndex - 1))) { PixelVal = FgColor; } else { PixelVal = BgColor; } /* * Sets the color value to pixel. */ XTft_SetPixel(InstancePtr, ColStartVal+ColIndex, RowStartVal+RowIndex, PixelVal); } } }
void drawHorLine(XTft *Tft, int y, int x1, int x2, int col) { int i = 0; if (x1<0) { x2 = x2-x1; x1=0; } if (x2>639) { x1=x1-(x2-639); x2=639; } if (y>=0 && y<=479) { for (i=x1; i<= x2; i++) { XTft_SetPixel(Tft, i, y, col); } } }
/** * * This function inserts a new blank line at the bottom of the screen, it * deletes the first line and moves the remaining lines up by one line. * * @param InstancePtr is a pointer to the XTft instance. * * @return None. * * @note None. * ****************************************************************************/ void XTft_Scroll(XTft *InstancePtr) { u32 PixelVal; u32 ColIndex; u32 RowIndex; /* * Assert validates the input arguments. */ Xil_AssertVoid(InstancePtr != NULL); Xil_AssertVoid(InstancePtr->IsReady == XIL_COMPONENT_IS_READY); /* * Takes each pixel value from the second line and puts in the first * line. This process is repeated till the second line * from bottom. */ for (RowIndex = 0; RowIndex < (XTFT_DISPLAY_HEIGHT - 1) - XTFT_CHAR_HEIGHT; RowIndex++) { for (ColIndex = 0; ColIndex < (XTFT_DISPLAY_WIDTH - 1); ColIndex++) { XTft_GetPixel(InstancePtr, ColIndex, RowIndex + XTFT_CHAR_HEIGHT, &PixelVal); XTft_SetPixel( InstancePtr, ColIndex, RowIndex, PixelVal); } } /* * Fills the last line with the background color. */ XTft_FillScreen(InstancePtr, XTFT_DEF_COLVAL, (XTFT_DISPLAY_HEIGHT - 1)-XTFT_CHAR_HEIGHT, (XTFT_DISPLAY_WIDTH - 1), (XTFT_DISPLAY_HEIGHT - 1), InstancePtr->BgColor); }
/** * Draws a line between two points with a specified color. * * @param InstancePtr is a pointer to the XTft instance. * @param ColStartPos is the Start point of Column. * The valid value is 0 to (XTFT_DISPLAY_WIDTH - 1). * @param RowStartPos is the Start point of Row. * The valid value is 0 to (XTFT_DISPLAY_HEIGHT - 1). * @param ColEndPos is the End point of Column. * The valid value is 0 to (XTFT_DISPLAY_WIDTH - 1). * @param RowEndPos is the End point of Row. * The valid value is 0 to (XTFT_DISPLAY_HEIGHT - 1). * @param PixelVal is the Color Value to be put at pixel. * * @return * - XST_SUCCESS if successful. * - XST_FAILURE if unsuccessful. * * @note None. * ******************************************************************************/ static int TftDrawLine(XTft *InstancePtr, u32 ColStartPos, u32 RowStartPos, u32 ColEndPos, u32 RowEndPos, u32 PixelVal) { u32 Slope; u32 YIntercept; u32 Xmin; u32 Ymin; u32 Xmax; u32 Ymax; u32 Index1; u32 Index2; u32 Mx; /* * Check whether the given position of X,Y dimensions * are below the limits of the screen. */ if (ColStartPos >= 0 && ColStartPos <= (XTFT_DISPLAY_WIDTH - 1) && ColEndPos >= 0 && ColEndPos <= (XTFT_DISPLAY_WIDTH - 1) && RowStartPos >= 0 && RowStartPos <= (XTFT_DISPLAY_HEIGHT - 1) && RowEndPos >= 0 && RowEndPos <= (XTFT_DISPLAY_HEIGHT - 1)) { /* * Check the exception case where slope can be infinite * that is vertical line. */ if (ColEndPos-ColStartPos != 0) { /* * Calculate slope. */ Slope = ((RowEndPos - RowStartPos) / (ColEndPos - ColStartPos) * 100000); /* * Calculate y intercept. */ YIntercept = RowStartPos - ((Slope / 100000) * ColStartPos); } else { /* * Divide by zero. */ Slope = 0; YIntercept = (-1); } /* * Update the min and max position by conditional checking. */ if (ColEndPos < ColStartPos) { Xmin = ColEndPos; Xmax = ColStartPos; } else { Xmin = ColStartPos; Xmax = ColEndPos; } if (RowEndPos < RowStartPos) { Ymin = RowEndPos; Ymax = RowStartPos; } else { Ymin = RowStartPos; Ymax = RowEndPos; } /* * Increment X and Y position values and calculate * slope at the corresponding x position. Check the condition * for general line equation and set the pixel. Otherwise check * for the case of vertical line. */ for (Index1 = Xmin; Index1 <= Xmax; Index1++) { Mx = (Slope * Index1) / 100000; for (Index2 = Ymin; Index2 <= Ymax; Index2++) { if ((Index2 - Mx) == YIntercept) { /* * Calculate visible line. */ XTft_SetPixel(InstancePtr, Index1, Index2, PixelVal); } else { /* * Divide by zero. */ if((Slope == 0) && (YIntercept == -1)) { /* * Vertical line. */ XTft_SetPixel(InstancePtr, Index1, Index2, PixelVal); } } } } return XST_SUCCESS; } else { return XST_FAILURE; } }