1 |
786 |
skrzyp |
//==========================================================================
|
2 |
|
|
//
|
3 |
|
|
// fb.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 FB CYGDAT_IO_FRAMEBUF_TEST_DEVICE
|
59 |
|
|
#elif defined(CYGDAT_IO_FRAMEBUF_DEFAULT_TEST_DEVICE)
|
60 |
|
|
# define FB 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(FB) < 4)
|
67 |
|
|
# define NA_MSG "Testcase requires a display depth of at least 4 bits/pixel"
|
68 |
|
|
# else
|
69 |
|
|
# define FRAMEBUF CYG_FB_STRUCT(FB)
|
70 |
|
|
# endif
|
71 |
|
|
#endif
|
72 |
|
|
|
73 |
|
|
#ifdef NA_MSG
|
74 |
|
|
void
|
75 |
|
|
cyg_start(void)
|
76 |
|
|
{
|
77 |
|
|
CYG_TEST_INIT();
|
78 |
|
|
CYG_TEST_NA(NA_MSG);
|
79 |
|
|
}
|
80 |
|
|
#else
|
81 |
|
|
|
82 |
|
|
#define STRING1(_a_) # _a_
|
83 |
|
|
#define STRING(_a_) STRING1(_a_)
|
84 |
|
|
|
85 |
|
|
// A simple bitmap. Black on the outside, then blue,
|
86 |
|
|
// then green, and a red centre.
|
87 |
|
|
static cyg_uint8 bitmap8[8][8] = {
|
88 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
89 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
90 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
91 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
92 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
93 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
94 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
95 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
96 |
|
|
};
|
97 |
|
|
|
98 |
|
|
static cyg_uint16 bitmap16[8][8] = {
|
99 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
100 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
101 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
102 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
103 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
104 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
105 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
106 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
107 |
|
|
};
|
108 |
|
|
|
109 |
|
|
static cyg_uint32 bitmap32[8][8] = {
|
110 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 },
|
111 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
112 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
113 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
114 |
|
|
{ 0x00, 0x01, 0x02, 0x04, 0x04, 0x02, 0x01, 0x00 },
|
115 |
|
|
{ 0x00, 0x01, 0x02, 0x02, 0x02, 0x02, 0x01, 0x00 },
|
116 |
|
|
{ 0x00, 0x01, 0x01, 0x01, 0x01, 0x01, 0x01, 0x00 },
|
117 |
|
|
{ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }
|
118 |
|
|
};
|
119 |
|
|
|
120 |
|
|
// The colours used by this test code. Default to the standard palette
|
121 |
|
|
// but if running on a true colour display then adjust.
|
122 |
|
|
static cyg_ucount32 colours[16] = {
|
123 |
|
|
CYG_FB_DEFAULT_PALETTE_BLACK,
|
124 |
|
|
CYG_FB_DEFAULT_PALETTE_BLUE,
|
125 |
|
|
CYG_FB_DEFAULT_PALETTE_GREEN,
|
126 |
|
|
CYG_FB_DEFAULT_PALETTE_CYAN,
|
127 |
|
|
CYG_FB_DEFAULT_PALETTE_RED,
|
128 |
|
|
CYG_FB_DEFAULT_PALETTE_MAGENTA,
|
129 |
|
|
CYG_FB_DEFAULT_PALETTE_BROWN,
|
130 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTGREY,
|
131 |
|
|
CYG_FB_DEFAULT_PALETTE_DARKGREY,
|
132 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTBLUE,
|
133 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTGREEN,
|
134 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTCYAN,
|
135 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTRED,
|
136 |
|
|
CYG_FB_DEFAULT_PALETTE_LIGHTMAGENTA,
|
137 |
|
|
CYG_FB_DEFAULT_PALETTE_YELLOW,
|
138 |
|
|
CYG_FB_DEFAULT_PALETTE_WHITE
|
139 |
|
|
};
|
140 |
|
|
|
141 |
|
|
#define BLACK colours[0x00]
|
142 |
|
|
#define BLUE colours[0x01]
|
143 |
|
|
#define GREEN colours[0x02]
|
144 |
|
|
#define CYAN colours[0x03]
|
145 |
|
|
#define RED colours[0x04]
|
146 |
|
|
#define MAGENTA colours[0x05]
|
147 |
|
|
#define BROWN colours[0x06]
|
148 |
|
|
#define LIGHTGREY colours[0x07]
|
149 |
|
|
#define DARKGREY colours[0x08]
|
150 |
|
|
#define LIGHTBLUE colours[0x09]
|
151 |
|
|
#define LIGHTGREEN colours[0x0A]
|
152 |
|
|
#define LIGHTCYAN colours[0x0B]
|
153 |
|
|
#define LIGHTRED colours[0x0C]
|
154 |
|
|
#define LIGHTMAGENTA colours[0x0D]
|
155 |
|
|
#define YELLOW colours[0x0E]
|
156 |
|
|
#define WHITE colours[0x0F]
|
157 |
|
|
|
158 |
|
|
static void
|
159 |
|
|
reset_colours_to_true(void)
|
160 |
|
|
{
|
161 |
|
|
int i, j;
|
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 |
|
|
}
|
173 |
|
|
|
174 |
|
|
void
|
175 |
|
|
cyg_start(void)
|
176 |
|
|
{
|
177 |
|
|
int i;
|
178 |
|
|
cyg_ucount16 block_width;
|
179 |
|
|
|
180 |
|
|
CYG_TEST_INIT();
|
181 |
|
|
diag_printf("Frame buffer %s\n", STRING(FRAMEBUF));
|
182 |
|
|
diag_printf("Depth %d, width %d, height %d\n", FRAMEBUF.fb_depth, FRAMEBUF.fb_width, FRAMEBUF.fb_height);
|
183 |
|
|
cyg_fb_on(&FRAMEBUF);
|
184 |
|
|
|
185 |
|
|
if (FRAMEBUF.fb_flags0 & CYG_FB_FLAGS0_TRUE_COLOUR) {
|
186 |
|
|
reset_colours_to_true();
|
187 |
|
|
}
|
188 |
|
|
|
189 |
|
|
// A white background
|
190 |
|
|
cyg_fb_fill_block(&FRAMEBUF, 0, 0, FRAMEBUF.fb_width, FRAMEBUF.fb_height, WHITE);
|
191 |
|
|
// A black block in the middle, 25 pixels in.
|
192 |
|
|
cyg_fb_fill_block(&FRAMEBUF, 25, 25, FRAMEBUF.fb_width - 50, FRAMEBUF.fb_height - 50, BLACK);
|
193 |
|
|
|
194 |
|
|
// Four diagonal lines in the corners. Red in the top left, blue in the top right,
|
195 |
|
|
// green in the bottom left, and yellow in the bottom right.
|
196 |
|
|
for (i = 0; i < 25; i++) {
|
197 |
|
|
cyg_fb_write_pixel(&FRAMEBUF, i, i, RED);
|
198 |
|
|
cyg_fb_write_pixel(&FRAMEBUF, (FRAMEBUF.fb_width - 1) - i, i, BLUE);
|
199 |
|
|
cyg_fb_write_pixel(&FRAMEBUF, i, (FRAMEBUF.fb_height - 1) - i, GREEN);
|
200 |
|
|
cyg_fb_write_pixel(&FRAMEBUF, (FRAMEBUF.fb_width - 1) - i, (FRAMEBUF.fb_height - 1) - i, YELLOW);
|
201 |
|
|
}
|
202 |
|
|
|
203 |
|
|
// Horizontal and vertical lines. Cyan at the top, magenta on the bottom,
|
204 |
|
|
// brown on the left, lightgrey on the right.
|
205 |
|
|
cyg_fb_write_hline(&FRAMEBUF, 25, 12, FRAMEBUF.fb_width - 50, CYAN);
|
206 |
|
|
cyg_fb_write_hline(&FRAMEBUF, 25, FRAMEBUF.fb_height - 12, FRAMEBUF.fb_width - 50, MAGENTA);
|
207 |
|
|
cyg_fb_write_vline(&FRAMEBUF, 12, 25, FRAMEBUF.fb_height - 50, BROWN);
|
208 |
|
|
cyg_fb_write_vline(&FRAMEBUF, FRAMEBUF.fb_width - 12, 25, FRAMEBUF.fb_height - 50, LIGHTGREY);
|
209 |
|
|
|
210 |
|
|
// Display a simple bitmap on the left, halfway down.
|
211 |
|
|
if (8 == FRAMEBUF.fb_depth) {
|
212 |
|
|
cyg_fb_write_block(&FRAMEBUF, 0, FRAMEBUF.fb_height / 2, 8, 8, bitmap8, 0, 8);
|
213 |
|
|
} else if (16 == FRAMEBUF.fb_depth) {
|
214 |
|
|
cyg_fb_write_block(&FRAMEBUF, 0, FRAMEBUF.fb_height / 2, 8, 8, bitmap16, 0, 8);
|
215 |
|
|
} else if (32 == FRAMEBUF.fb_depth) {
|
216 |
|
|
cyg_fb_write_block(&FRAMEBUF, 0, FRAMEBUF.fb_height / 2, 8, 8, bitmap32, 0, 8);
|
217 |
|
|
}
|
218 |
|
|
|
219 |
|
|
// And 14 vertical stripes, from blue to yellow, in the centre of the box.
|
220 |
|
|
block_width = (FRAMEBUF.fb_width - 100) / 14;
|
221 |
|
|
for (i = 1; i <= 14; i++) {
|
222 |
|
|
cyg_fb_fill_block(&FRAMEBUF, 50 + ((i - 1) * block_width), 50, block_width, FRAMEBUF.fb_height - 100, colours[i]);
|
223 |
|
|
}
|
224 |
|
|
|
225 |
|
|
cyg_fb_synch(&FRAMEBUF, CYG_FB_UPDATE_NOW);
|
226 |
|
|
|
227 |
|
|
CYG_TEST_EXIT("Done");
|
228 |
|
|
}
|
229 |
|
|
#endif // NA_MSG
|