raspi_lcd 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/ext/RaspiLCD-V0.9.0/bcm2835.c +715 -0
- data/ext/RaspiLCD-V0.9.0/bcm2835.h +801 -0
- data/ext/RaspiLCD-V0.9.0/bmp_men.inc +89 -0
- data/ext/RaspiLCD-V0.9.0/bmp_raspi.inc +42 -0
- data/ext/RaspiLCD-V0.9.0/font_fixedsys_8x15.inc +913 -0
- data/ext/RaspiLCD-V0.9.0/font_lucida_10x16.inc +1137 -0
- data/ext/RaspiLCD-V0.9.0/font_terminal_12x16.inc +1137 -0
- data/ext/RaspiLCD-V0.9.0/font_terminal_6x8.inc +689 -0
- data/ext/RaspiLCD-V0.9.0/lcd.c +536 -0
- data/ext/RaspiLCD-V0.9.0/lcd.h +80 -0
- data/ext/RaspiLCD-V0.9.0/main.c +309 -0
- data/ext/RaspiLCD-V0.9.0/raspilcd.c +230 -0
- data/ext/RaspiLCD-V0.9.0/raspilcd.h +104 -0
- data/ext/RaspiLCD-V0.9.0/resource_bmp.inc +324 -0
- data/ext/RaspiLCD-V0.9.0/resource_font_6x8.inc +354 -0
- data/ext/RaspiLCD-V0.9.0/std_c.h +55 -0
- data/ext/raspi_lcd/extconf.rb +2 -0
- data/ext/raspi_lcd/raspi_lcd.c +137 -0
- data/ext/raspi_lcd/test.rb +31 -0
- data/lib/raspi_lcd.rb +5 -0
- metadata +66 -0
@@ -0,0 +1,536 @@
|
|
1
|
+
//--------------------------------------------------------------------------------------------------
|
2
|
+
// _ _
|
3
|
+
// | | | |
|
4
|
+
// ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__
|
5
|
+
// / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \.
|
6
|
+
// | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | |
|
7
|
+
// \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_|
|
8
|
+
// __/ |
|
9
|
+
// |___/ Engineering (www.emsystech.de)
|
10
|
+
//
|
11
|
+
// Filename:
|
12
|
+
// Description:
|
13
|
+
//
|
14
|
+
// Open Source Licensing
|
15
|
+
//
|
16
|
+
// This program is free software: you can redistribute it and/or modify it under the terms of
|
17
|
+
// the GNU General Public License as published by the Free Software Foundation, either version 3
|
18
|
+
// of the License, or (at your option) any later version.
|
19
|
+
//
|
20
|
+
// This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
|
21
|
+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
// GNU General Public License for more details.
|
23
|
+
//
|
24
|
+
// You should have received a copy of the GNU General Public License along with this program.
|
25
|
+
// If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
//
|
27
|
+
// Dieses Programm ist Freie Software: Sie k�nnen es unter den Bedingungen der GNU General Public
|
28
|
+
// License, wie von der Free Software Foundation, Version 3 der Lizenz oder (nach Ihrer Option)
|
29
|
+
// jeder sp�teren ver�ffentlichten Version, weiterverbreiten und/oder modifizieren.
|
30
|
+
//
|
31
|
+
// Dieses Programm wird in der Hoffnung, dass es n�tzlich sein wird, aber OHNE JEDE GEW�HRLEISTUNG,
|
32
|
+
// bereitgestellt; sogar ohne die implizite Gew�hrleistung der MARKTF�HIGKEIT oder EIGNUNG F�R
|
33
|
+
// EINEN BESTIMMTEN ZWECK. Siehe die GNU General Public License f�r weitere Details.
|
34
|
+
//
|
35
|
+
// Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Programm erhalten
|
36
|
+
// haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
37
|
+
//
|
38
|
+
// Author: Martin Steppuhn
|
39
|
+
// History: 05.11.2012 Initial version V0.9.0
|
40
|
+
//--------------------------------------------------------------------------------------------------
|
41
|
+
|
42
|
+
//=== Includes =====================================================================================
|
43
|
+
|
44
|
+
#include "std_c.h"
|
45
|
+
#include "lcd.h"
|
46
|
+
#include <stdio.h>
|
47
|
+
#include <stdlib.h>
|
48
|
+
#include "raspilcd.h"
|
49
|
+
|
50
|
+
//=== Preprocessing directives (#define) ===========================================================
|
51
|
+
|
52
|
+
//=== Type definitions (typedef) ===================================================================
|
53
|
+
|
54
|
+
//=== Global constants =============================================================================
|
55
|
+
|
56
|
+
//=== Global variables =============================================================================
|
57
|
+
|
58
|
+
//=== Local constants =============================================================================
|
59
|
+
|
60
|
+
#include "font_terminal_6x8.inc"
|
61
|
+
#include "font_terminal_12x16.inc"
|
62
|
+
#include "font_fixedsys_8x15.inc"
|
63
|
+
#include "font_lucida_10x16.inc"
|
64
|
+
|
65
|
+
//=== Local variables ==============================================================================
|
66
|
+
|
67
|
+
uint8 framebuffer[LCD_WIDTH][LCD_HEIGHT/8];
|
68
|
+
uint8 PenColor;
|
69
|
+
uint8 FillColor;
|
70
|
+
uint8 FontNumber;
|
71
|
+
|
72
|
+
//=== Local function prototypes ====================================================================
|
73
|
+
|
74
|
+
void lcd_write_cmd(uint8 d);
|
75
|
+
void lcd_write_data(uint8 d);
|
76
|
+
void lcd_set_xy(uint8 x,uint8 ypage);
|
77
|
+
|
78
|
+
//--------------------------------------------------------------------------------------------------
|
79
|
+
// Name: LCD_SSetPenColor
|
80
|
+
// Function: Set pen color
|
81
|
+
//
|
82
|
+
// Parameter: 0=White 1=Black
|
83
|
+
// Return: -
|
84
|
+
//--------------------------------------------------------------------------------------------------
|
85
|
+
void LCD_SetPenColor(uint8 c)
|
86
|
+
{
|
87
|
+
PenColor = c;
|
88
|
+
}
|
89
|
+
|
90
|
+
//--------------------------------------------------------------------------------------------------
|
91
|
+
// Name: LCD_SSetFillColor
|
92
|
+
// Function: Set fill color
|
93
|
+
//
|
94
|
+
// Parameter: -1=transparent, 0=white, 1=black
|
95
|
+
// Return:
|
96
|
+
//--------------------------------------------------------------------------------------------------
|
97
|
+
void LCD_SetFillColor(int8 c)
|
98
|
+
{
|
99
|
+
FillColor = c;
|
100
|
+
}
|
101
|
+
|
102
|
+
//--------------------------------------------------------------------------------------------------
|
103
|
+
// Name: LCD_SSetFont
|
104
|
+
// Function: Set font
|
105
|
+
//
|
106
|
+
// Parameter: 0..3 for Fonts
|
107
|
+
// Return: -
|
108
|
+
//--------------------------------------------------------------------------------------------------
|
109
|
+
void LCD_SetFont(uint8 f)
|
110
|
+
{
|
111
|
+
FontNumber = f;
|
112
|
+
}
|
113
|
+
|
114
|
+
//--------------------------------------------------------------------------------------------------
|
115
|
+
// Name: LCD_ClearScreen
|
116
|
+
// Function: Clear Screen
|
117
|
+
//
|
118
|
+
// Parameter: -
|
119
|
+
// Return: -
|
120
|
+
//--------------------------------------------------------------------------------------------------
|
121
|
+
void LCD_ClearScreen(void)
|
122
|
+
{
|
123
|
+
uint16 x,y;
|
124
|
+
|
125
|
+
for(y=0;y<(LCD_HEIGHT/8);y++)
|
126
|
+
{
|
127
|
+
for(x=0;x<LCD_WIDTH;x++) framebuffer[x][y] = 0;
|
128
|
+
}
|
129
|
+
}
|
130
|
+
|
131
|
+
//--------------------------------------------------------------------------------------------------
|
132
|
+
// Name: LCD_PutPixel
|
133
|
+
// Function: Set single pixel at x,x
|
134
|
+
//
|
135
|
+
// Parameter: x,y position, color
|
136
|
+
// Return: -
|
137
|
+
//--------------------------------------------------------------------------------------------------
|
138
|
+
void LCD_PutPixel(uint8 x,uint8 y,uint8 color)
|
139
|
+
{
|
140
|
+
if((x < LCD_WIDTH) && (y < LCD_HEIGHT))
|
141
|
+
{
|
142
|
+
if(color) framebuffer[x][y>>3] |= (1<<(y & 7));
|
143
|
+
else framebuffer[x][y>>3] &= ~(1<<(y & 7));
|
144
|
+
}
|
145
|
+
}
|
146
|
+
|
147
|
+
//--------------------------------------------------------------------------------------------------
|
148
|
+
// Name: LCD_DrawLine
|
149
|
+
// Function: Draw line from xy to xy
|
150
|
+
//
|
151
|
+
// Parameter: Start and endpoint
|
152
|
+
// Return: -
|
153
|
+
//--------------------------------------------------------------------------------------------------
|
154
|
+
void LCD_DrawLine(uint8 x0,uint8 y0,uint8 x1,uint8 y1)
|
155
|
+
{
|
156
|
+
int16 dx,sx,dy,sy,err,e2; // for Bresenham
|
157
|
+
int8 i;
|
158
|
+
|
159
|
+
if(y0 == y1) // horizontale Linie
|
160
|
+
{
|
161
|
+
if(x0 > x1) { i=x0; x0=x1; x1=i; } // swap direction
|
162
|
+
while (x0 <= x1) LCD_PutPixel(x0++,y0,PenColor);
|
163
|
+
}
|
164
|
+
else if(x0 == x1) // vertikale Linie
|
165
|
+
{
|
166
|
+
if(y0 > y1) { i=y0; y0=x1; y1=i; } // swap direction
|
167
|
+
while (y0 <= y1) LCD_PutPixel(x0,y0++,PenColor);
|
168
|
+
}
|
169
|
+
else // Bresenham Algorithmus
|
170
|
+
{
|
171
|
+
dx = abs(x1-x0);
|
172
|
+
sx = x0<x1 ? 1 : -1;
|
173
|
+
dy = -abs(y1-y0);
|
174
|
+
sy = y0<y1 ? 1 : -1;
|
175
|
+
err = dx+dy;
|
176
|
+
for(;;)
|
177
|
+
{
|
178
|
+
LCD_PutPixel(x0,y0,PenColor);
|
179
|
+
if (x0==x1 && y0==y1) break;
|
180
|
+
e2 = 2*err;
|
181
|
+
if (e2 > dy) { err += dy; x0 += sx; } /* e_xy+e_x > 0 */
|
182
|
+
if (e2 < dx) { err += dx; y0 += sy; } /* e_xy+e_y < 0 */
|
183
|
+
}
|
184
|
+
}
|
185
|
+
}
|
186
|
+
|
187
|
+
//--------------------------------------------------------------------------------------------------
|
188
|
+
// Name: LCD_DrawCircle
|
189
|
+
// Function: Draw circle with centerpont an radius
|
190
|
+
// linewidth=1 pixel, no fill
|
191
|
+
//
|
192
|
+
// Parameter: xy centerpoint and radius
|
193
|
+
// Return: -
|
194
|
+
//--------------------------------------------------------------------------------------------------
|
195
|
+
void LCD_DrawCircle(uint8 x0,uint8 y0,uint8 radius)
|
196
|
+
{
|
197
|
+
int f = 1 - radius;
|
198
|
+
int ddF_x = 0;
|
199
|
+
int ddF_y = -2 * radius;
|
200
|
+
int x = 0;
|
201
|
+
int y = radius;
|
202
|
+
|
203
|
+
LCD_PutPixel(x0, y0 + radius,PenColor);
|
204
|
+
LCD_PutPixel(x0, y0 - radius,PenColor);
|
205
|
+
LCD_PutPixel(x0 + radius, y0,PenColor);
|
206
|
+
LCD_PutPixel(x0 - radius, y0,PenColor);
|
207
|
+
|
208
|
+
while(x < y)
|
209
|
+
{
|
210
|
+
if(f >= 0)
|
211
|
+
{
|
212
|
+
y--;
|
213
|
+
ddF_y += 2;
|
214
|
+
f += ddF_y;
|
215
|
+
}
|
216
|
+
x++;
|
217
|
+
ddF_x += 2;
|
218
|
+
f += ddF_x + 1;
|
219
|
+
|
220
|
+
LCD_PutPixel(x0 + x, y0 + y,PenColor);
|
221
|
+
LCD_PutPixel(x0 - x, y0 + y,PenColor);
|
222
|
+
LCD_PutPixel(x0 + x, y0 - y,PenColor);
|
223
|
+
LCD_PutPixel(x0 - x, y0 - y,PenColor);
|
224
|
+
LCD_PutPixel(x0 + y, y0 + x,PenColor);
|
225
|
+
LCD_PutPixel(x0 - y, y0 + x,PenColor);
|
226
|
+
LCD_PutPixel(x0 + y, y0 - x,PenColor);
|
227
|
+
LCD_PutPixel(x0 - y, y0 - x,PenColor);
|
228
|
+
}
|
229
|
+
}
|
230
|
+
|
231
|
+
//--------------------------------------------------------------------------------------------------
|
232
|
+
// Name: LCD_DrawEllipse
|
233
|
+
// Function: Draw ellipse with centerpont an "radius"
|
234
|
+
// linewidth=1 pixel, no fill
|
235
|
+
//
|
236
|
+
// Parameter: xy centerpoint and "x,y radius"
|
237
|
+
// Return: -
|
238
|
+
//--------------------------------------------------------------------------------------------------
|
239
|
+
void LCD_DrawEllipse(int xm, int ym, int a, int b)
|
240
|
+
{
|
241
|
+
int dx = 0, dy = b; /* im I. Quadranten von links oben nach rechts unten */
|
242
|
+
long a2 = a*a, b2 = b*b;
|
243
|
+
long err = b2-(2*b-1)*a2, e2; /* Fehler im 1. Schritt */
|
244
|
+
|
245
|
+
do
|
246
|
+
{
|
247
|
+
LCD_PutPixel(xm+dx, ym+dy,PenColor); /* I. Quadrant */
|
248
|
+
LCD_PutPixel(xm-dx, ym+dy,PenColor); /* II. Quadrant */
|
249
|
+
LCD_PutPixel(xm-dx, ym-dy,PenColor); /* III. Quadrant */
|
250
|
+
LCD_PutPixel(xm+dx, ym-dy,PenColor); /* IV. Quadrant */
|
251
|
+
|
252
|
+
e2 = 2*err;
|
253
|
+
if (e2 < (2*dx+1)*b2) { dx++; err += (2*dx+1)*b2; }
|
254
|
+
if (e2 > -(2*dy-1)*a2) { dy--; err -= (2*dy-1)*a2; }
|
255
|
+
}
|
256
|
+
while (dy >= 0);
|
257
|
+
|
258
|
+
while (dx++ < a)
|
259
|
+
{ /* fehlerhafter Abbruch bei flachen Ellipsen (b=1) */
|
260
|
+
LCD_PutPixel(xm+dx, ym,PenColor); /* -> Spitze der Ellipse vollenden */
|
261
|
+
LCD_PutPixel(xm-dx, ym,PenColor);
|
262
|
+
}
|
263
|
+
}
|
264
|
+
|
265
|
+
//--------------------------------------------------------------------------------------------------
|
266
|
+
// Name: LCD_DrawRect
|
267
|
+
// Function: Draw rectangle, with pencolor and fillcolor
|
268
|
+
//
|
269
|
+
// Parameter: two diagonal points and linewidth
|
270
|
+
// Return: -
|
271
|
+
//--------------------------------------------------------------------------------------------------
|
272
|
+
void LCD_DrawRect(uint8 x0,uint8 y0,uint8 x1,uint8 y1,uint8 line)
|
273
|
+
{
|
274
|
+
uint8 x,y;
|
275
|
+
|
276
|
+
y = y0;
|
277
|
+
while(y<=y1) // zeilenweise durcharbeiten
|
278
|
+
{
|
279
|
+
x = x0;
|
280
|
+
while(x<=x1)
|
281
|
+
{
|
282
|
+
if((y < y0 + line) || (y > y1 - line) || (x < x0 + line) || (x > x1 - line))
|
283
|
+
{
|
284
|
+
LCD_PutPixel(x,y,PenColor);
|
285
|
+
}
|
286
|
+
else
|
287
|
+
{
|
288
|
+
if( FillColor == 0) LCD_PutPixel(x,y,0);
|
289
|
+
else if(FillColor == 1) LCD_PutPixel(x,y,1);
|
290
|
+
}
|
291
|
+
x++;
|
292
|
+
}
|
293
|
+
y++;
|
294
|
+
}
|
295
|
+
}
|
296
|
+
|
297
|
+
//--------------------------------------------------------------------------------------------------
|
298
|
+
// Name: LCD_PrintXY
|
299
|
+
// Function: Print String
|
300
|
+
//
|
301
|
+
// Parameter: x,y startpoint, string
|
302
|
+
// Return: -
|
303
|
+
//--------------------------------------------------------------------------------------------------
|
304
|
+
void LCD_PrintXY(uint8 x0,uint8 y0,char *s)
|
305
|
+
{
|
306
|
+
uint8 ix,iy,y;
|
307
|
+
const uint8 *font;
|
308
|
+
const uint8 *pt;
|
309
|
+
uint8 d;
|
310
|
+
char c;
|
311
|
+
uint8 char_width,char_height,char_size;
|
312
|
+
uint8 i_char_height;
|
313
|
+
|
314
|
+
if( FontNumber == 1) font = font_fixedsys_8x15;
|
315
|
+
else if(FontNumber == 2) font= font_lucida_10x16;
|
316
|
+
else if(FontNumber == 3) font = font_terminal_12x16;
|
317
|
+
else font = font_terminal_6x8;
|
318
|
+
|
319
|
+
char_size = *font++;
|
320
|
+
char_width = *font++;
|
321
|
+
char_height = *font++;
|
322
|
+
|
323
|
+
while(*s)
|
324
|
+
{
|
325
|
+
c = 0;
|
326
|
+
if(*s > 31) c = (*s) - 32;
|
327
|
+
pt = &font[(uint16)c * char_size];
|
328
|
+
i_char_height = char_height;
|
329
|
+
|
330
|
+
y = y0;
|
331
|
+
|
332
|
+
while(i_char_height)
|
333
|
+
{
|
334
|
+
for(ix=0;ix<char_width;ix++)
|
335
|
+
{
|
336
|
+
d = *pt++;
|
337
|
+
for(iy=0;iy<8;iy++) // je ein Byte vertikal ausgeben
|
338
|
+
{
|
339
|
+
if(d & (1<<iy)) LCD_PutPixel(x0+ix,y+iy,1);
|
340
|
+
else LCD_PutPixel(x0+ix,y+iy,0);
|
341
|
+
}
|
342
|
+
}
|
343
|
+
i_char_height = (i_char_height >= 8) ? i_char_height - 8 : 0;
|
344
|
+
y+=8; // n�chste "Page"
|
345
|
+
}
|
346
|
+
|
347
|
+
x0+=char_width;
|
348
|
+
s++; // n�chstes Zeichen
|
349
|
+
}
|
350
|
+
}
|
351
|
+
|
352
|
+
//--------------------------------------------------------------------------------------------------
|
353
|
+
// Name: LCD_DrawBitmap
|
354
|
+
// Function: Draw bitmap at startingpoint
|
355
|
+
//
|
356
|
+
// Parameter: Startpoint xy, pointer to bitmaparray
|
357
|
+
// Return: -
|
358
|
+
//--------------------------------------------------------------------------------------------------
|
359
|
+
void LCD_DrawBitmap(uint8 x0,uint8 y0,const uint8 *bmp)
|
360
|
+
{
|
361
|
+
uint8 width,height;
|
362
|
+
uint16 ix,iy;
|
363
|
+
|
364
|
+
width = *bmp++;
|
365
|
+
height = *bmp++;
|
366
|
+
|
367
|
+
for(iy=0;iy<height;iy++)
|
368
|
+
{
|
369
|
+
for(ix=0;ix<width;ix++)
|
370
|
+
{
|
371
|
+
if(bmp[ix+((iy/8)*width)] & (1<<(iy & 7))) LCD_PutPixel(x0+ix,y0+iy,1);
|
372
|
+
else LCD_PutPixel(x0+ix,y0+iy,0);
|
373
|
+
}
|
374
|
+
}
|
375
|
+
}
|
376
|
+
|
377
|
+
/*
|
378
|
+
//--------------------------------------------------------------------------------------------------
|
379
|
+
// Name: LCD_DrawBitmapFromFile
|
380
|
+
// Function: Draw bitmap from file UNDER CONSTRUCTION !!!
|
381
|
+
//
|
382
|
+
// Parameter:
|
383
|
+
// Return:
|
384
|
+
//--------------------------------------------------------------------------------------------------
|
385
|
+
void LCD_DrawBitmapFromFile(uint8 x0,uint8 y0,const char *filename)
|
386
|
+
{
|
387
|
+
uint8 width,height;
|
388
|
+
uint16 ix,iy;
|
389
|
+
FILE *fp;
|
390
|
+
uint8 buf[10000];
|
391
|
+
uint8 i;
|
392
|
+
|
393
|
+
|
394
|
+
fp = fopen(filename, "rb"); // open as file
|
395
|
+
if(fp != NULL)
|
396
|
+
{
|
397
|
+
fread(buf, 1, 58,fp);
|
398
|
+
|
399
|
+
fread(buf,1,1024,fp);
|
400
|
+
|
401
|
+
width = 128;
|
402
|
+
height = 64;
|
403
|
+
|
404
|
+
i = 0;
|
405
|
+
for(iy=0;iy<height;iy++)
|
406
|
+
{
|
407
|
+
for(ix=0;ix<width;ix++)
|
408
|
+
{
|
409
|
+
if(buf[(ix/8)+(iy*(width/8))] & (0x80>>(ix & 7))) LCD_PutPixel(x0+ix,y0+(height-iy),0);
|
410
|
+
else LCD_PutPixel(x0+ix,y0+(height-iy),1);
|
411
|
+
}
|
412
|
+
}
|
413
|
+
}
|
414
|
+
}
|
415
|
+
*/
|
416
|
+
|
417
|
+
//--------------------------------------------------------------------------------------------------
|
418
|
+
// Name: LCD_WriteFramebuffer
|
419
|
+
// Function: Transfer Framebuffer (RAM) to display via SPI
|
420
|
+
//
|
421
|
+
// Parameter: -
|
422
|
+
// Return: -
|
423
|
+
//--------------------------------------------------------------------------------------------------
|
424
|
+
void LCD_WriteFramebuffer(void)
|
425
|
+
{
|
426
|
+
uint8 x;
|
427
|
+
lcd_set_xy(0,0); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][0]);
|
428
|
+
lcd_set_xy(0,1); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][1]);
|
429
|
+
lcd_set_xy(0,2); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][2]);
|
430
|
+
lcd_set_xy(0,3); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][3]);
|
431
|
+
lcd_set_xy(0,4); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][4]);
|
432
|
+
lcd_set_xy(0,5); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][5]);
|
433
|
+
lcd_set_xy(0,6); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][6]);
|
434
|
+
lcd_set_xy(0,7); for(x=0;x<LCD_WIDTH;x++) lcd_write_data(framebuffer[x][7]);
|
435
|
+
}
|
436
|
+
|
437
|
+
//--------------------------------------------------------------------------------------------------
|
438
|
+
// Name: LCD_SetContrast
|
439
|
+
// Function: Kontrasteinstellung
|
440
|
+
//
|
441
|
+
// Parameter: Kontrast (0..63)
|
442
|
+
// Return: -
|
443
|
+
//--------------------------------------------------------------------------------------------------
|
444
|
+
void LCD_SetContrast(uint8 contrast)
|
445
|
+
{
|
446
|
+
lcd_write_cmd(0x81);
|
447
|
+
lcd_write_cmd(contrast);
|
448
|
+
}
|
449
|
+
|
450
|
+
//--------------------------------------------------------------------------------------------------
|
451
|
+
// Name: LCD_Init
|
452
|
+
// Function: Init displaycontroller
|
453
|
+
//
|
454
|
+
// Parameter: -
|
455
|
+
// Return: -
|
456
|
+
//--------------------------------------------------------------------------------------------------
|
457
|
+
void LCD_Init(void)
|
458
|
+
{
|
459
|
+
LCD_RST_CLR; // Reset LCD-Display
|
460
|
+
SleepMs(50); // Wait ~ 200ms
|
461
|
+
LCD_RST_SET;
|
462
|
+
SleepMs(200); // Wait ~ 200ms
|
463
|
+
|
464
|
+
lcd_write_cmd(0xE2);
|
465
|
+
lcd_write_cmd(0x40);
|
466
|
+
lcd_write_cmd(0xA1);
|
467
|
+
lcd_write_cmd(0xC0);
|
468
|
+
lcd_write_cmd(0xA4);
|
469
|
+
lcd_write_cmd(0xA6);
|
470
|
+
lcd_write_cmd(0xA2);
|
471
|
+
lcd_write_cmd(0x2F);
|
472
|
+
lcd_write_cmd(0x27);
|
473
|
+
|
474
|
+
lcd_write_cmd(0x81);
|
475
|
+
lcd_write_cmd(8);
|
476
|
+
|
477
|
+
lcd_write_cmd(0xFA);
|
478
|
+
lcd_write_cmd(0x90);
|
479
|
+
lcd_write_cmd(0xAF);
|
480
|
+
|
481
|
+
LCD_ClearScreen();
|
482
|
+
LCD_WriteFramebuffer();
|
483
|
+
}
|
484
|
+
|
485
|
+
//--------------------------------------------------------------------------------------------------
|
486
|
+
//--------------------------------------------------------------------------------------------------
|
487
|
+
//--------------------------------------------------------------------------------------------------
|
488
|
+
//--------------------------------------------------------------------------------------------------
|
489
|
+
|
490
|
+
|
491
|
+
//--------------------------------------------------------------------------------------------------
|
492
|
+
// Name: LcdWriteCmd
|
493
|
+
// Function: Kommandobyte an Display senden
|
494
|
+
//
|
495
|
+
// Parameter: Byte
|
496
|
+
// Return: -
|
497
|
+
//--------------------------------------------------------------------------------------------------
|
498
|
+
void lcd_write_cmd(uint8 d)
|
499
|
+
{
|
500
|
+
LCD_CS_CLR;
|
501
|
+
LCD_RS_CLR; // Command Mode
|
502
|
+
LCD_SPI_PUTC(d);
|
503
|
+
LCD_SPI_WAIT_BUSY;
|
504
|
+
LCD_CS_SET;
|
505
|
+
}
|
506
|
+
|
507
|
+
//--------------------------------------------------------------------------------------------------
|
508
|
+
// Name: lcd_write_data
|
509
|
+
// Function: Datenbyte an Display senden
|
510
|
+
//
|
511
|
+
// Parameter: Byte
|
512
|
+
// Return: -
|
513
|
+
//--------------------------------------------------------------------------------------------------
|
514
|
+
void lcd_write_data(uint8 d)
|
515
|
+
{
|
516
|
+
LCD_CS_CLR;
|
517
|
+
LCD_RS_SET; // Data Mode
|
518
|
+
LCD_SPI_PUTC(d);
|
519
|
+
LCD_SPI_WAIT_BUSY;
|
520
|
+
LCD_CS_SET;
|
521
|
+
}
|
522
|
+
|
523
|
+
//--------------------------------------------------------------------------------------------------
|
524
|
+
// Name: LcdSetXY
|
525
|
+
// Function: Position f�r Ausgabe festlegen (Koordinaten)
|
526
|
+
//
|
527
|
+
// Parameter: X Position (Pixel), Y Position (Page / 8 Pixel Blocks)
|
528
|
+
// Return: -
|
529
|
+
//--------------------------------------------------------------------------------------------------
|
530
|
+
void lcd_set_xy(uint8 x,uint8 ypage)
|
531
|
+
{
|
532
|
+
x += LCD_X_OFFSET;
|
533
|
+
lcd_write_cmd(0x00 + (x & 0x0F));
|
534
|
+
lcd_write_cmd(0x10 + ((x>>4) & 0x0F));
|
535
|
+
lcd_write_cmd(0xB0 + (ypage & 0x07));
|
536
|
+
}
|
@@ -0,0 +1,80 @@
|
|
1
|
+
//--------------------------------------------------------------------------------------------------
|
2
|
+
// _ _
|
3
|
+
// | | | |
|
4
|
+
// ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__
|
5
|
+
// / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \.
|
6
|
+
// | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | |
|
7
|
+
// \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_|
|
8
|
+
// __/ |
|
9
|
+
// |___/ Engineering (www.emsystech.de)
|
10
|
+
//
|
11
|
+
// Filename:
|
12
|
+
// Description:
|
13
|
+
//
|
14
|
+
// Open Source Licensing
|
15
|
+
//
|
16
|
+
// This program is free software: you can redistribute it and/or modify it under the terms of
|
17
|
+
// the GNU General Public License as published by the Free Software Foundation, either version 3
|
18
|
+
// of the License, or (at your option) any later version.
|
19
|
+
//
|
20
|
+
// This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY; without
|
21
|
+
// even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
22
|
+
// GNU General Public License for more details.
|
23
|
+
//
|
24
|
+
// You should have received a copy of the GNU General Public License along with this program.
|
25
|
+
// If not, see <http://www.gnu.org/licenses/>.
|
26
|
+
//
|
27
|
+
// Dieses Programm ist Freie Software: Sie k�nnen es unter den Bedingungen der GNU General Public
|
28
|
+
// License, wie von der Free Software Foundation, Version 3 der Lizenz oder (nach Ihrer Option)
|
29
|
+
// jeder sp�teren ver�ffentlichten Version, weiterverbreiten und/oder modifizieren.
|
30
|
+
//
|
31
|
+
// Dieses Programm wird in der Hoffnung, dass es n�tzlich sein wird, aber OHNE JEDE GEW�HRLEISTUNG,
|
32
|
+
// bereitgestellt; sogar ohne die implizite Gew�hrleistung der MARKTF�HIGKEIT oder EIGNUNG F�R
|
33
|
+
// EINEN BESTIMMTEN ZWECK. Siehe die GNU General Public License f�r weitere Details.
|
34
|
+
//
|
35
|
+
// Sie sollten eine Kopie der GNU General Public License zusammen mit diesem Programm erhalten
|
36
|
+
// haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
|
37
|
+
//
|
38
|
+
// Author: Martin Steppuhn
|
39
|
+
// History: 05.11.2012 Initial version V0.9.0
|
40
|
+
//--------------------------------------------------------------------------------------------------
|
41
|
+
|
42
|
+
#ifndef LCD_H
|
43
|
+
#define LCD_H
|
44
|
+
|
45
|
+
//=== Includes =====================================================================================
|
46
|
+
|
47
|
+
#include "std_c.h"
|
48
|
+
|
49
|
+
//=== Preprocessing directives (#define) ===========================================================
|
50
|
+
|
51
|
+
#define LCD_WIDTH 128
|
52
|
+
#define LCD_HEIGHT 64
|
53
|
+
#define LCD_X_OFFSET 4 // Pixel Offset
|
54
|
+
|
55
|
+
//=== Type definitions (typedef) ===================================================================
|
56
|
+
|
57
|
+
//=== Global constants (extern) ====================================================================
|
58
|
+
|
59
|
+
//=== Global variables (extern) ====================================================================
|
60
|
+
|
61
|
+
//=== Global function prototypes ===================================================================
|
62
|
+
|
63
|
+
void LCD_ClearScreen(void);
|
64
|
+
void LCD_SetPenColor(uint8 c);
|
65
|
+
void LCD_SetFillColor(int8 c);
|
66
|
+
void LCD_SetFont(uint8 f);
|
67
|
+
void LCD_SetContrast(uint8 contrast);
|
68
|
+
|
69
|
+
void LCD_PutPixel(uint8 x,uint8 y,uint8 color);
|
70
|
+
void LCD_DrawLine(uint8 x0,uint8 y0,uint8 x1,uint8 y1);
|
71
|
+
void LCD_DrawCircle(uint8 x0,uint8 y0,uint8 radius);
|
72
|
+
void LCD_DrawEllipse(int xm, int ym, int a, int b);
|
73
|
+
void LCD_DrawRect(uint8 x0,uint8 y0,uint8 x1,uint8 y1,uint8 line);
|
74
|
+
void LCD_PrintXY(uint8 x,uint8 y,char *s);
|
75
|
+
void LCD_DrawBitmap(uint8 x0,uint8 y0,const uint8 *bmp);
|
76
|
+
|
77
|
+
void LCD_Init(void);
|
78
|
+
void LCD_WriteFramebuffer(void);
|
79
|
+
|
80
|
+
#endif
|