summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--apps/lang/english.lang2
-rw-r--r--apps/menus/settings_menu.c10
-rw-r--r--apps/plugin.h4
-rw-r--r--apps/screens.c6
-rw-r--r--apps/settings.c4
-rw-r--r--apps/settings.h4
-rw-r--r--apps/settings_list.c4
-rw-r--r--firmware/backlight.c12
-rw-r--r--firmware/export/config-gigabeat-s.h5
-rw-r--r--firmware/export/config-gigabeat.h4
-rw-r--r--firmware/export/config-h300.h4
-rw-r--r--firmware/export/power.h51
-rw-r--r--firmware/powermgmt.c24
-rw-r--r--firmware/target/arm/archos/av300/power-av300.c31
-rw-r--r--firmware/target/arm/as3525/power-as3525.c13
-rw-r--r--firmware/target/arm/imx31/gigabeat-s/power-imx31.c37
-rw-r--r--firmware/target/arm/ipod/power-ipod.c20
-rw-r--r--firmware/target/arm/iriver/h10/power-h10.c6
-rw-r--r--firmware/target/arm/olympus/mrobe-100/power-mr100.c7
-rwxr-xr-xfirmware/target/arm/philips/hdd1630/power-hdd1630.c4
-rw-r--r--firmware/target/arm/philips/sa9200/power-sa9200.c10
-rw-r--r--firmware/target/arm/s3c2440/gigabeat-fx/power-meg-fx.c48
-rw-r--r--firmware/target/arm/sandisk/power-c200_e200.c24
-rw-r--r--firmware/target/arm/tatung/tpj1022/power-tpj1022.c6
-rw-r--r--firmware/target/arm/tcc77x/c100/power-c100.c21
-rw-r--r--firmware/target/arm/tcc77x/iaudio7/power-iaudio7.c5
-rw-r--r--firmware/target/arm/tcc77x/logikdax/power-logikdax.c25
-rw-r--r--firmware/target/arm/tcc77x/m200/power-m200.c25
-rw-r--r--firmware/target/arm/tcc780x/cowond2/power-cowond2.c30
-rw-r--r--firmware/target/arm/tms320dm320/creative-zvm/power-creativezvm.c25
-rw-r--r--firmware/target/arm/tms320dm320/mrobe-500/power-mr500.c30
-rw-r--r--firmware/target/coldfire/iaudio/m3/power-m3.c11
-rw-r--r--firmware/target/coldfire/iaudio/m5/power-m5.c11
-rw-r--r--firmware/target/coldfire/iaudio/x5/power-x5.c11
-rw-r--r--firmware/target/coldfire/iriver/h100/power-h100.c21
-rw-r--r--firmware/target/coldfire/iriver/h300/power-h300.c53
-rw-r--r--firmware/target/sh/archos/fm_v2/power-fm_v2.c15
-rw-r--r--firmware/target/sh/archos/player/power-player.c5
-rw-r--r--firmware/target/sh/archos/recorder/power-recorder.c5
-rw-r--r--firmware/usb.c37
-rw-r--r--uisimulator/common/stubs.c15
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 @@
</phrase>
<phrase>
id: LANG_USB_CHARGING
- desc: in Battery menu
+ desc: in Battery menu, TODO: cleanup unless HAVE_USB_CHARGING_ENABLE defined
user:
<source>
*: 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);
#if BATTERY_TYPES_COUNT > 1
MENUITEM_SETTING(battery_type, &global_settings.battery_type, NULL);
#endif
-#ifdef HAVE_USB_POWER
-#if CONFIG_CHARGING
+#ifdef HAVE_USB_CHARGING_ENABLE
static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
{
(void)this_item;
@@ -158,8 +157,7 @@ static int usbcharging_callback(int action,const struct menu_item_ex *this_item)
return action;
}
MENUITEM_SETTING(usb_charging, &global_settings.usb_charging, usbcharging_callback);
-#endif
-#endif
+#endif /* HAVE_USB_CHARGING_ENABLE */
MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
#if BATTERY_CAPACITY_INC > 0
&battery_capacity,
@@ -167,11 +165,9 @@ MAKE_MENU(battery_menu, ID2P(LANG_BATTERY_MENU), 0, Icon_NOICON,
#if BATTERY_TYPES_COUNT > 1
&battery_type,
#endif
-#ifdef HAVE_USB_POWER
-#if CONFIG_CHARGING
+#ifdef HAVE_USB_CHARGING_ENABLE
&usb_charging,
#endif
-#endif
);
/* Disk */
#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);
#define PLUGIN_MAGIC 0x526F634B /* RocK */
/* increase this every time the api struct changes */
-#define PLUGIN_API_VERSION 126
+#define PLUGIN_API_VERSION 127
/* update this to latest version if a change to the api struct breaks
backwards compatibility (and please take the opportunity to sort in any
new function which are "waiting" at the end of the function table) */
-#define PLUGIN_MIN_API_VERSION 125
+#define PLUGIN_MIN_API_VERSION 127
/* plugin return codes */
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)
while(1)
{
#if CONFIG_CHARGING
- if (charger_inserted()
-#ifdef HAVE_USB_POWER
- || usb_powered()
-#endif
- )
+ if (charger_inserted())
{
global_status.runtime = 0;
}
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)
sound_set(SOUND_TREBLE_CUTOFF, global_settings.treble_cutoff);
#endif
-#ifdef HAVE_USB_POWER
-#if CONFIG_CHARGING
+#ifdef HAVE_USB_CHARGING_ENABLE
usb_charging_enable(global_settings.usb_charging);
#endif
-#endif
}
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
unsigned char kbd_file[MAX_FILENAME+1]; /* last keyboard */
#endif
-#ifdef HAVE_USB_POWER
-#if CONFIG_CHARGING
+#ifdef HAVE_USB_CHARGING_ENABLE
bool usb_charging;
#endif
-#endif
bool hold_lr_for_scroll_in_list; /* hold L/R scrolls the list left/right */
#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[] = {
#ifdef HAVE_LCD_BITMAP
TEXT_SETTING(0,kbd_file,"kbd","",ROCKBOX_DIR "/",".kbd"),
#endif
-#ifdef HAVE_USB_POWER
-#if CONFIG_CHARGING
+#ifdef HAVE_USB_CHARGING_ENABLE
OFFON_SETTING(0,usb_charging,LANG_USB_CHARGING,false,"usb charging",NULL),
#endif
-#endif
OFFON_SETTING(F_BANFROMQS,cuesheet,LANG_CUESHEET_ENABLE,false,"cuesheet support",
NULL),
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)
else
#endif
#if CONFIG_CHARGING
- if (charger_inserted()
-#ifdef HAVE_USB_POWER
- || usb_powered()
-#endif
- )
+ if (power_input_present())
backlight_timeout = backlight_timeout_plugged;
else
#endif
@@ -532,11 +528,7 @@ static void remote_backlight_update_state(void)
else
#endif
#if CONFIG_CHARGING
- if (charger_inserted()
-#ifdef HAVE_USB_POWER
- || usb_powered()
-#endif
- )
+ if (power_input_present())
remote_backlight_timeout = remote_backlight_timeout_plugged;
else
#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 @@
/* define this if the unit can be powered or charged via USB */
//#define HAVE_USB_POWER /* Disable for now */
+//#define HAVE_USB_CHARGING_ENABLE
+
+/* define this if the unit has a battery switch or battery can be removed
+ * when running */
+#define HAVE_BATTERY_SWITCH
/* USB On-the-go */
#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 @@
/* define this if the unit can be powered or charged via USB */
#define HAVE_USB_POWER
+/* define this if the unit has a battery switch or battery can be removed
+ * when running */
+#define HAVE_BATTERY_SWITCH
+
#ifndef SIMULATOR
/* 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 @@
/* define this if the unit can be powered or charged via USB */
#define HAVE_USB_POWER
+/* define this if the unit can have USB charging disabled by user -
+ * if USB/MAIN power is discernable and hardware doesn't compel charging */
+#define HAVE_USB_CHARGING_ENABLE
+
#ifndef SIMULATOR
/* 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);
#endif
#if CONFIG_CHARGING
-bool charger_inserted(void);
+enum power_input_flags {
+ /* No external power source? Default. */
+ POWER_INPUT_NONE = 0x00,
+
+ /* Main power source is available (AC?), the default other than
+ * battery if for instance USB and others cannot be distinguished or
+ * USB is the only possibility. */
+ POWER_INPUT_MAIN = 0x01,
+
+ /* USB power source is available (and is discernable from MAIN). */
+ POWER_INPUT_USB = 0x02,
+
+ /* Something is plugged. */
+ POWER_INPUT = 0x0f,
+
+ /* POWER_INPUT_*_CHARGER of course implies presence of the respective
+ * power source. */
+
+ /* Battery not included in CHARGER (it can't charge itself) */
+
+ /* Charging is possible on main. */
+ POWER_INPUT_MAIN_CHARGER = 0x10 | POWER_INPUT_MAIN,
+
+ /* Charging is possible on USB. */
+ POWER_INPUT_USB_CHARGER = 0x20 | POWER_INPUT_USB,
+
+ /* Charging is possible from something. */
+ POWER_INPUT_CHARGER = 0xf0,
+
+#ifdef HAVE_BATTERY_SWITCH
+ /* Battery is powering device or is available to power device. It
+ * could also be used if the battery is hot-swappable to indicate if
+ * it is present ("switch" as verb vs. noun). */
+ POWER_INPUT_BATTERY = 0x100,
#endif
+};
+
+/* Returns detailed power input status information from device. */
+unsigned int power_input_status(void);
+
+/* Shortcuts */
+/* Returns true if any power source that is connected is capable of
+ * charging the batteries.
+ * > (power_input_status() & POWER_INPUT_CHARGER) != 0 */
+bool charger_inserted(void);
+
+/* Returns true if any power input is connected - charging-capable
+ * or not.
+ * > (power_input_status() & POWER_INPUT) != 0 */
+bool power_input_present(void);
+#endif /* CONFIG_CHARGING */
void power_off(void);
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)
}
#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
+#if CONFIG_CHARGING
+/* Shortcut function calls - compatibility, simplicity. */
+
+/* Returns true if any power input is capable of charging. */
+bool charger_inserted(void)
+{
+ return power_input_status() & POWER_INPUT_CHARGER;
+}
+
+/* Returns true if any power input is connected - charging-capable
+ * or not. */
+bool power_input_present(void)
+{
+ return power_input_status() & POWER_INPUT;
+}
+#endif /* CONFIG_CHARGING */
+
/*
* This function is called to do the relativly long sleep waits from within the
* main power_thread loop while at the same time servicing any other periodic
@@ -957,12 +974,7 @@ static void power_thread_sleep(int ticks)
* loop (including the subroutines), and end up back here where we
* transition to the appropriate steady state charger on/off state.
*/
- if(charger_inserted()
-#ifdef HAVE_USB_POWER /* USB powered or USB inserted both provide power */
- || usb_powered()
- || (usb_inserted() && usb_charging_enabled())
-#endif
- ) {
+ if(power_input_status() & POWER_INPUT_CHARGER) {
switch(charger_input_state) {
case NO_CHARGER:
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 @@
#include "system.h"
#include "power.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Charger detect */
}
-bool charger_inserted(void)
-{
- return false;
+unsigned int power_input_status(void)
+{
+ return POWER_INPUT_NONE;
}
void ide_power_enable(bool on)
@@ -61,29 +59,6 @@ void power_off(void)
{
}
-#else
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#endif /* SIMULATOR */
-
bool tuner_power(bool status)
{
(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 @@
* KIND, either express or implied.
*
****************************************************************************/
-
#include <stdbool.h>
#include "config.h"
#include "ascodec-target.h"
@@ -40,14 +39,14 @@ void power_init(void)
}
#if CONFIG_CHARGING
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- if(ascodec_read(AS3514_IRQ_ENRD0) & (1<<5))
- return true;
- else
- return false;
+ return (ascodec_read(AS3514_IRQ_ENRD0) & (1<<5)) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
+
+ /* TODO: Handle USB and other sources properly */
}
-#endif
+#endif /* CONFIG_CHARGING */
void ide_power_enable(bool on)
{
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 @@
#include "avic-imx31.h"
#include "mc13783.h"
-#ifndef SIMULATOR
-
static bool charger_detect = false;
/* This is called from the mc13783 interrupt thread */
@@ -38,9 +36,17 @@ void charger_detect_event(void)
mc13783_read(MC13783_INTERRUPT_SENSE0) & MC13783_CHGDETS;
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return charger_detect;
+ unsigned int status = POWER_INPUT_NONE;
+
+ if ((GPIO3_DR & (1 << 20)) != 0)
+ status |= POWER_INPUT_BATTERY;
+
+ if (charger_detect)
+ status |= POWER_INPUT_MAIN_CHARGER;
+
+ return status;
}
/* Returns true if the unit is charging the batteries. */
@@ -90,26 +96,3 @@ void power_init(void)
mc13783_enable_event(MC13783_CHGDET_EVENT);
}
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#endif /* SIMULATOR */
-
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)
}
#if CONFIG_CHARGING
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
-#if defined(IPOD_VIDEO)
- return (GPIOL_INPUT_VAL & 0x08)?false:true;
+ unsigned int status = POWER_INPUT_NONE;
+
+#if defined(IPOD_NANO) || defined(IPOD_VIDEO)
+ if ((GPIOL_INPUT_VAL & 0x08) == 0)
+ status = POWER_INPUT_MAIN_CHARGER;
+
+ if ((GPIOL_INPUT_VAL & 0x10) != 0)
+ status |= POWER_INPUT_USB_CHARGER;
+ /* */
#elif defined(IPOD_4G) || defined(IPOD_COLOR) \
|| defined(IPOD_MINI) || defined(IPOD_MINI2G)
/* C2 is firewire power */
- return (GPIOC_INPUT_VAL & 0x04)?false:true;
+ if ((GPIOC_INPUT_VAL & 0x04) == 0)
+ status = POWER_INPUT_MAIN_CHARGER;
+ /* */
#else
/* This needs filling in for other ipods. */
- return false;
#endif
+
+ return status;
}
/* 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)
{
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return (GPIOF_INPUT_VAL & 0x08)?true:false;
+ /* No separate source for USB and charges from USB on its own */
+ return (GPIOF_INPUT_VAL & 0x08) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
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)
GPIOB_OUTPUT_EN |= 0x80;
}
-bool charger_inserted(void)
-{
- return (GPIOL_INPUT_VAL & 0x24) ? true : false ;
+unsigned int power_input_status(void)
+{
+ return (GPIOL_INPUT_VAL & 0x24) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
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)
{
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return false ;
+ return POWER_INPUT_NONE;
}
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)
}
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
-#ifdef SANSA_E200
- if(GPIOB_INPUT_VAL & 0x10)
-#else /* SANSA_C200 */
- if(GPIOH_INPUT_VAL & 0x2)
-#endif
- return true;
- return false;
+ return POWER_INPUT_NONE;
}
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 @@
#include "pcf50606.h"
#include "backlight.h"
#include "backlight-target.h"
-
-#ifndef SIMULATOR
+#include "usb.h"
void power_init(void)
{
@@ -39,13 +38,28 @@ void power_init(void)
/* Charger detect */
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return (GPFDAT & (1 << 4)) ? false : true;
+ unsigned int status = POWER_INPUT_NONE;
+
+ /* Is the battery switch ON? */
+ if ((GPGDAT & (1 << 9)) == 0)
+ status |= POWER_INPUT_BATTERY;
+
+ /* Main or cradle power available? */
+ if ((GPFDAT & (1 << 4)) == 0)
+ status |= POWER_INPUT_MAIN_CHARGER;
+
+ /* Is the USB cable inserted? */
+ if (usb_detect() == USB_INSERTED)
+ status |= POWER_INPUT_USB_CHARGER;
+
+ return status;
}
/* Returns true if the unit is charging the batteries. */
-bool charging_state(void) {
+bool charging_state(void)
+{
return (GPGDAT & (1 << 8)) ? false : true;
}
@@ -87,27 +101,3 @@ void power_off(void)
reboot_point();
}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#endif /* SIMULATOR */
-
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 @@
#include "tuner.h"
#include "as3514.h"
#include "power.h"
+#include "usb.h"
void power_init(void)
{
@@ -53,15 +54,24 @@ void power_off(void)
}
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
-#ifdef SANSA_E200
- if(GPIOB_INPUT_VAL & 0x10)
-#else /* SANSA_C200 */
- if(GPIOH_INPUT_VAL & 0x2)
+ unsigned int status = POWER_INPUT_NONE;
+
+#if defined(SANSA_E200)
+ #define _charger_present() (GPIOB_INPUT_VAL & 0x10)
+#elif defined(SANSA_C200)
+ #define _charger_present() (GPIOH_INPUT_VAL & 0x2)
+#else
+ #define _charger_present() 0
#endif
- return true;
- return false;
+
+ if (_charger_present())
+ status = POWER_INPUT_MAIN_CHARGER;
+
+ /* No separate source for USB */
+
+ return status;
}
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)
{
}
-bool charger_inserted(void)
-{
- return false;
+unsigned int power_input_status(void)
+{
+ return POWER_INPUT_NONE;
}
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 @@
#include "system.h"
#include "power.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
}
@@ -43,22 +41,3 @@ bool ide_powered(void)
void power_off(void)
{
}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#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)
#endif /* CONFIG_TUNER */
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return (GPIOA & 0x1) ? true : false;
+ return (GPIOA & 0x1) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
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 @@
#include "system.h"
#include "power.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
}
@@ -43,26 +41,3 @@ bool ide_powered(void)
void power_off(void)
{
}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#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 @@
#include "system.h"
#include "power.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
}
@@ -43,26 +41,3 @@ bool ide_powered(void)
void power_off(void)
{
}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#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 @@
#include "button-target.h"
#include "tuner.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
unsigned char data[3]; /* 0 = INT1, 1 = INT2, 2 = INT3 */
@@ -93,9 +91,10 @@ void EXT3(void)
#endif
#if CONFIG_CHARGING
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return (GPIOC & (1<<26)) ? false:true;
+ return ((GPIOC & (1<<26)) == 0) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
#endif
@@ -147,26 +146,3 @@ bool tuner_power(bool status)
}
#endif /* CONFIG_TUNER */
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#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 @@
#include "backlight.h"
#include "backlight-target.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Initialize IDE power pin */
@@ -37,34 +35,17 @@ void power_init(void)
/* Charger detect */
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return false;
+ return POWER_INPUT_NONE;
}
/* Returns true if the unit is charging the batteries. */
-bool charging_state(void) {
- return false;
-}
-
-void power_off(void)
-{
-}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
+bool charging_state(void)
{
return false;
}
-void charger_enable(bool on)
-{
- (void)on;
-}
-
void power_off(void)
{
}
-
-#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 @@
#include "backlight.h"
#include "backlight-target.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Initialize IDE power pin */
@@ -40,9 +38,9 @@ void power_init(void)
/* Charger detect */
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return false;
+ return POWER_INPUT_NONE;
}
/* Returns true if the unit is charging the batteries. */
@@ -71,27 +69,3 @@ void power_off(void)
/* Hard shutdown */
IO_GIO_BITSET1|=1<<10;
}
-
-#else /* SIMULATOR */
-
-bool charger_inserted(void)
-{
- return false;
-}
-
-void charger_enable(bool on)
-{
- (void)on;
-}
-
-void power_off(void)
-{
-}
-
-void ide_power_enable(bool on)
-{
- (void)on;
-}
-
-#endif /* SIMULATOR */
-
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 @@
#include "power.h"
#include "system.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Set KEEPACT */
@@ -47,9 +45,10 @@ void power_init(void)
#endif
}
-bool charger_inserted(void)
-{
- return (GPIO1_READ & 0x00000020) == 0;
+unsigned int power_input_status(void)
+{
+ return ((GPIO1_READ & 0x00000020) == 0) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
void ide_power_enable(bool on)
@@ -77,8 +76,6 @@ void power_off(void)
asm("halt");
}
-#endif /* SIMULATOR */
-
bool tuner_power(bool status)
{
(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 @@
#include "pcf50606.h"
#include "lcd-remote-target.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Charger detect */
@@ -38,9 +36,10 @@ void power_init(void)
pcf50606_init();
}
-bool charger_inserted(void)
-{
- return (GPIO1_READ & 0x01000000) != 0;
+unsigned int power_input_status(void)
+{
+ return (GPIO1_READ & 0x01000000) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
void ide_power_enable(bool on)
@@ -66,5 +65,3 @@ void power_off(void)
and_l(~0x00000008, &GPIO_OUT); /* Set KEEPACT low */
asm("halt");
}
-
-#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 @@
#include "pcf50606.h"
#include "lcd-remote-target.h"
-#ifndef SIMULATOR
-
void power_init(void)
{
/* Charger detect */
@@ -38,9 +36,10 @@ void power_init(void)
pcf50606_init();
}
-bool charger_inserted(void)
-{
- return (GPIO1_READ & 0x01000000) != 0;
+unsigned int power_input_status(void)
+{
+ return (GPIO1_READ & 0x01000000) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
void ide_power_enable(bool on)
@@ -67,8 +66,6 @@ void power_off(void)
asm("halt");
}
-#endif /* SIMULATOR */
-
bool tuner_power(bool status)
{
(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 @@
#include "power.h"
#include "spdif.h"
-
#if CONFIG_TUNER
-
bool tuner_power(bool status)
{
(void)status;
return true;
}
-
#endif /* #if CONFIG_TUNER */
-#ifndef SIMULATOR
-
void power_init(void)
{
or_l(0x00080000, &GPIO1_OUT);
@@ -56,14 +51,16 @@ void power_init(void)
#endif
}
-
-bool charger_inserted(void)
-{
- return (GPIO1_READ & 0x00400000)?true:false;
+unsigned int power_input_status(void)
+{
+ return (GPIO1_READ & 0x00400000) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
+
/* Returns true if the unit is charging the batteries. */
-bool charging_state(void) {
- return charger_inserted();
+bool charging_state(void)
+{
+ return (power_input_status() & POWER_INPUT_CHARGER) != 0;
}
#ifdef HAVE_SPDIF_POWER
@@ -119,5 +116,3 @@ void power_off(void)
asm("halt");
while(1);
}
-
-#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 @@
#include "system.h"
#include "power.h"
#include "pcf50606.h"
+#include "usb.h"
+#include "logf.h"
#if CONFIG_TUNER
-
bool tuner_power(bool status)
{
(void)status;
return true;
}
-
#endif /* #if CONFIG_TUNER */
-#ifndef SIMULATOR
-
void power_init(void)
{
or_l(0x00080000, &GPIO1_OUT);
@@ -56,17 +54,54 @@ void power_init(void)
#if CONFIG_CHARGING
-bool charger_inserted(void)
-{
- return (GPIO1_READ & 0x00400000)?true:false;
+unsigned int power_input_status(void)
+{
+ unsigned int status = POWER_INPUT_NONE;
+
+ if (GPIO1_READ & 0x00400000)
+ status |= POWER_INPUT_MAIN_CHARGER;
+
+#ifdef HAVE_USB_POWER
+ if (usb_detect() == USB_INSERTED && pcf50606_usb_charging_enabled())
+ status |= POWER_INPUT_USB_CHARGER;
+ /* CHECK: Can the device be powered from USB w/o charging it? */
+#endif
+
+ return status;
}
+
+#ifdef HAVE_USB_POWER
+bool usb_charging_enable(bool on)
+{
+ bool rc = false;
+ int irqlevel;
+ logf("usb_charging_enable(%s)\n", on ? "on" : "off" );
+ irqlevel = disable_irq_save();
+ pcf50606_set_usb_charging(on);
+ rc = on;
+ restore_irq(irqlevel);
+ return rc;
+}
+#endif /* HAVE_USB_POWER */
+
#endif /* CONFIG_CHARGING */
/* Returns true if the unit is charging the batteries. */
-bool charging_state(void) {
+bool charging_state(void)
+{
return (GPIO_READ & 0x00800000)?true:false;
}
+bool usb_charging_enabled(void)
+{
+ bool rc = false;
+ /* TODO: read the state of the GPOOD2 register...
+ * (this also means to set the irq level here) */
+ rc = pcf50606_usb_charging_enabled();
+
+ logf("usb charging %s", rc ? "enabled" : "disabled" );
+ return rc;
+}
void ide_power_enable(bool on)
{
@@ -90,5 +125,3 @@ void power_off(void)
asm("halt");
while(1);
}
-
-#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 @@
#include "usb.h"
#if CONFIG_TUNER
-
bool tuner_power(bool status)
{
(void)status;
@@ -44,10 +43,20 @@ void power_init(void)
or_b(0x20, &PBDRL); /* hold power */
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
+ unsigned int status = POWER_INPUT_NONE;
+
/* FM or V2 can also charge from the USB port */
- return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF);
+ if (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF)
+ status = POWER_INPUT_MAIN_CHARGER;
+
+#ifdef HAVE_USB_POWER
+ if (usb_detect() == USB_INSERTED)
+ status |= POWER_INPUT_USB_CHARGER;
+#endif
+
+ return status;
}
/* 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)
{
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
/* Player */
- return (PADR & 1) == 0;
+ return ((PADR & 1) == 0) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
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)
charger_enable(false); /* Default to charger OFF */
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
/* Recorder */
- return adc_read(ADC_EXT_POWER) > 0x100;
+ return (adc_read(ADC_EXT_POWER) > 0x100) ?
+ POWER_INPUT_MAIN_CHARGER : POWER_INPUT_NONE;
}
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 @@
#ifdef HAVE_USBSTACK
#include "usb_core.h"
#endif
-#ifdef IRIVER_H300_SERIES
-#include "pcf50606.h" /* for pcf50606_usb_charging_... */
-#endif
#include "logf.h"
/* Conditions under which we want the entire driver */
@@ -588,40 +585,6 @@ bool usb_powered(void)
{
return usb_state == USB_POWERED;
}
-
-#if CONFIG_CHARGING
-bool usb_charging_enable(bool on)
-{
- bool rc = false;
-#ifdef IRIVER_H300_SERIES
- int irqlevel;
- logf("usb_charging_enable(%s)\n", on ? "on" : "off" );
- irqlevel = disable_irq_save();
- pcf50606_set_usb_charging(on);
- rc = on;
- restore_irq(irqlevel);
-#else
- /* TODO: implement it for other targets... */
- (void)on;
-#endif
- return rc;
-}
-
-bool usb_charging_enabled(void)
-{
- bool rc = false;
-#ifdef IRIVER_H300_SERIES
- /* TODO: read the state of the GPOOD2 register...
- * (this also means to set the irq level here) */
- rc = pcf50606_usb_charging_enabled();
-#else
- /* TODO: implement it for other targets... */
-#endif
-
- logf("usb charging %s", rc ? "enabled" : "disabled" );
- return rc;
-}
-#endif
#endif
#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 @@
#include "string.h"
#include "lcd.h"
+#include "power.h"
+
#include "ata.h" /* for volume definitions */
extern char having_new_lcd;
@@ -212,9 +214,13 @@ bool charging_state(void)
return false;
}
-bool charger_inserted(void)
+unsigned int power_input_status(void)
{
- return false;
+#ifdef HAVE_BATTERY_SWITCH
+ return POWER_INPUT_BATTERY;
+#else
+ return POWER_INPUT_NONE;
+#endif
}
#ifdef HAVE_SPDIF_POWER
@@ -241,6 +247,11 @@ bool usb_powered(void)
}
#if CONFIG_CHARGING
+bool charger_inserted(void)
+{
+ return false;
+}
+
bool usb_charging_enable(bool on)
{
(void)on;