OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-2.0/] [packages/] [services/] [gfx/] [mw/] [v2_0/] [src/] [drivers/] [scr_ecos.c] - Blame information for rev 174

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 27 unneback
/*
2
 * Copyright (c) 1999, 2000, 2002 Greg Haerr <greg@censoft.com>
3
 *
4
 * Microwindows Screen Driver for Linux kernel framebuffers
5
 *
6
 * Portions used from Ben Pfaff's BOGL <pfaffben@debian.org>
7
 *
8
 * Modified for eCos by
9
 *   Gary Thomas <gthomas@redhat.com>
10
 *   Richard Panton <richard.panton@3glab.org>
11
 *
12
 * Note: modify select_fb_driver() to add new framebuffer subdrivers
13
 */
14
#define _GNU_SOURCE 1
15
 
16
#include <pkgconf/system.h>
17
#ifdef CYGPKG_HAL_ARM
18
 
19
#include <assert.h>
20
#include <fcntl.h>
21
#include <limits.h>
22
#include <cyg/hal/drv_api.h>
23
#include <cyg/infra/diag.h>
24
#include <cyg/io/io.h>
25
#include <stdarg.h>
26
#include <stdio.h>
27
#include <stdlib.h>
28
#include <sys/stat.h>
29
#include <sys/time.h>
30
#include <sys/types.h>
31
#include <unistd.h>
32
#include "device.h"
33
#include "genfont.h"
34
#include "genmem.h"
35
#include "fb.h"
36
#include <cyg/hal/lcd_support.h>
37
 
38
static PSD  fb_open(PSD psd);
39
static void fb_close(PSD psd);
40
static void fb_setpalette(PSD psd,int first, int count, MWPALENTRY *palette);
41
static void gen_getscreeninfo(PSD psd,PMWSCREENINFO psi);
42
static void set_portrait_mode(PSD psd, int portraitmode);
43
 
44
SCREENDEVICE    scrdev = {
45
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
46
        fb_open,
47
        fb_close,
48
        gen_getscreeninfo,
49
        fb_setpalette,
50
        NULL,                   /* DrawPixel subdriver*/
51
        NULL,                   /* ReadPixel subdriver*/
52
        NULL,                   /* DrawHorzLine subdriver*/
53
        NULL,                   /* DrawVertLine subdriver*/
54
        NULL,                   /* FillRect subdriver*/
55
        gen_fonts,
56
        NULL,                   /* Blit subdriver*/
57
        NULL,                   /* PreSelect*/
58
        NULL,                   /* DrawArea subdriver*/
59
        NULL,                   /* SetIOPermissions*/
60
        gen_allocatememgc,
61
        fb_mapmemgc,
62
        gen_freememgc,
63
        NULL,                   /* StretchBlit subdriver*/
64
        set_portrait_mode       /* SetPortrait*/
65
};
66
 
67
/* static variables*/
68
static int status;              /* 0=never inited, 1=once inited, 2=inited. */
69
#if 0
70
static short saved_red[256];    /* original hw palette*/
71
static short saved_green[256];
72
static short saved_blue[256];
73
#endif
74
extern SUBDRIVER fbportrait_left, fbportrait_right, fbportrait_down;
75
 
76
/* local functions*/
77
static void     set_directcolor_palette(PSD psd);
78
 
