diff options
author | Michael Sevakis <jethead71@rockbox.org> | 2006-10-30 11:33:38 +0000 |
---|---|---|
committer | Michael Sevakis <jethead71@rockbox.org> | 2006-10-30 11:33:38 +0000 |
commit | 9e8fe0e4c662d3d5c26ea2f1f64c7da66cf3ce04 (patch) | |
tree | e5b0bd4076b66c55b49f36cdd0898de2e2717a86 /apps | |
parent | ede3d646b9a248a1893ec20482eaa30641df078e (diff) | |
download | rockbox-9e8fe0e4c662d3d5c26ea2f1f64c7da66cf3ce04.tar.gz rockbox-9e8fe0e4c662d3d5c26ea2f1f64c7da66cf3ce04.zip |
General: changed local adc to voltage conversions in several places to use battery_voltage. Added battery_read_info function for unfiltered battery information. x5: removed adc_read as a distinct function. Removed adc tick task. adc_init is empty inline. Adjusted battery scale, voltage to level array and read 10 bits from the ADC for battery since 255 levels is not enough for true centivolt resolution.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@11396 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps')
-rw-r--r-- | apps/debug_menu.c | 58 | ||||
-rw-r--r-- | apps/screens.c | 52 |
2 files changed, 38 insertions, 72 deletions
diff --git a/apps/debug_menu.c b/apps/debug_menu.c index 9d721d02e0..47a2042eff 100644 --- a/apps/debug_menu.c +++ b/apps/debug_menu.c | |||
@@ -318,7 +318,7 @@ bool dbg_audio_thread(void) | |||
318 | break; | 318 | break; |
319 | case ACTION_STD_CANCEL: | 319 | case ACTION_STD_CANCEL: |
320 | done = true; | 320 | done = true; |
321 | break; | 321 | break; |
322 | } | 322 | } |
323 | action_signalscreenchange(); | 323 | action_signalscreenchange(); |
324 | line = 0; | 324 | line = 0; |
@@ -968,8 +968,7 @@ bool dbg_ports(void) | |||
968 | unsigned short portb; | 968 | unsigned short portb; |
969 | unsigned char portc; | 969 | unsigned char portc; |
970 | char buf[32]; | 970 | char buf[32]; |
971 | int battery_voltage; | 971 | int adc_battery_voltage, adc_battery_level; |
972 | int batt_int, batt_frac; | ||
973 | 972 | ||
974 | lcd_setfont(FONT_SYSFIXED); | 973 | lcd_setfont(FONT_SYSFIXED); |
975 | lcd_setmargins(0, 0); | 974 | lcd_setmargins(0, 0); |
@@ -995,12 +994,10 @@ bool dbg_ports(void) | |||
995 | snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); | 994 | snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); |
996 | lcd_puts(0, 5, buf); | 995 | lcd_puts(0, 5, buf); |
997 | 996 | ||
998 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | 997 | battery_read_info(NULL, &adc_battery_voltage, |
999 | batt_int = battery_voltage / 100; | 998 | &adc_battery_level); |
1000 | batt_frac = battery_voltage % 100; | 999 | snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100, |
1001 | 1000 | adc_battery_voltage % 100, adc_battery_level); | |
1002 | snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac, | ||
1003 | battery_level()); | ||
1004 | lcd_puts(0, 6, buf); | 1001 | lcd_puts(0, 6, buf); |
1005 | #ifndef HAVE_MMC /* have ATA */ | 1002 | #ifndef HAVE_MMC /* have ATA */ |
1006 | snprintf(buf, 32, "ATA: %s, 0x%x", | 1003 | snprintf(buf, 32, "ATA: %s, 0x%x", |
@@ -1020,14 +1017,10 @@ bool dbg_ports(void) | |||
1020 | unsigned int gpio1_function; | 1017 | unsigned int gpio1_function; |
1021 | unsigned int gpio_enable; | 1018 | unsigned int gpio_enable; |
1022 | unsigned int gpio1_enable; | 1019 | unsigned int gpio1_enable; |
1023 | int adc_buttons, adc_remote, adc_battery; | 1020 | int adc_buttons, adc_remote; |
1024 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 1021 | int adc_battery, adc_battery_voltage, adc_battery_level; |
1025 | int adc_remotedetect; | ||
1026 | #endif | ||
1027 | char buf[128]; | 1022 | char buf[128]; |
1028 | int line; | 1023 | int line; |
1029 | int battery_voltage; | ||
1030 | int batt_int, batt_frac; | ||
1031 | 1024 | ||
1032 | lcd_setmargins(0, 0); | 1025 | lcd_setmargins(0, 0); |
1033 | lcd_clear_display(); | 1026 | lcd_clear_display(); |
@@ -1064,12 +1057,9 @@ bool dbg_ports(void) | |||
1064 | lcd_puts(0, line++, buf); | 1057 | lcd_puts(0, line++, buf); |
1065 | 1058 | ||
1066 | adc_buttons = adc_read(ADC_BUTTONS); | 1059 | adc_buttons = adc_read(ADC_BUTTONS); |
1067 | adc_remote = adc_read(ADC_REMOTE); | 1060 | adc_remote = adc_read(ADC_REMOTE); |
1068 | adc_battery = adc_read(ADC_BATTERY); | 1061 | battery_read_info(&adc_battery, &adc_battery_voltage, |
1069 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 1062 | &adc_battery_level); |
1070 | adc_remotedetect = adc_read(ADC_REMOTEDETECT); | ||
1071 | #endif | ||
1072 | |||
1073 | #if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES) | 1063 | #if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES) |
1074 | snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", | 1064 | snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", |
1075 | button_scan_enabled() ? '+' : '-', adc_buttons); | 1065 | button_scan_enabled() ? '+' : '-', adc_buttons); |
@@ -1083,20 +1073,18 @@ bool dbg_ports(void) | |||
1083 | #else | 1073 | #else |
1084 | snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); | 1074 | snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); |
1085 | #endif | 1075 | #endif |
1076 | |||
1086 | lcd_puts(0, line++, buf); | 1077 | lcd_puts(0, line++, buf); |
1087 | snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); | 1078 | snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); |
1088 | lcd_puts(0, line++, buf); | 1079 | lcd_puts(0, line++, buf); |
1089 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 1080 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
1090 | snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x", adc_remotedetect); | 1081 | snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x", |
1082 | adc_read(ADC_REMOTEDETECT)); | ||
1091 | lcd_puts(0, line++, buf); | 1083 | lcd_puts(0, line++, buf); |
1092 | #endif | 1084 | #endif |
1093 | 1085 | ||
1094 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; | 1086 | snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100, |
1095 | batt_int = battery_voltage / 100; | 1087 | adc_battery_voltage % 100, adc_battery_level); |
1096 | batt_frac = battery_voltage % 100; | ||
1097 | |||
1098 | snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac, | ||
1099 | battery_level()); | ||
1100 | lcd_puts(0, line++, buf); | 1088 | lcd_puts(0, line++, buf); |
1101 | 1089 | ||
1102 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) | 1090 | #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) |
@@ -1209,8 +1197,7 @@ bool dbg_ports(void) | |||
1209 | unsigned char portc; | 1197 | unsigned char portc; |
1210 | char buf[32]; | 1198 | char buf[32]; |
1211 | int button; | 1199 | int button; |
1212 | int battery_voltage; | 1200 | int adc_battery_voltage; |
1213 | int batt_int, batt_frac; | ||
1214 | int currval = 0; | 1201 | int currval = 0; |
1215 | 1202 | ||
1216 | lcd_clear_display(); | 1203 | lcd_clear_display(); |
@@ -1260,12 +1247,9 @@ bool dbg_ports(void) | |||
1260 | } | 1247 | } |
1261 | lcd_puts(0, 0, buf); | 1248 | lcd_puts(0, 0, buf); |
1262 | 1249 | ||
1263 | battery_voltage = (adc_read(ADC_UNREG_POWER) * | 1250 | battery_read_info(NULL, &adc_battery_voltage, NULL); |
1264 | BATTERY_SCALE_FACTOR) / 10000; | 1251 | snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100, |
1265 | batt_int = battery_voltage / 100; | 1252 | adc_battery_voltage % 100); |
1266 | batt_frac = battery_voltage % 100; | ||
1267 | |||
1268 | snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac); | ||
1269 | lcd_puts(0, 1, buf); | 1253 | lcd_puts(0, 1, buf); |
1270 | 1254 | ||
1271 | button = get_action(CONTEXT_SETTINGS,HZ/5); | 1255 | button = get_action(CONTEXT_SETTINGS,HZ/5); |
@@ -1418,7 +1402,7 @@ bool view_battery(void) | |||
1418 | lcd_clear_display(); | 1402 | lcd_clear_display(); |
1419 | lcd_puts(0, 0, "Power status:"); | 1403 | lcd_puts(0, 0, "Power status:"); |
1420 | 1404 | ||
1421 | y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | 1405 | battery_read_info(NULL, &y, NULL); |
1422 | snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100); | 1406 | snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100); |
1423 | lcd_puts(0, 1, buf); | 1407 | lcd_puts(0, 1, buf); |
1424 | #ifdef ADC_EXT_POWER | 1408 | #ifdef ADC_EXT_POWER |
diff --git a/apps/screens.c b/apps/screens.c index 9787e682bc..b81932b941 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -98,8 +98,8 @@ void usb_screen(void) | |||
98 | 98 | ||
99 | #ifdef HAVE_REMOTE_LCD | 99 | #ifdef HAVE_REMOTE_LCD |
100 | lcd_remote_clear_display(); | 100 | lcd_remote_clear_display(); |
101 | lcd_remote_bitmap(remote_usblogo, | 101 | lcd_remote_bitmap(remote_usblogo, |
102 | (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo)/2, | 102 | (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo)/2, |
103 | (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2, | 103 | (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2, |
104 | BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo); | 104 | BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo); |
105 | lcd_remote_update(); | 105 | lcd_remote_update(); |
@@ -107,7 +107,7 @@ void usb_screen(void) | |||
107 | 107 | ||
108 | lcd_clear_display(); | 108 | lcd_clear_display(); |
109 | #ifdef HAVE_LCD_BITMAP | 109 | #ifdef HAVE_LCD_BITMAP |
110 | lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo)/2, | 110 | lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo)/2, |
111 | (LCD_HEIGHT-BMPHEIGHT_usblogo)/2, | 111 | (LCD_HEIGHT-BMPHEIGHT_usblogo)/2, |
112 | BMPWIDTH_usblogo, BMPHEIGHT_usblogo); | 112 | BMPWIDTH_usblogo, BMPHEIGHT_usblogo); |
113 | lcd_update(); | 113 | lcd_update(); |
@@ -167,17 +167,6 @@ int mmc_remove_request(void) | |||
167 | } | 167 | } |
168 | #endif | 168 | #endif |
169 | 169 | ||
170 | |||
171 | /* some simulator dummies */ | ||
172 | #ifdef SIMULATOR | ||
173 | #define BATTERY_SCALE_FACTOR 7000 | ||
174 | unsigned short adc_read(int channel) | ||
175 | { | ||
176 | (void)channel; | ||
177 | return 100; | ||
178 | } | ||
179 | #endif | ||
180 | |||
181 | #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) | 170 | #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) |
182 | 171 | ||
183 | #ifdef HAVE_LCD_BITMAP | 172 | #ifdef HAVE_LCD_BITMAP |
@@ -195,15 +184,9 @@ void charging_display_info(bool animate) | |||
195 | if (ide_powered()) /* FM and V2 can only measure when ATA power is on */ | 184 | if (ide_powered()) /* FM and V2 can only measure when ATA power is on */ |
196 | #endif | 185 | #endif |
197 | { | 186 | { |
198 | int battery_voltage; | 187 | int battv = battery_voltage(); |
199 | int batt_int, batt_frac; | 188 | snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 100, |
200 | 189 | battv % 100, battery_level()); | |
201 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | ||
202 | batt_int = battery_voltage / 100; | ||
203 | batt_frac = battery_voltage % 100; | ||
204 | |||
205 | snprintf(buf, 32, " Batt: %d.%02dV %d%% ", batt_int, batt_frac, | ||
206 | battery_level()); | ||
207 | lcd_puts(0, 7, buf); | 190 | lcd_puts(0, 7, buf); |
208 | } | 191 | } |
209 | 192 | ||
@@ -294,15 +277,14 @@ static void logo_lock_patterns(bool on) | |||
294 | 277 | ||
295 | void charging_display_info(bool animate) | 278 | void charging_display_info(bool animate) |
296 | { | 279 | { |
297 | int battery_voltage; | 280 | int battv; |
298 | unsigned i, ypos; | 281 | unsigned i, ypos; |
299 | static unsigned phase = 3; | 282 | static unsigned phase = 3; |
300 | char buf[28]; | 283 | char buf[28]; |
301 | 284 | ||
302 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) | 285 | battv = battery_voltage(); |
303 | / 10000; | ||
304 | snprintf(buf, sizeof(buf), "%s %d.%02dV", logo_chars, | 286 | snprintf(buf, sizeof(buf), "%s %d.%02dV", logo_chars, |
305 | battery_voltage / 100, battery_voltage % 100); | 287 | battv / 100, battv % 100); |
306 | lcd_puts(0, 1, buf); | 288 | lcd_puts(0, 1, buf); |
307 | 289 | ||
308 | memcpy(buf, logo_pattern, 28); /* copy logo patterns */ | 290 | memcpy(buf, logo_pattern, 28); /* copy logo patterns */ |
@@ -337,7 +319,7 @@ void charging_display_info(bool animate) | |||
337 | 2 if Off/Stop key was pressed | 319 | 2 if Off/Stop key was pressed |
338 | 3 if On key was pressed | 320 | 3 if On key was pressed |
339 | 4 if USB was connected */ | 321 | 4 if USB was connected */ |
340 | 322 | ||
341 | int charging_screen(void) | 323 | int charging_screen(void) |
342 | { | 324 | { |
343 | unsigned int button; | 325 | unsigned int button; |
@@ -391,7 +373,7 @@ void pitch_screen_draw(struct screen *display, int pitch) | |||
391 | int w, h; | 373 | int w, h; |
392 | 374 | ||
393 | display->clear_display(); | 375 | display->clear_display(); |
394 | 376 | ||
395 | if (display->nb_lines < 4) /* very small screen, just show the pitch value */ | 377 | if (display->nb_lines < 4) /* very small screen, just show the pitch value */ |
396 | { | 378 | { |
397 | w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH), | 379 | w = snprintf((char *)buf, sizeof(buf), "%s: %d.%d%%",str(LANG_SYSFONT_PITCH), |
@@ -415,21 +397,21 @@ void pitch_screen_draw(struct screen *display, int pitch) | |||
415 | display->putsxy((display->width-w)/2, display->height - h, ptr); | 397 | display->putsxy((display->width-w)/2, display->height - h, ptr); |
416 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], | 398 | display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], |
417 | display->width/2 - 3, display->height - h*2, 7, 8); | 399 | display->width/2 - 3, display->height - h*2, 7, 8); |
418 | 400 | ||
419 | /* RIGHT: +2% */ | 401 | /* RIGHT: +2% */ |
420 | ptr = "+2%"; | 402 | ptr = "+2%"; |
421 | display->getstringsize(ptr,&w,&h); | 403 | display->getstringsize(ptr,&w,&h); |
422 | display->putsxy(display->width-w, (display->height-h)/2, ptr); | 404 | display->putsxy(display->width-w, (display->height-h)/2, ptr); |
423 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], | 405 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], |
424 | display->width-w-8, (display->height-h)/2, 7, 8); | 406 | display->width-w-8, (display->height-h)/2, 7, 8); |
425 | 407 | ||
426 | /* LEFT: -2% */ | 408 | /* LEFT: -2% */ |
427 | ptr = "-2%"; | 409 | ptr = "-2%"; |
428 | display->getstringsize(ptr,&w,&h); | 410 | display->getstringsize(ptr,&w,&h); |
429 | display->putsxy(0, (display->height-h)/2, ptr); | 411 | display->putsxy(0, (display->height-h)/2, ptr); |
430 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], | 412 | display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], |
431 | w+1, (display->height-h)/2, 7, 8); | 413 | w+1, (display->height-h)/2, 7, 8); |
432 | 414 | ||
433 | /* "Pitch" */ | 415 | /* "Pitch" */ |
434 | snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH)); | 416 | snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH)); |
435 | display->getstringsize(buf,&w,&h); | 417 | display->getstringsize(buf,&w,&h); |
@@ -1027,7 +1009,7 @@ bool shutdown_screen(void) | |||
1027 | break; | 1009 | break; |
1028 | 1010 | ||
1029 | /* do nothing here, because ACTION_UNKNOWN might be caused | 1011 | /* do nothing here, because ACTION_UNKNOWN might be caused |
1030 | * by timeout or button release. In case of timeout the loop | 1012 | * by timeout or button release. In case of timeout the loop |
1031 | * is terminated by TIME_BEFORE */ | 1013 | * is terminated by TIME_BEFORE */ |
1032 | case ACTION_UNKNOWN: | 1014 | case ACTION_UNKNOWN: |
1033 | break; | 1015 | break; |
@@ -1164,8 +1146,8 @@ bool browse_id3(void) | |||
1164 | while (true) { | 1146 | while (true) { |
1165 | gui_syncstatusbar_draw(&statusbars, false); | 1147 | gui_syncstatusbar_draw(&statusbars, false); |
1166 | key = get_action(CONTEXT_LIST,HZ/2); | 1148 | key = get_action(CONTEXT_LIST,HZ/2); |
1167 | if(key!=ACTION_NONE && key!=ACTION_UNKNOWN | 1149 | if(key!=ACTION_NONE && key!=ACTION_UNKNOWN |
1168 | && !gui_synclist_do_button(&id3_lists, key)) | 1150 | && !gui_synclist_do_button(&id3_lists, key)) |
1169 | { | 1151 | { |
1170 | action_signalscreenchange(); | 1152 | action_signalscreenchange(); |
1171 | return(default_event_handler(key) == SYS_USB_CONNECTED); | 1153 | return(default_event_handler(key) == SYS_USB_CONNECTED); |