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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [mw/] [src/] [drivers/] [scr_ecos.c] - Blame information for rev 1773

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 673 markom
/*
2
 * Copyright (c) 1999, 2000 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
#include <assert.h>
16
#include <fcntl.h>
17
#include <limits.h>
18
#include <cyg/hal/drv_api.h>
19
#include <cyg/io/io.h>
20
#include <stdarg.h>
21
#include <stdio.h>
22
#include <stdlib.h>
23
#include <sys/stat.h>
24
#include <sys/time.h>
25
#include <sys/types.h>
26
#include <unistd.h>
27
#include "device.h"
28
#include "genfont.h"
29
#include "genmem.h"
30
#include "fb.h"
31
#include <cyg/hal/lcd_support.h>
32
 
33
static PSD  fb_open(PSD psd);
34
static void fb_close(PSD psd);
35
static void fb_setpalette(PSD psd,int first, int count, MWPALENTRY *palette);
36
static void gen_getscreeninfo(PSD psd,PMWSCREENINFO psi);
37
 
38
SCREENDEVICE    scrdev = {
39
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL,
40
        fb_open,
41
        fb_close,
42
        gen_getscreeninfo,
43
        fb_setpalette,
44
        NULL,                   /* DrawPixel subdriver*/
45
        NULL,                   /* ReadPixel subdriver*/
46
        NULL,                   /* DrawHorzLine subdriver*/
47
        NULL,                   /* DrawVertLine subdriver*/
48
        NULL,                   /* FillRect subdriver*/
49
        gen_fonts,
50
        NULL,                   /* Blit subdriver*/
51
        NULL,                   /* PreSelect*/
52
        NULL,                   /* DrawArea subdriver*/
53
        NULL,                   /* SetIOPermissions*/
54
        gen_allocatememgc,
55
        fb_mapmemgc,
56
        gen_freememgc
57
};
58
 
59
/* static variables*/
60
static int status;              /* 0=never inited, 1=once inited, 2=inited. */
61
#if 0
62
static short saved_red[256];    /* original hw palette*/
63
static short saved_green[256];
64
static short saved_blue[256];
65
#endif
66
#if PORTRAIT
67
int gr_portraitmode = PORTRAIT; /* =1 portrait left, =2 portrait right*/
68
#endif
69
 
70
/* local functions*/
71
static void     set_directcolor_palette(PSD psd);
72
 
