]> git.zerfleddert.de Git - proxmark3-svn/blame - armsrc/LCD.c
FIX: lf hitag : Mea culpa, simulation should not have reader_field on. thanks to...
[proxmark3-svn] / armsrc / LCD.c
CommitLineData
bd20f8f4 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//-----------------------------------------------------------------------------
15c4dc5a 8#include "LCD.h"
9
10void LCDSend(unsigned int data)
11{
12 // 9th bit set for data, clear for command
13 while ((AT91C_BASE_SPI->SPI_SR & AT91C_SPI_TXEMPTY) == 0); // wait for the transfer to complete
14 // For clarity's sake we pass data with 9th bit clear and commands with 9th
15 // bit set since they're implemented as defines, se we need to invert bit
16 AT91C_BASE_SPI->SPI_TDR = data^0x100; // Send the data/command
17}
18
19void LCDSetXY(unsigned char x, unsigned char y)
20{
21 LCDSend(PPASET); // page start/end ram
22 LCDSend(y); // Start Page to display to
23 LCDSend(131); // End Page to display to
24
25 LCDSend(PCASET); // column start/end ram
26 LCDSend(x); // Start Column to display to
27 LCDSend(131); // End Column to display to
28}
29
30void LCDSetPixel(unsigned char x, unsigned char y, unsigned char color)
31{
32 LCDSetXY(x,y); // Set position
33 LCDSend(PRAMWR); // Now write the pixel to the display
34 LCDSend(color); // Write the data in the specified Color
35}
36
37void LCDFill (unsigned char xs,unsigned char ys,unsigned char width,unsigned char height, unsigned char color)
38{
39 unsigned char i,j;
40
41 for (i=0;i < height;i++) // Number of horizontal lines
42 {
43 LCDSetXY(xs,ys+i); // Goto start of fill area (Top Left)
44 LCDSend(PRAMWR); // Write to display
45
46 for (j=0;j < width;j++) // pixels per line
47 LCDSend(color);
48 }
49}
50
51void LCDString (char *lcd_string, const char *font_style,unsigned char x, unsigned char y, unsigned char fcolor, unsigned char bcolor)
52{
53 unsigned int i;
54 unsigned char mask=0, px, py, xme, yme, offset;
55 const char *data;
56
57 data = font_style; // point to the start of the font table
58
59 xme = *data; // get font x width
60 data++;
61 yme = *data; // get font y length
62 data++;
63 offset = *data; // get data bytes per font
64
65 do
66 {
67 // point to data in table to be loaded
68 data = (font_style + offset) + (offset * (int)(*lcd_string - 32));
69
70 for (i=0;i < yme;i++) {
71 mask |=0x80;
72
73 for (px=x; px < (x + xme); px++) {
74 py= y + i;
75
76 if (*data & mask) LCDSetPixel (px,py,fcolor);
77 else LCDSetPixel (px,py,bcolor);
78
79 mask>>=1;
80 }
81 data++;
82 }
83 x+=xme;
84
85 lcd_string++; // next character in string
86
87 } while(*lcd_string !='\0'); // keep spitting chars out until end of string
88}
89
90void LCDReset(void)
91{
92 LED_A_ON();
93 SetupSpi(SPI_LCD_MODE);
94 LOW(GPIO_LRST);
95 SpinDelay(100);
96
97 HIGH(GPIO_LRST);
98 SpinDelay(100);
99 LED_A_OFF();
100}
101
102void LCDInit(void)
103{
104 int i;
105
106 LCDReset();
107
108 LCDSend(PSWRESET); // software reset
109 SpinDelay(100);
110 LCDSend(PSLEEPOUT); // exit sleep mode
111 LCDSend(PBSTRON); // booster on
112 LCDSend(PDISPON); // display on
113 LCDSend(PNORON); // normal on
114 LCDSend(PMADCTL); // rotate display 180 deg
115 LCDSend(0xC0);
116
117 LCDSend(PCOLMOD); // color mode
118 LCDSend(0x02); // 8bpp color mode
119
120 LCDSend(PSETCON); // set contrast
121 LCDSend(0xDC);
e30c654b 122
15c4dc5a 123 // clear display
124 LCDSetXY(0,0);
125 LCDSend(PRAMWR); // Write to display
126 i=LCD_XRES*LCD_YRES;
127 while(i--) LCDSend(WHITE);
902cb3c0 128
129 // test text on different colored backgrounds
130 LCDString(" The quick brown fox ", (char *)&FONT6x8,1,1+8*0,WHITE ,BLACK );
131 LCDString(" jumped over the ", (char *)&FONT6x8,1,1+8*1,BLACK ,WHITE );
132 LCDString(" lazy dog. ", (char *)&FONT6x8,1,1+8*2,YELLOW ,RED );
133 LCDString(" AaBbCcDdEeFfGgHhIiJj ", (char *)&FONT6x8,1,1+8*3,RED ,GREEN );
134 LCDString(" KkLlMmNnOoPpQqRrSsTt ", (char *)&FONT6x8,1,1+8*4,MAGENTA,BLUE );
135 LCDString("UuVvWwXxYyZz0123456789", (char *)&FONT6x8,1,1+8*5,BLUE ,YELLOW);
136 LCDString("`-=[]_;',./~!@#$%^&*()", (char *)&FONT6x8,1,1+8*6,BLACK ,CYAN );
137 LCDString(" _+{}|:\\\"<>? ",(char *)&FONT6x8,1,1+8*7,BLUE ,MAGENTA);
138
139 // color bands
140 LCDFill(0, 1+8* 8, 132, 8, BLACK);
141 LCDFill(0, 1+8* 9, 132, 8, WHITE);
142 LCDFill(0, 1+8*10, 132, 8, RED);
143 LCDFill(0, 1+8*11, 132, 8, GREEN);
144 LCDFill(0, 1+8*12, 132, 8, BLUE);
145 LCDFill(0, 1+8*13, 132, 8, YELLOW);
146 LCDFill(0, 1+8*14, 132, 8, CYAN);
147 LCDFill(0, 1+8*15, 132, 8, MAGENTA);
148
15c4dc5a 149}
Impressum, Datenschutz