Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 1 | /*************************************************************************** |
| 2 | * __________ __ ___. |
| 3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ |
| 4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / |
| 5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < |
| 6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ |
| 7 | * \/ \/ \/ \/ \/ |
| 8 | * $Id$ |
| 9 | * |
| 10 | * Copyright (C) 2006 Jens Arnold |
| 11 | * |
Daniel Stenberg | 2acc0ac | 2008-06-28 18:10:04 +0000 | [diff] [blame^] | 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. |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 16 | * |
| 17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY |
| 18 | * KIND, either express or implied. |
| 19 | * |
| 20 | ****************************************************************************/ |
| 21 | |
| 22 | #include "plugin.h" |
| 23 | |
| 24 | #if defined(HAVE_LCD_BITMAP) && (LCD_DEPTH < 4) && !defined(SIMULATOR) |
| 25 | |
| 26 | PLUGIN_HEADER |
| 27 | |
| 28 | #if (CONFIG_KEYPAD == RECORDER_PAD) || (CONFIG_KEYPAD == ONDIO_PAD) \ |
| 29 | || (CONFIG_KEYPAD == IRIVER_H100_PAD) |
| 30 | #define SCANRATE_DONE BUTTON_OFF |
| 31 | #define SCANRATE_FASTINC BUTTON_UP |
| 32 | #define SCANRATE_FASTDEC BUTTON_DOWN |
| 33 | #define SCANRATE_INC BUTTON_RIGHT |
| 34 | #define SCANRATE_DEC BUTTON_LEFT |
| 35 | |
Robert Kukla | 1317ebb | 2008-04-07 22:09:14 +0000 | [diff] [blame] | 36 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) \ |
| 37 | || (CONFIG_KEYPAD == MROBE100_PAD) |
Jens Arnold | fc61a67 | 2007-08-10 10:39:23 +0000 | [diff] [blame] | 38 | #define SCANRATE_DONE BUTTON_POWER |
| 39 | #define SCANRATE_FASTINC BUTTON_UP |
| 40 | #define SCANRATE_FASTDEC BUTTON_DOWN |
| 41 | #define SCANRATE_INC BUTTON_RIGHT |
| 42 | #define SCANRATE_DEC BUTTON_LEFT |
| 43 | |
Jens Arnold | 29361ab | 2008-03-22 10:24:28 +0000 | [diff] [blame] | 44 | #elif CONFIG_KEYPAD == IAUDIO_M3_PAD |
| 45 | #define SCANRATE_DONE BUTTON_RC_REC |
| 46 | #define SCANRATE_FASTINC BUTTON_RC_VOL_UP |
| 47 | #define SCANRATE_FASTDEC BUTTON_RC_VOL_DOWN |
| 48 | #define SCANRATE_INC BUTTON_RC_FF |
| 49 | #define SCANRATE_DEC BUTTON_RC_REW |
| 50 | |
Jens Arnold | b701322 | 2007-07-27 09:57:27 +0000 | [diff] [blame] | 51 | #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \ |
| 52 | || (CONFIG_KEYPAD == IPOD_1G2G_PAD) |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 53 | #define SCANRATE_DONE BUTTON_MENU |
| 54 | #define SCANRATE_FASTINC BUTTON_SCROLL_FWD |
| 55 | #define SCANRATE_FASTDEC BUTTON_SCROLL_BACK |
| 56 | #define SCANRATE_INC BUTTON_RIGHT |
| 57 | #define SCANRATE_DEC BUTTON_LEFT |
| 58 | |
| 59 | #endif |
| 60 | |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 61 | /* Default refresh rates in 1/10 Hz */ |
Jens Arnold | aae436d | 2008-04-02 22:48:42 +0000 | [diff] [blame] | 62 | #if defined ARCHOS_RECORDER || defined ARCHOS_FMRECORDER \ |
| 63 | || defined ARCHOS_RECORDERV2 || defined ARCHOS_ONDIOFM \ |
| 64 | || defined ARCHOS_ONDIOSP |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 65 | #define DEFAULT_SCAN_RATE 670 |
Jens Arnold | aae436d | 2008-04-02 22:48:42 +0000 | [diff] [blame] | 66 | #elif defined IAUDIO_M3 |
| 67 | #define DEFAULT_SCAN_RATE 1500 |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 68 | #define HORIZ_SCAN /* LCD controller updates the panel sideways */ |
| 69 | #define NEED_BOOST |
Jens Arnold | aae436d | 2008-04-02 22:48:42 +0000 | [diff] [blame] | 70 | #elif defined IAUDIO_M5 |
| 71 | #define DEFAULT_SCAN_RATE 730 |
| 72 | #elif defined IPOD_1G2G |
| 73 | #define DEFAULT_SCAN_RATE 960 |
| 74 | #elif defined IPOD_MINI2G || defined IPOD_MINI \ |
| 75 | || defined IPOD_3G || defined IPOD_4G |
| 76 | #define DEFAULT_SCAN_RATE 870 |
| 77 | #elif defined IRIVER_H100_SERIES |
| 78 | #define DEFAULT_SCAN_RATE 700 |
Jens Arnold | 29361ab | 2008-03-22 10:24:28 +0000 | [diff] [blame] | 79 | #else |
| 80 | #define DEFAULT_SCAN_RATE 700 |
| 81 | #warning Generic default scanrate |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 82 | #endif |
| 83 | |
Jens Arnold | aae436d | 2008-04-02 22:48:42 +0000 | [diff] [blame] | 84 | #ifdef HORIZ_SCAN |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 85 | #define TEXT_X 0 |
| 86 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
| 87 | #define BUF_WIDTH ((LCD_WIDTH+7)/8) |
| 88 | #define BUF_HEIGHT (LCD_HEIGHT/4) |
| 89 | #define TEXT_Y BUF_HEIGHT |
| 90 | #else |
| 91 | #define BUF_WIDTH (LCD_WIDTH) |
| 92 | #define BUF_HEIGHT (LCD_HEIGHT/8/4) |
| 93 | #define TEXT_Y (BUF_HEIGHT*8) |
| 94 | #endif |
| 95 | #else /* !HORIZ_SCAN */ |
| 96 | #define TEXT_Y 0 |
| 97 | #if LCD_PIXELFORMAT == HORIZONTAL_PACKING |
| 98 | #define BUF_WIDTH ((LCD_WIDTH+7)/8/4) |
| 99 | #define BUF_HEIGHT LCD_HEIGHT |
| 100 | #define TEXT_X (BUF_WIDTH*8) |
| 101 | #else |
| 102 | #define BUF_WIDTH (LCD_WIDTH/4) |
| 103 | #define BUF_HEIGHT (LCD_HEIGHT/8) |
| 104 | #define TEXT_X BUF_WIDTH |
| 105 | #endif |
| 106 | #endif /* !HORIZ_SCAN */ |
| 107 | |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 108 | #if defined(CPU_PP) && defined(HAVE_ADJUSTABLE_CPU_FREQ) |
| 109 | #define NEED_BOOST |
| 110 | #endif |
| 111 | |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 112 | static const struct plugin_api* rb; |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 113 | static unsigned char bitbuffer[2][BUF_HEIGHT][BUF_WIDTH]; |
| 114 | static int curbuf = 0; |
| 115 | static int scan_rate = DEFAULT_SCAN_RATE; |
| 116 | static bool need_refresh = false; |
| 117 | |
| 118 | static void timer_isr(void) |
| 119 | { |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 120 | rb->lcd_blit_mono(bitbuffer[curbuf][0], 0, 0, BUF_WIDTH, BUF_HEIGHT, BUF_WIDTH); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 121 | curbuf = (curbuf + 1) & 1; |
| 122 | if (need_refresh) |
| 123 | { |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 124 | rb->lcd_update_rect(TEXT_X, TEXT_Y, LCD_WIDTH-TEXT_X, 8); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 125 | need_refresh = false; |
| 126 | } |
| 127 | } |
| 128 | |
| 129 | int plugin_main(void) |
| 130 | { |
| 131 | unsigned char buf[32]; |
| 132 | int button; |
| 133 | bool done = false; |
| 134 | bool change = true; |
| 135 | |
| 136 | rb->lcd_setfont(FONT_SYSFIXED); |
| 137 | |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 138 | rb->lcd_putsxy(TEXT_X, TEXT_Y+12, "Adjust Frequ."); |
| 139 | rb->lcd_putsxy(TEXT_X, TEXT_Y+20, "so the block"); |
| 140 | rb->lcd_putsxy(TEXT_X, TEXT_Y+28, "stops moving."); |
| 141 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) || (CONFIG_KEYPAD == IPOD_3G_PAD) \ |
| 142 | || (CONFIG_KEYPAD == IPOD_1G2G_PAD) |
| 143 | rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "Scroll: Coarse"); |
| 144 | #else |
| 145 | rb->lcd_putsxy(TEXT_X, TEXT_Y+40, "U/D: Coarse"); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 146 | #endif |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 147 | rb->lcd_putsxy(TEXT_X, TEXT_Y+48, "L/R: Fine"); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 148 | rb->lcd_update(); |
| 149 | |
| 150 | rb->memset(bitbuffer[0], 0, sizeof(bitbuffer[0])); |
| 151 | rb->memset(bitbuffer[1], 0xff, sizeof(bitbuffer[1])); |
| 152 | #ifdef NEED_BOOST |
| 153 | rb->cpu_boost(true); |
| 154 | #endif |
| 155 | /* The actual frequency is twice the displayed value */ |
Jens Arnold | ac9b927 | 2008-04-04 19:38:46 +0000 | [diff] [blame] | 156 | rb->timer_register(1, NULL, TIMER_FREQ * 5 / scan_rate, 1, |
| 157 | timer_isr IF_COP(, CPU)); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 158 | |
| 159 | while (!done) |
| 160 | { |
| 161 | if (change) |
| 162 | { |
| 163 | /* The actual frequency is twice the displayed value */ |
| 164 | rb->timer_set_period(TIMER_FREQ * 5 / scan_rate); |
| 165 | rb->snprintf(buf, sizeof(buf), "f: %d.%d Hz", scan_rate / 10, |
| 166 | scan_rate % 10); |
Jens Arnold | 395b785 | 2008-03-24 01:03:02 +0000 | [diff] [blame] | 167 | rb->lcd_putsxy(TEXT_X, TEXT_Y, buf); |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 168 | need_refresh = true; |
| 169 | change = false; |
| 170 | } |
| 171 | button = rb->button_get(true); |
| 172 | switch (button) |
| 173 | { |
| 174 | case SCANRATE_FASTINC: |
| 175 | case SCANRATE_FASTINC|BUTTON_REPEAT: |
| 176 | scan_rate += 10; |
| 177 | change = true; |
| 178 | break; |
| 179 | |
| 180 | case SCANRATE_FASTDEC: |
| 181 | case SCANRATE_FASTDEC|BUTTON_REPEAT: |
| 182 | scan_rate -= 10; |
| 183 | change = true; |
| 184 | break; |
| 185 | |
| 186 | case SCANRATE_INC: |
| 187 | case SCANRATE_INC|BUTTON_REPEAT: |
| 188 | scan_rate++; |
| 189 | change = true; |
| 190 | break; |
| 191 | |
| 192 | case SCANRATE_DEC: |
| 193 | case SCANRATE_DEC|BUTTON_REPEAT: |
| 194 | scan_rate--; |
| 195 | change = true; |
| 196 | break; |
| 197 | |
| 198 | case SCANRATE_DONE: |
| 199 | done = true; |
| 200 | break; |
| 201 | } |
| 202 | } |
| 203 | rb->timer_unregister(); |
| 204 | #ifdef NEED_BOOST |
| 205 | rb->cpu_boost(false); |
| 206 | #endif |
| 207 | |
| 208 | rb->lcd_setfont(FONT_UI); |
| 209 | |
| 210 | return PLUGIN_OK; |
| 211 | } |
| 212 | |
| 213 | |
| 214 | /* this is the plugin entry point */ |
Steve Bavin | 6526577 | 2008-05-13 09:57:56 +0000 | [diff] [blame] | 215 | enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) |
Jens Arnold | b002d2d | 2006-08-28 00:01:14 +0000 | [diff] [blame] | 216 | { |
| 217 | (void)parameter; |
| 218 | rb = api; |
| 219 | return plugin_main(); |
| 220 | } |
| 221 | |
| 222 | #endif |