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 #ifdef HAVE_LCD_BITMAP
29 #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) || \
30 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
31 #define FPS_QUIT BUTTON_MENU
32 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
33 #define FPS_QUIT BUTTON_RC_REC
34 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
35 #define FPS_QUIT (BUTTON_HOME|BUTTON_REPEAT)
36 #elif defined(BUTTON_OFF)
37 #define FPS_QUIT BUTTON_OFF
39 #define FPS_QUIT BUTTON_POWER
42 #define DURATION (2*HZ) /* longer duration gives more precise results */
49 #ifdef HAVE_REMOTE_LCD
50 static int remote_line
;
51 static int remote_max_line
;
54 static unsigned char *gbuf
;
55 static size_t gbuf_size
;
58 static void log_init(void)
62 rb
->lcd_getstringsize("A", NULL
, &h
);
63 max_line
= LCD_HEIGHT
/ h
;
65 rb
->lcd_clear_display();
67 #ifdef HAVE_REMOTE_LCD
68 rb
->lcd_remote_getstringsize("A", NULL
, &h
);
69 remote_max_line
= LCD_REMOTE_HEIGHT
/ h
;
71 rb
->lcd_remote_clear_display();
72 rb
->lcd_remote_update();
76 static void log_text(char *text
)
78 rb
->lcd_puts(0, line
, text
);
79 if (++line
>= max_line
)
82 #ifdef HAVE_REMOTE_LCD
83 rb
->lcd_remote_puts(0, remote_line
, text
);
84 if (++remote_line
>= remote_max_line
)
86 rb
->lcd_remote_update();
90 static int calc_tenth_fps(int framecount
, long ticks
)
92 return (10*HZ
) * framecount
/ ticks
;
95 static void time_main_update(void)
97 char str
[32]; /* text buffer */
98 long time_start
; /* start tickcount */
99 long time_end
; /* end tickcount */
103 const int part14_x
= LCD_WIDTH
/4; /* x-offset for 1/4 update test */
104 const int part14_w
= LCD_WIDTH
/2; /* x-size for 1/4 update test */
105 const int part14_y
= LCD_HEIGHT
/4; /* y-offset for 1/4 update test */
106 const int part14_h
= LCD_HEIGHT
/2; /* y-size for 1/4 update test */
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 rb
->memset(ydata
, 128, sizeof(ydata
)); /* medium grey */
187 /* Test 1: full LCD update */
188 make_gradient_rect(YUV_WIDTH
, YUV_HEIGHT
);
191 rb
->sleep(0); /* sync to tick */
192 time_start
= *rb
->current_tick
;
193 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
195 rb
->lcd_blit_yuv(yuvbuf
, 0, 0, YUV_WIDTH
,
196 0, 0, YUV_WIDTH
, YUV_HEIGHT
);
199 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
200 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
203 /* Test 2: quarter LCD update */
204 make_gradient_rect(YUV_WIDTH
/2, YUV_HEIGHT
/2);
207 rb
->sleep(0); /* sync to tick */
208 time_start
= *rb
->current_tick
;
209 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
211 rb
->lcd_blit_yuv(yuvbuf
, 0, 0, YUV_WIDTH
,
212 part14_x
, part14_y
, part14_w
, part14_h
);
215 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
216 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
221 #ifdef HAVE_REMOTE_LCD
222 static void time_remote_update(void)
224 char str
[32]; /* text buffer */
225 long time_start
; /* start tickcount */
226 long time_end
; /* end tickcount */
230 const int part14_x
= LCD_REMOTE_WIDTH
/4; /* x-offset for 1/4 update test */
231 const int part14_w
= LCD_REMOTE_WIDTH
/2; /* x-size for 1/4 update test */
232 const int part14_y
= LCD_REMOTE_HEIGHT
/4; /* y-offset for 1/4 update test */
233 const int part14_h
= LCD_REMOTE_HEIGHT
/2; /* y-size for 1/4 update test */
235 /* Test 1: full LCD update */
237 rb
->sleep(0); /* sync to tick */
238 time_start
= *rb
->current_tick
;
239 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
241 rb
->lcd_remote_update();
244 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
245 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
248 /* Test 2: quarter LCD update */
250 rb
->sleep(0); /* sync to tick */
251 time_start
= *rb
->current_tick
;
252 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
254 rb
->lcd_remote_update_rect(part14_x
, part14_y
, part14_w
, part14_h
);
257 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
258 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
265 GREY_INFO_STRUCT_IRAM
266 static unsigned char greydata
[LCD_HEIGHT
][LCD_WIDTH
];
268 static void make_grey_rect(int width
, int height
)
270 unsigned char vline
[LCD_WIDTH
];
273 for (x
= 0; x
< width
; x
++)
274 vline
[x
] = (x
<< 8) / width
;
275 for (y
= 0; y
< height
; y
++)
276 rb
->memcpy(greydata
[y
], vline
, width
);
279 static void time_greyscale(void)
281 char str
[32]; /* text buffer */
282 long time_start
; /* start tickcount */
283 long time_end
; /* end tickcount */
285 int frames_1
, frames_2
;
288 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
289 if (!grey_init(gbuf
, gbuf_size
, GREY_ON_COP
,
290 LCD_WIDTH
, LCD_HEIGHT
, NULL
))
292 log_text("greylib: out of memory.");
295 make_grey_rect(LCD_WIDTH
, LCD_HEIGHT
);
297 /* Test 1 - greyscale overlay not yet enabled */
299 rb
->sleep(0); /* sync to tick */
300 time_start
= *rb
->current_tick
;
301 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
303 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
306 time_1
= time_end
- time_start
;
308 /* Test 2 - greyscale overlay enabled */
311 rb
->sleep(0); /* sync to tick */
312 time_start
= *rb
->current_tick
;
313 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
315 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
318 time_2
= time_end
- time_start
;
321 fps
= calc_tenth_fps(frames_2
, time_2
);
322 load
= 100 - (100 * frames_2
* time_1
) / (frames_1
* time_2
);
323 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
326 if (load
> 0 && load
< 100)
328 rb
->snprintf(str
, sizeof(str
), "CPU load: %d%%", load
);
332 log_text("CPU load err (boost?)");
336 /* plugin entry point */
337 enum plugin_status
plugin_start(const void* parameter
)
350 cpu_freq
= *rb
->cpu_frequency
; /* remember CPU frequency */
352 backlight_force_on(); /* backlight control in lib/helper.c */
354 log_text("Main LCD Update");
356 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
357 log_text("Main LCD YUV");
361 log_text("Greyscale library");
364 #ifdef HAVE_REMOTE_LCD
365 log_text("Remote LCD Update");
366 time_remote_update();
370 if (*rb
->cpu_frequency
!= cpu_freq
)
371 rb
->snprintf(str
, sizeof(str
), "CPU clock changed!");
373 rb
->snprintf(str
, sizeof(str
), "CPU: %d MHz",
374 (cpu_freq
+ 500000) / 1000000);
377 backlight_use_settings(); /* backlight control in lib/helper.c */
379 /* wait until user closes plugin */
380 while (rb
->button_get(true) != FPS_QUIT
);