79
/* init framebuffer*/
80
static PSD
81
fb_open(PSD psd)
82
{
83
    PSUBDRIVER subdriver;
84
    struct lcd_info li;
85
 
86
    assert(status < 2);
87
 
88
    // Initialize LCD screen
89
    lcd_init(16);
90
    lcd_getinfo(&li);
91
 
92
    psd->xres = psd->xvirtres = li.width;
93
    psd->yres = psd->yvirtres = li.height;
94
    psd->portrait = MWPORTRAIT_NONE;
95
 
96
    /* set planes from fb type*/
97
    if (1 /*type == FB_TYPE_PACKED_PIXELS*/)
98
        psd->planes = 1;   /* FIXME */
99
    else psd->planes = 0;        /* force error later*/
100
 
101
    psd->bpp = li.bpp;
102
    psd->ncolors = (psd->bpp >= 24)? (1 << 24): (1 << psd->bpp);
103
 
104
    /* set linelen to byte length, possibly converted later*/
105
    psd->linelen = li.rlen;
106
    psd->size = 0;               /* force subdriver init of size*/
107
 
108
    psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
109
    if (psd->bpp == 16)
110
        psd->flags |= PSF_HAVEOP_COPY;
111
 
112
    /* set pixel format*/
113
    switch (li.type) {
114
#ifdef FB_TRUE_RGB555
115
    case FB_TRUE_RGB555:
116
        psd->pixtype = MWPF_TRUECOLOR555;
117
        break;
118
#endif
119
#ifdef FB_TRUE_RGB565
120
    case FB_TRUE_RGB565:
121
        psd->pixtype = MWPF_TRUECOLOR565;
122
        break;
123
#endif
124
    default:
125
        EPRINTF("Unsupported display type: %d\n", li.type);
126
        goto fail;
127
    }
128
#if 0
129
    if(1 /*visual == FB_VISUAL_TRUECOLOR || visual == FB_VISUAL_DIRECTCOLOR*/) {
130
        switch(psd->bpp) {
131
        case 8:
132
            psd->pixtype = MWPF_TRUECOLOR332;
133
            break;
134
        case 16:
135
            psd->pixtype = MWPF_TRUECOLOR565;
136
            break;
137
        case 24:
138
            psd->pixtype = MWPF_TRUECOLOR888;
139
            break;
140
        case 32:
141
            psd->pixtype = MWPF_TRUECOLOR0888;
142
            break;
143
        default:
144
            EPRINTF(
145
                "Unsupported %d color (%d bpp) truecolor framebuffer\n",
146
                psd->ncolors, psd->bpp);
147
            goto fail;
148
        }
149
    } else psd->pixtype = MWPF_PALETTE;
150
#endif
151
 
152
    diag_printf("%dx%dx%d linelen %d type %d bpp %d\n", psd->xres,
153
      psd->yres, psd->ncolors, psd->linelen, li.type, psd->bpp);
154
 
155
    /* select a framebuffer subdriver based on planes and bpp*/
156
    subdriver = select_fb_subdriver(psd);
157
    if (!subdriver) {
158
        EPRINTF("No driver for screen\n", psd->bpp);
159
        goto fail;
160
    }
161
 
162
    /*
163
     * set and initialize subdriver into screen driver
164
     * psd->size is calculated by subdriver init
165
     */
166
    if(!set_subdriver(psd, subdriver, TRUE)) {
167
        EPRINTF("Driver initialize failed\n", psd->bpp);
168
        goto fail;
169
    }
170
    /* Remember this as the original (HW) subdriver */
171
    psd->orgsubdriver = subdriver;
172
 
173
    /* mmap framebuffer into this address space*/
174
    psd->addr = li.fb;
175
    if(psd->addr == NULL || psd->addr == (unsigned char *)-1) {
176
//        EPRINTF("Error mmaping %s: %m\n", env);
177
        goto fail;
178
    }
179
 
180
#if 0    /* FIXME */
181
    /* save original palette*/
182
    ioctl_getpalette(0, 16, saved_red, saved_green, saved_blue);
183
 
184
    /* setup direct color palette if required (ATI cards)*/
185
    if(visual == FB_VISUAL_DIRECTCOLOR)
186
        set_directcolor_palette(psd);
187
#endif
188
 
189
    status = 2;
190
    return psd; /* success*/
191
 
192
 fail:
193
    return NULL;
194
}
195
 
196
/* close framebuffer*/
197
static void
198
fb_close(PSD psd)
199
{
200
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);
201
#if 0
202
        int     tty;
203
 
204
        /* if not opened, return*/
205
        if(status != 2)
206
                return;
207
        status = 1;
208
 
209
        /* reset hw palette*/
210
        ioctl_setpalette(0, 256, saved_red, saved_green, saved_blue);
211
 
212
        /* unmap framebuffer*/
213
        // munmap(psd->addr, psd->size);
214
 
215
        /* close framebuffer*/
216
        close(fb);
217
#endif
218
}
219
 
