1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Jens Arnold
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
20 //#define TEST_GREYLIB /* Uncomment for testing greylib instead of core gfx */
23 #ifdef TEST_GREYLIB /* otherwise, mylcd defaults to core gfx */
26 #include "lib/helper.h"
27 #include "lib/mylcd.h"
31 static unsigned char *gbuf
;
32 static size_t gbuf_size
= 0;
35 #define DURATION (HZ) /* longer duration gives more precise results */
36 #define RND_SEED 0x43A678C3 /* arbirary */
40 static uint16_t rand_table
[0x400];
44 static int log_init(void)
46 char logfilename
[MAX_PATH
];
49 rb
->create_numbered_filename(logfilename
, "/", "test_gfx_log_", ".txt",
50 2 IF_CNFN_NUM_(, NULL
));
51 fd
= rb
->open(logfilename
, O_RDWR
|O_CREAT
|O_TRUNC
, 0666);
55 static void init_rand_table(void)
59 rb
->srand(RND_SEED
); /* make it reproducable */
60 for (i
= 0; i
< 0x400; i
++)
61 rand_table
[i
] = rb
->rand();
64 static void time_drawpixel(void)
66 long time_start
; /* start tickcount */
67 long time_end
; /* end tickcount */
68 int count1
, count2
, count3
, count4
;
70 /* Test 1: DRMODE_SOLID */
71 mylcd_set_drawmode(DRMODE_SOLID
);
73 rb
->sleep(0); /* sync to tick */
74 time_start
= *rb
->current_tick
;
75 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
77 unsigned rnd
= rand_table
[count1
++ & 0x3ff];
78 mylcd_drawpixel((rnd
>> 8) & 0x3f, rnd
& 0x3f);
81 /* Test 2: DRMODE_FG */
82 mylcd_set_drawmode(DRMODE_FG
);
84 rb
->sleep(0); /* sync to tick */
85 time_start
= *rb
->current_tick
;
86 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
88 unsigned rnd
= rand_table
[count2
++ & 0x3ff];
89 mylcd_drawpixel((rnd
>> 8) & 0x3f, rnd
& 0x3f);
91 /* Test 3: DRMODE_BG */
92 mylcd_set_drawmode(DRMODE_BG
);
94 rb
->sleep(0); /* sync to tick */
95 time_start
= *rb
->current_tick
;
96 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
98 unsigned rnd
= rand_table
[count3
++ & 0x3ff];
99 mylcd_drawpixel((rnd
>> 8) & 0x3f, rnd
& 0x3f);
101 /* Test 4: DRMODE_COMPLEMENT */
102 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
104 rb
->sleep(0); /* sync to tick */
105 time_start
= *rb
->current_tick
;
106 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
108 unsigned rnd
= rand_table
[count4
++ & 0x3ff];
109 mylcd_drawpixel((rnd
>> 8) & 0x3f, rnd
& 0x3f);
112 rb
->fdprintf(log_fd
, "lcd_drawpixel (pixels/s): %d/%d/%d/%d\n",
113 count1
, count2
, count3
, count4
);
116 static void time_drawline(void)
118 long time_start
; /* start tickcount */
119 long time_end
; /* end tickcount */
120 int count1
, count2
, count3
, count4
;
122 /* Test 1: DRMODE_SOLID */
123 mylcd_set_drawmode(DRMODE_SOLID
);
125 rb
->sleep(0); /* sync to tick */
126 time_start
= *rb
->current_tick
;
127 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
129 unsigned rnd1
= rand_table
[count1
++ & 0x3ff];
130 unsigned rnd2
= rand_table
[count1
++ & 0x3ff];
131 mylcd_drawline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
132 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
135 /* Test 2: DRMODE_FG */
136 mylcd_set_drawmode(DRMODE_FG
);
138 rb
->sleep(0); /* sync to tick */
139 time_start
= *rb
->current_tick
;
140 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
142 unsigned rnd1
= rand_table
[count2
++ & 0x3ff];
143 unsigned rnd2
= rand_table
[count2
++ & 0x3ff];
144 mylcd_drawline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
145 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
147 /* Test 3: DRMODE_BG */
148 mylcd_set_drawmode(DRMODE_BG
);
150 rb
->sleep(0); /* sync to tick */
151 time_start
= *rb
->current_tick
;
152 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
154 unsigned rnd1
= rand_table
[count3
++ & 0x3ff];
155 unsigned rnd2
= rand_table
[count3
++ & 0x3ff];
156 mylcd_drawline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
157 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
159 /* Test 4: DRMODE_COMPLEMENT */
160 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
162 rb
->sleep(0); /* sync to tick */
163 time_start
= *rb
->current_tick
;
164 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
166 unsigned rnd1
= rand_table
[count4
++ & 0x3ff];
167 unsigned rnd2
= rand_table
[count4
++ & 0x3ff];
168 mylcd_drawline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
169 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
172 rb
->fdprintf(log_fd
, "lcd_drawline (lines/s): %d/%d/%d/%d\n",
173 count1
, count2
, count3
, count4
);
176 static void time_hline(void)
178 long time_start
; /* start tickcount */
179 long time_end
; /* end tickcount */
180 int count1
, count2
, count3
, count4
;
182 /* Test 1: DRMODE_SOLID */
183 mylcd_set_drawmode(DRMODE_SOLID
);
185 rb
->sleep(0); /* sync to tick */
186 time_start
= *rb
->current_tick
;
187 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
189 unsigned rnd1
= rand_table
[count1
++ & 0x3ff];
190 unsigned rnd2
= rand_table
[count1
++ & 0x3ff];
191 mylcd_hline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
194 /* Test 2: DRMODE_FG */
195 mylcd_set_drawmode(DRMODE_FG
);
197 rb
->sleep(0); /* sync to tick */
198 time_start
= *rb
->current_tick
;
199 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
201 unsigned rnd1
= rand_table
[count2
++ & 0x3ff];
202 unsigned rnd2
= rand_table
[count2
++ & 0x3ff];
203 mylcd_hline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
205 /* Test 3: DRMODE_BG */
206 mylcd_set_drawmode(DRMODE_BG
);
208 rb
->sleep(0); /* sync to tick */
209 time_start
= *rb
->current_tick
;
210 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
212 unsigned rnd1
= rand_table
[count3
++ & 0x3ff];
213 unsigned rnd2
= rand_table
[count3
++ & 0x3ff];
214 mylcd_hline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
216 /* Test 4: DRMODE_COMPLEMENT */
217 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
219 rb
->sleep(0); /* sync to tick */
220 time_start
= *rb
->current_tick
;
221 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
223 unsigned rnd1
= rand_table
[count4
++ & 0x3ff];
224 unsigned rnd2
= rand_table
[count4
++ & 0x3ff];
225 mylcd_hline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
228 rb
->fdprintf(log_fd
, "lcd_hline (lines/s): %d/%d/%d/%d\n",
229 count1
, count2
, count3
, count4
);
232 static void time_vline(void)
234 long time_start
; /* start tickcount */
235 long time_end
; /* end tickcount */
236 int count1
, count2
, count3
, count4
;
238 /* Test 1: DRMODE_SOLID */
239 mylcd_set_drawmode(DRMODE_SOLID
);
241 rb
->sleep(0); /* sync to tick */
242 time_start
= *rb
->current_tick
;
243 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
245 unsigned rnd1
= rand_table
[count1
++ & 0x3ff];
246 unsigned rnd2
= rand_table
[count1
++ & 0x3ff];
247 mylcd_vline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
250 /* Test 2: DRMODE_FG */
251 mylcd_set_drawmode(DRMODE_FG
);
253 rb
->sleep(0); /* sync to tick */
254 time_start
= *rb
->current_tick
;
255 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
257 unsigned rnd1
= rand_table
[count2
++ & 0x3ff];
258 unsigned rnd2
= rand_table
[count2
++ & 0x3ff];
259 mylcd_vline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
261 /* Test 3: DRMODE_BG */
262 mylcd_set_drawmode(DRMODE_BG
);
264 rb
->sleep(0); /* sync to tick */
265 time_start
= *rb
->current_tick
;
266 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
268 unsigned rnd1
= rand_table
[count3
++ & 0x3ff];
269 unsigned rnd2
= rand_table
[count3
++ & 0x3ff];
270 mylcd_vline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
272 /* Test 4: DRMODE_COMPLEMENT */
273 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
275 rb
->sleep(0); /* sync to tick */
276 time_start
= *rb
->current_tick
;
277 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
279 unsigned rnd1
= rand_table
[count4
++ & 0x3ff];
280 unsigned rnd2
= rand_table
[count4
++ & 0x3ff];
281 mylcd_vline((rnd1
>> 8) & 0x3f, rnd1
& 0x3f, rnd2
& 0x3f);
284 rb
->fdprintf(log_fd
, "lcd_vline (lines/s): %d/%d/%d/%d\n",
285 count1
, count2
, count3
, count4
);
288 static void time_fillrect(void)
290 long time_start
; /* start tickcount */
291 long time_end
; /* end tickcount */
292 int count1
, count2
, count3
, count4
;
294 /* Test 1: DRMODE_SOLID */
295 mylcd_set_drawmode(DRMODE_SOLID
);
297 rb
->sleep(0); /* sync to tick */
298 time_start
= *rb
->current_tick
;
299 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
301 unsigned rnd1
= rand_table
[count1
++ & 0x3ff];
302 unsigned rnd2
= rand_table
[count1
++ & 0x3ff];
303 mylcd_fillrect((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
304 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
307 /* Test 2: DRMODE_FG */
308 mylcd_set_drawmode(DRMODE_FG
);
310 rb
->sleep(0); /* sync to tick */
311 time_start
= *rb
->current_tick
;
312 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
314 unsigned rnd1
= rand_table
[count2
++ & 0x3ff];
315 unsigned rnd2
= rand_table
[count2
++ & 0x3ff];
316 mylcd_fillrect((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
317 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
319 /* Test 3: DRMODE_BG */
320 mylcd_set_drawmode(DRMODE_BG
);
322 rb
->sleep(0); /* sync to tick */
323 time_start
= *rb
->current_tick
;
324 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
326 unsigned rnd1
= rand_table
[count3
++ & 0x3ff];
327 unsigned rnd2
= rand_table
[count3
++ & 0x3ff];
328 mylcd_fillrect((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
329 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
331 /* Test 4: DRMODE_COMPLEMENT */
332 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
334 rb
->sleep(0); /* sync to tick */
335 time_start
= *rb
->current_tick
;
336 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
338 unsigned rnd1
= rand_table
[count4
++ & 0x3ff];
339 unsigned rnd2
= rand_table
[count4
++ & 0x3ff];
340 mylcd_fillrect((rnd1
>> 8) & 0x3f, rnd1
& 0x3f,
341 (rnd2
>> 8) & 0x3f, rnd2
& 0x3f);
344 rb
->fdprintf(log_fd
, "lcd_fillrect (rects/s): %d/%d/%d/%d\n",
345 count1
, count2
, count3
, count4
);
348 static void time_text(void) /* tests mono_bitmap performance */
350 long time_start
; /* start tickcount */
351 long time_end
; /* end tickcount */
352 int count1
, count2
, count3
, count4
;
354 rb
->lcd_setfont(FONT_SYSFIXED
);
356 /* Test 1: DRMODE_SOLID */
357 mylcd_set_drawmode(DRMODE_SOLID
);
359 rb
->sleep(0); /* sync to tick */
360 time_start
= *rb
->current_tick
;
361 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
363 unsigned rnd
= rand_table
[count1
++ & 0x3ff];
364 mylcd_putsxy((rnd
>> 8) & 0x3f, rnd
& 0x3f, "Rockbox!");
367 /* Test 2: DRMODE_FG */
368 mylcd_set_drawmode(DRMODE_FG
);
370 rb
->sleep(0); /* sync to tick */
371 time_start
= *rb
->current_tick
;
372 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
374 unsigned rnd
= rand_table
[count2
++ & 0x3ff];
375 mylcd_putsxy((rnd
>> 8) & 0x3f, rnd
& 0x3f, "Rockbox!");
377 /* Test 3: DRMODE_BG */
378 mylcd_set_drawmode(DRMODE_BG
);
380 rb
->sleep(0); /* sync to tick */
381 time_start
= *rb
->current_tick
;
382 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
384 unsigned rnd
= rand_table
[count3
++ & 0x3ff];
385 mylcd_putsxy((rnd
>> 8) & 0x3f, rnd
& 0x3f, "Rockbox!");
387 /* Test 4: DRMODE_COMPLEMENT */
388 mylcd_set_drawmode(DRMODE_COMPLEMENT
);
390 rb
->sleep(0); /* sync to tick */
391 time_start
= *rb
->current_tick
;
392 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
394 unsigned rnd
= rand_table
[count4
++ & 0x3ff];
395 mylcd_putsxy((rnd
>> 8) & 0x3f, rnd
& 0x3f, "Rockbox!");
398 rb
->fdprintf(log_fd
, "lcd_putsxy (strings/s): %d/%d/%d/%d\n",
399 count1
, count2
, count3
, count4
);
402 /* plugin entry point */
403 enum plugin_status
plugin_start(const void* parameter
)
415 rb
->splash(HZ
, "Could not create logfile");
418 rb
->fdprintf(log_fd
, "%s",
420 "Greylib performance test.\n"
422 "LCD driver performance test.\n"
424 "----------------------------\n\n"
425 "Results are printed in the following drawmode order:\n"
426 "solid/foreground/background/complement\n\n");
429 /* get the remainder of the plugin buffer */
430 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
432 /* initialize the greyscale buffer.*/
433 if (!grey_init(gbuf
, gbuf_size
, GREY_BUFFERED
|GREY_ON_COP
,
434 LCD_WIDTH
, LCD_HEIGHT
, NULL
))
437 rb
->splash(HZ
, "Couldn't init greyscale library");
441 rb
->lcd_set_backdrop(NULL
);
442 rb
->lcd_clear_display();
444 backlight_ignore_timeout();
446 rb
->splashf(0, "LCD driver performance test, please wait %d sec",
451 cpu_freq
= *rb
->cpu_frequency
; /* remember CPU frequency */
462 if (*rb
->cpu_frequency
!= cpu_freq
)
463 rb
->fdprintf(log_fd
, "\nCPU: %s\n", "clock changed!");
465 rb
->fdprintf(log_fd
, "\nCPU: %d MHz\n",
466 (cpu_freq
+ 500000) / 1000000);
469 backlight_use_settings();