73
/* init framebuffer*/
74
static PSD
75
fb_open(PSD psd)
76
{
77
    PSUBDRIVER subdriver;
78
    struct lcd_info li;
79
 
80
    assert(status < 2);
81
 
82
    // Initialize LCD screen
83
    lcd_init(16);
84
    lcd_getinfo(&li);
85
 
86
    psd->xres = psd->xvirtres = li.width;
87
    psd->yres = psd->yvirtres = li.height;
88
#if PORTRAIT
89
    /* automatic portrait mode if y resolution is greater than x res*/
90
    /*** commented out, PORTRAIT_MODE=[R,L] used for compile time option***/
91
    /***if(psd->yres > psd->xres)
92
        gr_portraitmode = 1;***/
93
#endif
94
    /* set planes from fb type*/
95
    if (1 /*type == FB_TYPE_PACKED_PIXELS*/)
96
        psd->planes = 1;   /* FIXME */
97
    else psd->planes = 0;        /* force error later*/
98
 
99
    psd->bpp = li.bpp;
100
    psd->ncolors = (psd->bpp >= 24)? (1 << 24): (1 << psd->bpp);
101
 
102
    /* set linelen to byte length, possibly converted later*/
103
    psd->linelen = li.rlen;
104
    psd->size = 0;               /* force subdriver init of size*/
105
 
106
    psd->flags = PSF_SCREEN | PSF_HAVEBLIT;
107
    if (psd->bpp == 16)
108
        psd->flags |= PSF_HAVEOP_COPY;
109
 
110
#if PORTRAIT
111
    /* determine whether to run in portrait mode*/
112
    if(1 /*gr_portraitmode*/) {
113
        psd->flags |= PSF_PORTRAIT;
114
 
115
        /* swap x, y*/
116
        psd->xvirtres = psd->yres;
117
        psd->yvirtres = psd->xres;
118
    }
119
#endif
120
 
121
    /* set pixel format*/
122
    switch (li.type) {
123
    case FB_TRUE_RGB565:
124
        psd->pixtype = MWPF_TRUECOLOR565;
125
        break;
126
    default:
127
        EPRINTF("Unsupported display type: %d\n", li.type);
128
        goto fail;
129
    }
130
#if 0
131
    if(1 /*visual == FB_VISUAL_TRUECOLOR || visual == FB_VISUAL_DIRECTCOLOR*/) {
132
        switch(psd->bpp) {
133
        case 8:
134
            psd->pixtype = MWPF_TRUECOLOR332;
135
            break;
136
        case 16:
137
            psd->pixtype = MWPF_TRUECOLOR565;
138
            break;
139
        case 24:
140
            psd->pixtype = MWPF_TRUECOLOR888;
141
            break;
142
        case 32:
143
            psd->pixtype = MWPF_TRUECOLOR0888;
144
            break;
145
        default:
146
            EPRINTF(
147
                "Unsupported %d color (%d bpp) truecolor framebuffer\n",
148
                psd->ncolors, psd->bpp);
149
            goto fail;
150
        }
151
    } else psd->pixtype = MWPF_PALETTE;
152
#endif
153
 
154
    diag_printf("%dx%dx%d linelen %d type %d bpp %d\n", psd->xres,
155
      psd->yres, psd->ncolors, psd->linelen, li.type, psd->bpp);
156
 
157
    /* select a framebuffer subdriver based on planes and bpp*/
158
    subdriver = select_fb_subdriver(psd);
159
    if (!subdriver) {
160
        EPRINTF("No driver for screen\n", psd->bpp);
161
        goto fail;
162
    }
163
 
164
    /*
165
     * set and initialize subdriver into screen driver
166
     * psd->size is calculated by subdriver init
167
     */
168
    if(!set_subdriver(psd, subdriver, TRUE)) {
169
        EPRINTF("Driver initialize failed\n", psd->bpp);
170
        goto fail;
171
    }
172
 
173
#if PORTRAIT
174
    if(psd->flags & PSF_PORTRAIT) {
175
        /* remember original subdriver*/
176
        _subdriver = subdriver;
177
 
178
        /* assign portrait subdriver which calls original subdriver*/
179
        set_subdriver(psd, &fbportrait, FALSE);
180
    }
181
#endif
182
    /* mmap framebuffer into this address space*/
183
    psd->addr = li.fb;
184
    if(psd->addr == NULL || psd->addr == (unsigned char *)-1) {
185
//        EPRINTF("Error mmaping %s: %m\n", env);
186
        goto fail;
187
    }
188
 
189
#if 0    /* FIXME */
190
    /* save original palette*/
191
    ioctl_getpalette(0, 16, saved_red, saved_green, saved_blue);
192
 
193
    /* setup direct color palette if required (ATI cards)*/
194
    if(visual == FB_VISUAL_DIRECTCOLOR)
195
        set_directcolor_palette(psd);
196
#endif
197
 
198
    status = 2;
199
    return psd; /* success*/
200
 
201
 fail:
202
    return NULL;
203
}
204
 
205
/* close framebuffer*/
206
static void
207
fb_close(PSD psd)
208
{
209
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);
210
#if 0
211
        int     tty;
212
 
213
        /* if not opened, return*/
214
        if(status != 2)
215
                return;
216
        status = 1;
217
 
218
        /* reset hw palette*/
219
        ioctl_setpalette(0, 256, saved_red, saved_green, saved_blue);
220
 
221
        /* unmap framebuffer*/
222
        // munmap(psd->addr, psd->size);
223
 
224
        /* close framebuffer*/
225
        close(fb);
226
#endif
227
}
228
 
229
/* setup directcolor palette - required for ATI cards*/
230
static void
231
set_directcolor_palette(PSD psd)
232
{
233
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
234
#if 0
235
        int i;
236
        short r[256], g[256], b[256];
237
 
238
        /* 16bpp uses 32 palette entries*/
239
        if(psd->bpp == 16) {
240
                /* FIXME: this still doesn't work*/
241
                for(i=0; i<32; ++i) {
242
                        //r[i] = g[i] = b[i] = ((i<<11)|(i<<6)|i)<<8;
243
                        //r[i] = g[i] = b[i] = ((i<<5)|i)<<10;
244
                        //r[i] = g[i] = b[i] = i<<11;
245
                        //r[i] = g[i] = b[i] = (i<<11) | (i<<3);
246
                        r[i] = g[i] = b[i] = (i<<11);
247
                        //r[i] = i << 8;
248
                        //g[i] = i << 10;
249
                        //b[i] = i << 8;
250
                }
251
                ioctl_setpalette(0, 32, r, g, b);
252
        } else {
253
                /* 32bpp uses 256 entries*/
254
                for(i=0; i<256; ++i)
255
                        r[i] = i<<8;
256
                ioctl_setpalette(0, 256, r, r, r);
257
        }
258
#endif
259
}
260
 
261
static int fade = 100;
262
 