220
/* setup directcolor palette - required for ATI cards*/
221
static void
222
set_directcolor_palette(PSD psd)
223
{
224
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
225
#if 0
226
        int i;
227
        short r[256], g[256], b[256];
228
 
229
        /* 16bpp uses 32 palette entries*/
230
        if(psd->bpp == 16) {
231
                /* FIXME: this still doesn't work*/
232
                for(i=0; i<32; ++i) {
233
                        //r[i] = g[i] = b[i] = ((i<<11)|(i<<6)|i)<<8;
234
                        //r[i] = g[i] = b[i] = ((i<<5)|i)<<10;
235
                        //r[i] = g[i] = b[i] = i<<11;
236
                        //r[i] = g[i] = b[i] = (i<<11) | (i<<3);
237
                        r[i] = g[i] = b[i] = (i<<11);
238
                        //r[i] = i << 8;
239
                        //g[i] = i << 10;
240
                        //b[i] = i << 8;
241
                }
242
                ioctl_setpalette(0, 32, r, g, b);
243
        } else {
244
                /* 32bpp uses 256 entries*/
245
                for(i=0; i<256; ++i)
246
                        r[i] = i<<8;
247
                ioctl_setpalette(0, 256, r, r, r);
248
        }
249
#endif
250
}
251
 
252
static int fade = 100;
253
 
254
/* convert Microwindows palette to framebuffer format and set it*/
255
static void
256
fb_setpalette(PSD psd,int first, int count, MWPALENTRY *palette)
257
{
258
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
259
#if 0
260
        int     i;
261
        unsigned short  red[count];
262
        unsigned short  green[count];
263
        unsigned short  blue[count];
264
 
265
        /* convert palette to framebuffer format*/
266
        for(i=0; i < count; i++) {
267
                MWPALENTRY *p = &palette[i];
268
 
269
                /* grayscale computation:
270
                 * red[i] = green[i] = blue[i] =
271
                 *      (p->r * 77 + p->g * 151 + p->b * 28);
272
                 */
273
                red[i] = (p->r * fade / 100) << 8;
274
                green[i] = (p->g * fade / 100) << 8;
275
                blue[i] = (p->b * fade / 100) << 8;
276
        }
277
        ioctl_setpalette(first, count, red, green, blue);
278
#endif
279
}
280
 
281
/* get framebuffer palette*/
282
void
283
ioctl_getpalette(int start, int len, short *red, short *green, short *blue)
284
{
285
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
286
#if 0
287
        struct fb_cmap cmap;
288
        cyg_uint32 sz = sizeof(cmap);
289
 
290
        cmap.start = start;
291
        cmap.len = len;
292
        cmap.red = red;
293
        cmap.green = green;
294
        cmap.blue = blue;
295
        cmap.transp = NULL;
296
 
297
        cyg_io_get_config( fb_handle, CYG_IO_GET_CONFIG_FB_PALETTE, &cmap, &sz );
298
        // ioctl(fb, FBIOGETCMAP, &cmap);
299
#endif
300
}
301
 
302
/* set framebuffer palette*/
303
void
304
ioctl_setpalette(int start, int len, short *red, short *green, short *blue)
305
{
306
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
307
#if 0
308
        struct fb_cmap cmap;
309
        cyg_uint32 sz = sizeof(cmap);
310
 
311
        cmap.start = start;
312
        cmap.len = len;
313
        cmap.red = red;
314
        cmap.green = green;
315
        cmap.blue = blue;
316
        cmap.transp = NULL;
317
 
318
        cyg_io_set_config( fb_handle, CYG_IO_SET_CONFIG_FB_PALETTE, &cmap, &sz );
319
        // ioctl(fb, FBIOPUTCMAP, &cmap);
320
#endif
321
}
322
 
323
/* experimental palette animation*/
324
void
325
setfadelevel(PSD psd, int f)
326
{
327
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
328
#if 0
329
        int             i;
330
        unsigned short  r[256], g[256], b[256];
331
        extern MWPALENTRY gr_palette[256];
332
 
333
        if(psd->pixtype != MWPF_PALETTE)
334
                return;
335
 
336
        fade = f;
337
        if(fade > 100)
338
                fade = 100;
339
        for(i=0; i<256; ++i) {
340
                r[i] = (gr_palette[i].r * fade / 100) << 8;
341
                g[i] = (gr_palette[i].g * fade / 100) << 8;
342
                b[i] = (gr_palette[i].b * fade / 100) << 8;
343
        }
344
        ioctl_setpalette(0, 256, r, g, b);
345
#endif
346
}
347
 
