1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2005 Peter D'Hoye
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "lib/helper.h"
25 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
26 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
27 #define FPS_QUIT BUTTON_MENU
28 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
29 #define FPS_QUIT BUTTON_RC_REC
30 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
31 #define FPS_QUIT BUTTON_PLAY
32 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
33 #define FPS_QUIT (BUTTON_HOME|BUTTON_REPEAT)
34 #elif CONFIG_KEYPAD == MPIO_HD200_PAD
35 #define FPS_QUIT (BUTTON_REC|BUTTON_PLAY)
36 #elif CONFIG_KEYPAD == MPIO_HD300_PAD
37 #define FPS_QUIT (BUTTON_REC|BUTTON_REPEAT)
38 #elif defined(BUTTON_OFF)
39 #define FPS_QUIT BUTTON_OFF
41 #define FPS_QUIT BUTTON_POWER
44 #define DURATION (2*HZ) /* longer duration gives more precise results */
51 #ifdef HAVE_REMOTE_LCD
52 static int remote_line
;
53 static int remote_max_line
;
56 static void log_init(void)
60 rb
->lcd_getstringsize("A", NULL
, &h
);
61 max_line
= LCD_HEIGHT
/ h
;
63 rb
->lcd_clear_display();
65 #ifdef HAVE_REMOTE_LCD
66 rb
->lcd_remote_getstringsize("A", NULL
, &h
);
67 remote_max_line
= LCD_REMOTE_HEIGHT
/ h
;
69 rb
->lcd_remote_clear_display();
70 rb
->lcd_remote_update();
74 static void log_text(char *text
)
76 rb
->lcd_puts(0, line
, text
);
77 if (++line
>= max_line
)
80 #ifdef HAVE_REMOTE_LCD
81 rb
->lcd_remote_puts(0, remote_line
, text
);
82 if (++remote_line
>= remote_max_line
)
84 rb
->lcd_remote_update();
88 static int calc_tenth_fps(int framecount
, long ticks
)
90 return (10*HZ
) * framecount
/ ticks
;
93 static void time_main_update(void)
95 char str
[32]; /* text buffer */
96 long time_start
; /* start tickcount */
97 long time_end
; /* end tickcount */
101 const int part14_x
= LCD_WIDTH
/4; /* x-offset for 1/4 update test */
102 const int part14_w
= LCD_WIDTH
/2; /* x-size for 1/4 update test */
103 const int part14_y
= LCD_HEIGHT
/4; /* y-offset for 1/4 update test */
104 const int part14_h
= LCD_HEIGHT
/2; /* y-size for 1/4 update test */
106 log_text("Main LCD Update");
108 /* Test 1: full LCD update */
110 rb
->sleep(0); /* sync to tick */
111 time_start
= *rb
->current_tick
;
112 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
117 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
118 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
121 /* Test 2: quarter LCD update */
123 rb
->sleep(0); /* sync to tick */
124 time_start
= *rb
->current_tick
;
125 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
127 rb
->lcd_update_rect(part14_x
, part14_y
, part14_w
, part14_h
);
130 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
131 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
135 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
137 #if LCD_WIDTH >= LCD_HEIGHT
138 #define YUV_WIDTH LCD_WIDTH
139 #define YUV_HEIGHT LCD_HEIGHT
140 #else /* Assume the screen is rotated on portrait LCDs */
141 #define YUV_WIDTH LCD_HEIGHT
142 #define YUV_HEIGHT LCD_WIDTH
145 static unsigned char ydata
[YUV_HEIGHT
][YUV_WIDTH
];
146 static unsigned char udata
[YUV_HEIGHT
/2][YUV_WIDTH
/2];
147 static unsigned char vdata
[YUV_HEIGHT
/2][YUV_WIDTH
/2];
149 static unsigned char * const yuvbuf
[3] = {
155 static void make_gradient_rect(int width
, int height
)
157 unsigned char vline
[YUV_WIDTH
/2];
163 for (x
= 0; x
< width
; x
++)
164 vline
[x
] = (x
<< 8) / width
;
165 for (y
= 0; y
< height
; y
++)
167 rb
->memset(udata
[y
], (y
<< 8) / height
, width
);
168 rb
->memcpy(vdata
[y
], vline
, width
);
172 static void time_main_yuv(void)
174 char str
[32]; /* text buffer */
175 long time_start
; /* start tickcount */
176 long time_end
; /* end tickcount */
180 const int part14_x
= YUV_WIDTH
/4; /* x-offset for 1/4 update test */
181 const int part14_w
= YUV_WIDTH
/2; /* x-size for 1/4 update test */
182 const int part14_y
= YUV_HEIGHT
/4; /* y-offset for 1/4 update test */
183 const int part14_h
= YUV_HEIGHT
/2; /* y-size for 1/4 update test */
185 log_text("Main LCD YUV");
187 rb
->memset(ydata
, 128, sizeof(ydata
)); /* medium grey */
189 /* Test 1: full LCD update */
190 make_gradient_rect(YUV_WIDTH
, YUV_HEIGHT
);
193 rb
->sleep(0); /* sync to tick */
194 time_start
= *rb
->current_tick
;
195 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
197 rb
->lcd_blit_yuv(yuvbuf
, 0, 0, YUV_WIDTH
,
198 0, 0, YUV_WIDTH
, YUV_HEIGHT
);
201 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
202 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
205 /* Test 2: quarter LCD update */
206 make_gradient_rect(YUV_WIDTH
/2, YUV_HEIGHT
/2);
209 rb
->sleep(0); /* sync to tick */
210 time_start
= *rb
->current_tick
;
211 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
213 rb
->lcd_blit_yuv(yuvbuf
, 0, 0, YUV_WIDTH
,
214 part14_x
, part14_y
, part14_w
, part14_h
);
217 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
218 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
223 #ifdef HAVE_REMOTE_LCD
224 static void time_remote_update(void)
226 char str
[32]; /* text buffer */
227 long time_start
; /* start tickcount */
228 long time_end
; /* end tickcount */
232 const int part14_x
= LCD_REMOTE_WIDTH
/4; /* x-offset for 1/4 update test */
233 const int part14_w
= LCD_REMOTE_WIDTH
/2; /* x-size for 1/4 update test */
234 const int part14_y
= LCD_REMOTE_HEIGHT
/4; /* y-offset for 1/4 update test */
235 const int part14_h
= LCD_REMOTE_HEIGHT
/2; /* y-size for 1/4 update test */
237 log_text("Remote LCD Update");
239 /* Test 1: full LCD update */
241 rb
->sleep(0); /* sync to tick */
242 time_start
= *rb
->current_tick
;
243 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
245 rb
->lcd_remote_update();
248 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
249 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
252 /* Test 2: quarter LCD update */
254 rb
->sleep(0); /* sync to tick */
255 time_start
= *rb
->current_tick
;
256 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
258 rb
->lcd_remote_update_rect(part14_x
, part14_y
, part14_w
, part14_h
);
261 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
262 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
269 GREY_INFO_STRUCT_IRAM
270 static unsigned char greydata
[LCD_HEIGHT
][LCD_WIDTH
];
272 static void make_grey_rect(int width
, int height
)
274 unsigned char vline
[LCD_WIDTH
];
277 for (x
= 0; x
< width
; x
++)
278 vline
[x
] = (x
<< 8) / width
;
279 for (y
= 0; y
< height
; y
++)
280 rb
->memcpy(greydata
[y
], vline
, width
);
283 static void time_greyscale(void)
285 char str
[32]; /* text buffer */
286 long time_start
; /* start tickcount */
287 long time_end
; /* end tickcount */
289 int frames_1
, frames_2
;
292 unsigned char *gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
296 for (i
= 0; i
< NUM_CORES
; i
++)
298 rb
->snprintf(str
, sizeof(str
), "Greyscale (%s)",
299 (i
> 0) ? "COP" : "CPU");
303 log_text("Greyscale library");
307 if (!grey_init(gbuf
, gbuf_size
, (i
> 0) ? GREY_ON_COP
: 0,
308 LCD_WIDTH
, LCD_HEIGHT
, NULL
))
310 log_text("greylib: out of memory.");
313 make_grey_rect(LCD_WIDTH
, LCD_HEIGHT
);
315 /* Test 1 - greyscale overlay not yet enabled */
317 rb
->sleep(0); /* sync to tick */
318 time_start
= *rb
->current_tick
;
319 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
321 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
324 time_1
= time_end
- time_start
;
326 /* Test 2 - greyscale overlay enabled */
329 rb
->sleep(0); /* sync to tick */
330 time_start
= *rb
->current_tick
;
331 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
333 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
336 time_2
= time_end
- time_start
;
339 fps
= calc_tenth_fps(frames_2
, time_2
);
340 load
= 100 - (100 * frames_2
* time_1
) / (frames_1
* time_2
);
341 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
344 if (load
> 0 && load
< 100)
346 rb
->snprintf(str
, sizeof(str
), "CPU load: %d%%", load
);
350 log_text("CPU load err (boost?)");
355 /* plugin entry point */
356 enum plugin_status
plugin_start(const void* parameter
)
358 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
367 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
368 cpu_freq
= *rb
->cpu_frequency
; /* remember CPU frequency */
370 backlight_force_on(); /* backlight control in lib/helper.c */
374 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
380 #ifdef HAVE_REMOTE_LCD
381 time_remote_update();
384 #if (CONFIG_PLATFORM & PLATFORM_NATIVE)
385 if (*rb
->cpu_frequency
!= cpu_freq
)
386 rb
->snprintf(str
, sizeof(str
), "CPU clock changed!");
388 rb
->snprintf(str
, sizeof(str
), "CPU: %d MHz",
389 (cpu_freq
+ 500000) / 1000000);
392 backlight_use_settings(); /* backlight control in lib/helper.c */
394 /* wait until user closes plugin */
395 while (rb
->button_get(true) != FPS_QUIT
);