From 9e8fe0e4c662d3d5c26ea2f1f64c7da66cf3ce04 Mon Sep 17 00:00:00 2001 From: Michael Sevakis Date: Mon, 30 Oct 2006 11:33:38 +0000 Subject: 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 --- apps/debug_menu.c | 58 ++++++++++++++++++++----------------------------------- apps/screens.c | 52 ++++++++++++++++--------------------------------- 2 files changed, 38 insertions(+), 72 deletions(-) (limited to 'apps') 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) break; case ACTION_STD_CANCEL: done = true; - break; + break; } action_signalscreenchange(); line = 0; @@ -968,8 +968,7 @@ bool dbg_ports(void) unsigned short portb; unsigned char portc; char buf[32]; - int battery_voltage; - int batt_int, batt_frac; + int adc_battery_voltage, adc_battery_level; lcd_setfont(FONT_SYSFIXED); lcd_setmargins(0, 0); @@ -995,12 +994,10 @@ bool dbg_ports(void) snprintf(buf, 32, "AN3: %03x AN7: %03x", adc_read(3), adc_read(7)); lcd_puts(0, 5, buf); - battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; - batt_int = battery_voltage / 100; - batt_frac = battery_voltage % 100; - - snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac, - battery_level()); + battery_read_info(NULL, &adc_battery_voltage, + &adc_battery_level); + snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100, + adc_battery_voltage % 100, adc_battery_level); lcd_puts(0, 6, buf); #ifndef HAVE_MMC /* have ATA */ snprintf(buf, 32, "ATA: %s, 0x%x", @@ -1020,14 +1017,10 @@ bool dbg_ports(void) unsigned int gpio1_function; unsigned int gpio_enable; unsigned int gpio1_enable; - int adc_buttons, adc_remote, adc_battery; -#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - int adc_remotedetect; -#endif + int adc_buttons, adc_remote; + int adc_battery, adc_battery_voltage, adc_battery_level; char buf[128]; int line; - int battery_voltage; - int batt_int, batt_frac; lcd_setmargins(0, 0); lcd_clear_display(); @@ -1064,12 +1057,9 @@ bool dbg_ports(void) lcd_puts(0, line++, buf); adc_buttons = adc_read(ADC_BUTTONS); - adc_remote = adc_read(ADC_REMOTE); - adc_battery = adc_read(ADC_BATTERY); -#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - adc_remotedetect = adc_read(ADC_REMOTEDETECT); -#endif - + adc_remote = adc_read(ADC_REMOTE); + battery_read_info(&adc_battery, &adc_battery_voltage, + &adc_battery_level); #if defined(IAUDIO_X5) || defined(IRIVER_H300_SERIES) snprintf(buf, sizeof(buf), "ADC_BUTTONS (%c): %02x", button_scan_enabled() ? '+' : '-', adc_buttons); @@ -1083,20 +1073,18 @@ bool dbg_ports(void) #else snprintf(buf, sizeof(buf), "ADC_REMOTE: %02x", adc_remote); #endif + lcd_puts(0, line++, buf); snprintf(buf, sizeof(buf), "ADC_BATTERY: %02x", adc_battery); lcd_puts(0, line++, buf); #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) - snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x", adc_remotedetect); + snprintf(buf, sizeof(buf), "ADC_REMOTEDETECT: %02x", + adc_read(ADC_REMOTEDETECT)); lcd_puts(0, line++, buf); #endif - battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; - batt_int = battery_voltage / 100; - batt_frac = battery_voltage % 100; - - snprintf(buf, 32, "Batt: %d.%02dV %d%% ", batt_int, batt_frac, - battery_level()); + snprintf(buf, 32, "Batt: %d.%02dV %d%% ", adc_battery_voltage / 100, + adc_battery_voltage % 100, adc_battery_level); lcd_puts(0, line++, buf); #if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES) @@ -1209,8 +1197,7 @@ bool dbg_ports(void) unsigned char portc; char buf[32]; int button; - int battery_voltage; - int batt_int, batt_frac; + int adc_battery_voltage; int currval = 0; lcd_clear_display(); @@ -1260,12 +1247,9 @@ bool dbg_ports(void) } lcd_puts(0, 0, buf); - battery_voltage = (adc_read(ADC_UNREG_POWER) * - BATTERY_SCALE_FACTOR) / 10000; - batt_int = battery_voltage / 100; - batt_frac = battery_voltage % 100; - - snprintf(buf, 32, "Batt: %d.%02dV", batt_int, batt_frac); + battery_read_info(NULL, &adc_battery_voltage, NULL); + snprintf(buf, 32, "Batt: %d.%02dV", adc_battery_voltage / 100, + adc_battery_voltage % 100); lcd_puts(0, 1, buf); button = get_action(CONTEXT_SETTINGS,HZ/5); @@ -1418,7 +1402,7 @@ bool view_battery(void) lcd_clear_display(); lcd_puts(0, 0, "Power status:"); - y = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; + battery_read_info(NULL, &y, NULL); snprintf(buf, 30, "Battery: %d.%02d V", y / 100, y % 100); lcd_puts(0, 1, buf); #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) #ifdef HAVE_REMOTE_LCD lcd_remote_clear_display(); - lcd_remote_bitmap(remote_usblogo, - (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo)/2, + lcd_remote_bitmap(remote_usblogo, + (LCD_REMOTE_WIDTH-BMPWIDTH_remote_usblogo)/2, (LCD_REMOTE_HEIGHT-BMPHEIGHT_remote_usblogo)/2, BMPWIDTH_remote_usblogo, BMPHEIGHT_remote_usblogo); lcd_remote_update(); @@ -107,7 +107,7 @@ void usb_screen(void) lcd_clear_display(); #ifdef HAVE_LCD_BITMAP - lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo)/2, + lcd_bitmap(usblogo, (LCD_WIDTH-BMPWIDTH_usblogo)/2, (LCD_HEIGHT-BMPHEIGHT_usblogo)/2, BMPWIDTH_usblogo, BMPHEIGHT_usblogo); lcd_update(); @@ -167,17 +167,6 @@ int mmc_remove_request(void) } #endif - -/* some simulator dummies */ -#ifdef SIMULATOR -#define BATTERY_SCALE_FACTOR 7000 -unsigned short adc_read(int channel) -{ - (void)channel; - return 100; -} -#endif - #if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING) #ifdef HAVE_LCD_BITMAP @@ -195,15 +184,9 @@ void charging_display_info(bool animate) if (ide_powered()) /* FM and V2 can only measure when ATA power is on */ #endif { - int battery_voltage; - int batt_int, batt_frac; - - battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; - batt_int = battery_voltage / 100; - batt_frac = battery_voltage % 100; - - snprintf(buf, 32, " Batt: %d.%02dV %d%% ", batt_int, batt_frac, - battery_level()); + int battv = battery_voltage(); + snprintf(buf, 32, " Batt: %d.%02dV %d%% ", battv / 100, + battv % 100, battery_level()); lcd_puts(0, 7, buf); } @@ -294,15 +277,14 @@ static void logo_lock_patterns(bool on) void charging_display_info(bool animate) { - int battery_voltage; + int battv; unsigned i, ypos; static unsigned phase = 3; char buf[28]; - battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) - / 10000; + battv = battery_voltage(); snprintf(buf, sizeof(buf), "%s %d.%02dV", logo_chars, - battery_voltage / 100, battery_voltage % 100); + battv / 100, battv % 100); lcd_puts(0, 1, buf); memcpy(buf, logo_pattern, 28); /* copy logo patterns */ @@ -337,7 +319,7 @@ void charging_display_info(bool animate) 2 if Off/Stop key was pressed 3 if On key was pressed 4 if USB was connected */ - + int charging_screen(void) { unsigned int button; @@ -391,7 +373,7 @@ void pitch_screen_draw(struct screen *display, int pitch) int w, h; display->clear_display(); - + if (display->nb_lines < 4) /* very small screen, just show the pitch value */ { 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) display->putsxy((display->width-w)/2, display->height - h, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_DownArrow], display->width/2 - 3, display->height - h*2, 7, 8); - + /* RIGHT: +2% */ ptr = "+2%"; display->getstringsize(ptr,&w,&h); display->putsxy(display->width-w, (display->height-h)/2, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_FastForward], display->width-w-8, (display->height-h)/2, 7, 8); - + /* LEFT: -2% */ ptr = "-2%"; display->getstringsize(ptr,&w,&h); display->putsxy(0, (display->height-h)/2, ptr); display->mono_bitmap(bitmap_icons_7x8[Icon_FastBackward], w+1, (display->height-h)/2, 7, 8); - + /* "Pitch" */ snprintf((char *)buf, sizeof(buf), str(LANG_SYSFONT_PITCH)); display->getstringsize(buf,&w,&h); @@ -1027,7 +1009,7 @@ bool shutdown_screen(void) break; /* do nothing here, because ACTION_UNKNOWN might be caused - * by timeout or button release. In case of timeout the loop + * by timeout or button release. In case of timeout the loop * is terminated by TIME_BEFORE */ case ACTION_UNKNOWN: break; @@ -1164,8 +1146,8 @@ bool browse_id3(void) while (true) { gui_syncstatusbar_draw(&statusbars, false); key = get_action(CONTEXT_LIST,HZ/2); - if(key!=ACTION_NONE && key!=ACTION_UNKNOWN - && !gui_synclist_do_button(&id3_lists, key)) + if(key!=ACTION_NONE && key!=ACTION_UNKNOWN + && !gui_synclist_do_button(&id3_lists, key)) { action_signalscreenchange(); return(default_event_handler(key) == SYS_USB_CONNECTED); -- cgit v1.2.3