/
displayBar.c
98 lines (83 loc) · 1.99 KB
/
displayBar.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#include "displayBar.h"
int initTFT()
{
int Status;
XTft_Config *TftConfigPtr;
/*
* Get address of the XTft_Config structure for the given device id.
*/
TftConfigPtr = XTft_LookupConfig(TFT_DEVICE_ID);
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);
XTft_SetPos(&TftInstance, 0,0);
XTft_SetPosChar(&TftInstance, 0,0);
XTft_SetColor(&TftInstance, 0x00000000, 0x00ffffff);
XTft_FillScreen(&TftInstance, 0, 0,639,479,0x00ffffff); // white
return XST_SUCCESS;
}
//(x0,y0) is the bottom left corner of the bar
void drawBar(int width, int length, int y0, int x0, int col)
{
int i = 0;
for (i=0; i<width; i++)
{
drawHorLine(&TftInstance, y0-i, x0, x0+length, col);
}
}
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);
}
}
}
void clearScreen()
{
XTft_ClearScreen(&TftInstance);
}
void fillScreen()
{
XTft_SetColor(&TftInstance, 0x00000000, 0x00ffffff);
}