348
static void
349
gen_getscreeninfo(PSD psd,PMWSCREENINFO psi)
350
{
351
    psi->rows = psd->yvirtres;
352
    psi->cols = psd->xvirtres;
353
    psi->planes = psd->planes;
354
    psi->bpp = psd->bpp;
355
    psi->ncolors = psd->ncolors;
356
    psi->pixtype = psd->pixtype;
357
    psi->fonts = NUMBER_FONTS;
358
    psi->portrait = psd->portrait;
359
 
360
    switch (psd->portrait) {
361
    case MWPORTRAIT_NONE:
362
        psi->fbdriver = psd->orgsubdriver;
363
        break;
364
    case MWPORTRAIT_RIGHT:
365
        psi->fbdriver = &fbportrait_right;
366
        break;
367
    case MWPORTRAIT_LEFT:
368
        psi->fbdriver = &fbportrait_left;
369
        break;
370
    case MWPORTRAIT_DOWN:
371
        psi->fbdriver = &fbportrait_down;
372
        break;
373
    }
374
 
375
    switch (psd->pixtype) {
376
    case MWPF_TRUECOLOR555:
377
        psi->rmask = 0x7c00;
378
        psi->gmask = 0x03e0;
379
        psi->bmask = 0x001f;
380
        break;
381
    case MWPF_TRUECOLOR565:
382
        psi->rmask = 0xf800;
383
        psi->gmask = 0x07e0;
384
        psi->bmask = 0x001f;
385
        break;
386
    default:
387
        printf("%s - unsupported pixtype\n", __FUNCTION__);
388
        psi->rmask = 0xff;
389
        psi->gmask = 0xff;
390
        psi->bmask = 0xff;
391
        break;
392
    }
393
 
394
 
395
#if 0
396
    if(psd->yvirtres > 480) {
397
        /* SVGA 800x600*/
398
        psi->xdpcm = 33;        /* assumes screen width of 24 cm*/
399
        psi->ydpcm = 33;        /* assumes screen height of 18 cm*/
400
    } else if(psd->yvirtres > 350) {
401
        /* VGA 640x480*/
402
        psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
403
        psi->ydpcm = 27;        /* assumes screen height of 18 cm*/
404
    } else {
405
        /* EGA 640x350*/
406
        psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
407
        psi->ydpcm = 19;        /* assumes screen height of 18 cm*/
408
    }
409
#else
410
    // FIXME
411
    psi->ydpcm = 42; // 320 / (3 * 2.54)
412
    psi->xdpcm = 38; //240 / (2.5 * 2.54)
413
#endif
414
}
415
 
416
static void
417
set_portrait_mode(PSD psd, int portraitmode)
418
{
419
    psd->portrait = portraitmode;
420
    switch (portraitmode) {
421
    case MWPORTRAIT_NONE:
422
        psd->xvirtres = psd->xres;
423
        psd->yvirtres = psd->yres;
424
        set_subdriver(psd, psd->orgsubdriver, FALSE);
425
        break;
426
    case MWPORTRAIT_RIGHT:
427
        psd->xvirtres = psd->yres;
428
        psd->yvirtres = psd->xres;
429
        set_subdriver(psd, &fbportrait_right, FALSE);
430
        break;
431
    case MWPORTRAIT_LEFT:
432
        psd->xvirtres = psd->yres;
433
        psd->yvirtres = psd->xres;
434
        set_subdriver(psd, &fbportrait_left, FALSE);
435
        break;
436
    case MWPORTRAIT_DOWN:
437
        psd->xvirtres = psd->xres;
438
        psd->yvirtres = psd->yres;
439
        set_subdriver(psd, &fbportrait_down, FALSE);
440
        break;
441
    default:
442
        break;
443
    }
444
}
445
 
446
#endif

powered by: WebSVN 2.1.0

© copyright 1999-2025 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.