diff options
-rw-r--r-- | apps/debug_menu.c | 58 | ||||
-rw-r--r-- | apps/screens.c | 52 | ||||
-rw-r--r-- | bootloader/main.c | 56 | ||||
-rw-r--r-- | firmware/export/config-iaudiox5.h | 13 | ||||
-rw-r--r-- | firmware/export/config.h | 1 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 5 | ||||
-rw-r--r-- | firmware/powermgmt.c | 54 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/adc-target.h | 5 | ||||
-rwxr-xr-x | firmware/target/coldfire/iaudio/x5/adc-x5.c | 48 | ||||
-rw-r--r-- | firmware/target/coldfire/iaudio/x5/pcf50606-x5.c | 4 | ||||
-rw-r--r-- | flash/bootbox/main.c | 15 |
11 files changed, 155 insertions, 156 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); |
diff --git a/bootloader/main.c b/bootloader/main.c index 77866573e9..99eb449151 100644 --- a/bootloader/main.c +++ b/bootloader/main.c | |||
@@ -99,7 +99,7 @@ int load_firmware(void) | |||
99 | unsigned long sum; | 99 | unsigned long sum; |
100 | int i; | 100 | int i; |
101 | unsigned char *buf = (unsigned char *)DRAM_START; | 101 | unsigned char *buf = (unsigned char *)DRAM_START; |
102 | 102 | ||
103 | fd = open("/.rockbox/" BOOTFILE, O_RDONLY); | 103 | fd = open("/.rockbox/" BOOTFILE, O_RDONLY); |
104 | if(fd < 0) | 104 | if(fd < 0) |
105 | { | 105 | { |
@@ -114,7 +114,7 @@ int load_firmware(void) | |||
114 | lcd_update(); | 114 | lcd_update(); |
115 | 115 | ||
116 | lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); | 116 | lseek(fd, FIRMWARE_OFFSET_FILE_CRC, SEEK_SET); |
117 | 117 | ||
118 | rc = read(fd, &chksum, 4); | 118 | rc = read(fd, &chksum, 4); |
119 | if(rc < 4) | 119 | if(rc < 4) |
120 | return -2; | 120 | return -2; |
@@ -127,7 +127,7 @@ int load_firmware(void) | |||
127 | return -3; | 127 | return -3; |
128 | 128 | ||
129 | model[4] = 0; | 129 | model[4] = 0; |
130 | 130 | ||
131 | printf("Model name: %s", model); | 131 | printf("Model name: %s", model); |
132 | lcd_update(); | 132 | lcd_update(); |
133 | 133 | ||
@@ -140,7 +140,7 @@ int load_firmware(void) | |||
140 | close(fd); | 140 | close(fd); |
141 | 141 | ||
142 | sum = MODEL_NUMBER; | 142 | sum = MODEL_NUMBER; |
143 | 143 | ||
144 | for(i = 0;i < len;i++) { | 144 | for(i = 0;i < len;i++) { |
145 | sum += buf[i]; | 145 | sum += buf[i]; |
146 | } | 146 | } |
@@ -159,7 +159,7 @@ int load_flashed_rockbox(void) | |||
159 | struct flash_header hdr; | 159 | struct flash_header hdr; |
160 | unsigned char *buf = (unsigned char *)DRAM_START; | 160 | unsigned char *buf = (unsigned char *)DRAM_START; |
161 | uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT; | 161 | uint8_t *src = (uint8_t *)FLASH_ENTRYPOINT; |
162 | 162 | ||
163 | cpu_boost(true); | 163 | cpu_boost(true); |
164 | memcpy(&hdr, src, sizeof(struct flash_header)); | 164 | memcpy(&hdr, src, sizeof(struct flash_header)); |
165 | src += sizeof(struct flash_header); | 165 | src += sizeof(struct flash_header); |
@@ -221,7 +221,7 @@ void main(void) | |||
221 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; | 221 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; |
222 | batt_int = battery_voltage / 100; | 222 | batt_int = battery_voltage / 100; |
223 | batt_frac = battery_voltage % 100; | 223 | batt_frac = battery_voltage % 100; |
224 | 224 | ||
225 | printf("Batt: %d.%02dV", batt_int, batt_frac); | 225 | printf("Batt: %d.%02dV", batt_int, batt_frac); |
226 | lcd_update(); | 226 | lcd_update(); |
227 | 227 | ||
@@ -248,12 +248,12 @@ void main(void) | |||
248 | i = load_firmware(); | 248 | i = load_firmware(); |
249 | printf("Result: %d", i); | 249 | printf("Result: %d", i); |
250 | lcd_update(); | 250 | lcd_update(); |
251 | 251 | ||
252 | if(i == 0) | 252 | if(i == 0) |
253 | start_firmware(); | 253 | start_firmware(); |
254 | 254 | ||
255 | power_off(); | 255 | power_off(); |
256 | 256 | ||
257 | #else | 257 | #else |
258 | /* We want to read the buttons as early as possible, before the user | 258 | /* We want to read the buttons as early as possible, before the user |
259 | releases the ON button */ | 259 | releases the ON button */ |
@@ -266,19 +266,19 @@ void main(void) | |||
266 | data = GPIO1_READ; | 266 | data = GPIO1_READ; |
267 | if ((data & 0x20) == 0) | 267 | if ((data & 0x20) == 0) |
268 | on_button = true; | 268 | on_button = true; |
269 | 269 | ||
270 | if ((data & 0x40) == 0) | 270 | if ((data & 0x40) == 0) |
271 | rc_on_button = true; | 271 | rc_on_button = true; |
272 | 272 | ||
273 | /* Set the default state of the hard drive power to OFF */ | 273 | /* Set the default state of the hard drive power to OFF */ |
274 | ide_power_enable(false); | 274 | ide_power_enable(false); |
275 | 275 | ||
276 | power_init(); | 276 | power_init(); |
277 | 277 | ||
278 | /* Turn off if neither ON button is pressed */ | 278 | /* Turn off if neither ON button is pressed */ |
279 | if(!(on_button || rc_on_button || usb_detect())) | 279 | if(!(on_button || rc_on_button || usb_detect())) |
280 | power_off(); | 280 | power_off(); |
281 | 281 | ||
282 | /* Backlight ON */ | 282 | /* Backlight ON */ |
283 | or_l(0x00020000, &GPIO1_ENABLE); | 283 | or_l(0x00020000, &GPIO1_ENABLE); |
284 | or_l(0x00020000, &GPIO1_FUNCTION); | 284 | or_l(0x00020000, &GPIO1_FUNCTION); |
@@ -304,7 +304,7 @@ void main(void) | |||
304 | ide_power_enable(true); | 304 | ide_power_enable(true); |
305 | } | 305 | } |
306 | #endif | 306 | #endif |
307 | 307 | ||
308 | system_init(); | 308 | system_init(); |
309 | kernel_init(); | 309 | kernel_init(); |
310 | 310 | ||
@@ -316,7 +316,7 @@ void main(void) | |||
316 | #ifdef HAVE_UDA1380 | 316 | #ifdef HAVE_UDA1380 |
317 | uda1380_reset(); | 317 | uda1380_reset(); |
318 | #endif | 318 | #endif |
319 | 319 | ||
320 | backlight_init(); | 320 | backlight_init(); |
321 | set_irq_level(0); | 321 | set_irq_level(0); |
322 | lcd_init(); | 322 | lcd_init(); |
@@ -331,9 +331,9 @@ void main(void) | |||
331 | lcd_update(); | 331 | lcd_update(); |
332 | 332 | ||
333 | sleep(HZ/50); /* Allow the button driver to check the buttons */ | 333 | sleep(HZ/50); /* Allow the button driver to check the buttons */ |
334 | rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC) | 334 | rec_button = ((button_status() & BUTTON_REC) == BUTTON_REC) |
335 | || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC); | 335 | || ((button_status() & BUTTON_RC_REC) == BUTTON_RC_REC); |
336 | 336 | ||
337 | /* Don't start if the Hold button is active on the device you | 337 | /* Don't start if the Hold button is active on the device you |
338 | are starting with */ | 338 | are starting with */ |
339 | if (!usb_detect() && ((on_button && button_hold()) || | 339 | if (!usb_detect() && ((on_button && button_hold()) || |
@@ -363,7 +363,7 @@ void main(void) | |||
363 | if (detect_flashed_rockbox()) | 363 | if (detect_flashed_rockbox()) |
364 | { | 364 | { |
365 | bool load_from_flash; | 365 | bool load_from_flash; |
366 | 366 | ||
367 | load_from_flash = !rec_button; | 367 | load_from_flash = !rec_button; |
368 | #ifdef HAVE_EEPROM_SETTINGS | 368 | #ifdef HAVE_EEPROM_SETTINGS |
369 | if (eeprom_settings_init()) | 369 | if (eeprom_settings_init()) |
@@ -372,7 +372,7 @@ void main(void) | |||
372 | * not be intact. */ | 372 | * not be intact. */ |
373 | if (firmware_settings.bl_version) | 373 | if (firmware_settings.bl_version) |
374 | firmware_settings.disk_clean = false; | 374 | firmware_settings.disk_clean = false; |
375 | 375 | ||
376 | firmware_settings.bl_version = 7; | 376 | firmware_settings.bl_version = 7; |
377 | /* Invert the record button if we want to load from disk | 377 | /* Invert the record button if we want to load from disk |
378 | * by default. */ | 378 | * by default. */ |
@@ -380,7 +380,7 @@ void main(void) | |||
380 | load_from_flash = rec_button; | 380 | load_from_flash = rec_button; |
381 | } | 381 | } |
382 | #endif | 382 | #endif |
383 | 383 | ||
384 | if (load_from_flash) | 384 | if (load_from_flash) |
385 | { | 385 | { |
386 | /* Load firmware from flash */ | 386 | /* Load firmware from flash */ |
@@ -400,7 +400,7 @@ void main(void) | |||
400 | power_off(); | 400 | power_off(); |
401 | } | 401 | } |
402 | } | 402 | } |
403 | 403 | ||
404 | printf("Loading from disk..."); | 404 | printf("Loading from disk..."); |
405 | lcd_update(); | 405 | lcd_update(); |
406 | } | 406 | } |
@@ -416,13 +416,13 @@ void main(void) | |||
416 | } | 416 | } |
417 | 417 | ||
418 | usb_init(); | 418 | usb_init(); |
419 | 419 | ||
420 | adc_battery = adc_read(ADC_BATTERY); | 420 | adc_battery = adc_read(ADC_BATTERY); |
421 | 421 | ||
422 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; | 422 | battery_voltage = (adc_battery * BATTERY_SCALE_FACTOR) / 10000; |
423 | batt_int = battery_voltage / 100; | 423 | batt_int = battery_voltage / 100; |
424 | batt_frac = battery_voltage % 100; | 424 | batt_frac = battery_voltage % 100; |
425 | 425 | ||
426 | printf("Batt: %d.%02dV", batt_int, batt_frac); | 426 | printf("Batt: %d.%02dV", batt_int, batt_frac); |
427 | lcd_update(); | 427 | lcd_update(); |
428 | 428 | ||
@@ -431,7 +431,7 @@ void main(void) | |||
431 | lcd_update(); | 431 | lcd_update(); |
432 | sleep(HZ*2); | 432 | sleep(HZ*2); |
433 | } | 433 | } |
434 | 434 | ||
435 | rc = ata_init(); | 435 | rc = ata_init(); |
436 | if(rc) | 436 | if(rc) |
437 | { | 437 | { |
@@ -456,7 +456,7 @@ void main(void) | |||
456 | #ifdef IRIVER_H300_SERIES | 456 | #ifdef IRIVER_H300_SERIES |
457 | sleep(HZ); | 457 | sleep(HZ); |
458 | #endif | 458 | #endif |
459 | 459 | ||
460 | #ifdef HAVE_EEPROM_SETTINGS | 460 | #ifdef HAVE_EEPROM_SETTINGS |
461 | if (firmware_settings.initialized) | 461 | if (firmware_settings.initialized) |
462 | { | 462 | { |
@@ -472,7 +472,7 @@ void main(void) | |||
472 | { | 472 | { |
473 | ata_spin(); /* Prevent the drive from spinning down */ | 473 | ata_spin(); /* Prevent the drive from spinning down */ |
474 | sleep(HZ); | 474 | sleep(HZ); |
475 | 475 | ||
476 | /* Backlight OFF */ | 476 | /* Backlight OFF */ |
477 | or_l(0x00020000, &GPIO1_OUT); | 477 | or_l(0x00020000, &GPIO1_OUT); |
478 | } | 478 | } |
@@ -480,12 +480,12 @@ void main(void) | |||
480 | cpu_idle_mode(false); | 480 | cpu_idle_mode(false); |
481 | usb_enable(false); | 481 | usb_enable(false); |
482 | ata_init(); /* Reinitialize ATA and continue booting */ | 482 | ata_init(); /* Reinitialize ATA and continue booting */ |
483 | 483 | ||
484 | lcd_clear_display(); | 484 | lcd_clear_display(); |
485 | line = 0; | 485 | line = 0; |
486 | lcd_update(); | 486 | lcd_update(); |
487 | } | 487 | } |
488 | 488 | ||
489 | disk_init(); | 489 | disk_init(); |
490 | 490 | ||
491 | rc = disk_mount_all(); | 491 | rc = disk_mount_all(); |
@@ -507,10 +507,10 @@ void main(void) | |||
507 | if (firmware_settings.initialized) | 507 | if (firmware_settings.initialized) |
508 | eeprom_settings_store(); | 508 | eeprom_settings_store(); |
509 | #endif | 509 | #endif |
510 | 510 | ||
511 | if (i == 0) | 511 | if (i == 0) |
512 | start_firmware(); | 512 | start_firmware(); |
513 | 513 | ||
514 | if (detect_flashed_rockbox()) | 514 | if (detect_flashed_rockbox()) |
515 | { | 515 | { |
516 | printf("No firmware found on disk"); | 516 | printf("No firmware found on disk"); |
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h index df24850892..3e835605da 100644 --- a/firmware/export/config-iaudiox5.h +++ b/firmware/export/config-iaudiox5.h | |||
@@ -113,12 +113,13 @@ | |||
113 | #define CPU_FREQ 11289600 | 113 | #define CPU_FREQ 11289600 |
114 | 114 | ||
115 | /* Type of mobile power */ | 115 | /* Type of mobile power */ |
116 | #define CONFIG_BATTERY BATT_LIPOL1300 | 116 | #define X5_BATT_CONFIG 2 |
117 | #define BATTERY_CAPACITY_MIN 950 /* min. capacity selectable */ | 117 | #define CONFIG_BATTERY BATT_IAUDIO_X5 |
118 | #define BATTERY_CAPACITY_MAX 2250 /* max. capacity selectable */ | 118 | #define BATTERY_CAPACITY_MIN 950 /* min. capacity selectable */ |
119 | #define BATTERY_CAPACITY_INC 50 /* capacity increment */ | 119 | #define BATTERY_CAPACITY_MAX 2250 /* max. capacity selectable */ |
120 | #define BATTERY_TYPES_COUNT 1 /* only one type */ | 120 | #define BATTERY_CAPACITY_INC 50 /* capacity increment */ |
121 | #define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */ | 121 | #define BATTERY_TYPES_COUNT 1 /* only one type */ |
122 | #define BATTERY_SCALE_FACTOR 5859 /* (420703125 + 35900) / 71800 */ | ||
122 | 123 | ||
123 | /* define this if you have a real-time clock */ | 124 | /* define this if you have a real-time clock */ |
124 | #define CONFIG_RTC RTC_PCF50606 | 125 | #define CONFIG_RTC RTC_PCF50606 |
diff --git a/firmware/export/config.h b/firmware/export/config.h index 6f6d253fe9..765bcfdb07 100644 --- a/firmware/export/config.h +++ b/firmware/export/config.h | |||
@@ -70,6 +70,7 @@ | |||
70 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ | 70 | #define BATT_LIION2200 2200 /* FM/V2 recorder type */ |
71 | #define BATT_4AA_NIMH 1500 | 71 | #define BATT_4AA_NIMH 1500 |
72 | #define BATT_3AAA 1000 /* Ondio */ | 72 | #define BATT_3AAA 1000 /* Ondio */ |
73 | #define BATT_IAUDIO_X5 950 | ||
73 | #define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */ | 74 | #define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */ |
74 | #define BATT_LPCS355385 1550 /* iriver h10 20Gb - SKC LPCS355385 */ | 75 | #define BATT_LPCS355385 1550 /* iriver h10 20Gb - SKC LPCS355385 */ |
75 | #define BATT_BP009 820 /* iriver H10 5/6Gb - iriver BP009 */ | 76 | #define BATT_BP009 820 /* iriver H10 5/6Gb - iriver BP009 */ |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index 30fe60c293..ba2cc02318 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -63,7 +63,7 @@ extern int trickle_sec; /* trickle charge: How many seconds per minute | |||
63 | 63 | ||
64 | #if CONFIG_CHARGING >= CHARGING_MONITOR | 64 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
65 | typedef enum { /* sorted by increasing charging current */ | 65 | typedef enum { /* sorted by increasing charging current */ |
66 | DISCHARGING = 0, | 66 | DISCHARGING = 0, |
67 | TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */ | 67 | TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */ |
68 | TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */ | 68 | TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */ |
69 | CHARGING /* Can occur for all CONFIG_CHARGING options */ | 69 | CHARGING /* Can occur for all CONFIG_CHARGING options */ |
@@ -126,6 +126,9 @@ int battery_time(void); /* minutes */ | |||
126 | 126 | ||
127 | unsigned int battery_voltage(void); /* filtered batt. voltage in centivolts */ | 127 | unsigned int battery_voltage(void); /* filtered batt. voltage in centivolts */ |
128 | 128 | ||
129 | /* read unfiltered battery info */ | ||
130 | void battery_read_info(int *adc, int *voltage, int *level); | ||
131 | |||
129 | /* Tells if the battery level is safe for disk writes */ | 132 | /* Tells if the battery level is safe for disk writes */ |
130 | bool battery_level_safe(void); | 133 | bool battery_level_safe(void); |
131 | 134 | ||
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 50b734bbbd..f18ea3c636 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -112,6 +112,20 @@ static void battery_status_update(void) | |||
112 | } | 112 | } |
113 | } | 113 | } |
114 | 114 | ||
115 | void battery_read_info(int *adc, int *voltage, int *level) | ||
116 | { | ||
117 | battery_status_update(); | ||
118 | |||
119 | if (adc) | ||
120 | *adc = batt_centivolts*10000 / BATTERY_SCALE_FACTOR; | ||
121 | |||
122 | if (voltage) | ||
123 | *voltage = batt_centivolts; | ||
124 | |||
125 | if (level) | ||
126 | *level = batt_level; | ||
127 | } | ||
128 | |||
115 | unsigned int battery_voltage(void) | 129 | unsigned int battery_voltage(void) |
116 | { | 130 | { |
117 | battery_status_update(); | 131 | battery_status_update(); |
@@ -167,6 +181,8 @@ static const unsigned int battery_level_dangerous[BATTERY_TYPES_COUNT] = | |||
167 | 105, 115 /* alkaline, NiHM */ | 181 | 105, 115 /* alkaline, NiHM */ |
168 | #elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver H1x0 */ | 182 | #elif CONFIG_BATTERY == BATT_LIPOL1300 /* iRiver H1x0 */ |
169 | 339 | 183 | 339 |
184 | #elif CONFIG_BATTERY == BATT_IAUDIO_X5 | ||
185 | 354 | ||
170 | #elif CONFIG_BATTERY == BATT_LPCS355385 /* iriver H10 20GB */ | 186 | #elif CONFIG_BATTERY == BATT_LPCS355385 /* iriver H10 20GB */ |
171 | 376 | 187 | 376 |
172 | #elif CONFIG_BATTERY == BATT_BP009 /* iriver H10 5/6GB */ | 188 | #elif CONFIG_BATTERY == BATT_BP009 /* iriver H10 5/6GB */ |
@@ -192,6 +208,13 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] = | |||
192 | * for the 1300 mAh stock battery. */ | 208 | * for the 1300 mAh stock battery. */ |
193 | // { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 } | 209 | // { 337, 358, 365, 369, 372, 377, 383, 389, 397, 406, 413 } |
194 | { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 } | 210 | { 337, 366, 372, 374, 378, 381, 385, 392, 399, 408, 417 } |
211 | #elif CONFIG_BATTERY == BATT_IAUDIO_X5 | ||
212 | /* iAudio x5 series - still experimenting with best curve */ | ||
213 | // Lithium ion discharge curve | ||
214 | { 355, 356, 357, 359, 362, 365, 369, 374, 380, 387, 395 } | ||
215 | // Linear | ||
216 | // { 355, 360, 364, 369, 373, 378, 382, 387, 391, 390, 400 } | ||
217 | // { 355, 359, 363, 367, 371, 375, 379, 383, 387, 391, 395 } | ||
195 | #elif CONFIG_BATTERY == BATT_LPCS355385 | 218 | #elif CONFIG_BATTERY == BATT_LPCS355385 |
196 | /* iriver H10 20GB */ | 219 | /* iriver H10 20GB */ |
197 | { 376, 380, 385, 387, 390, 395, 402, 407, 411, 418, 424 } | 220 | { 376, 380, 385, 387, 390, 395, 402, 407, 411, 418, 424 } |
@@ -289,9 +312,25 @@ static long sleeptimer_endtick; | |||
289 | 312 | ||
290 | static long last_event_tick; | 313 | static long last_event_tick; |
291 | 314 | ||
315 | static int voltage_to_battery_level(int battery_centivolts); | ||
292 | static void battery_status_update(void); | 316 | static void battery_status_update(void); |
293 | static int runcurrent(void); | 317 | static int runcurrent(void); |
294 | 318 | ||
319 | void battery_read_info(int *adc, int *voltage, int *level) | ||
320 | { | ||
321 | int adc_battery = adc_read(ADC_UNREG_POWER); | ||
322 | int centivolts = adc_battery*BATTERY_SCALE_FACTOR / 10000; | ||
323 | |||
324 | if (adc) | ||
325 | *adc = adc_battery; | ||
326 | |||
327 | if (voltage) | ||
328 | *voltage = centivolts; | ||
329 | |||
330 | if (level) | ||
331 | *level = voltage_to_battery_level(centivolts); | ||
332 | } | ||
333 | |||
295 | unsigned int battery_voltage(void) | 334 | unsigned int battery_voltage(void) |
296 | { | 335 | { |
297 | return battery_centivolts; | 336 | return battery_centivolts; |
@@ -387,14 +426,14 @@ static int voltage_to_percent(int voltage, const short* table) | |||
387 | 426 | ||
388 | /* update battery level and estimated runtime, called once per minute or | 427 | /* update battery level and estimated runtime, called once per minute or |
389 | * when battery capacity / type settings are changed */ | 428 | * when battery capacity / type settings are changed */ |
390 | static void battery_status_update(void) | 429 | static int voltage_to_battery_level(int battery_centivolts) |
391 | { | 430 | { |
392 | int level; | 431 | int level; |
393 | 432 | ||
394 | #if CONFIG_CHARGING >= CHARGING_MONITOR | 433 | #if CONFIG_CHARGING >= CHARGING_MONITOR |
395 | if (charge_state == DISCHARGING) { | 434 | if (charge_state == DISCHARGING) { |
396 | level = voltage_to_percent(battery_centivolts, | 435 | level = voltage_to_percent(battery_centivolts, |
397 | percent_to_volt_discharge[battery_type]); | 436 | percent_to_volt_discharge[battery_type]); |
398 | } | 437 | } |
399 | else if (charge_state == CHARGING) { | 438 | else if (charge_state == CHARGING) { |
400 | /* battery level is defined to be < 100% until charging is finished */ | 439 | /* battery level is defined to be < 100% until charging is finished */ |
@@ -407,9 +446,16 @@ static void battery_status_update(void) | |||
407 | #else | 446 | #else |
408 | /* always use the discharge table */ | 447 | /* always use the discharge table */ |
409 | level = voltage_to_percent(battery_centivolts, | 448 | level = voltage_to_percent(battery_centivolts, |
410 | percent_to_volt_discharge[battery_type]); | 449 | percent_to_volt_discharge[battery_type]); |
411 | #endif | 450 | #endif |
412 | 451 | ||
452 | return level; | ||
453 | } | ||
454 | |||
455 | static void battery_status_update(void) | ||
456 | { | ||
457 | int level = voltage_to_battery_level(battery_centivolts); | ||
458 | |||
413 | #ifndef HAVE_MMC /* this adjustment is only needed for HD based */ | 459 | #ifndef HAVE_MMC /* this adjustment is only needed for HD based */ |
414 | if (battery_percent == -1) { /* first run of this procedure */ | 460 | if (battery_percent == -1) { /* first run of this procedure */ |
415 | /* The battery voltage is usually a little lower directly after | 461 | /* The battery voltage is usually a little lower directly after |
@@ -699,7 +745,6 @@ static void power_thread(void) | |||
699 | #endif | 745 | #endif |
700 | 746 | ||
701 | /* initialize the voltages for the exponential filter */ | 747 | /* initialize the voltages for the exponential filter */ |
702 | |||
703 | avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * | 748 | avgbat = adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR * |
704 | BATT_AVE_SAMPLES; | 749 | BATT_AVE_SAMPLES; |
705 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; | 750 | battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000; |
@@ -1010,7 +1055,6 @@ void powermgmt_init(void) | |||
1010 | { | 1055 | { |
1011 | /* init history to 0 */ | 1056 | /* init history to 0 */ |
1012 | memset(power_history, 0x00, sizeof(power_history)); | 1057 | memset(power_history, 0x00, sizeof(power_history)); |
1013 | |||
1014 | create_thread(power_thread, power_stack, sizeof(power_stack), | 1058 | create_thread(power_thread, power_stack, sizeof(power_stack), |
1015 | power_thread_name IF_PRIO(, PRIORITY_SYSTEM)); | 1059 | power_thread_name IF_PRIO(, PRIORITY_SYSTEM)); |
1016 | } | 1060 | } |
diff --git a/firmware/target/coldfire/iaudio/x5/adc-target.h b/firmware/target/coldfire/iaudio/x5/adc-target.h index 4081562fe5..28ba6225d1 100644 --- a/firmware/target/coldfire/iaudio/x5/adc-target.h +++ b/firmware/target/coldfire/iaudio/x5/adc-target.h | |||
@@ -28,5 +28,8 @@ | |||
28 | 28 | ||
29 | /* Force a scan now */ | 29 | /* Force a scan now */ |
30 | unsigned short adc_scan(int channel); | 30 | unsigned short adc_scan(int channel); |
31 | 31 | static inline unsigned short adc_read(int channel) | |
32 | { return adc_scan(channel); } | ||
33 | static inline void adc_init(void) | ||
34 | {} | ||
32 | #endif /* _ADC_TARGET_H_ */ | 35 | #endif /* _ADC_TARGET_H_ */ |
diff --git a/firmware/target/coldfire/iaudio/x5/adc-x5.c b/firmware/target/coldfire/iaudio/x5/adc-x5.c index 72aec7d547..1895cacfe9 100755 --- a/firmware/target/coldfire/iaudio/x5/adc-x5.c +++ b/firmware/target/coldfire/iaudio/x5/adc-x5.c | |||
@@ -24,49 +24,35 @@ | |||
24 | #include "adc.h" | 24 | #include "adc.h" |
25 | #include "pcf50606.h" | 25 | #include "pcf50606.h" |
26 | 26 | ||
27 | static unsigned short adcdata[NUM_ADC_CHANNELS]; | 27 | /* get remaining 2 bits and return 10 bit value */ |
28 | 28 | static int get_10bit_voltage(int msbdata) | |
29 | static const int adcc2_parms[] = | ||
30 | { | 29 | { |
31 | [ADC_BUTTONS] = 0x80 | (5 << 1) | 1, /* ADCIN2 */ | 30 | int data = msbdata << 2; |
32 | [ADC_REMOTE] = 0x80 | (6 << 1) | 1, /* ADCIN3 */ | 31 | data |= pcf50606_read(0x31) & 0x3; |
33 | [ADC_BATTERY] = 0x80 | (0 << 1) | 1, /* BATVOLT, resistive divider */ | 32 | return data; |
34 | }; | 33 | } |
35 | 34 | ||
36 | unsigned short adc_scan(int channel) | 35 | unsigned short adc_scan(int channel) |
37 | { | 36 | { |
37 | static const int adcc2_parms[] = | ||
38 | { | ||
39 | [ADC_BUTTONS] = 0x81 | (5 << 1), /* 8b - ADCIN2 */ | ||
40 | [ADC_REMOTE] = 0x81 | (6 << 1), /* 8b - ADCIN3 */ | ||
41 | [ADC_BATTERY] = 0x01 | (0 << 1), /* 10b - BATVOLT, resistive divider */ | ||
42 | }; | ||
43 | |||
38 | int level; | 44 | int level; |
39 | unsigned char data; | 45 | int data; |
40 | 46 | ||
41 | level = set_irq_level(HIGHEST_IRQ_LEVEL); | 47 | level = set_irq_level(HIGHEST_IRQ_LEVEL); |
42 | 48 | ||
43 | pcf50606_write(0x2f, adcc2_parms[channel]); | 49 | pcf50606_write(0x2f, adcc2_parms[channel]); |
44 | data = pcf50606_read(0x30); | 50 | data = pcf50606_read(0x30); |
45 | 51 | ||
46 | adcdata[channel] = data; | 52 | if (channel == ADC_BATTERY) |
53 | data = get_10bit_voltage(data); | ||
47 | 54 | ||
48 | set_irq_level(level); | 55 | set_irq_level(level); |
49 | return data; | ||
50 | } | ||
51 | |||
52 | unsigned short adc_read(int channel) | ||
53 | { | ||
54 | return adcdata[channel]; | ||
55 | } | ||
56 | |||
57 | static int adc_counter; | ||
58 | |||
59 | static void adc_tick(void) | ||
60 | { | ||
61 | if (++adc_counter == HZ) | ||
62 | { | ||
63 | adc_counter = 0; | ||
64 | adc_scan(ADC_BATTERY); | ||
65 | } | ||
66 | } | ||
67 | 56 | ||
68 | void adc_init(void) | 57 | return (unsigned short)data; |
69 | { | ||
70 | adc_scan(ADC_BATTERY); | ||
71 | tick_add_task(adc_tick); | ||
72 | } | 58 | } |
diff --git a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c index 3443d1e567..59140667ef 100644 --- a/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c +++ b/firmware/target/coldfire/iaudio/x5/pcf50606-x5.c | |||
@@ -128,8 +128,8 @@ void GPI0(void) | |||
128 | if (data[2] & 0x06) | 128 | if (data[2] & 0x06) |
129 | { | 129 | { |
130 | /* ACDINS/ACDREM */ | 130 | /* ACDINS/ACDREM */ |
131 | /* Check if adc_scan should actually scan main buttons or not - | 131 | /* Check if main buttons should be actually be scanned or not |
132 | bias towards "yes" out of paranoia. */ | 132 | - bias towards "yes" out of paranoia. */ |
133 | button_enable_scan((data[2] & 0x02) != 0 || | 133 | button_enable_scan((data[2] & 0x02) != 0 || |
134 | (pcf50606_read(0x33) & 0x01) != 0); | 134 | (pcf50606_read(0x33) & 0x01) != 0); |
135 | } | 135 | } |
diff --git a/flash/bootbox/main.c b/flash/bootbox/main.c index 4f5efdd7c6..af822b4a64 100644 --- a/flash/bootbox/main.c +++ b/flash/bootbox/main.c | |||
@@ -99,21 +99,16 @@ void charging_screen(void) | |||
99 | lcd_puts(0, 0, msg); | 99 | lcd_puts(0, 0, msg); |
100 | { | 100 | { |
101 | char buf[32]; | 101 | char buf[32]; |
102 | int battery_voltage; | 102 | int battv = battery_voltage(); |
103 | int batt_int, batt_frac; | ||
104 | battery_voltage = (adc_read(ADC_UNREG_POWER) * BATTERY_SCALE_FACTOR) / 10000; | ||
105 | batt_int = battery_voltage / 100; | ||
106 | batt_frac = battery_voltage % 100; | ||
107 | |||
108 | snprintf(buf, sizeof(buf), "%d.%02dV %d%%", | 103 | snprintf(buf, sizeof(buf), "%d.%02dV %d%%", |
109 | batt_int, batt_frac, battery_level()); | 104 | battv / 100, battv % 100, battery_level()); |
110 | lcd_puts(0, 1, buf); | 105 | lcd_puts(0, 1, buf); |
111 | } | 106 | } |
112 | 107 | ||
113 | #ifdef HAVE_LCD_BITMAP | 108 | #ifdef HAVE_LCD_BITMAP |
114 | lcd_update(); | 109 | lcd_update(); |
115 | #endif | 110 | #endif |
116 | 111 | ||
117 | button = button_get_w_tmo(HZ/2); | 112 | button = button_get_w_tmo(HZ/2); |
118 | #ifdef BUTTON_ON | 113 | #ifdef BUTTON_ON |
119 | if (button == (BUTTON_ON | BUTTON_REL)) | 114 | if (button == (BUTTON_ON | BUTTON_REL)) |
@@ -144,7 +139,7 @@ void prompt_usb(const char* msg1, const char* msg2) | |||
144 | lcd_puts(0, 3, "and fix it."); | 139 | lcd_puts(0, 3, "and fix it."); |
145 | lcd_update(); | 140 | lcd_update(); |
146 | #endif | 141 | #endif |
147 | do | 142 | do |
148 | { | 143 | { |
149 | button = button_get(true); | 144 | button = button_get(true); |
150 | if (button == SYS_POWEROFF) | 145 | if (button == SYS_POWEROFF) |
@@ -215,7 +210,7 @@ void main(void) | |||
215 | } | 210 | } |
216 | 211 | ||
217 | { // rolo the firmware | 212 | { // rolo the firmware |
218 | static const char filename[] = "/" BOOTFILE; | 213 | static const char filename[] = "/" BOOTFILE; |
219 | rolo_load((char*)filename); /* won't return if started */ | 214 | rolo_load((char*)filename); /* won't return if started */ |
220 | 215 | ||
221 | prompt_usb("No firmware", filename); | 216 | prompt_usb("No firmware", filename); |