diff options
41 files changed, 283 insertions, 402 deletions
diff --git a/apps/lang/english.lang b/apps/lang/english.lang index 4a8d81dfbc..60e36db79f 100644 --- a/apps/lang/english.lang +++ b/apps/lang/english.lang | |||
@@ -8321,7 +8321,7 @@ | |||
8321 | </phrase> | 8321 | </phrase> |
8322 | <phrase> | 8322 | <phrase> |
8323 | id: LANG_USB_CHARGING | 8323 | id: LANG_USB_CHARGING |
8324 | desc: in Battery menu | 8324 | desc: in Battery menu, TODO: cleanup unless HAVE_USB_CHARGING_ENABLE defined |
8325 | user: | 8325 | user: |
8326 | <source> | 8326 | <source> |
8327 | *: none | 8327 | *: none |
diff --git a/apps/menus/settings_menu.c b/apps/menus/settings_menu.c index 6bb032d169..d05726ea44 100644 --- a/apps/menus/settings_menu.c +++ b/apps/menus/settings_menu.c | |||
@@ -144,8 +144,7 @@ MENUITEM_SETTING(battery_capacity, &global_settings.battery_capacity, NULL); | |||
144 | #if BATTERY_TYPES_COUNT > 1 | 144 | #if BATTERY_TYPES_COUNT > 1 |
145 | MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL); | 145 | MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL); |
146 | #endif | 146 | #endif |
147 | #ifdef HAVE_USB_POWER | 147 | #ifdef HAVE_USB_CHARGING_ENABLE |
148 | #if CONFIG_CHARGING | ||
149 | static int usbcharging_callback(int action,const struct menu_item_ex *this_item) | 148 | static int usbcharging_callback(int action,const struct menu_item_ex *this_item) |
150 | { | 149 | { |
151 | (void)this_item; | 150 | (void)this_item; |
@@ -158,8 +157,7 @@ static int usbcharging_callback(int action,const struct menu_item_ex *this_item) | |||
158 | return action; | 157 | return action; |
159 | } | 158 | } |
160 | MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback); | 159 | MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback); |
161 | #endif | 160 | #endif /* HAVE_USB_CHARGING_ENABLE */ |
162 | #endif | ||
163 | MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON, | 161 | MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON, |
164 | #if BATTERY_CAPACITY_INC > 0 | 162 | #if BATTERY_CAPACITY_INC > 0 |
165 | &battery_capacity, | 163 | &battery_capacity, |
@@ -167,11 +165,9 @@ MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON, | |||
167 | #if BATTERY_TYPES_COUNT > 1 | 165 | #if BATTERY_TYPES_COUNT > 1 |
168 | &battery_type, | 166 | &battery_type, |
169 | #endif | 167 | #endif |
170 | #ifdef HAVE_USB_POWER | 168 | #ifdef HAVE_USB_CHARGING_ENABLE |
171 | #if CONFIG_CHARGING | ||
172 | &usb_charging, | 169 | &usb_charging, |
173 | #endif | 170 | #endif |
174 | #endif | ||
175 | ); | 171 | ); |
176 | /* Disk */ | 172 | /* Disk */ |
177 | #ifdef HAVE_DISK_STORAGE | 173 | #ifdef HAVE_DISK_STORAGE |
diff --git a/apps/plugin.h b/apps/plugin.h index 464614dcf9..99a76ad399 100644 --- a/apps/plugin.h +++ b/apps/plugin.h | |||
@@ -131,12 +131,12 @@ void* plugin_get_buffer(size_t *buffer_size); | |||
131 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ | 131 | #define PLUGIN_MAGIC 0x526F634B /* RocK */ |
132 | 132 | ||
133 | /* increase this every time the api struct changes */ | 133 | /* increase this every time the api struct changes */ |
134 | #define PLUGIN_API_VERSION 126 | 134 | #define PLUGIN_API_VERSION 127 |
135 | 135 | ||
136 | /* update this to latest version if a change to the api struct breaks | 136 | /* update this to latest version if a change to the api struct breaks |
137 | backwards compatibility (and please take the opportunity to sort in any | 137 | backwards compatibility (and please take the opportunity to sort in any |
138 | new function which are "waiting" at the end of the function table) */ | 138 | new function which are "waiting" at the end of the function table) */ |
139 | #define PLUGIN_MIN_API_VERSION 125 | 139 | #define PLUGIN_MIN_API_VERSION 127 |
140 | 140 | ||
141 | /* plugin return codes */ | 141 | /* plugin return codes */ |
142 | enum plugin_status { | 142 | enum plugin_status { |
diff --git a/apps/screens.c b/apps/screens.c index 2bd7775569..6d16982dc4 100644 --- a/apps/screens.c +++ b/apps/screens.c | |||
@@ -906,11 +906,7 @@ bool view_runtime(void) | |||
906 | while(1) | 906 | while(1) |
907 | { | 907 | { |
908 | #if CONFIG_CHARGING | 908 | #if CONFIG_CHARGING |
909 | if (charger_inserted() | 909 | if (charger_inserted()) |
910 | #ifdef HAVE_USB_POWER | ||
911 | || usb_powered() | ||
912 | #endif | ||
913 | ) | ||
914 | { | 910 | { |
915 | global_status.runtime = 0; | 911 | global_status.runtime = 0; |
916 | } | 912 | } |
diff --git a/apps/settings.c b/apps/settings.c index 609cb3f93f..f8c9acd151 100644 --- a/apps/settings.c +++ b/apps/settings.c | |||
@@ -717,11 +717,9 @@ void sound_settings_apply(void) | |||
717 | sound_set(SOUND_TREBLE_CUTOFF, global_settings.treble_cutoff); | 717 | sound_set(SOUND_TREBLE_CUTOFF, global_settings.treble_cutoff); |
718 | #endif | 718 | #endif |
719 | 719 | ||
720 | #ifdef HAVE_USB_POWER | 720 | #ifdef HAVE_USB_CHARGING_ENABLE |
721 | #if CONFIG_CHARGING | ||
722 | usb_charging_enable(global_settings.usb_charging); | 721 | usb_charging_enable(global_settings.usb_charging); |
723 | #endif | 722 | #endif |
724 | #endif | ||
725 | } | 723 | } |
726 | 724 | ||
727 | void settings_apply(bool read_disk) | 725 | void settings_apply(bool read_disk) |
diff --git a/apps/settings.h b/apps/settings.h index be83689368..f79fb9d09e 100644 --- a/apps/settings.h +++ b/apps/settings.h | |||
@@ -684,11 +684,9 @@ struct user_settings | |||
684 | unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */ | 684 | unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */ |
685 | #endif | 685 | #endif |
686 | 686 | ||
687 | #ifdef HAVE_USB_POWER | 687 | #ifdef HAVE_USB_CHARGING_ENABLE |
688 | #if CONFIG_CHARGING | ||
689 | bool usb_charging; | 688 | bool usb_charging; |
690 | #endif | 689 | #endif |
691 | #endif | ||
692 | 690 | ||
693 | bool hold_lr_for_scroll_in_list; /* hold L/R scrolls the list left/right */ | 691 | bool hold_lr_for_scroll_in_list; /* hold L/R scrolls the list left/right */ |
694 | #ifdef HAVE_LCD_BITMAP | 692 | #ifdef HAVE_LCD_BITMAP |
diff --git a/apps/settings_list.c b/apps/settings_list.c index fe379ca229..2678fe0861 100644 --- a/apps/settings_list.c +++ b/apps/settings_list.c | |||
@@ -1310,11 +1310,9 @@ const struct settings_list settings[] = { | |||
1310 | #ifdef HAVE_LCD_BITMAP | 1310 | #ifdef HAVE_LCD_BITMAP |
1311 | TEXT_SETTING(0,kbd_file,"kbd","",ROCKBOX_DIR "/",".kbd"), | 1311 | TEXT_SETTING(0,kbd_file,"kbd","",ROCKBOX_DIR "/",".kbd"), |
1312 | #endif | 1312 | #endif |
1313 | #ifdef HAVE_USB_POWER | 1313 | #ifdef HAVE_USB_CHARGING_ENABLE |
1314 | #if CONFIG_CHARGING | ||
1315 | OFFON_SETTING(0,usb_charging,LANG_USB_CHARGING,false,"usb charging",NULL), | 1314 | OFFON_SETTING(0,usb_charging,LANG_USB_CHARGING,false,"usb charging",NULL), |
1316 | #endif | 1315 | #endif |
1317 | #endif | ||
1318 | OFFON_SETTING(F_BANFROMQS,cuesheet,LANG_CUESHEET_ENABLE,false,"cuesheet support", | 1316 | OFFON_SETTING(F_BANFROMQS,cuesheet,LANG_CUESHEET_ENABLE,false,"cuesheet support", |
1319 | NULL), | 1317 | NULL), |
1320 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, skip_length, | 1318 | TABLE_SETTING(F_ALLOW_ARBITRARY_VALS, skip_length, |
diff --git a/firmware/backlight.c b/firmware/backlight.c index 1208973944..07cc9532be 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c | |||
@@ -488,11 +488,7 @@ static void backlight_update_state(void) | |||
488 | else | 488 | else |
489 | #endif | 489 | #endif |
490 | #if CONFIG_CHARGING | 490 | #if CONFIG_CHARGING |
491 | if (charger_inserted() | 491 | if (power_input_present()) |
492 | #ifdef HAVE_USB_POWER | ||
493 | || usb_powered() | ||
494 | #endif | ||
495 | ) | ||
496 | backlight_timeout = backlight_timeout_plugged; | 492 | backlight_timeout = backlight_timeout_plugged; |
497 | else | 493 | else |
498 | #endif | 494 | #endif |
@@ -532,11 +528,7 @@ static void remote_backlight_update_state(void) | |||
532 | else | 528 | else |
533 | #endif | 529 | #endif |
534 | #if CONFIG_CHARGING | 530 | #if CONFIG_CHARGING |
535 | if (charger_inserted() | 531 | if (power_input_present()) |
536 | #ifdef HAVE_USB_POWER | ||
537 | || usb_powered() | ||
538 | #endif | ||
539 | ) | ||
540 | remote_backlight_timeout = remote_backlight_timeout_plugged; | 532 | remote_backlight_timeout = remote_backlight_timeout_plugged; |
541 | else | 533 | else |
542 | #endif | 534 | #endif |
diff --git a/firmware/export/config-gigabeat-s.h b/firmware/export/config-gigabeat-s.h index 8ddca5ca6d..f0e9e92a04 100644 --- a/firmware/export/config-gigabeat-s.h +++ b/firmware/export/config-gigabeat-s.h | |||
@@ -134,6 +134,11 @@ | |||
134 | 134 | ||
135 | /* define this if the unit can be powered or charged via USB */ | 135 | /* define this if the unit can be powered or charged via USB */ |
136 | //#define HAVE_USB_POWER /* Disable for now */ | 136 | //#define HAVE_USB_POWER /* Disable for now */ |
137 | //#define HAVE_USB_CHARGING_ENABLE | ||
138 | |||
139 | /* define this if the unit has a battery switch or battery can be removed | ||
140 | * when running */ | ||
141 | #define HAVE_BATTERY_SWITCH | ||
137 | 142 | ||
138 | /* USB On-the-go */ | 143 | /* USB On-the-go */ |
139 | #define CONFIG_USBOTG USBOTG_ARC | 144 | #define CONFIG_USBOTG USBOTG_ARC |
diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h index 0c5462400b..313bdadcdd 100644 --- a/firmware/export/config-gigabeat.h +++ b/firmware/export/config-gigabeat.h | |||
@@ -114,6 +114,10 @@ | |||
114 | /* define this if the unit can be powered or charged via USB */ | 114 | /* define this if the unit can be powered or charged via USB */ |
115 | #define HAVE_USB_POWER | 115 | #define HAVE_USB_POWER |
116 | 116 | ||
117 | /* define this if the unit has a battery switch or battery can be removed | ||
118 | * when running */ | ||
119 | #define HAVE_BATTERY_SWITCH | ||
120 | |||
117 | #ifndef SIMULATOR | 121 | #ifndef SIMULATOR |
118 | 122 | ||
119 | /* The LCD on a Gigabeat is 240x320 - it is portrait */ | 123 | /* The LCD on a Gigabeat is 240x320 - it is portrait */ |
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h index 680ca91245..fa0046ac03 100644 --- a/firmware/export/config-h300.h +++ b/firmware/export/config-h300.h | |||
@@ -112,6 +112,10 @@ | |||
112 | /* define this if the unit can be powered or charged via USB */ | 112 | /* define this if the unit can be powered or charged via USB */ |
113 | #define HAVE_USB_POWER | 113 | #define HAVE_USB_POWER |
114 | 114 | ||
115 | /* define this if the unit can have USB charging disabled by user - | ||
116 | * if USB/MAIN power is discernable and hardware doesn't compel charging */ | ||
117 | #define HAVE_USB_CHARGING_ENABLE | ||
118 | |||
115 | #ifndef SIMULATOR | 119 | #ifndef SIMULATOR |
116 | 120 | ||
117 | /* define this if the backlight thread is used for fade, not for sim, needs | 121 | /* define this if the backlight thread is used for fade, not for sim, needs |
diff --git a/firmware/export/power.h b/firmware/export/power.h index f74e6fe0c2..747887921d 100644 --- a/firmware/export/power.h +++ b/firmware/export/power.h | |||
@@ -27,8 +27,57 @@ void charger_enable(bool on); | |||
27 | #endif | 27 | #endif |
28 | 28 | ||
29 | #if CONFIG_CHARGING | 29 | #if CONFIG_CHARGING |
30 | bool charger_inserted(void); | 30 | enum power_input_flags { |
31 | /* No external power source? Default. */ | ||
32 | POWER_INPUT_NONE = 0x00, | ||
33 | |||
34 | /* Main power source is available (AC?), the default other than | ||
35 | * battery if for instance USB and others cannot be distinguished or | ||
36 | * USB is the only possibility. */ | ||
37 | POWER_INPUT_MAIN = 0x01, | ||
38 | |||
39 | /* USB power source is available (and is discernable from MAIN). */ | ||
40 | POWER_INPUT_USB = 0x02, | ||
41 | |||
42 | /* Something is plugged. */ | ||
43 | POWER_INPUT = 0x0f, | ||
44 | |||
45 | /* POWER_INPUT_*_CHARGER of course implies presence of the respective | ||
46 | * power source. */ | ||
47 | |||
48 | /* Battery not included in CHARGER (it can't charge itself) */ | ||
49 | |||
50 | /* Charging is possible on main. */ | ||
51 | POWER_INPUT_MAIN_CHARGER = 0x10 | POWER_INPUT_MAIN, | ||
52 | |||
53 | /* Charging is possible on USB. */ | ||
54 | POWER_INPUT_USB_CHARGER = 0x20 | POWER_INPUT_USB, | ||
55 | |||
56 | /* Charging is possible from something. */ | ||
57 | POWER_INPUT_CHARGER = 0xf0, | ||
58 | |||
59 | #ifdef HAVE_BATTERY_SWITCH | ||
60 | /* Battery is powering device or is available to power device. It | ||
61 | * could also be used if the battery is hot-swappable to indicate if | ||
62 | * it is present ("switch" as verb vs. noun). */ | ||
63 | POWER_INPUT_BATTERY = 0x100, | ||
31 | #endif | 64 | #endif |
65 | }; | ||
66 | |||
67 | /* Returns detailed power input status information from device. */ | ||
68 | unsigned int power_input_status(void); | ||
69 | |||
70 | /* Shortcuts */ | ||
71 | /* Returns true if any power source that is connected is capable of | ||
72 | * charging the batteries. | ||
73 | * > (power_input_status() & POWER_INPUT_CHARGER) != 0 */ | ||
74 | bool charger_inserted(void); | ||
75 | |||
76 | /* Returns true if any power input is connected - charging-capable | ||
77 | * or not. | ||
78 | * > (power_input_status() & POWER_INPUT) != 0 */ | ||
79 | bool power_input_present(void); | ||
80 | #endif /* CONFIG_CHARGING */ | ||
32 | 81 | ||
33 | void power_off(void); | 82 | void power_off(void); |
34 | void ide_power_enable(bool on); | 83 | void ide_power_enable(bool on); |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 6f0c37b3c7..899e103d59 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -935,6 +935,23 @@ static inline void charging_algorithm_close(void) | |||
935 | } | 935 | } |
936 | #endif /* CONFIG_CHARGING == CHARGING_CONTROL */ | 936 | #endif /* CONFIG_CHARGING == CHARGING_CONTROL */ |
937 | 937 | ||
938 | #if CONFIG_CHARGING | ||
939 | /* Shortcut function calls - compatibility, simplicity. */ | ||
940 | |||
941 | /* Returns true if any power input is capable of charging. */ | ||
942 | bool charger_inserted(void) | ||
943 | { | ||
944 | return power_input_status() & POWER_INPUT_CHARGER; | ||
945 | } | ||
946 | |||
947 | /* Returns true if any power input is connected - charging-capable | ||
948 | * or not. */ | ||
949 | bool power_input_present(void) | ||
950 | { | ||
951 | return power_input_status() & POWER_INPUT; | ||
952 | } | ||
953 | #endif /* CONFIG_CHARGING */ | ||
954 | |||
938 | /* | 955 | /* |
939 | * This function is called to do the relativly long sleep waits from within the | 956 | * This function is called to do the relativly long sleep waits from within the |
940 | * main power_thread loop while at the same time servicing any other periodic | 957 | * main power_thread loop while at the same time servicing any other periodic |
@@ -957,12 +974,7 @@ static void power_thread_sleep(int ticks) | |||
957 | * loop (including the subroutines), and end up back here where we | 974 | * loop (including the subroutines), and end up back here where we |
958 | * transition to the appropriate steady state charger on/off state. | 975 | * transition to the appropriate steady state charger on/off state. |
959 | */ | 976 | */ |
960 | if(charger_inserted() | 977 | if(power_input_status() & POWER_INPUT_CHARGER) { |
961 | #ifdef HAVE_USB_POWER /* USB powered or USB inserted both provide power */ | ||
962 | || usb_powered() | ||
963 | || (usb_inserted() && usb_charging_enabled()) | ||
964 | #endif | ||
965 | ) { | ||
966 | switch(charger_input_state) { | 978 | switch(charger_input_state) { |
967 | case NO_CHARGER: | 979 | case NO_CHARGER: |
968 | case CHARGER_UNPLUGGED: | 980 | case CHARGER_UNPLUGGED: |
diff --git a/firmware/target/arm/archos/av300/power-av300.c b/firmware/target/arm/archos/av300/power-av300.c index 5aa757d3e6..013fd04691 100644 --- a/firmware/target/arm/archos/av300/power-av300.c +++ b/firmware/target/arm/archos/av300/power-av300.c | |||
@@ -32,16 +32,14 @@ | |||
32 | #include "system.h" | 32 | #include "system.h" |
33 | #include "power.h" | 33 | #include "power.h" |
34 | 34 | ||
35 | #ifndef SIMULATOR | ||
36 | |||
37 | void power_init(void) | 35 | void power_init(void) |
38 | { | 36 | { |
39 | /* Charger detect */ | 37 | /* Charger detect */ |
40 | } | 38 | } |
41 | 39 | ||
42 | bool charger_inserted(void) | 40 | unsigned int power_input_status(void) |
43 | { | 41 | { |
44 | return false; | 42 | return POWER_INPUT_NONE; |
45 | } | 43 | } |
46 | 44 | ||
47 | void ide_power_enable(bool on) | 45 | void ide_power_enable(bool on) |
@@ -61,29 +59,6 @@ void power_off(void) | |||
61 | { | 59 | { |
62 | } | 60 | } |
63 | 61 | ||
64 | #else | ||
65 | |||
66 | bool charger_inserted(void) | ||
67 | { | ||
68 | return false; | ||
69 | } | ||
70 | |||
71 | void charger_enable(bool on) | ||
72 | { | ||
73 | (void)on; | ||
74 | } | ||
75 | |||
76 | void power_off(void) | ||
77 | { | ||
78 | } | ||
79 | |||
80 | void ide_power_enable(bool on) | ||
81 | { | ||
82 | (void)on; | ||
83 | } | ||
84 | |||
85 | #endif /* SIMULATOR */ | ||
86 | |||
87 | bool tuner_power(bool status) | 62 | bool tuner_power(bool status) |
88 | { | 63 | { |
89 | (void)status; | 64 | (void)status; |
diff --git a/firmware/target/arm/as3525/power-as3525.c b/firmware/target/arm/as3525/power-as3525.c index a61cb59c12..07867546c2 100644 --- a/firmware/target/arm/as3525/power-as3525.c +++ b/firmware/target/arm/as3525/power-as3525.c | |||
@@ -18,7 +18,6 @@ | |||
18 | * KIND, either express or implied. | 18 | * KIND, either express or implied. |
19 | * | 19 | * |
20 | ****************************************************************************/ | 20 | ****************************************************************************/ |
21 | |||
22 | #include <stdbool.h> | 21 | #include <stdbool.h> |
23 | #include "config.h" | 22 | #include "config.h" |
24 | #include "ascodec-target.h" | 23 | #include "ascodec-target.h" |
@@ -40,14 +39,14 @@ void power_init(void) | |||
40 | } | 39 | } |
41 | 40 | ||
42 | #if CONFIG_CHARGING | 41 | #if CONFIG_CHARGING |
43 | bool charger_inserted(void) | 42 | unsigned int power_input_status(void) |
44 | { | 43 | { |
45 | if(ascodec_read(AS3514_IRQ_ENRD0) & (1<<5)) | 44 | return (ascodec_read(AS3514_IRQ_ENRD0) & (1<<5)) ? |
46 | return true; | 45 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; |
47 | else | 46 | |
48 | return false; | 47 | /* TODO: Handle USB and other sources properly */ |
49 | } | 48 | } |
50 | #endif | 49 | #endif /* CONFIG_CHARGING */ |
51 | 50 | ||
52 | void ide_power_enable(bool on) | 51 | void ide_power_enable(bool on) |
53 | { | 52 | { |
diff --git a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c index 9d9cc6bcb6..62f9982dd5 100644 --- a/firmware/target/arm/imx31/gigabeat-s/power-imx31.c +++ b/firmware/target/arm/imx31/gigabeat-s/power-imx31.c | |||
@@ -27,8 +27,6 @@ | |||
27 | #include "avic-imx31.h" | 27 | #include "avic-imx31.h" |
28 | #include "mc13783.h" | 28 | #include "mc13783.h" |
29 | 29 | ||
30 | #ifndef SIMULATOR | ||
31 | |||
32 | static bool charger_detect = false; | 30 | static bool charger_detect = false; |
33 | 31 | ||
34 | /* This is called from the mc13783 interrupt thread */ | 32 | /* This is called from the mc13783 interrupt thread */ |
@@ -38,9 +36,17 @@ void charger_detect_event(void) | |||
38 | mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_CHGDETS; | 36 | mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_CHGDETS; |
39 | } | 37 | } |
40 | 38 | ||
41 | bool charger_inserted(void) | 39 | unsigned int power_input_status(void) |
42 | { | 40 | { |
43 | return charger_detect; | 41 | unsigned int status = POWER_INPUT_NONE; |
42 | |||
43 | if ((GPIO3_DR & (1 << 20)) != 0) | ||
44 | status |= POWER_INPUT_BATTERY; | ||
45 | |||
46 | if (charger_detect) | ||
47 | status |= POWER_INPUT_MAIN_CHARGER; | ||
48 | |||
49 | return status; | ||
44 | } | 50 | } |
45 | 51 | ||
46 | /* Returns true if the unit is charging the batteries. */ | 52 | /* Returns true if the unit is charging the batteries. */ |
@@ -90,26 +96,3 @@ void power_init(void) | |||
90 | mc13783_enable_event(MC13783_CHGDET_EVENT); | 96 | mc13783_enable_event(MC13783_CHGDET_EVENT); |
91 | } | 97 | } |
92 | 98 | ||
93 | #else /* SIMULATOR */ | ||
94 | |||
95 | bool charger_inserted(void) | ||
96 | { | ||
97 | return false; | ||
98 | } | ||
99 | |||
100 | void charger_enable(bool on) | ||
101 | { | ||
102 | (void)on; | ||
103 | } | ||
104 | |||
105 | void power_off(void) | ||
106 | { | ||
107 | } | ||
108 | |||
109 | void ide_power_enable(bool on) | ||
110 | { | ||
111 | (void)on; | ||
112 | } | ||
113 | |||
114 | #endif /* SIMULATOR */ | ||
115 | |||
diff --git a/firmware/target/arm/ipod/power-ipod.c b/firmware/target/arm/ipod/power-ipod.c index af1ac9fc87..cb93fe398f 100644 --- a/firmware/target/arm/ipod/power-ipod.c +++ b/firmware/target/arm/ipod/power-ipod.c | |||
@@ -43,18 +43,28 @@ void power_init(void) | |||
43 | } | 43 | } |
44 | 44 | ||
45 | #if CONFIG_CHARGING | 45 | #if CONFIG_CHARGING |
46 | bool charger_inserted(void) | 46 | unsigned int power_input_status(void) |
47 | { | 47 | { |
48 | #if defined(IPOD_VIDEO) | 48 | unsigned int status = POWER_INPUT_NONE; |
49 | return (GPIOL_INPUT_VAL & 0x08)?false:true; | 49 | |
50 | #if defined(IPOD_NANO) || defined(IPOD_VIDEO) | ||
51 | if ((GPIOL_INPUT_VAL & 0x08) == 0) | ||
52 | status = POWER_INPUT_MAIN_CHARGER; | ||
53 | |||
54 | if ((GPIOL_INPUT_VAL & 0x10) != 0) | ||
55 | status |= POWER_INPUT_USB_CHARGER; | ||
56 | /* */ | ||
50 | #elif defined(IPOD_4G) || defined(IPOD_COLOR) \ | 57 | #elif defined(IPOD_4G) || defined(IPOD_COLOR) \ |
51 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) | 58 | || defined(IPOD_MINI) || defined(IPOD_MINI2G) |
52 | /* C2 is firewire power */ | 59 | /* C2 is firewire power */ |
53 | return (GPIOC_INPUT_VAL & 0x04)?false:true; | 60 | if ((GPIOC_INPUT_VAL & 0x04) == 0) |
61 | status = POWER_INPUT_MAIN_CHARGER; | ||
62 | /* */ | ||
54 | #else | 63 | #else |
55 | /* This needs filling in for other ipods. */ | 64 | /* This needs filling in for other ipods. */ |
56 | return false; | ||
57 | #endif | 65 | #endif |
66 | |||
67 | return status; | ||
58 | } | 68 | } |
59 | 69 | ||
60 | /* Returns true if the unit is charging the batteries. */ | 70 | /* Returns true if the unit is charging the batteries. */ |
diff --git a/firmware/target/arm/iriver/h10/power-h10.c b/firmware/target/arm/iriver/h10/power-h10.c index dd09387889..deca3258e2 100644 --- a/firmware/target/arm/iriver/h10/power-h10.c +++ b/firmware/target/arm/iriver/h10/power-h10.c | |||
@@ -52,9 +52,11 @@ void power_init(void) | |||
52 | { | 52 | { |
53 | } | 53 | } |
54 | 54 | ||
55 | bool charger_inserted(void) | 55 | unsigned int power_input_status(void) |
56 | { | 56 | { |
57 | return (GPIOF_INPUT_VAL & 0x08)?true:false; | 57 | /* No separate source for USB and charges from USB on its own */ |
58 | return (GPIOF_INPUT_VAL & 0x08) ? | ||
59 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
58 | } | 60 | } |
59 | 61 | ||
60 | void ide_power_enable(bool on) | 62 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/olympus/mrobe-100/power-mr100.c b/firmware/target/arm/olympus/mrobe-100/power-mr100.c index 1ff15c57bf..c3eb96b03c 100644 --- a/firmware/target/arm/olympus/mrobe-100/power-mr100.c +++ b/firmware/target/arm/olympus/mrobe-100/power-mr100.c | |||
@@ -41,9 +41,10 @@ void power_init(void) | |||
41 | GPIOB_OUTPUT_EN |= 0x80; | 41 | GPIOB_OUTPUT_EN |= 0x80; |
42 | } | 42 | } |
43 | 43 | ||
44 | bool charger_inserted(void) | 44 | unsigned int power_input_status(void) |
45 | { | 45 | { |
46 | return (GPIOL_INPUT_VAL & 0x24) ? true : false ; | 46 | return (GPIOL_INPUT_VAL & 0x24) ? |
47 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
47 | } | 48 | } |
48 | 49 | ||
49 | void ide_power_enable(bool on) | 50 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/philips/hdd1630/power-hdd1630.c b/firmware/target/arm/philips/hdd1630/power-hdd1630.c index 91193bae35..ade2536154 100755 --- a/firmware/target/arm/philips/hdd1630/power-hdd1630.c +++ b/firmware/target/arm/philips/hdd1630/power-hdd1630.c | |||
@@ -37,9 +37,9 @@ void power_init(void) | |||
37 | { | 37 | { |
38 | } | 38 | } |
39 | 39 | ||
40 | bool charger_inserted(void) | 40 | unsigned int power_input_status(void) |
41 | { | 41 | { |
42 | return false ; | 42 | return POWER_INPUT_NONE; |
43 | } | 43 | } |
44 | 44 | ||
45 | void ide_power_enable(bool on) | 45 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/philips/sa9200/power-sa9200.c b/firmware/target/arm/philips/sa9200/power-sa9200.c index 44df437577..654beee064 100644 --- a/firmware/target/arm/philips/sa9200/power-sa9200.c +++ b/firmware/target/arm/philips/sa9200/power-sa9200.c | |||
@@ -54,15 +54,9 @@ void power_off(void) | |||
54 | } | 54 | } |
55 | } | 55 | } |
56 | 56 | ||
57 | bool charger_inserted(void) | 57 | unsigned int power_input_status(void) |
58 | { | 58 | { |
59 | #ifdef SANSA_E200 | 59 | return POWER_INPUT_NONE; |
60 | if(GPIOB_INPUT_VAL & 0x10) | ||
61 | #else /* SANSA_C200 */ | ||
62 | if(GPIOH_INPUT_VAL & 0x2) | ||
63 | #endif | ||
64 | return true; | ||
65 | return false; | ||
66 | } | 60 | } |
67 | 61 | ||
68 | void ide_power_enable(bool on) | 62 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c b/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c index c1c0595262..ad9098dd8a 100644 --- a/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c +++ b/firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c | |||
@@ -27,8 +27,7 @@ | |||
27 | #include "pcf50606.h" | 27 | #include "pcf50606.h" |
28 | #include "backlight.h" | 28 | #include "backlight.h" |
29 | #include "backlight-target.h" | 29 | #include "backlight-target.h" |
30 | 30 | #include "usb.h" | |
31 | #ifndef SIMULATOR | ||
32 | 31 | ||
33 | void power_init(void) | 32 | void power_init(void) |
34 | { | 33 | { |
@@ -39,13 +38,28 @@ void power_init(void) | |||
39 | /* Charger detect */ | 38 | /* Charger detect */ |
40 | } | 39 | } |
41 | 40 | ||
42 | bool charger_inserted(void) | 41 | unsigned int power_input_status(void) |
43 | { | 42 | { |
44 | return (GPFDAT & (1 << 4)) ? false : true; | 43 | unsigned int status = POWER_INPUT_NONE; |
44 | |||
45 | /* Is the battery switch ON? */ | ||
46 | if ((GPGDAT & (1 << 9)) == 0) | ||
47 | status |= POWER_INPUT_BATTERY; | ||
48 | |||
49 | /* Main or cradle power available? */ | ||
50 | if ((GPFDAT & (1 << 4)) == 0) | ||
51 | status |= POWER_INPUT_MAIN_CHARGER; | ||
52 | |||
53 | /* Is the USB cable inserted? */ | ||
54 | if (usb_detect() == USB_INSERTED) | ||
55 | status |= POWER_INPUT_USB_CHARGER; | ||
56 | |||
57 | return status; | ||
45 | } | 58 | } |
46 | 59 | ||
47 | /* Returns true if the unit is charging the batteries. */ | 60 | /* Returns true if the unit is charging the batteries. */ |
48 | bool charging_state(void) { | 61 | bool charging_state(void) |
62 | { | ||
49 | return (GPGDAT & (1 << 8)) ? false : true; | 63 | return (GPGDAT & (1 << 8)) ? false : true; |
50 | } | 64 | } |
51 | 65 | ||
@@ -87,27 +101,3 @@ void power_off(void) | |||
87 | 101 | ||
88 | reboot_point(); | 102 | reboot_point(); |
89 | } | 103 | } |
90 | |||
91 | #else /* SIMULATOR */ | ||
92 | |||
93 | bool charger_inserted(void) | ||
94 | { | ||
95 | return false; | ||
96 | } | ||
97 | |||
98 | void charger_enable(bool on) | ||
99 | { | ||
100 | (void)on; | ||
101 | } | ||
102 | |||
103 | void power_off(void) | ||
104 | { | ||
105 | } | ||
106 | |||
107 | void ide_power_enable(bool on) | ||
108 | { | ||
109 | (void)on; | ||
110 | } | ||
111 | |||
112 | #endif /* SIMULATOR */ | ||
113 | |||
diff --git a/firmware/target/arm/sandisk/power-c200_e200.c b/firmware/target/arm/sandisk/power-c200_e200.c index d6319f44bb..cc9d16f466 100644 --- a/firmware/target/arm/sandisk/power-c200_e200.c +++ b/firmware/target/arm/sandisk/power-c200_e200.c | |||
@@ -26,6 +26,7 @@ | |||
26 | #include "tuner.h" | 26 | #include "tuner.h" |
27 | #include "as3514.h" | 27 | #include "as3514.h" |
28 | #include "power.h" | 28 | #include "power.h" |
29 | #include "usb.h" | ||
29 | 30 | ||
30 | void power_init(void) | 31 | void power_init(void) |
31 | { | 32 | { |
@@ -53,15 +54,24 @@ void power_off(void) | |||
53 | } | 54 | } |
54 | } | 55 | } |
55 | 56 | ||
56 | bool charger_inserted(void) | 57 | unsigned int power_input_status(void) |
57 | { | 58 | { |
58 | #ifdef SANSA_E200 | 59 | unsigned int status = POWER_INPUT_NONE; |
59 | if(GPIOB_INPUT_VAL & 0x10) | 60 | |
60 | #else /* SANSA_C200 */ | 61 | #if defined(SANSA_E200) |
61 | if(GPIOH_INPUT_VAL & 0x2) | 62 | #define _charger_present() (GPIOB_INPUT_VAL & 0x10) |
63 | #elif defined(SANSA_C200) | ||
64 | #define _charger_present() (GPIOH_INPUT_VAL & 0x2) | ||
65 | #else | ||
66 | #define _charger_present() 0 | ||
62 | #endif | 67 | #endif |
63 | return true; | 68 | |
64 | return false; | 69 | if (_charger_present()) |
70 | status = POWER_INPUT_MAIN_CHARGER; | ||
71 | |||
72 | /* No separate source for USB */ | ||
73 | |||
74 | return status; | ||
65 | } | 75 | } |
66 | 76 | ||
67 | void ide_power_enable(bool on) | 77 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/tatung/tpj1022/power-tpj1022.c b/firmware/target/arm/tatung/tpj1022/power-tpj1022.c index f16d3c9cc2..abf5790702 100644 --- a/firmware/target/arm/tatung/tpj1022/power-tpj1022.c +++ b/firmware/target/arm/tatung/tpj1022/power-tpj1022.c | |||
@@ -41,9 +41,9 @@ void power_init(void) | |||
41 | { | 41 | { |
42 | } | 42 | } |
43 | 43 | ||
44 | bool charger_inserted(void) | 44 | unsigned int power_input_status(void) |
45 | { | 45 | { |
46 | return false; | 46 | return POWER_INPUT_NONE; |
47 | } | 47 | } |
48 | 48 | ||
49 | void ide_power_enable(bool on) | 49 | void ide_power_enable(bool on) |
diff --git a/firmware/target/arm/tcc77x/c100/power-c100.c b/firmware/target/arm/tcc77x/c100/power-c100.c index 77574ccc87..e84ff1c852 100644 --- a/firmware/target/arm/tcc77x/c100/power-c100.c +++ b/firmware/target/arm/tcc77x/c100/power-c100.c | |||
@@ -25,8 +25,6 @@ | |||
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "power.h" | 26 | #include "power.h" |
27 | 27 | ||
28 | #ifndef SIMULATOR | ||
29 | |||
30 | void power_init(void) | 28 | void power_init(void) |
31 | { | 29 | { |
32 | } | 30 | } |
@@ -43,22 +41,3 @@ bool ide_powered(void) | |||
43 | void power_off(void) | 41 | void power_off(void) |
44 | { | 42 | { |
45 | } | 43 | } |
46 | |||
47 | #else /* SIMULATOR */ | ||
48 | |||
49 | bool charger_inserted(void) | ||
50 | { | ||
51 | return false; | ||
52 | } | ||
53 | |||
54 | void charger_enable(bool on) | ||
55 | { | ||
56 | (void)on; | ||
57 | } | ||
58 | |||
59 | void ide_power_enable(bool on) | ||
60 | { | ||
61 | (void)on; | ||
62 | } | ||
63 | |||
64 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c index ce7175ef55..0501ba272c 100644 --- a/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c +++ b/firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c | |||
@@ -141,7 +141,8 @@ bool tuner_power(bool status) | |||
141 | 141 | ||
142 | #endif /* CONFIG_TUNER */ | 142 | #endif /* CONFIG_TUNER */ |
143 | 143 | ||
144 | bool charger_inserted(void) | 144 | unsigned int power_input_status(void) |
145 | { | 145 | { |
146 | return (GPIOA & 0x1) ? true : false; | 146 | return (GPIOA & 0x1) ? |
147 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
147 | } | 148 | } |
diff --git a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c index 82eb8dce02..e84ff1c852 100644 --- a/firmware/target/arm/tcc77x/logikdax/power-logikdax.c +++ b/firmware/target/arm/tcc77x/logikdax/power-logikdax.c | |||
@@ -25,8 +25,6 @@ | |||
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "power.h" | 26 | #include "power.h" |
27 | 27 | ||
28 | #ifndef SIMULATOR | ||
29 | |||
30 | void power_init(void) | 28 | void power_init(void) |
31 | { | 29 | { |
32 | } | 30 | } |
@@ -43,26 +41,3 @@ bool ide_powered(void) | |||
43 | void power_off(void) | 41 | void power_off(void) |
44 | { | 42 | { |
45 | } | 43 | } |
46 | |||
47 | #else /* SIMULATOR */ | ||
48 | |||
49 | bool charger_inserted(void) | ||
50 | { | ||
51 | return false; | ||
52 | } | ||
53 | |||
54 | void charger_enable(bool on) | ||
55 | { | ||
56 | (void)on; | ||
57 | } | ||
58 | |||
59 | void power_off(void) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | void ide_power_enable(bool on) | ||
64 | { | ||
65 | (void)on; | ||
66 | } | ||
67 | |||
68 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/arm/tcc77x/m200/power-m200.c b/firmware/target/arm/tcc77x/m200/power-m200.c index 82eb8dce02..e84ff1c852 100644 --- a/firmware/target/arm/tcc77x/m200/power-m200.c +++ b/firmware/target/arm/tcc77x/m200/power-m200.c | |||
@@ -25,8 +25,6 @@ | |||
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "power.h" | 26 | #include "power.h" |
27 | 27 | ||
28 | #ifndef SIMULATOR | ||
29 | |||
30 | void power_init(void) | 28 | void power_init(void) |
31 | { | 29 | { |
32 | } | 30 | } |
@@ -43,26 +41,3 @@ bool ide_powered(void) | |||
43 | void power_off(void) | 41 | void power_off(void) |
44 | { | 42 | { |
45 | } | 43 | } |
46 | |||
47 | #else /* SIMULATOR */ | ||
48 | |||
49 | bool charger_inserted(void) | ||
50 | { | ||
51 | return false; | ||
52 | } | ||
53 | |||
54 | void charger_enable(bool on) | ||
55 | { | ||
56 | (void)on; | ||
57 | } | ||
58 | |||
59 | void power_off(void) | ||
60 | { | ||
61 | } | ||
62 | |||
63 | void ide_power_enable(bool on) | ||
64 | { | ||
65 | (void)on; | ||
66 | } | ||
67 | |||
68 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c index 9eb0871c6e..d3f6a1ce16 100644 --- a/firmware/target/arm/tcc780x/cowond2/power-cowond2.c +++ b/firmware/target/arm/tcc780x/cowond2/power-cowond2.c | |||
@@ -26,8 +26,6 @@ | |||
26 | #include "button-target.h" | 26 | #include "button-target.h" |
27 | #include "tuner.h" | 27 | #include "tuner.h" |
28 | 28 | ||
29 | #ifndef SIMULATOR | ||
30 | |||
31 | void power_init(void) | 29 | void power_init(void) |
32 | { | 30 | { |
33 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ | 31 | unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */ |
@@ -93,9 +91,10 @@ void EXT3(void) | |||
93 | #endif | 91 | #endif |
94 | 92 | ||
95 | #if CONFIG_CHARGING | 93 | #if CONFIG_CHARGING |
96 | bool charger_inserted(void) | 94 | unsigned int power_input_status(void) |
97 | { | 95 | { |
98 | return (GPIOC & (1<<26)) ? false:true; | 96 | return ((GPIOC & (1<<26)) == 0) ? |
97 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
99 | } | 98 | } |
100 | #endif | 99 | #endif |
101 | 100 | ||
@@ -147,26 +146,3 @@ bool tuner_power(bool status) | |||
147 | } | 146 | } |
148 | 147 | ||
149 | #endif /* CONFIG_TUNER */ | 148 | #endif /* CONFIG_TUNER */ |
150 | |||
151 | #else /* SIMULATOR */ | ||
152 | |||
153 | bool charger_inserted(void) | ||
154 | { | ||
155 | return false; | ||
156 | } | ||
157 | |||
158 | void charger_enable(bool on) | ||
159 | { | ||
160 | (void)on; | ||
161 | } | ||
162 | |||
163 | void power_off(void) | ||
164 | { | ||
165 | } | ||
166 | |||
167 | void ide_power_enable(bool on) | ||
168 | { | ||
169 | (void)on; | ||
170 | } | ||
171 | |||
172 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c index a76e827bec..9c0f9c3cb7 100644 --- a/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c +++ b/firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c | |||
@@ -28,8 +28,6 @@ | |||
28 | #include "backlight.h" | 28 | #include "backlight.h" |
29 | #include "backlight-target.h" | 29 | #include "backlight-target.h" |
30 | 30 | ||
31 | #ifndef SIMULATOR | ||
32 | |||
33 | void power_init(void) | 31 | void power_init(void) |
34 | { | 32 | { |
35 | /* Initialize IDE power pin */ | 33 | /* Initialize IDE power pin */ |
@@ -37,34 +35,17 @@ void power_init(void) | |||
37 | /* Charger detect */ | 35 | /* Charger detect */ |
38 | } | 36 | } |
39 | 37 | ||
40 | bool charger_inserted(void) | 38 | unsigned int power_input_status(void) |
41 | { | 39 | { |
42 | return false; | 40 | return POWER_INPUT_NONE; |
43 | } | 41 | } |
44 | 42 | ||
45 | /* Returns true if the unit is charging the batteries. */ | 43 | /* Returns true if the unit is charging the batteries. */ |
46 | bool charging_state(void) { | 44 | bool charging_state(void) |
47 | return false; | ||
48 | } | ||
49 | |||
50 | void power_off(void) | ||
51 | { | ||
52 | } | ||
53 | |||
54 | #else /* SIMULATOR */ | ||
55 | |||
56 | bool charger_inserted(void) | ||
57 | { | 45 | { |
58 | return false; | 46 | return false; |
59 | } | 47 | } |
60 | 48 | ||
61 | void charger_enable(bool on) | ||
62 | { | ||
63 | (void)on; | ||
64 | } | ||
65 | |||
66 | void power_off(void) | 49 | void power_off(void) |
67 | { | 50 | { |
68 | } | 51 | } |
69 | |||
70 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c b/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c index 7f4a3b31de..8e8531e4ff 100644 --- a/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c +++ b/firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c | |||
@@ -29,8 +29,6 @@ | |||
29 | #include "backlight.h" | 29 | #include "backlight.h" |
30 | #include "backlight-target.h" | 30 | #include "backlight-target.h" |
31 | 31 | ||
32 | #ifndef SIMULATOR | ||
33 | |||
34 | void power_init(void) | 32 | void power_init(void) |
35 | { | 33 | { |
36 | /* Initialize IDE power pin */ | 34 | /* Initialize IDE power pin */ |
@@ -40,9 +38,9 @@ void power_init(void) | |||
40 | /* Charger detect */ | 38 | /* Charger detect */ |
41 | } | 39 | } |
42 | 40 | ||
43 | bool charger_inserted(void) | 41 | unsigned int power_input_status(void) |
44 | { | 42 | { |
45 | return false; | 43 | return POWER_INPUT_NONE; |
46 | } | 44 | } |
47 | 45 | ||
48 | /* Returns true if the unit is charging the batteries. */ | 46 | /* Returns true if the unit is charging the batteries. */ |
@@ -71,27 +69,3 @@ void power_off(void) | |||
71 | /* Hard shutdown */ | 69 | /* Hard shutdown */ |
72 | IO_GIO_BITSET1|=1<<10; | 70 | IO_GIO_BITSET1|=1<<10; |
73 | } | 71 | } |
74 | |||
75 | #else /* SIMULATOR */ | ||
76 | |||
77 | bool charger_inserted(void) | ||
78 | { | ||
79 | return false; | ||
80 | } | ||
81 | |||
82 | void charger_enable(bool on) | ||
83 | { | ||
84 | (void)on; | ||
85 | } | ||
86 | |||
87 | void power_off(void) | ||
88 | { | ||
89 | } | ||
90 | |||
91 | void ide_power_enable(bool on) | ||
92 | { | ||
93 | (void)on; | ||
94 | } | ||
95 | |||
96 | #endif /* SIMULATOR */ | ||
97 | |||
diff --git a/firmware/target/coldfire/iaudio/m3/power-m3.c b/firmware/target/coldfire/iaudio/m3/power-m3.c index 5dbeadf732..4c446e54d0 100644 --- a/firmware/target/coldfire/iaudio/m3/power-m3.c +++ b/firmware/target/coldfire/iaudio/m3/power-m3.c | |||
@@ -27,8 +27,6 @@ | |||
27 | #include "power.h" | 27 | #include "power.h" |
28 | #include "system.h" | 28 | #include "system.h" |
29 | 29 | ||
30 | #ifndef SIMULATOR | ||
31 | |||
32 | void power_init(void) | 30 | void power_init(void) |
33 | { | 31 | { |
34 | /* Set KEEPACT */ | 32 | /* Set KEEPACT */ |
@@ -47,9 +45,10 @@ void power_init(void) | |||
47 | #endif | 45 | #endif |
48 | } | 46 | } |
49 | 47 | ||
50 | bool charger_inserted(void) | 48 | unsigned int power_input_status(void) |
51 | { | 49 | { |
52 | return (GPIO1_READ & 0x00000020) == 0; | 50 | return ((GPIO1_READ & 0x00000020) == 0) ? |
51 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
53 | } | 52 | } |
54 | 53 | ||
55 | void ide_power_enable(bool on) | 54 | void ide_power_enable(bool on) |
@@ -77,8 +76,6 @@ void power_off(void) | |||
77 | asm("halt"); | 76 | asm("halt"); |
78 | } | 77 | } |
79 | 78 | ||
80 | #endif /* SIMULATOR */ | ||
81 | |||
82 | bool tuner_power(bool status) | 79 | bool tuner_power(bool status) |
83 | { | 80 | { |
84 | (void)status; | 81 | (void)status; |
diff --git a/firmware/target/coldfire/iaudio/m5/power-m5.c b/firmware/target/coldfire/iaudio/m5/power-m5.c index 987ce0f3c5..8bb36c663d 100644 --- a/firmware/target/coldfire/iaudio/m5/power-m5.c +++ b/firmware/target/coldfire/iaudio/m5/power-m5.c | |||
@@ -27,8 +27,6 @@ | |||
27 | #include "pcf50606.h" | 27 | #include "pcf50606.h" |
28 | #include "lcd-remote-target.h" | 28 | #include "lcd-remote-target.h" |
29 | 29 | ||
30 | #ifndef SIMULATOR | ||
31 | |||
32 | void power_init(void) | 30 | void power_init(void) |
33 | { | 31 | { |
34 | /* Charger detect */ | 32 | /* Charger detect */ |
@@ -38,9 +36,10 @@ void power_init(void) | |||
38 | pcf50606_init(); | 36 | pcf50606_init(); |
39 | } | 37 | } |
40 | 38 | ||
41 | bool charger_inserted(void) | 39 | unsigned int power_input_status(void) |
42 | { | 40 | { |
43 | return (GPIO1_READ & 0x01000000) != 0; | 41 | return (GPIO1_READ & 0x01000000) ? |
42 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
44 | } | 43 | } |
45 | 44 | ||
46 | void ide_power_enable(bool on) | 45 | void ide_power_enable(bool on) |
@@ -66,5 +65,3 @@ void power_off(void) | |||
66 | and_l(~0x00000008, &GPIO_OUT); /* Set KEEPACT low */ | 65 | and_l(~0x00000008, &GPIO_OUT); /* Set KEEPACT low */ |
67 | asm("halt"); | 66 | asm("halt"); |
68 | } | 67 | } |
69 | |||
70 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/coldfire/iaudio/x5/power-x5.c b/firmware/target/coldfire/iaudio/x5/power-x5.c index 22f56961bf..4feb9c15d0 100644 --- a/firmware/target/coldfire/iaudio/x5/power-x5.c +++ b/firmware/target/coldfire/iaudio/x5/power-x5.c | |||
@@ -27,8 +27,6 @@ | |||
27 | #include "pcf50606.h" | 27 | #include "pcf50606.h" |
28 | #include "lcd-remote-target.h" | 28 | #include "lcd-remote-target.h" |
29 | 29 | ||
30 | #ifndef SIMULATOR | ||
31 | |||
32 | void power_init(void) | 30 | void power_init(void) |
33 | { | 31 | { |
34 | /* Charger detect */ | 32 | /* Charger detect */ |
@@ -38,9 +36,10 @@ void power_init(void) | |||
38 | pcf50606_init(); | 36 | pcf50606_init(); |
39 | } | 37 | } |
40 | 38 | ||
41 | bool charger_inserted(void) | 39 | unsigned int power_input_status(void) |
42 | { | 40 | { |
43 | return (GPIO1_READ & 0x01000000) != 0; | 41 | return (GPIO1_READ & 0x01000000) ? |
42 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
44 | } | 43 | } |
45 | 44 | ||
46 | void ide_power_enable(bool on) | 45 | void ide_power_enable(bool on) |
@@ -67,8 +66,6 @@ void power_off(void) | |||
67 | asm("halt"); | 66 | asm("halt"); |
68 | } | 67 | } |
69 | 68 | ||
70 | #endif /* SIMULATOR */ | ||
71 | |||
72 | bool tuner_power(bool status) | 69 | bool tuner_power(bool status) |
73 | { | 70 | { |
74 | (void)status; | 71 | (void)status; |
diff --git a/firmware/target/coldfire/iriver/h100/power-h100.c b/firmware/target/coldfire/iriver/h100/power-h100.c index 6eb403732d..2717e42f4a 100644 --- a/firmware/target/coldfire/iriver/h100/power-h100.c +++ b/firmware/target/coldfire/iriver/h100/power-h100.c | |||
@@ -26,19 +26,14 @@ | |||
26 | #include "power.h" | 26 | #include "power.h" |
27 | #include "spdif.h" | 27 | #include "spdif.h" |
28 | 28 | ||
29 | |||
30 | #if CONFIG_TUNER | 29 | #if CONFIG_TUNER |
31 | |||
32 | bool tuner_power(bool status) | 30 | bool tuner_power(bool status) |
33 | { | 31 | { |
34 | (void)status; | 32 | (void)status; |
35 | return true; | 33 | return true; |
36 | } | 34 | } |
37 | |||
38 | #endif /* #if CONFIG_TUNER */ | 35 | #endif /* #if CONFIG_TUNER */ |
39 | 36 | ||
40 | #ifndef SIMULATOR | ||
41 | |||
42 | void power_init(void) | 37 | void power_init(void) |
43 | { | 38 | { |
44 | or_l(0x00080000, &GPIO1_OUT); | 39 | or_l(0x00080000, &GPIO1_OUT); |
@@ -56,14 +51,16 @@ void power_init(void) | |||
56 | #endif | 51 | #endif |
57 | } | 52 | } |
58 | 53 | ||
59 | 54 | unsigned int power_input_status(void) | |
60 | bool charger_inserted(void) | 55 | { |
61 | { | 56 | return (GPIO1_READ & 0x00400000) ? |
62 | return (GPIO1_READ & 0x00400000)?true:false; | 57 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; |
63 | } | 58 | } |
59 | |||
64 | /* Returns true if the unit is charging the batteries. */ | 60 | /* Returns true if the unit is charging the batteries. */ |
65 | bool charging_state(void) { | 61 | bool charging_state(void) |
66 | return charger_inserted(); | 62 | { |
63 | return (power_input_status() & POWER_INPUT_CHARGER) != 0; | ||
67 | } | 64 | } |
68 | 65 | ||
69 | #ifdef HAVE_SPDIF_POWER | 66 | #ifdef HAVE_SPDIF_POWER |
@@ -119,5 +116,3 @@ void power_off(void) | |||
119 | asm("halt"); | 116 | asm("halt"); |
120 | while(1); | 117 | while(1); |
121 | } | 118 | } |
122 | |||
123 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/coldfire/iriver/h300/power-h300.c b/firmware/target/coldfire/iriver/h300/power-h300.c index ea66625794..400dc02526 100644 --- a/firmware/target/coldfire/iriver/h300/power-h300.c +++ b/firmware/target/coldfire/iriver/h300/power-h300.c | |||
@@ -25,20 +25,18 @@ | |||
25 | #include "system.h" | 25 | #include "system.h" |
26 | #include "power.h" | 26 | #include "power.h" |
27 | #include "pcf50606.h" | 27 | #include "pcf50606.h" |
28 | #include "usb.h" | ||
29 | #include "logf.h" | ||
28 | 30 | ||
29 | 31 | ||
30 | #if CONFIG_TUNER | 32 | #if CONFIG_TUNER |
31 | |||
32 | bool tuner_power(bool status) | 33 | bool tuner_power(bool status) |
33 | { | 34 | { |
34 | (void)status; | 35 | (void)status; |
35 | return true; | 36 | return true; |
36 | } | 37 | } |
37 | |||
38 | #endif /* #if CONFIG_TUNER */ | 38 | #endif /* #if CONFIG_TUNER */ |
39 | 39 | ||
40 | #ifndef SIMULATOR | ||
41 | |||
42 | void power_init(void) | 40 | void power_init(void) |
43 | { | 41 | { |
44 | or_l(0x00080000, &GPIO1_OUT); | 42 | or_l(0x00080000, &GPIO1_OUT); |
@@ -56,17 +54,54 @@ void power_init(void) | |||
56 | 54 | ||
57 | 55 | ||
58 | #if CONFIG_CHARGING | 56 | #if CONFIG_CHARGING |
59 | bool charger_inserted(void) | 57 | unsigned int power_input_status(void) |
60 | { | 58 | { |
61 | return (GPIO1_READ & 0x00400000)?true:false; | 59 | unsigned int status = POWER_INPUT_NONE; |
60 | |||
61 | if (GPIO1_READ & 0x00400000) | ||
62 | status |= POWER_INPUT_MAIN_CHARGER; | ||
63 | |||
64 | #ifdef HAVE_USB_POWER | ||
65 | if (usb_detect() == USB_INSERTED && pcf50606_usb_charging_enabled()) | ||
66 | status |= POWER_INPUT_USB_CHARGER; | ||
67 | /* CHECK: Can the device be powered from USB w/o charging it? */ | ||
68 | #endif | ||
69 | |||
70 | return status; | ||
62 | } | 71 | } |
72 | |||
73 | #ifdef HAVE_USB_POWER | ||
74 | bool usb_charging_enable(bool on) | ||
75 | { | ||
76 | bool rc = false; | ||
77 | int irqlevel; | ||
78 | logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); | ||
79 | irqlevel = disable_irq_save(); | ||
80 | pcf50606_set_usb_charging(on); | ||
81 | rc = on; | ||
82 | restore_irq(irqlevel); | ||
83 | return rc; | ||
84 | } | ||
85 | #endif /* HAVE_USB_POWER */ | ||
86 | |||
63 | #endif /* CONFIG_CHARGING */ | 87 | #endif /* CONFIG_CHARGING */ |
64 | 88 | ||
65 | /* Returns true if the unit is charging the batteries. */ | 89 | /* Returns true if the unit is charging the batteries. */ |
66 | bool charging_state(void) { | 90 | bool charging_state(void) |
91 | { | ||
67 | return (GPIO_READ & 0x00800000)?true:false; | 92 | return (GPIO_READ & 0x00800000)?true:false; |
68 | } | 93 | } |
69 | 94 | ||
95 | bool usb_charging_enabled(void) | ||
96 | { | ||
97 | bool rc = false; | ||
98 | /* TODO: read the state of the GPOOD2 register... | ||
99 | * (this also means to set the irq level here) */ | ||
100 | rc = pcf50606_usb_charging_enabled(); | ||
101 | |||
102 | logf("usb charging %s", rc ? "enabled" : "disabled" ); | ||
103 | return rc; | ||
104 | } | ||
70 | 105 | ||
71 | void ide_power_enable(bool on) | 106 | void ide_power_enable(bool on) |
72 | { | 107 | { |
@@ -90,5 +125,3 @@ void power_off(void) | |||
90 | asm("halt"); | 125 | asm("halt"); |
91 | while(1); | 126 | while(1); |
92 | } | 127 | } |
93 | |||
94 | #endif /* SIMULATOR */ | ||
diff --git a/firmware/target/sh/archos/fm_v2/power-fm_v2.c b/firmware/target/sh/archos/fm_v2/power-fm_v2.c index 32b5c95da9..24bccf6eb2 100644 --- a/firmware/target/sh/archos/fm_v2/power-fm_v2.c +++ b/firmware/target/sh/archos/fm_v2/power-fm_v2.c | |||
@@ -28,7 +28,6 @@ | |||
28 | #include "usb.h" | 28 | #include "usb.h" |
29 | 29 | ||
30 | #if CONFIG_TUNER | 30 | #if CONFIG_TUNER |
31 | |||
32 | bool tuner_power(bool status) | 31 | bool tuner_power(bool status) |
33 | { | 32 | { |
34 | (void)status; | 33 | (void)status; |
@@ -44,10 +43,20 @@ void power_init(void) | |||
44 | or_b(0x20, &PBDRL); /* hold power */ | 43 | or_b(0x20, &PBDRL); /* hold power */ |
45 | } | 44 | } |
46 | 45 | ||
47 | bool charger_inserted(void) | 46 | unsigned int power_input_status(void) |
48 | { | 47 | { |
48 | unsigned int status = POWER_INPUT_NONE; | ||
49 | |||
49 | /* FM or V2 can also charge from the USB port */ | 50 | /* FM or V2 can also charge from the USB port */ |
50 | return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF); | 51 | if (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) |
52 | status = POWER_INPUT_MAIN_CHARGER; | ||
53 | |||
54 | #ifdef HAVE_USB_POWER | ||
55 | if (usb_detect() == USB_INSERTED) | ||
56 | status |= POWER_INPUT_USB_CHARGER; | ||
57 | #endif | ||
58 | |||
59 | return status; | ||
51 | } | 60 | } |
52 | 61 | ||
53 | /* Returns true if the unit is charging the batteries. */ | 62 | /* Returns true if the unit is charging the batteries. */ |
diff --git a/firmware/target/sh/archos/player/power-player.c b/firmware/target/sh/archos/player/power-player.c index 59b87f69a5..857ba25e50 100644 --- a/firmware/target/sh/archos/player/power-player.c +++ b/firmware/target/sh/archos/player/power-player.c | |||
@@ -31,10 +31,11 @@ void power_init(void) | |||
31 | { | 31 | { |
32 | } | 32 | } |
33 | 33 | ||
34 | bool charger_inserted(void) | 34 | unsigned int power_input_status(void) |
35 | { | 35 | { |
36 | /* Player */ | 36 | /* Player */ |
37 | return (PADR & 1) == 0; | 37 | return ((PADR & 1) == 0) ? |
38 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
38 | } | 39 | } |
39 | 40 | ||
40 | void ide_power_enable(bool on) | 41 | void ide_power_enable(bool on) |
diff --git a/firmware/target/sh/archos/recorder/power-recorder.c b/firmware/target/sh/archos/recorder/power-recorder.c index b0a7ad1786..d90c029890 100644 --- a/firmware/target/sh/archos/recorder/power-recorder.c +++ b/firmware/target/sh/archos/recorder/power-recorder.c | |||
@@ -36,10 +36,11 @@ void power_init(void) | |||
36 | charger_enable(false); /* Default to charger OFF */ | 36 | charger_enable(false); /* Default to charger OFF */ |
37 | } | 37 | } |
38 | 38 | ||
39 | bool charger_inserted(void) | 39 | unsigned int power_input_status(void) |
40 | { | 40 | { |
41 | /* Recorder */ | 41 | /* Recorder */ |
42 | return adc_read(ADC_EXT_POWER) > 0x100; | 42 | return (adc_read(ADC_EXT_POWER) > 0x100) ? |
43 | POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE; | ||
43 | } | 44 | } |
44 | 45 | ||
45 | void charger_enable(bool on) | 46 | void charger_enable(bool on) |
diff --git a/firmware/usb.c b/firmware/usb.c index 00e0bb3607..9d4bb00180 100644 --- a/firmware/usb.c +++ b/firmware/usb.c | |||
@@ -42,9 +42,6 @@ | |||
42 | #ifdef HAVE_USBSTACK | 42 | #ifdef HAVE_USBSTACK |
43 | #include "usb_core.h" | 43 | #include "usb_core.h" |
44 | #endif | 44 | #endif |
45 | #ifdef IRIVER_H300_SERIES | ||
46 | #include "pcf50606.h" /* for pcf50606_usb_charging_... */ | ||
47 | #endif | ||
48 | #include "logf.h" | 45 | #include "logf.h" |
49 | 46 | ||
50 | /* Conditions under which we want the entire driver */ | 47 | /* Conditions under which we want the entire driver */ |
@@ -588,40 +585,6 @@ bool usb_powered(void) | |||
588 | { | 585 | { |
589 | return usb_state == USB_POWERED; | 586 | return usb_state == USB_POWERED; |
590 | } | 587 | } |
591 | |||
592 | #if CONFIG_CHARGING | ||
593 | bool usb_charging_enable(bool on) | ||
594 | { | ||
595 | bool rc = false; | ||
596 | #ifdef IRIVER_H300_SERIES | ||
597 | int irqlevel; | ||
598 | logf("usb_charging_enable(%s)\n", on ? "on" : "off" ); | ||
599 | irqlevel = disable_irq_save(); | ||
600 | pcf50606_set_usb_charging(on); | ||
601 | rc = on; | ||
602 | restore_irq(irqlevel); | ||
603 | #else | ||
604 | /* TODO: implement it for other targets... */ | ||
605 | (void)on; | ||
606 | #endif | ||
607 | return rc; | ||
608 | } | ||
609 | |||
610 | bool usb_charging_enabled(void) | ||
611 | { | ||
612 | bool rc = false; | ||
613 | #ifdef IRIVER_H300_SERIES | ||
614 | /* TODO: read the state of the GPOOD2 register... | ||
615 | * (this also means to set the irq level here) */ | ||
616 | rc = pcf50606_usb_charging_enabled(); | ||
617 | #else | ||
618 | /* TODO: implement it for other targets... */ | ||
619 | #endif | ||
620 | |||
621 | logf("usb charging %s", rc ? "enabled" : "disabled" ); | ||
622 | return rc; | ||
623 | } | ||
624 | #endif | ||
625 | #endif | 588 | #endif |
626 | 589 | ||
627 | #else | 590 | #else |
diff --git a/uisimulator/common/stubs.c b/uisimulator/common/stubs.c index 169ce06067..8991bd73ca 100644 --- a/uisimulator/common/stubs.c +++ b/uisimulator/common/stubs.c | |||
@@ -30,6 +30,8 @@ | |||
30 | #include "string.h" | 30 | #include "string.h" |
31 | #include "lcd.h" | 31 | #include "lcd.h" |
32 | 32 | ||
33 | #include "power.h" | ||
34 | |||
33 | #include "ata.h" /* for volume definitions */ | 35 | #include "ata.h" /* for volume definitions */ |
34 | 36 | ||
35 | extern char having_new_lcd; | 37 | extern char having_new_lcd; |
@@ -212,9 +214,13 @@ bool charging_state(void) | |||
212 | return false; | 214 | return false; |
213 | } | 215 | } |
214 | 216 | ||
215 | bool charger_inserted(void) | 217 | unsigned int power_input_status(void) |
216 | { | 218 | { |
217 | return false; | 219 | #ifdef HAVE_BATTERY_SWITCH |
220 | return POWER_INPUT_BATTERY; | ||
221 | #else | ||
222 | return POWER_INPUT_NONE; | ||
223 | #endif | ||
218 | } | 224 | } |
219 | 225 | ||
220 | #ifdef HAVE_SPDIF_POWER | 226 | #ifdef HAVE_SPDIF_POWER |
@@ -241,6 +247,11 @@ bool usb_powered(void) | |||
241 | } | 247 | } |
242 | 248 | ||
243 | #if CONFIG_CHARGING | 249 | #if CONFIG_CHARGING |
250 | bool charger_inserted(void) | ||
251 | { | ||
252 | return false; | ||
253 | } | ||
254 | |||
244 | bool usb_charging_enable(bool on) | 255 | bool usb_charging_enable(bool on) |
245 | { | 256 | { |
246 | (void)on; | 257 | (void)on; |