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 == SAMSUNG_YH_PAD
35 #define FPS_QUIT BUTTON_PLAY
36 #elif CONFIG_KEYPAD == SANSA_FUZE_PAD
37 #define FPS_QUIT (BUTTON_HOME|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 unsigned char *gbuf
;
57 static size_t gbuf_size
;
60 static void log_init(void)
64 rb
->lcd_getstringsize("A", NULL
, &h
);
65 max_line
= LCD_HEIGHT
/ h
;
67 rb
->lcd_clear_display();
69 #ifdef HAVE_REMOTE_LCD
70 rb
->lcd_remote_getstringsize("A", NULL
, &h
);
71 remote_max_line
= LCD_REMOTE_HEIGHT
/ h
;
73 rb
->lcd_remote_clear_display();
74 rb
->lcd_remote_update();
78 static void log_text(char *text
)
80 rb
->lcd_puts(0, line
, text
);
81 if (++line
>= max_line
)
84 #ifdef HAVE_REMOTE_LCD
85 rb
->lcd_remote_puts(0, remote_line
, text
);
86 if (++remote_line
>= remote_max_line
)
88 rb
->lcd_remote_update();
92 static int calc_tenth_fps(int framecount
, long ticks
)
94 return (10*HZ
) * framecount
/ ticks
;
97 static void time_main_update(void)
99 char str
[32]; /* text buffer */
100 long time_start
; /* start tickcount */
101 long time_end
; /* end tickcount */
105 const int part14_x
= LCD_WIDTH
/4; /* x-offset for 1/4 update test */
106 const int part14_w
= LCD_WIDTH
/2; /* x-size for 1/4 update test */
107 const int part14_y
= LCD_HEIGHT
/4; /* y-offset for 1/4 update test */
108 const int part14_h
= LCD_HEIGHT
/2; /* y-size for 1/4 update test */
110 /* Test 1: full LCD update */
112 rb
->sleep(0); /* sync to tick */
113 time_start
= *rb
->current_tick
;
114 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
119 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
120 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
123 /* Test 2: quarter LCD update */
125 rb
->sleep(0); /* sync to tick */
126 time_start
= *rb
->current_tick
;
127 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
129 rb
->lcd_update_rect(part14_x
, part14_y
, part14_w
, part14_h
);
132 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
133 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
137 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
139 #if LCD_WIDTH >= LCD_HEIGHT
140 #define YUV_WIDTH LCD_WIDTH
141 #define YUV_HEIGHT LCD_HEIGHT
142 #else /* Assume the screen is rotated on portrait LCDs */
143 #define YUV_WIDTH LCD_HEIGHT
144 #define YUV_HEIGHT LCD_WIDTH
147 static unsigned char ydata
[YUV_HEIGHT
][YUV_WIDTH
];
148 static unsigned char udata
[YUV_HEIGHT
/2][YUV_WIDTH
/2];
149 static unsigned char vdata
[YUV_HEIGHT
/2][YUV_WIDTH
/2];
151 static unsigned char * const yuvbuf
[3] = {
157 static void make_gradient_rect(int width
, int height
)
159 unsigned char vline
[YUV_WIDTH
/2];
165 for (x
= 0; x
< width
; x
++)
166 vline
[x
] = (x
<< 8) / width
;
167 for (y
= 0; y
< height
; y
++)
169 rb
->memset(udata
[y
], (y
<< 8) / height
, width
);
170 rb
->memcpy(vdata
[y
], vline
, width
);
174 static void time_main_yuv(void)
176 char str
[32]; /* text buffer */
177 long time_start
; /* start tickcount */
178 long time_end
; /* end tickcount */
182 const int part14_x
= YUV_WIDTH
/4; /* x-offset for 1/4 update test */
183 const int part14_w
= YUV_WIDTH
/2; /* x-size for 1/4 update test */
184 const int part14_y
= YUV_HEIGHT
/4; /* y-offset for 1/4 update test */
185 const int part14_h
= YUV_HEIGHT
/2; /* y-size for 1/4 update test */
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 /* Test 1: full LCD update */
239 rb
->sleep(0); /* sync to tick */
240 time_start
= *rb
->current_tick
;
241 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
243 rb
->lcd_remote_update();
246 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
247 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
250 /* Test 2: quarter LCD update */
252 rb
->sleep(0); /* sync to tick */
253 time_start
= *rb
->current_tick
;
254 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
256 rb
->lcd_remote_update_rect(part14_x
, part14_y
, part14_w
, part14_h
);
259 fps
= calc_tenth_fps(frame_count
, time_end
- time_start
);
260 rb
->snprintf(str
, sizeof(str
), "1/4: %d.%d fps", fps
/ 10, fps
% 10);
267 GREY_INFO_STRUCT_IRAM
268 static unsigned char greydata
[LCD_HEIGHT
][LCD_WIDTH
];
270 static void make_grey_rect(int width
, int height
)
272 unsigned char vline
[LCD_WIDTH
];
275 for (x
= 0; x
< width
; x
++)
276 vline
[x
] = (x
<< 8) / width
;
277 for (y
= 0; y
< height
; y
++)
278 rb
->memcpy(greydata
[y
], vline
, width
);
281 static void time_greyscale(void)
283 char str
[32]; /* text buffer */
284 long time_start
; /* start tickcount */
285 long time_end
; /* end tickcount */
287 int frames_1
, frames_2
;
290 gbuf
= (unsigned char *) rb
->plugin_get_buffer(&gbuf_size
);
291 if (!grey_init(gbuf
, gbuf_size
, GREY_ON_COP
,
292 LCD_WIDTH
, LCD_HEIGHT
, NULL
))
294 log_text("greylib: out of memory.");
297 make_grey_rect(LCD_WIDTH
, LCD_HEIGHT
);
299 /* Test 1 - greyscale overlay not yet enabled */
301 rb
->sleep(0); /* sync to tick */
302 time_start
= *rb
->current_tick
;
303 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
305 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
308 time_1
= time_end
- time_start
;
310 /* Test 2 - greyscale overlay enabled */
313 rb
->sleep(0); /* sync to tick */
314 time_start
= *rb
->current_tick
;
315 while((time_end
= *rb
->current_tick
) - time_start
< DURATION
)
317 grey_ub_gray_bitmap(greydata
[0], 0, 0, LCD_WIDTH
, LCD_HEIGHT
);
320 time_2
= time_end
- time_start
;
323 fps
= calc_tenth_fps(frames_2
, time_2
);
324 load
= 100 - (100 * frames_2
* time_1
) / (frames_1
* time_2
);
325 rb
->snprintf(str
, sizeof(str
), "1/1: %d.%d fps", fps
/ 10, fps
% 10);
328 if (load
> 0 && load
< 100)
330 rb
->snprintf(str
, sizeof(str
), "CPU load: %d%%", load
);
334 log_text("CPU load err (boost?)");
338 /* plugin entry point */
339 enum plugin_status
plugin_start(const void* parameter
)
352 cpu_freq
= *rb
->cpu_frequency
; /* remember CPU frequency */
354 backlight_force_on(); /* backlight control in lib/helper.c */
356 log_text("Main LCD Update");
358 #if defined(HAVE_LCD_COLOR) && (MEMORYSIZE > 2)
359 log_text("Main LCD YUV");
363 log_text("Greyscale library");
366 #ifdef HAVE_REMOTE_LCD
367 log_text("Remote LCD Update");
368 time_remote_update();
372 if (*rb
->cpu_frequency
!= cpu_freq
)
373 rb
->snprintf(str
, sizeof(str
), "CPU clock changed!");
375 rb
->snprintf(str
, sizeof(str
), "CPU: %d MHz",
376 (cpu_freq
+ 500000) / 1000000);
379 backlight_use_settings(); /* backlight control in lib/helper.c */
381 /* wait until user closes plugin */
382 while (rb
->button_get(true) != FPS_QUIT
);