Test plugin for measuring the internal scan rate of the LCD, for developers. B&W...
[Rockbox.git] / apps / plugins / test_scanrate.c
blob22ec44b7a984e759fd2b4b45698278c72ec81fda
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2006 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 #include "plugin.h"
22 #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR)
24 PLUGIN_HEADER
26 #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) \
27 || (CONFIG_KEYPAD == IRIVER_H100_PAD)
28 #define SCANRATE_DONE BUTTON_OFF
29 #define SCANRATE_FASTINC BUTTON_UP
30 #define SCANRATE_FASTDEC BUTTON_DOWN
31 #define SCANRATE_INC BUTTON_RIGHT
32 #define SCANRATE_DEC BUTTON_LEFT
34 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD)
35 #define SCANRATE_DONE BUTTON_MENU
36 #define SCANRATE_FASTINC BUTTON_SCROLL_FWD
37 #define SCANRATE_FASTDEC BUTTON_SCROLL_BACK
38 #define SCANRATE_INC BUTTON_RIGHT
39 #define SCANRATE_DEC BUTTON_LEFT
41 #endif
43 #if LCD_PIXELFORMAT == HORIZONTAL_PACKING
44 #define BUF_WIDTH ((LCD_WIDTH+7)/8/4)
45 #define BUF_HEIGHT LCD_HEIGHT
46 #define TEXT_X (BUF_WIDTH*8)
47 #else
48 #define BUF_WIDTH (LCD_WIDTH/4)
49 #define BUF_HEIGHT (LCD_HEIGHT/8)
50 #define TEXT_X BUF_WIDTH
51 #endif
53 /* Default refresh rates in 1/10 Hz */
54 #if CONFIG_LCD == LCD_SSD1815
55 #define DEFAULT_SCAN_RATE 670
56 #elif CONFIG_LCD == LCD_S1D15E06
57 #define DEFAULT_SCAN_RATE 700
58 #elif CONFIG_LCD == LCD_IPOD2BPP
59 #define DEFAULT_SCAN_RATE 800
60 #elif CONFIG_LCD == LCD_IPODMINI
61 #define DEFAULT_SCAN_RATE 880
62 #endif
64 #if defined(CPU_PP) && defined(HAVE_ADJUSTABLE_CPU_FREQ)
65 #define NEED_BOOST
66 #endif
68 static struct plugin_api* rb;
69 static unsigned char bitbuffer[2][BUF_HEIGHT][BUF_WIDTH];
70 static int curbuf = 0;
71 static int scan_rate = DEFAULT_SCAN_RATE;
72 static bool need_refresh = false;
74 static void timer_isr(void)
76 rb->lcd_blit(bitbuffer[curbuf][0], 0, 0, BUF_WIDTH, BUF_HEIGHT, BUF_WIDTH);
77 curbuf = (curbuf + 1) & 1;
78 if (need_refresh)
80 rb->lcd_update_rect(TEXT_X, 0, LCD_WIDTH-TEXT_X, 8);
81 need_refresh = false;
85 int plugin_main(void)
87 unsigned char buf[32];
88 int button;
89 bool done = false;
90 bool change = true;
92 rb->lcd_setfont(FONT_SYSFIXED);
94 rb->lcd_putsxy(TEXT_X, 12, "Adjust Frequ.");
95 rb->lcd_putsxy(TEXT_X, 20, "so the block");
96 rb->lcd_putsxy(TEXT_X, 28, "stops moving.");
97 #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) \
98 || (CONFIG_KEYPAD == IRIVER_H100_PAD)
99 rb->lcd_putsxy(TEXT_X, 40, "U/D: Coarse");
100 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD)
101 rb->lcd_putsxy(TEXT_X, 40, "Scroll: Coarse");
102 #endif
103 rb->lcd_putsxy(TEXT_X, 48, "L/R: Fine");
104 rb->lcd_update();
106 rb->memset(bitbuffer[0], 0, sizeof(bitbuffer[0]));
107 rb->memset(bitbuffer[1], 0xff, sizeof(bitbuffer[1]));
108 #ifdef NEED_BOOST
109 rb->cpu_boost(true);
110 #endif
111 /* The actual frequency is twice the displayed value */
112 rb->timer_register(1, NULL, TIMER_FREQ * 5 / scan_rate, 1, timer_isr);
114 while (!done)
116 if (change)
118 /* The actual frequency is twice the displayed value */
119 rb->timer_set_period(TIMER_FREQ * 5 / scan_rate);
120 rb->snprintf(buf, sizeof(buf), "f: %d.%d Hz", scan_rate / 10,
121 scan_rate % 10);
122 rb->lcd_putsxy(TEXT_X, 0, buf);
123 need_refresh = true;
124 change = false;
126 button = rb->button_get(true);
127 switch (button)
129 case SCANRATE_FASTINC:
130 case SCANRATE_FASTINC|BUTTON_REPEAT:
131 scan_rate += 10;
132 change = true;
133 break;
135 case SCANRATE_FASTDEC:
136 case SCANRATE_FASTDEC|BUTTON_REPEAT:
137 scan_rate -= 10;
138 change = true;
139 break;
141 case SCANRATE_INC:
142 case SCANRATE_INC|BUTTON_REPEAT:
143 scan_rate++;
144 change = true;
145 break;
147 case SCANRATE_DEC:
148 case SCANRATE_DEC|BUTTON_REPEAT:
149 scan_rate--;
150 change = true;
151 break;
153 case SCANRATE_DONE:
154 done = true;
155 break;
158 rb->timer_unregister();
159 #ifdef NEED_BOOST
160 rb->cpu_boost(false);
161 #endif
163 rb->lcd_setfont(FONT_UI);
165 return PLUGIN_OK;
169 /* this is the plugin entry point */
170 enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
172 (void)parameter;
173 rb = api;
174 return plugin_main();
177 #endif