2 #include "../port/lib.h"
8 #include "../port/error.h"
19 int landscape = 0; /* orientation of the screen, default is 0: portait */
24 Pal0 = 0x2000, /* 16-bit pixel data in active mode (12 in passive) */
38 /* Frame buffer for 16-bit active color */
39 short palette[16]; /* entry 0 set to Pal0, the rest to 0 */
40 ushort pixel[Wid*Ht]; /* Pixel data */
44 /* LCD Control Register 0, lcd->lccr0 */
54 PDD = 12, /* 8 bits */
58 /* LCD Control Register 1, lcd->lccr1 */
59 PPL = 0, /* 10 bits */
60 HSW = 10, /* 6 bits */
61 ELW = 16, /* 8 bits */
62 BLW = 24, /* 8 bits */
66 /* LCD Control Register 2, lcd->lccr2 */
67 LPP = 0, /* 10 bits */
68 VSW = 10, /* 6 bits */
69 EFW = 16, /* 8 bits */
70 BFW = 24, /* 8 bits */
74 /* LCD Control Register 3, lcd->lccr3 */
77 API = 16, /* 4 bits */
85 /* LCD Status Register, lcd->lcsr */
115 static Memdata xgdata;
117 static Memimage xgscreen =
119 { 0, 0, Wid, Ht }, /* r */
120 { 0, 0, Wid, Ht }, /* clipr */
141 Memsubfont *memdefont;
146 ushort *vscreen; /* virtual screen */
152 static ulong rep(ulong, int);
153 static void screenwin(void);
154 static void screenputc(char *buf);
155 static void bitsyscreenputs(char *s, int n);
156 static void scroll(void);
161 /* the following line works because main memory is direct mapped */
162 gpioregs->direction |=
163 GPIO_LDD8_o|GPIO_LDD9_o|GPIO_LDD10_o|GPIO_LDD11_o
164 |GPIO_LDD12_o|GPIO_LDD13_o|GPIO_LDD14_o|GPIO_LDD15_o;
166 GPIO_LDD8_o|GPIO_LDD9_o|GPIO_LDD10_o|GPIO_LDD11_o
167 |GPIO_LDD12_o|GPIO_LDD13_o|GPIO_LDD14_o|GPIO_LDD15_o;
168 framebuf->palette[0] = Pal0;
169 lcd->dbar1 = framebuf->palette;
170 lcd->lccr3 = pcd<<PCD | 0<<ACB | 0<<API | 1<<VSP | 1<<HSP | 0<<PCP | 0<<OEP;
171 lcd->lccr2 = (Wid-1)<<LPP | vsw<<VSW | efw<<EFW | bfw<<BFW;
172 lcd->lccr1 = (Ht-16)<<PPL | hsw<<HSW | elw<<ELW | blw<<BLW;
173 lcd->lccr0 = 1<<LEN | 0<<CMS | 0<<SDS | 1<<LDM | 1<<BAM | 1<<ERM | 1<<PAS | 0<<BLE | 0<<DPD | 0<<PDD;
181 gscreen->r = Rect(0, 0, Ht, Wid);
182 gscreen->clipr = gscreen->r;
183 gscreen->width = Ht/2;
184 xgdata.bdata = (uchar *)framebuf->pixel;
186 gscreen->r = Rect(0, 0, Wid, Ht);
187 gscreen->clipr = gscreen->r;
188 gscreen->width = Wid/2;
189 xgdata.bdata = (uchar *)vscreen;
195 lcdtweak(Cmdbuf *cmd)
199 if(*cmd->f[0] == 'h')
200 lcd->lccr1 = ((Ht-16)<<PPL)
201 | (atoi(cmd->f[1])<<HSW)
202 | (atoi(cmd->f[2])<<ELW)
203 | (atoi(cmd->f[3])<<BLW);
204 if(*cmd->f[0] == 'v')
205 lcd->lccr2 = ((Wid-1)<<LPP)
206 | (atoi(cmd->f[1])<<VSW)
207 | (atoi(cmd->f[2])<<EFW)
208 | (atoi(cmd->f[3])<<BFW);
214 blankscreen(on == 0);
222 /* map the lcd regs into the kernel's virtual space */
223 lcd = (struct sa1110regs*)mapspecial(LCDREGS, sizeof(struct sa1110regs));;
225 framebuf = xspanalloc(sizeof *framebuf, 0x100, 0);
227 vscreen = xalloc(sizeof(ushort)*Wid*Ht);
237 gscreen->r = Rect(0, 0, Ht, Wid);
238 gscreen->clipr = gscreen->r;
239 gscreen->width = Ht/2;
240 xgdata.bdata = (uchar *)framebuf->pixel;
241 while (i < Wid*Ht*1/3) framebuf->pixel[i++] = 0xf800; /* red */
242 while (i < Wid*Ht*2/3) framebuf->pixel[i++] = 0xffff; /* white */
243 while (i < Wid*Ht*3/3) framebuf->pixel[i++] = 0x001f; /* blue */
245 gscreen->r = Rect(0, 0, Wid, Ht);
246 gscreen->clipr = gscreen->r;
247 gscreen->width = Wid/2;
248 xgdata.bdata = (uchar *)vscreen;
249 while (i < Wid*Ht*1/3) vscreen[i++] = 0xf800; /* red */
250 while (i < Wid*Ht*2/3) vscreen[i++] = 0xffff; /* white */
251 while (i < Wid*Ht*3/3) vscreen[i++] = 0x001f; /* blue */
252 flushmemscreen(gscreen->r);
255 memdefont = getmemdefont();
259 out.bwid = memdefont->info[' '].width;
261 blanktime = 3; /* minutes */
264 // screenputs = bitsyscreenputs;
269 flushmemscreen(Rectangle r)
274 if (landscape == 0) {
275 if (r.min.x < 0) r.min.x = 0;
276 if (r.max.x > Wid) r.max.x = Wid;
277 if (r.min.y < 0) r.min.y = 0;
278 if (r.max.y > Ht) r.max.y = Ht;
279 for (x = r.min.x; x < r.max.x; x++)
280 for (y = r.min.y; y < r.max.y; y++)
281 framebuf->pixel[(x+1)*Ht-1-y] = gamma[vscreen[y*Wid+x]];
282 start = (ulong)&framebuf->pixel[(r.min.x+1)*Ht-1-(r.max.y-1)];
283 end = (ulong)&framebuf->pixel[(r.max.x-1+1)*Ht-1-(r.min.y)];
285 start = (ulong)&framebuf->pixel[r.min.y*Ht + r.min.x];
286 end = (ulong)&framebuf->pixel[(r.max.y-1)*Ht + r.max.x - 1];
288 cachewbregion(start, end-start);
292 * export screen to devdraw
295 attachscreen(Rectangle *r, ulong *chan, int* d, int *width, int *softscreen)
299 *chan = gscreen->chan;
300 *width = gscreen->width;
301 *softscreen = (landscape == 0);
303 return (uchar*)gscreen->data->bdata;
307 getcolor(ulong p, ulong* pr, ulong* pg, ulong* pb)
313 setcolor(ulong p, ulong r, ulong g, ulong b)
320 blankscreen(int blank)
325 lcd->lccr0 &= ~(1<<LEN); /* disable the LCD */
327 while((lcd->lcsr & (1<<LDD)) == 0) {
330 iprint("LCD doesn't stop\n");
342 bitsyscreenputs(char *s, int n)
349 /* don't deadlock trying to print in interrupt */
350 if(!canlock(&screenlock))
357 i = chartorune(&r, s);
380 memsetchan(gscreen, RGB16);
385 orange = allocmemimage(Rect(0,0,1,1), RGB16);
386 orange->flags |= Frepl;
387 orange->clipr = gscreen->r;
388 orange->data->bdata[0] = 0x40;
389 orange->data->bdata[1] = 0xfd;
391 w = memdefont->info[' '].width;
392 h = memdefont->height;
394 r = insetrect(gscreen->r, 4);
396 memimagedraw(gscreen, r, memblack, ZP, memopaque, ZP, S);
397 window = insetrect(r, 4);
398 memimagedraw(gscreen, window, memwhite, ZP, memopaque, ZP, S);
400 memimagedraw(gscreen, Rect(window.min.x, window.min.y,
401 window.max.x, window.min.y+h+5+6), orange, ZP, nil, ZP, S);
402 freememimage(orange);
403 window = insetrect(window, 5);
405 greet = " Plan 9 Console ";
406 p = addpt(window.min, Pt(10, 0));
407 q = memsubfontwidth(memdefont, greet);
408 memimagestring(gscreen, p, conscol, ZP, memdefont, greet);
412 window.max.y = window.min.y+((window.max.y-window.min.y)/h)*h;
416 screenputc(char *buf)
422 static int xbuf[256];
424 if(xp < xbuf || xp >= &xbuf[sizeof(xbuf)])
429 if(curpos.y+h >= window.max.y)
436 curpos.x = window.min.x;
439 p = memsubfontwidth(memdefont, " ");
441 if(curpos.x >= window.max.x-4*w)
444 pos = (curpos.x-window.min.x)/w;
447 r = Rect(curpos.x, curpos.y, curpos.x+pos*w, curpos.y + h);
448 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
456 r = Rect(*xp, curpos.y, curpos.x, curpos.y + h);
457 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
464 p = memsubfontwidth(memdefont, buf);
467 if(curpos.x >= window.max.x-w)
471 r = Rect(curpos.x, curpos.y, curpos.x+w, curpos.y + h);
472 memimagedraw(gscreen, r, back, back->r.min, nil, back->r.min, S);
473 memimagestring(gscreen, curpos, conscol, ZP, memdefont, buf);
487 r = Rpt(window.min, Pt(window.max.x, window.max.y-o));
488 p = Pt(window.min.x, window.min.y+o);
489 memimagedraw(gscreen, r, gscreen, p, nil, p, S);
491 r = Rpt(Pt(window.min.x, window.max.y-o), window.max);
492 memimagedraw(gscreen, r, back, ZP, nil, ZP, S);