]> cvs.zerfleddert.de Git - proxmark3-svn/blob - armsrc/LCD.c
f37aa894401dda7021b5fc99bfd4412806962b6a
[proxmark3-svn] / armsrc / LCD.c
1 //-----------------------------------------------------------------------------
2 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
3 // at your option, any later version. See the LICENSE.txt file for the text of
4 // the license.
5 //-----------------------------------------------------------------------------
6 // LCD code
7 //-----------------------------------------------------------------------------
8
9 #include "proxmark3.h"
10 #include "apps.h"
11 #include "LCD.h"
12
13 void LCDSend(unsigned int data)
14 {
15 // 9th bit set for data, clear for command
16 while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
17 // For clarity's sake we pass data with 9th bit clear and commands with 9th
18 // bit set since they're implemented as defines, se we need to invert bit
19 AT91C_BASE_SPI->SPI_TDR = data^0x100; // Send the data/command
20 }
21
22 void LCDSetXY(unsigned char x, unsigned char y)
23 {
24 LCDSend(PPASET); // page start/end ram
25 LCDSend(y); // Start Page to display to
26 LCDSend(131); // End Page to display to
27
28 LCDSend(PCASET); // column start/end ram
29 LCDSend(x); // Start Column to display to
30 LCDSend(131); // End Column to display to
31 }
32
33 void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color)
34 {
35 LCDSetXY(x,y); // Set position
36 LCDSend(PRAMWR); // Now write the pixel to the display
37 LCDSend(color); // Write the data in the specified Color
38 }
39
40 void LCDFill (unsigned char xs,unsigned char ys,unsigned char width,unsigned char height, unsigned char color)
41 {
42 unsigned char i,j;
43
44 for (i=0;i < height;i++) // Number of horizontal lines
45 {
46 LCDSetXY(xs,ys+i); // Goto start of fill area (Top Left)
47 LCDSend(PRAMWR); // Write to display
48
49 for (j=0;j < width;j++) // pixels per line
50 LCDSend(color);
51 }
52 }
53
54 void LCDString (char *lcd_string, const char *font_style,unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor)
55 {
56 unsigned int i;
57 unsigned char mask=0, px, py, xme, yme, offset;
58 const char *data;
59
60 data = font_style; // point to the start of the font table
61
62 xme = *data; // get font x width
63 data++;
64 yme = *data; // get font y length
65 data++;
66 offset = *data; // get data bytes per font
67
68 do
69 {
70 // point to data in table to be loaded
71 data = (font_style + offset) + (offset * (int)(*lcd_string - 32));
72
73 for (i=0;i < yme;i++) {
74 mask |=0x80;
75
76 for (px=x; px < (x + xme); px++) {
77 py= y + i;
78
79 if (*data & mask) LCDSetPixel (px,py,fcolor);
80 else LCDSetPixel (px,py,bcolor);
81
82 mask>>=1;
83 }
84 data++;
85 }
86 x+=xme;
87
88 lcd_string++; // next character in string
89
90 } while(*lcd_string !='\0'); // keep spitting chars out until end of string
91 }
92
93 void LCDReset(void)
94 {
95 LED_A_ON();
96 SetupSpi(SPI_LCD_MODE);
97 LOW(GPIO_LRST);
98 SpinDelay(100);
99
100 HIGH(GPIO_LRST);
101 SpinDelay(100);
102 LED_A_OFF();
103 }
104
105 void LCDInit(void)
106 {
107 int i;
108
109 LCDReset();
110
111 LCDSend(PSWRESET); // software reset
112 SpinDelay(100);
113 LCDSend(PSLEEPOUT); // exit sleep mode
114 LCDSend(PBSTRON); // booster on
115 LCDSend(PDISPON); // display on
116 LCDSend(PNORON); // normal on
117 LCDSend(PMADCTL); // rotate display 180 deg
118 LCDSend(0xC0);
119
120 LCDSend(PCOLMOD); // color mode
121 LCDSend(0x02); // 8bpp color mode
122
123 LCDSend(PSETCON); // set contrast
124 LCDSend(0xDC);
125
126 // clear display
127 LCDSetXY(0,0);
128 LCDSend(PRAMWR); // Write to display
129 i=LCD_XRES*LCD_YRES;
130 while(i--) LCDSend(WHITE);
131 }
Impressum, Datenschutz