TranscodingSetup : fix misspelling name.
[vuplus_dvbapp] / lib / gdi / lcd.cpp
1 #include <lib/gdi/lcd.h>
2
3 #include <unistd.h>
4 #include <fcntl.h>
5 #include <sys/ioctl.h>
6
7 #if defined(HAVE_DBOX_FP_H) && defined(HAVE_DBOX_LCD_KS0713_H)
8 #include <dbox/fp.h>
9 #include <dbox/lcd-ks0713.h>
10 #else
11 #define NO_LCD 1
12 #endif
13
14 #include <lib/gdi/esize.h>
15 #include <lib/base/init.h>
16 #include <lib/base/init_num.h>
17 #include <lib/gdi/glcddc.h>
18
19 eDBoxLCD *eDBoxLCD::instance;
20
21 eLCD::eLCD()
22 {
23         lcdfd = -1;
24         locked=0;
25 }
26
27 void eLCD::setSize(int xres, int yres, int bpp)
28 {
29         res = eSize(xres, yres);
30         _buffer=new unsigned char[xres * yres * bpp/8];
31         memset(_buffer, 0, res.height()*res.width()*bpp/8);
32         _stride=res.width()*bpp/8;
33         eDebug("lcd buffer %p %d bytes, stride %d", _buffer, xres*yres*bpp/8, _stride);
34 }
35
36 eLCD::~eLCD()
37 {
38         delete [] _buffer;
39 }
40
41 int eLCD::lock()
42 {
43         if (locked)
44                 return -1;
45
46         locked=1;
47         return lcdfd;
48 }
49
50 void eLCD::unlock()
51 {
52         locked=0;
53 }
54
55 eDBoxLCD::eDBoxLCD()
56 {
57         int xres=132, yres=64, bpp=8;
58         is_oled = 0;
59 #ifndef NO_LCD
60         lcdfd = open("/dev/dbox/oled0", O_RDWR);
61         if (lcdfd < 0)
62         {
63                 FILE *f=fopen("/proc/stb/lcd/oled_brightness", "w");
64                 if (!f)
65                         f = fopen("/proc/stb/fp/oled_brightness", "w");
66                 if (f)
67                 {
68                         is_oled = 2;
69                         fclose(f);
70                 }
71                 lcdfd = open("/dev/dbox/lcd0", O_RDWR);
72         } else
73         {
74                 eDebug("found OLED display!");
75                 is_oled = 1;
76         }
77
78         if (lcdfd<0)
79                 eDebug("couldn't open LCD - load lcd.o!");
80         else
81         {
82                 int i=LCD_MODE_BIN;
83                 ioctl(lcdfd, LCD_IOCTL_ASC_MODE, &i);
84                 inverted=0;
85                 FILE *f = fopen("/proc/stb/lcd/xres", "r");
86                 if (f)
87                 {
88                         int tmp;
89                         if (fscanf(f, "%x", &tmp) == 1)
90                                 xres = tmp;
91                         fclose(f);
92                         f = fopen("/proc/stb/lcd/yres", "r");
93                         if (f)
94                         {
95                                 if (fscanf(f, "%x", &tmp) == 1)
96                                         yres = tmp;
97                                 fclose(f);
98                                 f = fopen("/proc/stb/lcd/bpp", "r");
99                                 if (f)
100                                 {
101                                         if (fscanf(f, "%x", &tmp) == 1)
102                                                 bpp = tmp;
103                                         fclose(f);
104                                 }
105                         }
106                         is_oled = 3;
107                 }
108         }
109 #endif
110 #ifdef SET_RIGHT_HALF_VFD_SKIN
111         fprintf(stdout,"SET RIGHT HALF VFD SKIN\n");
112         FILE *f = fopen("/proc/stb/lcd/right_half", "w");
113         fprintf(f,"skin");
114         fclose(f);
115 #endif
116         instance=this;
117
118         setSize(xres, yres, bpp);
119 }
120
121 void eDBoxLCD::setInverted(unsigned char inv)
122 {
123         inverted=inv;
124         update();
125 }
126
127 int eDBoxLCD::setLCDContrast(int contrast)
128 {
129 #ifndef NO_LCD
130         int fp;
131         if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
132         {
133                 eDebug("[LCD] can't open /dev/dbox/fp0");
134                 return(-1);
135         }
136
137         if(ioctl(lcdfd, LCD_IOCTL_SRV, &contrast))
138         {
139                 eDebug("[LCD] can't set lcd contrast");
140         }
141         close(fp);
142 #endif
143         return(0);
144 }
145
146 int eDBoxLCD::setLCDBrightness(int brightness)
147 {
148 #ifndef NO_LCD
149         eDebug("setLCDBrightness %d", brightness);
150         FILE *f=fopen("/proc/stb/lcd/oled_brightness", "w");
151         if (!f)
152                 f = fopen("/proc/stb/fp/oled_brightness", "w");
153         if (f)
154         {
155                 if (fprintf(f, "%d", brightness) == 0)
156                         eDebug("write /proc/stb/lcd/oled_brightness failed!! (%m)");
157                 fclose(f);
158         }
159         else
160         {
161                 int fp;
162                 if((fp=open("/dev/dbox/fp0", O_RDWR))<=0)
163                 {
164                         eDebug("[LCD] can't open /dev/dbox/fp0");
165                         return(-1);
166                 }
167
168                 if(ioctl(fp, FP_IOCTL_LCD_DIMM, &brightness)<=0)
169                         eDebug("[LCD] can't set lcd brightness (%m)");
170                 close(fp);
171         }
172 #endif
173         return(0);
174 }
175
176 eDBoxLCD::~eDBoxLCD()
177 {
178         if (lcdfd>=0)
179         {
180                 close(lcdfd);
181                 lcdfd=-1;
182         }
183 }
184
185 eDBoxLCD *eDBoxLCD::getInstance()
186 {
187         return instance;
188 }
189
190 void eDBoxLCD::update()
191 {
192 #ifdef BUILD_VUPLUS /* ikseong  */
193         return ;
194 #endif
195         if (lcdfd >= 0)
196         {
197                 if (!is_oled || is_oled == 2)
198                 {
199                         unsigned char raw[132*8];
200                         int x, y, yy;
201                         for (y=0; y<8; y++)
202                         {
203                                 for (x=0; x<132; x++)
204                                 {
205                                         int pix=0;
206                                         for (yy=0; yy<8; yy++)
207                                         {
208                                                 pix|=(_buffer[(y*8+yy)*132+x]>=108)<<yy;
209                                         }
210                                         raw[y*132+x]=(pix^inverted);
211                                 }
212                         }
213                         write(lcdfd, raw, 132*8);
214                 }
215                 else if (is_oled == 3)
216                         write(lcdfd, _buffer, _stride * res.height());
217                 else
218                 {
219                         unsigned char raw[64*64];
220                         int x, y;
221                         memset(raw, 0, 64*64);
222                         for (y=0; y<64; y++)
223                         {
224                                 int pix=0;
225                                 for (x=0; x<128 / 2; x++)
226                                 {
227                                         pix = (_buffer[y*132 + x * 2 + 2] & 0xF0) |(_buffer[y*132 + x * 2 + 1 + 2] >> 4);
228                                         if (inverted)
229                                                 pix = 0xFF - pix;
230                                         raw[y*64+x] = pix;
231                                 }
232                         }
233                         write(lcdfd, raw, 64*64);
234                 }
235         }
236 }
237