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.
@@ -0,0 +1,309 @@
1
+ //--------------------------------------------------------------------------------------------------
2
+ // _ _
3
+ // | | | |
4
+ // ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__
5
+ // / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \.
6
+ // | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | |
7
+ // \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_|
8
+ // __/ |
9
+ // |___/ Engineering (www.emsystech.de)
10
+ //
11
+ // Filename: main.c
12
+ // Description: Demonstration for RaspiLCD
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.09.2012 Initial version
40
+ // 18.10.2012 Update vor erster Auslieferung
41
+ // 05.11.2012 Version 0.9.0
42
+ //--------------------------------------------------------------------------------------------------
43
+
44
+ //=== Includes =====================================================================================
45
+
46
+ #include <stdio.h>
47
+ #include <string.h>
48
+ #include <stdlib.h>
49
+ #include <dirent.h>
50
+ #include <fcntl.h>
51
+ #include <assert.h>
52
+ #include <sys/mman.h>
53
+ #include <sys/types.h>
54
+ #include <sys/stat.h>
55
+ #include <unistd.h>
56
+ #include <sys/time.h>
57
+ #include <stdio.h>
58
+ #include "std_c.h"
59
+ #include "bcm2835.h"
60
+ #include "raspilcd.h"
61
+ #include "lcd.h"
62
+
63
+ //=== Preprocessing directives (#define) ===========================================================
64
+
65
+ //=== Type definitions (typedef) ===================================================================
66
+
67
+ //=== Global constants =============================================================================
68
+
69
+ //=== Global variables =============================================================================
70
+
71
+ //=== Local constants =============================================================================
72
+
73
+ #include "bmp_raspi.inc"
74
+ #include "bmp_men.inc"
75
+
76
+ //=== Local variables ==============================================================================
77
+
78
+ uint16 DemoCount;
79
+ uint8 DemoView;
80
+ char TempString[32];
81
+ uint16 DemoMem[256];
82
+
83
+ //=== Local function prototypes ====================================================================
84
+
85
+ //--------------------------------------------------------------------------------------------------
86
+ // Name: Demo Functions
87
+ // Function:
88
+ //
89
+ // Parameter:
90
+ // Return:
91
+ //--------------------------------------------------------------------------------------------------
92
+ void DemoLogo(void)
93
+ {
94
+ LCD_ClearScreen();
95
+ LCD_DrawBitmap(0,0,bmp_raspi);
96
+ LCD_SetFont(0);
97
+ LCD_PrintXY(70,4 ,"Raspi-LCD");
98
+ LCD_PrintXY(75,14,"Project");
99
+ LCD_PrintXY(68,32,"powered by");
100
+ LCD_PrintXY(70,42,"Emsystech");
101
+ LCD_PrintXY(62,52,"Engineering");
102
+ }
103
+
104
+ void DemoText(void)
105
+ {
106
+ LCD_ClearScreen();
107
+ LCD_SetFont(1);
108
+ LCD_PrintXY(30,0,"Raspi-LCD");
109
+ LCD_PrintXY(0,12,"www.emsystech.de");
110
+ LCD_SetFont(0);
111
+ LCD_PrintXY(8,29,"128 x 64 Pixel (BW)");
112
+ LCD_PrintXY(6,38,"White LED Backlight");
113
+ LCD_PrintXY(4,47,"8 Lines with 21 Char ");
114
+ LCD_PrintXY(4,56,"in the smallest Font ");
115
+ }
116
+
117
+ void DemoVector(void)
118
+ {
119
+ LCD_ClearScreen();
120
+ LCD_SetFillColor(1);
121
+ LCD_DrawRect(110,20,120,60,1);
122
+ LCD_DrawLine(0,0,127,0);
123
+ LCD_DrawLine(0,0,127,16);
124
+ LCD_DrawLine(0,0,127,32);
125
+ LCD_DrawLine(0,0,127,48);
126
+ LCD_DrawLine(0,0,127,63);
127
+ LCD_SetPenColor(1);
128
+ LCD_DrawCircle(63,31,31);
129
+ LCD_DrawCircle(8,50,5);
130
+ LCD_DrawEllipse(80,40, 30,10);
131
+ LCD_SetFillColor(0);
132
+ LCD_DrawRect(12,20,40,40,3);
133
+ LCD_SetFillColor(-1);
134
+ LCD_DrawRect(30,50,60,60,1);
135
+ }
136
+
137
+ void LogCpuTemperature(void)
138
+ {
139
+ FILE *fp;
140
+ unsigned int temp;
141
+ uint16 i;
142
+
143
+ TempString[0] = 0;
144
+
145
+ fp = fopen("/sys/class/thermal/thermal_zone0/temp", "r"); // open as file
146
+ if(fp != NULL)
147
+ {
148
+ fgets(TempString,32,fp); // get line
149
+ fclose(fp);
150
+ }
151
+
152
+ temp = 0;
153
+ if(TempString[0])
154
+ {
155
+ TempString[3]=0; // end at 1/10 �C
156
+ sscanf(TempString,"%u",&temp);
157
+ printf("%u\r\n",temp);
158
+ TempString[3]=TempString[2]; TempString[2]='.'; TempString[4]='�'; TempString[5]='C'; TempString[6]=0;
159
+ }
160
+
161
+ for(i=126;i>0;i--) DemoMem[i+1] = DemoMem[i];
162
+ DemoMem[1] = DemoMem[0];
163
+ DemoMem[0] = temp;
164
+ }
165
+
166
+ void DemoCpuTemperature(void)
167
+ {
168
+ uint16 i,y;
169
+
170
+ LCD_ClearScreen();
171
+ LCD_SetPenColor(1);
172
+ LCD_SetFont(1);
173
+ LCD_PrintXY(40,0,"CPU:");
174
+ LCD_PrintXY(80,0,TempString);
175
+
176
+ LCD_SetFont(0);
177
+ LCD_PrintXY(0,0, "60-");
178
+ LCD_PrintXY(0,18,"50-");
179
+ LCD_PrintXY(0,37,"40-");
180
+ LCD_PrintXY(0,56,"30-");
181
+ LCD_DrawLine(15,0,15,63);
182
+
183
+ for(i=16;i<128;i++)
184
+ {
185
+ y = DemoMem[127-i];
186
+
187
+ if(y > 290)
188
+ {
189
+ y = ((y - 290) / 5);
190
+ y = 64 - y;
191
+ LCD_PutPixel(i,y,1);
192
+ LCD_PutPixel(i,y+1,1);
193
+ }
194
+ }
195
+ }
196
+
197
+ void DemoCpuTemperatureInit(void)
198
+ {
199
+ uint8 i;
200
+ for(i=0;i<128;i++) DemoMem[i] = 0;
201
+ }
202
+
203
+ void DemoBubbles(void)
204
+ {
205
+ LCD_ClearScreen();
206
+ LCD_SetPenColor(1);
207
+
208
+ if(DemoMem[200]) { if(DemoMem[201] > 16) DemoMem[201]--; else DemoMem[200] = 0; }
209
+ else { if(DemoMem[201] <48) DemoMem[201]++; else DemoMem[200] = 1; }
210
+ DemoMem[202] = ((63 - DemoMem[201]) < DemoMem[201]) ? (63 - DemoMem[201]) : DemoMem[201];
211
+ DemoMem[202] = (DemoMem[202] > 20) ? 20 : DemoMem[202];
212
+ LCD_DrawEllipse(28,DemoMem[201],20+20-DemoMem[202],DemoMem[202]);
213
+
214
+ if(DemoMem[203]) { if(DemoMem[204] > 14) DemoMem[204]--; else DemoMem[203] = 0; }
215
+ else { if(DemoMem[204] <50) DemoMem[204]++; else DemoMem[203] = 1; }
216
+ DemoMem[205] = ((63 - DemoMem[204]) < DemoMem[204]) ? (63 - DemoMem[204]) : DemoMem[204];
217
+ DemoMem[205] = (DemoMem[205] > 20) ? 20 : DemoMem[205];
218
+ LCD_DrawEllipse(65,DemoMem[204],22+10-DemoMem[205],DemoMem[205]);
219
+
220
+ if(DemoMem[206]) { if(DemoMem[207] > 10) DemoMem[207]--; else DemoMem[206] = 0; }
221
+ else { if(DemoMem[207] <54) DemoMem[207]++; else DemoMem[206] = 1; }
222
+ DemoMem[208] = ((63 - DemoMem[207]) < DemoMem[207]) ? (63 - DemoMem[207]) : DemoMem[207];
223
+ DemoMem[208] = (DemoMem[208] > 15) ? 15 : DemoMem[208];
224
+ LCD_DrawEllipse(102,DemoMem[207],15+20-DemoMem[208],DemoMem[208]);
225
+ }
226
+
227
+ void DemoBubblesInit(void)
228
+ {
229
+ DemoMem[200] = 1;
230
+ DemoMem[201] = 10;
231
+ DemoMem[203] = 0;
232
+ DemoMem[204] = 40;
233
+ DemoMem[206] = 1;
234
+ DemoMem[207] = 40;
235
+ }
236
+
237
+ void DemoFont(void)
238
+ {
239
+ LCD_ClearScreen();
240
+ LCD_SetFont(0); LCD_PrintXY(0,0, "Font 0");
241
+ LCD_SetFont(1); LCD_PrintXY(0,8, "Font 1");
242
+ LCD_SetFont(2); LCD_PrintXY(0,23,"Font 2");
243
+ LCD_SetFont(3); LCD_PrintXY(0,39,"Font 3");
244
+ }
245
+
246
+ void DemoBitmap(void)
247
+ {
248
+ LCD_DrawBitmap(0,0,bmp_men);
249
+ LCD_SetFont(1); LCD_PrintXY(6,0, "Bitmap");
250
+ }
251
+
252
+ //--------------------------------------------------------------------------------------------------
253
+ //--------------------------------------------------------------------------------------------------
254
+ //--------------------------------------------------------------------------------------------------
255
+ //--------------------------------------------------------------------------------------------------
256
+ //--------------------------------------------------------------------------------------------------
257
+ int main(int argc, char **argv)
258
+ {
259
+ int Contrast,Backlight;
260
+
261
+ Contrast = 9;
262
+ Backlight = 1;
263
+
264
+ printf("RaspiLCD Demo V0.9 by Martin Steppuhn [" __DATE__ " " __TIME__"]\n");
265
+ printf("RaspberryHwRevision=%i\r\n",GetRaspberryHwRevision());
266
+
267
+ if(!RaspiLcdHwInit()) { printf("RaspiLcdHwInit() failed!\r\n"); return 1; }
268
+ LCD_Init(); // Init Display
269
+ SetBacklight(1); // Turn Backlight on
270
+
271
+ DemoView = 0;
272
+ DemoCpuTemperatureInit();
273
+ DemoBubblesInit();
274
+
275
+ while(1)
276
+ {
277
+ DemoCount++;
278
+ SleepMs(100);
279
+ UpdateButtons();
280
+ // printf("Buttons: %02X (%02X) Contrast=%i Backlight=%u\r\n",Button,ButtonPressed,Contrast,Backlight);
281
+
282
+ if((DemoCount & 3) == 0) LogCpuTemperature();
283
+
284
+ if(BUTTON_PRESSED_UP || BUTTON_PRESSED_DOWN)
285
+ {
286
+ if(BUTTON_PRESSED_UP && (Contrast < 20)) Contrast++;
287
+ if(BUTTON_PRESSED_DOWN && (Contrast > 0)) Contrast--;
288
+ LCD_SetContrast(Contrast);
289
+ }
290
+ if(BUTTON_PRESSED_CENTER)
291
+ {
292
+ Backlight = (Backlight) ? 0 : 1; // Toggle Backlight
293
+ SetBacklight(Backlight); // Write to Hardware
294
+ }
295
+ if(BUTTON_PRESSED_LEFT && DemoView) DemoView--;
296
+ if(BUTTON_PRESSED_RIGHT && (DemoView < 6)) DemoView++;
297
+
298
+ if( DemoView == 0) DemoLogo();
299
+ else if(DemoView == 1) { if((DemoCount & 3) == 0) DemoCpuTemperature(); }
300
+ else if(DemoView == 2) DemoBitmap();
301
+ else if(DemoView == 3) DemoFont();
302
+ else if(DemoView == 4) DemoVector();
303
+ else if(DemoView == 5) DemoBubbles();
304
+ else if(DemoView == 6) DemoText();
305
+
306
+ LCD_WriteFramebuffer();
307
+ }
308
+ return(0);
309
+ }
@@ -0,0 +1,230 @@
1
+ //--------------------------------------------------------------------------------------------------
2
+ // _ _
3
+ // | | | |
4
+ // ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__
5
+ // / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \.
6
+ // | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | |
7
+ // \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_|
8
+ // __/ |
9
+ // |___/ Engineering (www.emsystech.de)
10
+ //
11
+ // Filename: hal.c
12
+ // Description: Hardware abstraction layer for Raspi-LCD
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: 18.10.2012 Initial version
40
+ //--------------------------------------------------------------------------------------------------
41
+
42
+ //=== Includes =====================================================================================
43
+
44
+ #include "std_c.h"
45
+ #include <unistd.h>
46
+ #include <stdio.h>
47
+ #include <stdlib.h>
48
+ #include <string.h>
49
+ #include <time.h>
50
+ #include "raspilcd.h"
51
+
52
+ //=== Preprocessing directives (#define) ===========================================================
53
+
54
+ //=== Type definitions (typedef) ===================================================================
55
+
56
+ //=== Global constants =============================================================================
57
+
58
+ //=== Global variables =============================================================================
59
+
60
+ uint8 Button,ButtonPressed;
61
+
62
+ //=== Local constants =============================================================================
63
+
64
+ //=== Local variables ==============================================================================
65
+
66
+ uint8 PinButton[5];
67
+ uint8 ButtonMem;
68
+
69
+ //=== Local function prototypes ====================================================================
70
+
71
+
72
+ //--------------------------------------------------------------------------------------------------
73
+ // Name: HalInit
74
+ // Function: Setup GPIO for Raspi_LCD
75
+ //
76
+ // Parameter: -
77
+ // Return: -
78
+ //--------------------------------------------------------------------------------------------------
79
+ int RaspiLcdHwInit(void)
80
+ {
81
+ int HwRev;
82
+
83
+ HwRev = GetRaspberryHwRevision();
84
+
85
+ if (!bcm2835_init()) return 0;
86
+
87
+ // Buttons
88
+ PinButton[0] = 17;
89
+ PinButton[1] = (HwRev < 2) ? 21 : 27;
90
+ PinButton[2] = 22;
91
+ PinButton[3] = 23;
92
+ PinButton[4] = 24;
93
+
94
+ bcm2835_gpio_fsel(PinButton[0],BCM2835_GPIO_FSEL_INPT) ; // Set GPIO Pin to Input
95
+ bcm2835_gpio_fsel(PinButton[1],BCM2835_GPIO_FSEL_INPT) ; // Set GPIO Pin to Input
96
+ bcm2835_gpio_fsel(PinButton[2],BCM2835_GPIO_FSEL_INPT) ; // Set GPIO Pin to Input
97
+ bcm2835_gpio_fsel(PinButton[3],BCM2835_GPIO_FSEL_INPT) ; // Set GPIO Pin to Input
98
+ bcm2835_gpio_fsel(PinButton[4],BCM2835_GPIO_FSEL_INPT) ; // Set GPIO Pin to Input
99
+
100
+ bcm2835_gpio_set_pud(PinButton[0],BCM2835_GPIO_PUD_UP); // Enable Pullup
101
+ bcm2835_gpio_set_pud(PinButton[1],BCM2835_GPIO_PUD_UP); // Enable Pullup
102
+ bcm2835_gpio_set_pud(PinButton[2],BCM2835_GPIO_PUD_UP); // Enable Pullup
103
+ bcm2835_gpio_set_pud(PinButton[3],BCM2835_GPIO_PUD_UP); // Enable Pullup
104
+ bcm2835_gpio_set_pud(PinButton[4],BCM2835_GPIO_PUD_UP); // Enable Pullup
105
+
106
+ // LCD Display
107
+ bcm2835_gpio_fsel(PIN_LCD_MOSI, BCM2835_GPIO_FSEL_OUTP); // GPIO10 Output: MOSI
108
+ bcm2835_gpio_fsel(PIN_LCD_SCLK, BCM2835_GPIO_FSEL_OUTP); // GPIO11 Output: SCLK
109
+ bcm2835_gpio_fsel(PIN_LCD_RST, BCM2835_GPIO_FSEL_OUTP); // GPIO25 Output: RST
110
+ bcm2835_gpio_fsel(PIN_LCD_CS , BCM2835_GPIO_FSEL_OUTP); // GPIO8 Output: CS
111
+ bcm2835_gpio_fsel(PIN_LCD_RS, BCM2835_GPIO_FSEL_OUTP); // GPIO7 Output: RS
112
+ bcm2835_gpio_fsel(PIN_LCD_BACKLIGHT,BCM2835_GPIO_FSEL_OUTP); // GPIO18 Output: Backlight
113
+
114
+ Button = ButtonMem = ButtonPressed = 0;
115
+
116
+ return 1;
117
+ }
118
+
119
+ //--------------------------------------------------------------------------------------------------
120
+ // Name: UpdateButtons
121
+ // Function: Read button states and save them to the variable "Button" and "ButtonPressed"
122
+ //
123
+ // Parameter:
124
+ // Return:
125
+ //--------------------------------------------------------------------------------------------------
126
+ void UpdateButtons(void)
127
+ {
128
+ ButtonMem = Button; // Save last State
129
+
130
+ Button = 0;
131
+ if(!bcm2835_gpio_lev(PinButton[0])) Button |= (1<<0);
132
+ if(!bcm2835_gpio_lev(PinButton[1])) Button |= (1<<1);
133
+ if(!bcm2835_gpio_lev(PinButton[2])) Button |= (1<<2);
134
+ if(!bcm2835_gpio_lev(PinButton[3])) Button |= (1<<3);
135
+ if(!bcm2835_gpio_lev(PinButton[4])) Button |= (1<<4);
136
+
137
+ ButtonPressed = (Button ^ ButtonMem) & Button; // Set by Pressing a Button
138
+ }
139
+
140
+ //--------------------------------------------------------------------------------------------------
141
+ // Name: GetRaspberryHwRevision
142
+ // Function: Check wich Hardware is used:
143
+ // http://www.raspberrypi.org/archives/1929
144
+ //
145
+ // Model B Revision 1.0 2
146
+ // Model B Revision 1.0 + ECN0001 (no fuses, D14 removed) 3
147
+ // Model B Revision 2.0 4, 5, 6
148
+ //
149
+ // Parameter: -
150
+ // Return: 0=no info , 1=HW Rev.1, 2=HW Rev.2
151
+ //--------------------------------------------------------------------------------------------------
152
+ int GetRaspberryHwRevision(void)
153
+ {
154
+ FILE *fp;
155
+ char line[32];
156
+ char s[32];
157
+ int i;
158
+
159
+ fp = fopen("/proc/cpuinfo", "r"); // open as file
160
+ if(fp != NULL)
161
+ {
162
+ while(fgets(line,32,fp)) // get line
163
+ {
164
+ sscanf(line,"%s : %x",(char*)&s,&i); // parse for key and value
165
+ if(strcmp(s,"Revision") == 0) // check for "Revision"
166
+ {
167
+ //printf("Found: %s=%i\r\n",s,i);
168
+ if(i < 4) return 1;
169
+ else return 2;
170
+ }
171
+ }
172
+ }
173
+ else
174
+ {
175
+ //printf("cpuinfo not available.\r\n");
176
+ return 0;
177
+ }
178
+ //printf("no revision info available.\r\n");
179
+ return 0;
180
+ }
181
+
182
+
183
+ //--------------------------------------------------------------------------------------------------
184
+ // Name: SpiPutc
185
+ // Function: Emulate SPI on GPIO (Bitbanging)
186
+ //
187
+ // Parameter: Databyte to send
188
+ // Return: -
189
+ //--------------------------------------------------------------------------------------------------
190
+ void SpiPutc(unsigned char d)
191
+ {
192
+ int i,n;
193
+
194
+ for(i=0;i<8;i++)
195
+ {
196
+ if(d & 0x80) bcm2835_gpio_set(PIN_LCD_MOSI); // MOSI = 1
197
+ else bcm2835_gpio_clr(PIN_LCD_MOSI); // MOSI = 0
198
+ d <<= 1;
199
+
200
+ for(n=0;n<4;n++) bcm2835_gpio_clr(PIN_LCD_SCLK); // CLK = 0
201
+ for(n=0;n<4;n++) bcm2835_gpio_set(PIN_LCD_SCLK); // CLK = 1
202
+ }
203
+ }
204
+
205
+ //--------------------------------------------------------------------------------------------------
206
+ // Name: SetBacklight
207
+ // Function: Hintergrundbeleuchtung
208
+ //
209
+ // Parameter: 0=Off 1=On
210
+ // Return: -
211
+ //--------------------------------------------------------------------------------------------------
212
+ void SetBacklight(uint8 light)
213
+ {
214
+ if(light) bcm2835_gpio_set(PIN_LCD_BACKLIGHT);
215
+ else bcm2835_gpio_clr(PIN_LCD_BACKLIGHT) ;
216
+ }
217
+
218
+ //--------------------------------------------------------------------------------------------------
219
+ // Name: SleepMs
220
+ // Function: Sleep /Delay in Milliseconds
221
+ //
222
+ // Parameter: Milliseconds
223
+ // Return: -
224
+ //--------------------------------------------------------------------------------------------------
225
+ void SleepMs(uint32 ms)
226
+ {
227
+ bcm2835_delay(ms);
228
+ }
229
+
230
+
@@ -0,0 +1,104 @@
1
+ //--------------------------------------------------------------------------------------------------
2
+ // _ _
3
+ // | | | |
4
+ // ___ _ __ ___ ___ _ _ ___| |_ ___ ___| |__
5
+ // / _ \ '_ ` _ \/ __| | | / __| __/ _ \/ __| '_ \.
6
+ // | __/ | | | | \__ \ |_| \__ \ || __/ (__| | | |
7
+ // \___|_| |_| |_|___/\__, |___/\__\___|\___|_| |_|
8
+ // __/ |
9
+ // |___/ Engineering (www.emsystech.de)
10
+ //
11
+ // Filename: raspilcd.h
12
+ // Description: Hardware abstraction layer for Raspi-LCD
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: 18.10.2012 Initial version
40
+ // 04.11.2012 V0.9
41
+ //--------------------------------------------------------------------------------------------------
42
+
43
+ #ifndef RASPILCD_H
44
+ #define RASPILCD_H
45
+
46
+ //=== Includes =====================================================================================
47
+
48
+ #include "std_c.h"
49
+ #include "bcm2835.h"
50
+
51
+ //=== Preprocessing directives (#define) ===========================================================
52
+
53
+ // Pin Setup for RaspiLCD
54
+
55
+ #define PIN_LCD_RST 25
56
+ #define PIN_LCD_CS 8
57
+ #define PIN_LCD_RS 7
58
+ #define PIN_LCD_MOSI 10
59
+ #define PIN_LCD_SCLK 11
60
+ #define PIN_LCD_BACKLIGHT 18
61
+
62
+ #define LCD_RST_CLR bcm2835_gpio_clr(PIN_LCD_RST)
63
+ #define LCD_RST_SET bcm2835_gpio_set(PIN_LCD_RST)
64
+
65
+ #define LCD_CS_CLR bcm2835_gpio_clr(PIN_LCD_CS)
66
+ #define LCD_CS_SET bcm2835_gpio_set(PIN_LCD_CS)
67
+
68
+ #define LCD_RS_CLR bcm2835_gpio_clr(PIN_LCD_RS)
69
+ #define LCD_RS_SET bcm2835_gpio_set(PIN_LCD_RS)
70
+
71
+ #define LCD_SPI_PUTC(__d) SpiPutc(__d)
72
+ #define LCD_SPI_WAIT_BUSY
73
+
74
+ #define BUTTON_UP (Button & 0x01)
75
+ #define BUTTON_LEFT (Button & 0x02)
76
+ #define BUTTON_CENTER (Button & 0x04)
77
+ #define BUTTON_RIGHT (Button & 0x08)
78
+ #define BUTTON_DOWN (Button & 0x10)
79
+
80
+ #define BUTTON_PRESSED_UP (ButtonPressed & 0x01)
81
+ #define BUTTON_PRESSED_LEFT (ButtonPressed & 0x02)
82
+ #define BUTTON_PRESSED_CENTER (ButtonPressed & 0x04)
83
+ #define BUTTON_PRESSED_RIGHT (ButtonPressed & 0x08)
84
+ #define BUTTON_PRESSED_DOWN (ButtonPressed & 0x10)
85
+
86
+ //=== Type definitions (typedef) ===================================================================
87
+
88
+ //=== Global constants (extern) ====================================================================
89
+
90
+ //=== Global variables (extern) ====================================================================
91
+
92
+ extern uint8 Button;
93
+ extern uint8 ButtonPressed;
94
+
95
+ //=== Global function prototypes ===================================================================
96
+
97
+ int RaspiLcdHwInit(void);
98
+ void UpdateButtons(void);
99
+ int GetRaspberryHwRevision(void);
100
+ void SpiPutc(unsigned char d);
101
+ void SetBacklight(uint8 light);
102
+ void SleepMs(uint32 ms);
103
+
104
+ #endif