-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlcddraw.c
117 lines (106 loc) · 2.91 KB
/
lcddraw.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/** \file lcddraw.c
* \brief Adapted from RobG's EduKit
*/
#include "lcdutils.h"
#include "lcddraw.h"
/** Draw single pixel at x,row
*
* \param col Column to draw to
* \param row Row to draw to
* \param colorBGR Color of pixel in BGR
*/
void drawPixel(u_char col, u_char row, u_int colorBGR)
{
lcd_setArea(col, row, col, row);
lcd_writeColor(colorBGR);
}
/** Fill rectangle
*
* \param colMin Column start
* \param rowMin Row start
* \param width Width of rectangle
* \param height height of rectangle
* \param colorBGR Color of rectangle in BGR
*/
void fillRectangle(u_char colMin, u_char rowMin, u_char width, u_char height,
u_int colorBGR)
{
u_char colLimit = colMin + width, rowLimit = rowMin + height;
lcd_setArea(colMin, rowMin, colLimit - 1, rowLimit - 1);
u_int total = width * height;
u_int c = 0;
while ((c++) < total) {
lcd_writeColor(colorBGR);
}
}
/** Clear screen (fill with color)
*
* \param colorBGR The color to fill screen
*/
void clearScreen(u_int colorBGR)
{
u_char w = screenWidth;
u_char h = screenHeight;
fillRectangle(0, 0, screenWidth, screenHeight, colorBGR);
}
/** 5x7 font - this function draws background pixels
* Adapted from RobG's EduKit
*/
void drawChar5x7(u_char rcol, u_char rrow, char c,
u_int fgColorBGR, u_int bgColorBGR)
{
u_char col = 0;
u_char row = 0;
u_char bit = 0x01;
u_char oc = c - 0x20;
lcd_setArea(rcol, rrow, rcol + 4, rrow + 7); /* relative to requested col/row */
while (row < 8) {
while (col < 5) {
u_int colorBGR = (font_5x7[oc][col] & bit) ? fgColorBGR : bgColorBGR;
lcd_writeColor(colorBGR);
col++;
}
col = 0;
bit <<= 1;
row++;
}
}
/** Draw string at col,row
* Type:
* FONT_SM - small (5x8,) FONT_MD - medium (8x12,) FONT_LG - large (11x16)
* FONT_SM_BKG, FONT_MD_BKG, FONT_LG_BKG - as above, but with background color
* Adapted from RobG's EduKit
*
* \param col Column to start drawing string
* \param row Row to start drawing string
* \param string The string
* \param fgColorBGR Foreground color in BGR
* \param bgColorBGR Background color in BGR
*/
void drawString5x7(u_char col, u_char row, char *string,
u_int fgColorBGR, u_int bgColorBGR)
{
u_char cols = col;
while (*string) {
drawChar5x7(cols, row, *string++, fgColorBGR, bgColorBGR);
cols += 6;
}
}
/** Draw rectangle outline
*
* \param colMin Column start
* \param rowMin Row start
* \param width Width of rectangle
* \param height Height of rectangle
* \param colorBGR Color of rectangle in BGR
*/
void drawRectOutline(u_char colMin, u_char rowMin, u_char width, u_char height,
u_int colorBGR)
{
/**< top & bot */
fillRectangle(colMin, rowMin, width, 1, colorBGR);
fillRectangle(colMin, rowMin + height, width, 1, colorBGR);
/**< left & right */
fillRectangle(colMin, rowMin, 1, height, colorBGR);
fillRectangle(colMin + width, rowMin, 1, height, colorBGR);
}