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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [rtos/] [ecos-3.0/] [packages/] [io/] [framebuf/] [current/] [tests/] [fbmacro.c] - Blame information for rev 825

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

Line No. Rev Author Line
1 786 skrzyp
//==========================================================================
2
//
3
//      fbmacro.c
4
//
5
//      Framebuffer testcase
6
//
7
//==========================================================================
8
// ####ECOSGPLCOPYRIGHTBEGIN####                                            
9
// -------------------------------------------                              
10
// This file is part of eCos, the Embedded Configurable Operating System.   
11
// Copyright (C) 2008 Free Software Foundation, Inc.                        
12
//
13
// eCos is free software; you can redistribute it and/or modify it under    
14
// the terms of the GNU General Public License as published by the Free     
15
// Software Foundation; either version 2 or (at your option) any later      
16
// version.                                                                 
17
//
18
// eCos is distributed in the hope that it will be useful, but WITHOUT      
19
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or    
20
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License    
21
// for more details.                                                        
22
//
23
// You should have received a copy of the GNU General Public License        
24
// along with eCos; if not, write to the Free Software Foundation, Inc.,    
25
// 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.            
26
//
27
// As a special exception, if other files instantiate templates or use      
28
// macros or inline functions from this file, or you compile this file      
29
// and link it with other works to produce a work based on this file,       
30
// this file does not by itself cause the resulting work to be covered by   
31
// the GNU General Public License. However the source code for this file    
32
// must still be made available in accordance with section (3) of the GNU   
33
// General Public License v2.                                               
34
//
35
// This exception does not invalidate any other reasons why a work based    
36
// on this file might be covered by the GNU General Public License.         
37
// -------------------------------------------                              
38
// ####ECOSGPLCOPYRIGHTEND####                                              
39
//==========================================================================
40
//###DESCRIPTIONBEGIN####
41
//
42
// Author(s):     bartv
43
// Date:          2008-10-06
44
//
45
//###DESCRIPTIONEND####
46
//========================================================================
47
 
48
#include <pkgconf/system.h>
49
#include <cyg/infra/cyg_type.h>
50
#include <cyg/infra/testcase.h>
51
#include <cyg/infra/diag.h>
52
#include <cyg/hal/hal_arch.h>
53
#include <cyg/hal/hal_intr.h>
54
#include <pkgconf/io_framebuf.h>
55
#include <cyg/io/framebuf.h>
56
 
57
#if defined(CYGDAT_IO_FRAMEBUF_TEST_DEVICE)
58
# define FRAMEBUF   CYGDAT_IO_FRAMEBUF_TEST_DEVICE
59
#elif defined(CYGDAT_IO_FRAMEBUF_DEFAULT_TEST_DEVICE)
60
# define FRAMEBUF   CYGDAT_IO_FRAMEBUF_DEFAULT_TEST_DEVICE
61
#else
62
# define NA_MSG "No framebuffer test device selected"
63
#endif
64
 
65
#ifndef NA_MSG
66
# if (CYG_FB_DEPTH(FRAMEBUF) < 4)
67
#  define NA_MSG    "Testcase requires a display depth of at least 4 bits/pixel"
68
# endif
69
#endif
70
 
71
#ifdef NA_MSG
72
void
73
cyg_start(void)
74
{
75
    CYG_TEST_INIT();
76
    CYG_TEST_NA(NA_MSG);
77
}
78
#else
79
 
80
#define STRING1(_a_) # _a_
81
#define STRING(_a_) STRING1(_a_)
82
 
83
// A simple bitmap. Black on the outside, then blue,
84
// then green, and a red centre.
85
static cyg_uint8    bitmap8[8][8] = {
86
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
87
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
88
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
89
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
90
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
91
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
92
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
93
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
94
};
95
 
96
static cyg_uint16   bitmap16[8][8] = {
97
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
98
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
99
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
100
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
101
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
102
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
103
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
104
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
105
};
106
 
