-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLCD.c
More file actions
174 lines (148 loc) · 3.44 KB
/
LCD.c
File metadata and controls
174 lines (148 loc) · 3.44 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/* Chibios LCD Driver */
#include "ch.h"
#include "hal.h"
#include "LCD.h"
#include "font.h"
#if LCD_USE_FONT_SMALL == 1 && LCD_USE_FONTS == 1
extern const unsigned char FONT6x8[97][8];
#endif
#if LCD_USE_FONT_MEDIUM == 1 && LCD_USE_FONTS == 1
extern const unsigned char FONT8x8[97][8];
#endif
#if LCD_USE_FONT_LARGE == 1 && LCD_USE_FONTS == 1
extern const unsigned char FONT8x16[97][8];
#endif
/* build font table */
#if LCD_USE_FONTS == 1
unsigned char *FontTable[] = {
#if LCD_USE_FONT_SMALL == 1
(unsigned char *)FONT6x8,
#else
NULL,
#endif
#if LCD_USE_FONT_MEDIUM == 1
(unsigned char *)FONT8x8,
#else
NULL,
#endif
#if LCD_USE_FONT_LARGE == 1
(unsigned char *)FONT8x16
#else
NULL
#endif
};
#endif
void lcdInit(void) {
lcd_init_lld();
}
void lcdSetArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1) {
lcd_set_area_lld(x0, y0, x1, y1);
}
void lcdFillArea(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1, uint16_t colour) {
lcd_fill_area_lld(x0, y0, x1, y1, colour);
}
void lcdClearScreen(uint16_t colour) {
lcdFillArea(0, 0, LCD_SCREEN_WIDTH, LCD_SCREEN_HEIGHT, colour);
}
void lcdSetPixel(int x, int y, uint16_t colour) {
lcd_set_pixel_lld(x, y, colour);
}
void lcdDemo(void) {
}
void lcdDrawString(uint16_t x, uint16_t y, const char *str, uint16_t colour, uint8_t size) {
unsigned char *pFont = (unsigned char *)FontTable[size];
// get the nColumns, nRows and nBytes
uint8_t nCols = *pFont;
uint8_t nRows = *(pFont + 1);
uint8_t nBytes = *(pFont + 2);
while(*str) {
//cPrintf("%c",*str++);
lcdDrawChar(x,y,*str++,colour,size);
if (x < (LCD_SCREEN_WIDTH - nCols)) {
x += nCols;
} else if (y < (LCD_SCREEN_HEIGHT - nRows)) {
x=0;
y+=nRows;
} else {
x=0;
y=0;
}
}
}
void lcdDrawChar(uint16_t x, uint16_t y, const char c, uint16_t colour, uint8_t size) {
unsigned char PixelRow;
unsigned char Mask;
int i,j;
// get pointer to the beginning of the selected font table
unsigned char *pFont = (unsigned char *)FontTable[size];
// get the nColumns, nRows and nBytes
uint8_t nCols = *pFont;
uint8_t nRows = *(pFont + 1);
uint8_t nBytes = *(pFont + 2);
// get pointer to the last byte of the desired character
unsigned char *pChar = pFont + (nBytes * (c - 0x1F)) + nBytes - 1;
// loop on each row, working backwards from the bottom to the top
for (i = nRows - 1; i >= 0; i--) {
// copy pixel row from font table and then decrement row
PixelRow = *pChar--;
// loop on each pixel in the row (left to right)
// Note: we do two pixels each loop
Mask = 0x80;
for (j = 0; j < nCols; j += 2) {
if ( (PixelRow >> 7-j) & 0x01 == 0x01) {
lcdSetPixel(x+j,y+i, colour);
} else {
/* handle background colour somehow - maybe passed to this function? or store when set */
//lcdSetPixel(Xpos+j,Ypos+i,colour);
}
}
}
}
void lcdDrawLine(int x0, int y0, int x1, int y1,uint16_t colour)
{
int x,y,dx,dy,Dx,Dy,e,i;
Dx=x1-x0;
Dy=y1-y0;
dx=fabs(x1-x0);
dy=fabs(y1-y0);
x=x0;
y=y0;
if(dy>dx) {
e=-dy;
for(i=0;i<dy;i++)
{
lcdSetPixel(x,y,colour);
if(Dy>=0) y++;
else y--;
e+=2*dx;
if(e>=0)
{
if(Dx>=0) x++;
else x--;
e-=2*dy;
}
}
}
else
{
e=-dx;
for(i=0;i<dx;i++)
{
lcdSetPixel(x,y,colour);
if(Dx>=0) x++;
else x--;
e+=2*dy;
if(e>=0)
{
if(Dy>=0) y++;
else y--;
e-=2*dx;
}
}
}
}
void lcddrawBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const unsigned char *bmp) {
}
float lcdFPS(void) {
return 30.0f;
}