263
/* convert Microwindows palette to framebuffer format and set it*/
264
static void
265
fb_setpalette(PSD psd,int first, int count, MWPALENTRY *palette)
266
{
267
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
268
#if 0
269
        int     i;
270
        unsigned short  red[count];
271
        unsigned short  green[count];
272
        unsigned short  blue[count];
273
 
274
        /* convert palette to framebuffer format*/
275
        for(i=0; i < count; i++) {
276
                MWPALENTRY *p = &palette[i];
277
 
278
                /* grayscale computation:
279
                 * red[i] = green[i] = blue[i] =
280
                 *      (p->r * 77 + p->g * 151 + p->b * 28);
281
                 */
282
                red[i] = (p->r * fade / 100) << 8;
283
                green[i] = (p->g * fade / 100) << 8;
284
                blue[i] = (p->b * fade / 100) << 8;
285
        }
286
        ioctl_setpalette(first, count, red, green, blue);
287
#endif
288
}
289
 
290
/* get framebuffer palette*/
291
void
292
ioctl_getpalette(int start, int len, short *red, short *green, short *blue)
293
{
294
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
295
#if 0
296
        struct fb_cmap cmap;
297
        cyg_uint32 sz = sizeof(cmap);
298
 
299
        cmap.start = start;
300
        cmap.len = len;
301
        cmap.red = red;
302
        cmap.green = green;
303
        cmap.blue = blue;
304
        cmap.transp = NULL;
305
 
306
        cyg_io_get_config( fb_handle, CYG_IO_GET_CONFIG_FB_PALETTE, &cmap, &sz );
307
        // ioctl(fb, FBIOGETCMAP, &cmap);
308
#endif
309
}
310
 
311
/* set framebuffer palette*/
312
void
313
ioctl_setpalette(int start, int len, short *red, short *green, short *blue)
314
{
315
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
316
#if 0
317
        struct fb_cmap cmap;
318
        cyg_uint32 sz = sizeof(cmap);
319
 
320
        cmap.start = start;
321
        cmap.len = len;
322
        cmap.red = red;
323
        cmap.green = green;
324
        cmap.blue = blue;
325
        cmap.transp = NULL;
326
 
327
        cyg_io_set_config( fb_handle, CYG_IO_SET_CONFIG_FB_PALETTE, &cmap, &sz );
328
        // ioctl(fb, FBIOPUTCMAP, &cmap);
329
#endif
330
}
331
 
332
/* experimental palette animation*/
333
void
334
setfadelevel(PSD psd, int f)
335
{
336
    printf("%s - NOT IMPLEMENTED\n", __FUNCTION__);  while (1) ;
337
#if 0
338
        int             i;
339
        unsigned short  r[256], g[256], b[256];
340
        extern MWPALENTRY gr_palette[256];
341
 
342
        if(psd->pixtype != MWPF_PALETTE)
343
                return;
344
 
345
        fade = f;
346
        if(fade > 100)
347
                fade = 100;
348
        for(i=0; i<256; ++i) {
349
                r[i] = (gr_palette[i].r * fade / 100) << 8;
350
                g[i] = (gr_palette[i].g * fade / 100) << 8;
351
                b[i] = (gr_palette[i].b * fade / 100) << 8;
352
        }
353
        ioctl_setpalette(0, 256, r, g, b);
354
#endif
355
}
356
 
357
static void
358
gen_getscreeninfo(PSD psd,PMWSCREENINFO psi)
359
{
360
    psi->rows = psd->yvirtres;
361
    psi->cols = psd->xvirtres;
362
    psi->planes = psd->planes;
363
    psi->bpp = psd->bpp;
364
    psi->ncolors = psd->ncolors;
365
    psi->pixtype = psd->pixtype;
366
    psi->fonts = NUMBER_FONTS;
367
 
368
#if 0
369
    if(psd->yvirtres > 480) {
370
        /* SVGA 800x600*/
371
        psi->xdpcm = 33;        /* assumes screen width of 24 cm*/
372
        psi->ydpcm = 33;        /* assumes screen height of 18 cm*/
373
    } else if(psd->yvirtres > 350) {
374
        /* VGA 640x480*/
375
        psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
376
        psi->ydpcm = 27;        /* assumes screen height of 18 cm*/
377
    } else {
378
        /* EGA 640x350*/
379
        psi->xdpcm = 27;        /* assumes screen width of 24 cm*/
380
        psi->ydpcm = 19;        /* assumes screen height of 18 cm*/
381
    }
382
#else
383
    psi->ydpcm = 42; // 320 / (3 * 2.54)
384
    psi->xdpcm = 38; //240 / (2.5 * 2.54)
385
#endif
386
}

powered by: WebSVN 2.1.0

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