107
static cyg_uint32   bitmap32[8][8] = {
108
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
109
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
110
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
111
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
112
    { 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
113
    { 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
114
    { 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
115
    { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
116
};
117
 
118
// The colours used by this test code. Default to the standard palette
119
// but if running on a true colour display then adjust.
120
static cyg_ucount32 colours[16]  = {
121
    CYG_FB_DEFAULT_PALETTE_BLACK,
122
    CYG_FB_DEFAULT_PALETTE_BLUE,
123
    CYG_FB_DEFAULT_PALETTE_GREEN,
124
    CYG_FB_DEFAULT_PALETTE_CYAN,
125
    CYG_FB_DEFAULT_PALETTE_RED,
126
    CYG_FB_DEFAULT_PALETTE_MAGENTA,
127
    CYG_FB_DEFAULT_PALETTE_BROWN,
128
    CYG_FB_DEFAULT_PALETTE_LIGHTGREY,
129
    CYG_FB_DEFAULT_PALETTE_DARKGREY,
130
    CYG_FB_DEFAULT_PALETTE_LIGHTBLUE,
131
    CYG_FB_DEFAULT_PALETTE_LIGHTGREEN,
132
    CYG_FB_DEFAULT_PALETTE_LIGHTCYAN,
133
    CYG_FB_DEFAULT_PALETTE_LIGHTRED,
134
    CYG_FB_DEFAULT_PALETTE_LIGHTMAGENTA,
135
    CYG_FB_DEFAULT_PALETTE_YELLOW,
136
    CYG_FB_DEFAULT_PALETTE_WHITE
137
};
138
 
139
#define BLACK        colours[0x00]
140
#define BLUE         colours[0x01]
141
#define GREEN        colours[0x02]
142
#define CYAN         colours[0x03]
143
#define RED          colours[0x04]
144
#define MAGENTA      colours[0x05]
145
#define BROWN        colours[0x06]
146
#define LIGHTGREY    colours[0x07]
147
#define DARKGREY     colours[0x08]
148
#define LIGHTBLUE    colours[0x09]
149
#define LIGHTGREEN   colours[0x0A]
150
#define LIGHTCYAN    colours[0x0B]
151
#define LIGHTRED     colours[0x0C]
152
#define LIGHTMAGENTA colours[0x0D]
153
#define YELLOW       colours[0x0E]
154
#define WHITE        colours[0x0F]
155
 
156
static void
157
reset_colours_to_true(void)
158
{
159
#if (CYG_FB_FLAGS0_TRUE_COLOUR & CYG_FB_FLAGS0(FRAMEBUF))    
160
    int i, j;
161
 
162
    for (i = 0; i < 16; i++) {
163
        colours[i] = CYG_FB_MAKE_COLOUR(FRAMEBUF,
164
                                        cyg_fb_palette_vga[i + i + i], cyg_fb_palette_vga[i + i + i + 1],cyg_fb_palette_vga[i + i + i + 2]);
165
    }
166
    for (i = 0; i < 8; i++) {
167
        for (j = 0; j < 8; j++) {
168
            bitmap16[i][j]  = colours[bitmap16[i][j]];
169
            bitmap32[i][j]  = colours[bitmap32[i][j]];
170
        }
171
    }
172
#endif    
173
}
174
 
175
void
176
cyg_start(void)
177
{
178
    int             i, j;
179
    int             x = 0, y = 0;
180
    int             result;
181
    cyg_ucount16    block_width;
182
 
183
    CYG_FB_PIXEL0_VAR(FRAMEBUF);
184
    CYG_FB_PIXEL1_VAR(FRAMEBUF);
185
 
186
#define DEPTH   CYG_FB_DEPTH(FRAMEBUF)
187
#define WIDTH   CYG_FB_WIDTH(FRAMEBUF)
188
#define HEIGHT  CYG_FB_HEIGHT(FRAMEBUF)    
189
 
190
    CYG_TEST_INIT();
191
 
192
    diag_printf("Frame buffer %s\n", STRING(FRAMEBUF));
193
    diag_printf("Depth %d, width %d, height %d\n", DEPTH, WIDTH, HEIGHT);
194
 
195
    result = CYG_FB_ON(FRAMEBUF);
196
 
197
    if (CYG_FB_FLAGS0(FRAMEBUF) & CYG_FB_FLAGS0_TRUE_COLOUR) {
198
        reset_colours_to_true();
199
    }
200
 
201
    // A white background
202
    CYG_FB_FILL_BLOCK(FRAMEBUF, 0, 0, WIDTH, HEIGHT, WHITE);
203
    // A black block in the middle, 25 pixels in.
204
    CYG_FB_FILL_BLOCK(FRAMEBUF, 32, 32, WIDTH - 64, HEIGHT - 64, BLACK);
205
 
206
    // Four diagonal lines in the corners. Red in the top left, blue in the top right,
207
    // green in the bottom left, and yellow in the bottom right.
208
    for (i = 0; i < 32; i++) {
209
        CYG_FB_WRITE_PIXEL(FRAMEBUF, i,               i,                RED);
210
        CYG_FB_WRITE_PIXEL(FRAMEBUF, (WIDTH - 1) - i, i,                BLUE);
211
        CYG_FB_WRITE_PIXEL(FRAMEBUF, i,               (HEIGHT - 1) - i, GREEN);
212
        CYG_FB_WRITE_PIXEL(FRAMEBUF, (WIDTH - 1) - i, (HEIGHT - 1) - i, YELLOW);
213
    }
214
 
215
    // Horizontal and vertical lines. Cyan at the top, magenta on the bottom,
216
    // brown on the left, lightgrey on the right.
217
    CYG_FB_WRITE_HLINE(FRAMEBUF, 32,         16,            WIDTH - 64, CYAN);
218
    CYG_FB_WRITE_HLINE(FRAMEBUF, 32,         HEIGHT - 16,   WIDTH - 64, MAGENTA);
219
    CYG_FB_WRITE_VLINE(FRAMEBUF, 16,         32,            HEIGHT - 64, BROWN);
220
    CYG_FB_WRITE_VLINE(FRAMEBUF, WIDTH - 16, 32,            HEIGHT - 64, LIGHTGREY);
221
 
222
    // Top left, diagonal lines away from 0,0 with increasing spacing horizontally
223
    for (i = 0; i < 16; i++) {
224
        CYG_FB_PIXEL0_SET(FRAMEBUF, i + 16, i);
225
        for (j = 0; j < 16; j++) {
226
            CYG_FB_PIXEL0_WRITE(FRAMEBUF, colours[i]);
227
            CYG_FB_PIXEL0_ADDX(FRAMEBUF, j);
228
        }
229
    }
230
 
231
    // Top right, diagonal lines away from the corner, with increasing spacing horizontally
232
    for (i = 0; i < 16; i++) {
233
        CYG_FB_PIXEL0_SET(FRAMEBUF, WIDTH - (i + 16), i);
234
        for (j = 0; j < 16; j++) {
235
            CYG_FB_PIXEL0_WRITE(FRAMEBUF, colours[i]);
236
            CYG_FB_PIXEL0_ADDX(FRAMEBUF, -1 * j);
237
        }
238
    }
239
 
240
    // Top left, diagonal lines away from the corner, with increasing spacing vertically
241
    for (i = 0; i < 16; i++) {
242
        CYG_FB_PIXEL0_SET(FRAMEBUF, i, i + 16);
243
        for (j = 0; j < 16; j++) {
244
            CYG_FB_PIXEL0_WRITE(FRAMEBUF, colours[i]);
245
            CYG_FB_PIXEL0_ADDY(FRAMEBUF, j);
246
        }
247
    }
248
    // Bottom left, diagonal lines away from the corner, with increasing spacing vertically
249
    for (i = 0; i < 16; i++) {
250
        CYG_FB_PIXEL0_SET(FRAMEBUF, i, HEIGHT - (i + 16));
251
        for (j = 0; j < 16; j++) {
252
            CYG_FB_PIXEL0_WRITE(FRAMEBUF, colours[i]);
253
            CYG_FB_PIXEL0_ADDY(FRAMEBUF, -1 * j);
254
        }
255
    }
256
 
257
    // Thin vertical bars in the top-middle of the screen, between the hline and the box.
258
    // Starting in the center and moving out with increasing spacing.
259
    for (j = 0; j < 8; j++) {
260
        CYG_FB_PIXEL0_SET(FRAMEBUF, (WIDTH / 2) - 2, 20 + j);
261
        CYG_FB_PIXEL0_GET(FRAMEBUF, x, y);
262
        CYG_FB_PIXEL1_SET(FRAMEBUF, x + 3, y);
263
        for (i = 0; i < 16; i++) {
264
            CYG_FB_PIXEL0_ADDX(FRAMEBUF, -1 * i);
265
            CYG_FB_PIXEL1_ADDX(FRAMEBUF, i);
266
            CYG_FB_PIXEL0_WRITE(FRAMEBUF, colours[i]);
267
            CYG_FB_PIXEL1_WRITE(FRAMEBUF, colours[i]);
268
        }
269
    }
270
 
271
 
272
    if (8 == DEPTH) {
273
        CYG_FB_WRITE_BLOCK(FRAMEBUF, 0, HEIGHT / 2, 8, 8, bitmap8, 0, 8);
274
    } else if (16 == DEPTH) {
275
        CYG_FB_WRITE_BLOCK(FRAMEBUF, 0, HEIGHT / 2, 8, 8, bitmap16, 0, 8);
276
    } else if (32 == DEPTH) {
277
        CYG_FB_WRITE_BLOCK(FRAMEBUF, 0, HEIGHT / 2, 8, 8, bitmap32, 0, 8);
278
    }
279
 
280
    block_width     = (WIDTH - 100) / 14;
281
    for (i = 1; i <= 14; i++) {
282
        CYG_FB_FILL_BLOCK(FRAMEBUF, 50 + ((i - 1) * block_width), 50, block_width, HEIGHT - 100, colours[i]);
283
    }
284
 
285
    CYG_TEST_EXIT("Done");
286
}
287
#endif  // NA_MSG

powered by: WebSVN 2.1.0

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