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