summaryrefslogtreecommitdiffstats
path: root/firmware
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
committerJens Arnold <amiconn@rockbox.org>2006-06-06 22:23:52 +0000
commit0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f (patch)
treee3e77d4e6b25b82c82b3570cd8c4a988c7788e66 /firmware
parent8c9e22580e220b793130ed3ac67b9c54e85b3d0f (diff)
downloadrockbox-0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f.tar.gz
rockbox-0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f.tar.bz2
rockbox-0dd1f8ec11f28fe34c93ba97af95eb2be2fef44f.zip
Work-in-progress rework of charging status reading & display: * Changed several charging related HAVE_* macros into one multi-value CONFIG_CHARGING. * Always use proper macros for charging states. * Battery symbol charging animation now starts from current level on all targets with charging. Two-colour animation kept for non-b&w targets. Round down fill level while charging as before, but round to nearest pixel value for discharging on all targets. * Charging anim fixed on player. * Some code cleanup.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10080 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware')
-rw-r--r--firmware/backlight.c20
-rw-r--r--firmware/drivers/button.c4
-rw-r--r--firmware/drivers/power.c28
-rw-r--r--firmware/export/config-fmrecorder.h4
-rw-r--r--firmware/export/config-gigabeat.h4
-rw-r--r--firmware/export/config-gmini120.h4
-rw-r--r--firmware/export/config-gminisp.h4
-rw-r--r--firmware/export/config-h100.h8
-rw-r--r--firmware/export/config-h120.h8
-rw-r--r--firmware/export/config-h300.h10
-rw-r--r--firmware/export/config-iaudiox5.h4
-rw-r--r--firmware/export/config-ifp7xx.h4
-rw-r--r--firmware/export/config-ipod3g.h4
-rw-r--r--firmware/export/config-ipod4g.h4
-rw-r--r--firmware/export/config-ipodcolor.h4
-rw-r--r--firmware/export/config-ipodmini.h4
-rwxr-xr-xfirmware/export/config-ipodmini2g.h4
-rw-r--r--firmware/export/config-ipodnano.h4
-rw-r--r--firmware/export/config-ipodvideo.h6
-rw-r--r--firmware/export/config-player.h4
-rw-r--r--firmware/export/config-recorder.h7
-rw-r--r--firmware/export/config-recorderv2.h4
-rw-r--r--firmware/export/config.h5
-rw-r--r--firmware/export/power.h6
-rw-r--r--firmware/export/powermgmt.h22
-rw-r--r--firmware/powermgmt.c68
26 files changed, 112 insertions, 136 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c
index aac438c673..76ffc6f0e4 100644
--- a/firmware/backlight.c
+++ b/firmware/backlight.c
@@ -156,14 +156,14 @@ static struct event_queue backlight_queue;
static int backlight_timer;
static int backlight_timeout = 5*HZ;
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
static int backlight_timeout_plugged = 5*HZ;
#endif
#ifdef HAVE_REMOTE_LCD
static int remote_backlight_timer;
static int remote_backlight_timeout = 5*HZ;
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
static int remote_backlight_timeout_plugged = 5*HZ;
#endif
#endif
@@ -370,7 +370,7 @@ void backlight_thread(void)
{
#ifdef HAVE_REMOTE_LCD
case REMOTE_BACKLIGHT_ON:
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
@@ -399,7 +399,7 @@ void backlight_thread(void)
#endif /* HAVE_REMOTE_LCD */
case BACKLIGHT_ON:
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
@@ -447,7 +447,7 @@ void backlight_thread(void)
static void backlight_tick(void)
{
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
static bool charger_was_inserted = false;
bool charger_is_inserted = charger_inserted()
#ifdef HAVE_USB_POWER
@@ -463,7 +463,7 @@ static void backlight_tick(void)
#endif
}
charger_was_inserted = charger_is_inserted;
-#endif /* HAVE_CHARGING */
+#endif /* CONFIG_CHARGING */
if(backlight_timer)
{
@@ -535,7 +535,7 @@ bool is_backlight_on(void)
/* return value in ticks; 0 means always on, <0 means always off */
int backlight_get_current_timeout(void)
{
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
@@ -558,7 +558,7 @@ void backlight_set_timeout(int index)
backlight_on();
}
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
void backlight_set_timeout_plugged(int index)
{
if((unsigned)index >= sizeof(backlight_timeout_value))
@@ -589,7 +589,7 @@ void remote_backlight_set_timeout(int index)
remote_backlight_on();
}
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
void remote_backlight_set_timeout_plugged(int index)
{
if((unsigned)index >= sizeof(backlight_timeout_value))
@@ -603,7 +603,7 @@ void remote_backlight_set_timeout_plugged(int index)
/* return value in ticks; 0 means always on, <0 means always off */
int remote_backlight_get_current_timeout(void)
{
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
if (charger_inserted()
#ifdef HAVE_USB_POWER
|| usb_powered()
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c
index 6513fb4a3a..216c51ea15 100644
--- a/firmware/drivers/button.c
+++ b/firmware/drivers/button.c
@@ -490,7 +490,7 @@ static void button_tick(void)
|| btn == BUTTON_RC_STOP
#endif
) &&
-#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
+#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
!charger_inserted() &&
#endif
repeat_count > POWEROFF_COUNT)
@@ -1248,7 +1248,7 @@ static int button_read(void)
backlight_on();
}
/* TODO: add light handling for the remote */
-
+
hold_button = button_hold();
remote_hold_button = remote_button_hold();
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c
index c4b9fb5b7d..bda03b0f8b 100644
--- a/firmware/drivers/power.c
+++ b/firmware/drivers/power.c
@@ -29,7 +29,7 @@
#include "pcf50606.h"
#include "usb.h"
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
bool charger_enabled;
#endif
@@ -92,7 +92,7 @@ void power_init(void)
or_b(0x20, &PBIORL);
or_b(0x20, &PBDRL); /* hold power */
#endif
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
PBCR2 &= ~0x0c00; /* GPIO for PB5 */
or_b(0x20, &PBIORL); /* Set charging control bit to output */
charger_enable(false); /* Default to charger OFF */
@@ -106,7 +106,7 @@ void power_init(void)
}
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
bool charger_inserted(void)
{
#if defined(IRIVER_H100_SERIES) || defined(IRIVER_H300_SERIES)
@@ -115,7 +115,7 @@ bool charger_inserted(void)
return (P7 & 0x80) == 0;
#elif defined(IAUDIO_X5)
return (GPIO1_READ & 0x01000000)?true:false;
-#elif defined(HAVE_CHARGE_CTRL)
+#elif CONFIG_CHARGING == CHARGING_CONTROL
/* Recorder */
return adc_read(ADC_EXT_POWER) > 0x100;
#elif defined (HAVE_FMADC)
@@ -133,9 +133,9 @@ bool charger_inserted(void)
return (PADR & 1) == 0;
#endif
}
-#endif /* HAVE_CHARGING */
+#endif /* CONFIG_CHARGING */
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
void charger_enable(bool on)
{
if(on)
@@ -151,14 +151,22 @@ void charger_enable(bool on)
}
#endif
-#ifdef HAVE_CHARGE_STATE
+#if CONFIG_CHARGING == CHARGING_MONITOR
/* Returns true if the unit is charging the batteries. */
bool charging_state(void) {
-#if defined(IRIVER_H100_SERIES)
+#if CONFIG_BATTERY == BATT_LIION2200
+ /* We use the information from the ADC_EXT_POWER ADC channel, which
+ tells us the charging current from the LTC1734. When DC is
+ connected (either via the external adapter, or via USB), we try
+ to determine if it is actively charging or only maintaining the
+ charge. My tests show that ADC readings below about 0x80 means
+ that the LTC1734 is only maintaining the charge. */
+ return adc_read(ADC_EXT_POWER) >= 0x80;
+#elif defined(IRIVER_H100_SERIES) /* FIXME */
return charger_inserted();
-#elif defined(IRIVER_H300_SERIES)
+#elif defined IRIVER_H300_SERIES
return (GPIO_READ & 0x00800000)?true:false;
-#elif defined(IPOD_VIDEO)
+#elif defined IPOD_VIDEO
return (GPIOB_INPUT_VAL & 0x01)?false:true;
#endif
}
diff --git a/firmware/export/config-fmrecorder.h b/firmware/export/config-fmrecorder.h
index 8711640e93..7a78d48822 100644
--- a/firmware/export/config-fmrecorder.h
+++ b/firmware/export/config-fmrecorder.h
@@ -90,8 +90,8 @@
/* How to detect USB */
#define USB_FMRECORDERSTYLE 1
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging with monitoring */
+#define CONFIG_CHARGING CHARGING_MONITOR
/* The start address index for ROM builds */
/* #define ROM_START 0x14010 for behind original Archos */
diff --git a/firmware/export/config-gigabeat.h b/firmware/export/config-gigabeat.h
index 83a92ce140..1ebbdbf908 100644
--- a/firmware/export/config-gigabeat.h
+++ b/firmware/export/config-gigabeat.h
@@ -61,8 +61,8 @@
#define BATTERY_SCALE_FACTOR 23437 /* FIX: this value is picked at random */
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-gmini120.h b/firmware/export/config-gmini120.h
index 42424bb7b1..66ba7af09e 100644
--- a/firmware/export/config-gmini120.h
+++ b/firmware/export/config-gmini120.h
@@ -54,8 +54,8 @@
#define BATTERY_SCALE_FACTOR 6465
/* chosen values at random -- jyp */
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+#define CONFIG_CHARGING CHARGING_SIMPLE
#define CPU_FREQ 30000000
/* approximate value (and false in general since freq is variable) */
diff --git a/firmware/export/config-gminisp.h b/firmware/export/config-gminisp.h
index e066661061..8df7b0f5a1 100644
--- a/firmware/export/config-gminisp.h
+++ b/firmware/export/config-gminisp.h
@@ -45,8 +45,8 @@
#define BATTERY_SCALE_FACTOR 6465
/* chosen values at random -- jyp */
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+#define CONFIG_CHARGING CHARGING_SIMPLE
#define CPU_FREQ 30000000
/* approximate value (and false in general since freq is variable) */
diff --git a/firmware/export/config-h100.h b/firmware/export/config-h100.h
index d53adcec14..4461cc2d44 100644
--- a/firmware/export/config-h100.h
+++ b/firmware/export/config-h100.h
@@ -89,11 +89,9 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
-
-/* For units with a hardware charger that reports charge state */
-#define HAVE_CHARGE_STATE 1
+/* Hardware controlled charging */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
+#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-h120.h b/firmware/export/config-h120.h
index 34f5059b69..f2cd8c2665 100644
--- a/firmware/export/config-h120.h
+++ b/firmware/export/config-h120.h
@@ -84,11 +84,9 @@
/* Define if we have a hardware defect that causes ticking on the audio line */
#define HAVE_REMOTE_LCD_TICKING
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
-
-/* For units with a hardware charger that reports charge state */
-#define HAVE_CHARGE_STATE 1
+/* Hardware controlled charging */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
+#define CONFIG_CHARGING CHARGING_MONITOR /* FIXME: remove that once monitoring is fixed properly */
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-h300.h b/firmware/export/config-h300.h
index ae1940c987..7ed54958ca 100644
--- a/firmware/export/config-h300.h
+++ b/firmware/export/config-h300.h
@@ -85,14 +85,8 @@
/* Define if we have a hardware defect that causes ticking on the audio line */
#define HAVE_REMOTE_LCD_TICKING
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
-
-/* For units with a hardware charger that reports charge state */
-#define HAVE_CHARGE_STATE 1
-
-/* define this if the hardware can be powered off while charging */
-#define HAVE_POWEROFF_WHILE_CHARGING
+/* Hardware controlled charging with monitoring */
+#define CONFIG_CHARGING CHARGING_MONITOR
/* The size of the flash ROM */
#define FLASH_SIZE 0x400000
diff --git a/firmware/export/config-iaudiox5.h b/firmware/export/config-iaudiox5.h
index 4690feb8fe..b16a142a28 100644
--- a/firmware/export/config-iaudiox5.h
+++ b/firmware/export/config-iaudiox5.h
@@ -65,8 +65,8 @@
#define HAVE_TLV320
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ifp7xx.h b/firmware/export/config-ifp7xx.h
index 9e5a432260..6247625618 100644
--- a/firmware/export/config-ifp7xx.h
+++ b/firmware/export/config-ifp7xx.h
@@ -56,8 +56,8 @@
#define BATTERY_SCALE_FACTOR 16665 /* FIX: this value is picked at random */
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipod3g.h b/firmware/export/config-ipod3g.h
index a611dfdcaa..b3b5d14e85 100644
--- a/firmware/export/config-ipod3g.h
+++ b/firmware/export/config-ipod3g.h
@@ -68,8 +68,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipod4g.h b/firmware/export/config-ipod4g.h
index fa664acdb6..46abbdf72b 100644
--- a/firmware/export/config-ipod4g.h
+++ b/firmware/export/config-ipod4g.h
@@ -70,8 +70,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodcolor.h b/firmware/export/config-ipodcolor.h
index b8f3d89346..e063e93737 100644
--- a/firmware/export/config-ipodcolor.h
+++ b/firmware/export/config-ipodcolor.h
@@ -69,8 +69,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodmini.h b/firmware/export/config-ipodmini.h
index 64be801577..4871ea0acc 100644
--- a/firmware/export/config-ipodmini.h
+++ b/firmware/export/config-ipodmini.h
@@ -70,8 +70,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodmini2g.h b/firmware/export/config-ipodmini2g.h
index 454309a786..adbb0973ac 100755
--- a/firmware/export/config-ipodmini2g.h
+++ b/firmware/export/config-ipodmini2g.h
@@ -73,8 +73,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodnano.h b/firmware/export/config-ipodnano.h
index b7116bf249..3d4deb3abd 100644
--- a/firmware/export/config-ipodnano.h
+++ b/firmware/export/config-ipodnano.h
@@ -74,8 +74,8 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-//#define HAVE_CHARGING 1
+/* Hardware controlled charging? FIXME */
+//#define CONFIG_CHARGING CHARGING_SIMPLE
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
diff --git a/firmware/export/config-ipodvideo.h b/firmware/export/config-ipodvideo.h
index 1bbcfec157..79ef1a85ac 100644
--- a/firmware/export/config-ipodvideo.h
+++ b/firmware/export/config-ipodvideo.h
@@ -74,14 +74,12 @@
#define BATTERY_TYPES_COUNT 1 /* only one type */
#define BATTERY_SCALE_FACTOR 5865
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging with monitoring */
+#define CONFIG_CHARGING CHARGING_MONITOR
/* define this if the hardware can be powered off while charging */
//#define HAVE_POWEROFF_WHILE_CHARGING
-#define HAVE_CHARGE_STATE 1
-
/* The start address index for ROM builds */
#define ROM_START 0x00000000
diff --git a/firmware/export/config-player.h b/firmware/export/config-player.h
index 324a0a2300..3dfdb0e727 100644
--- a/firmware/export/config-player.h
+++ b/firmware/export/config-player.h
@@ -67,8 +67,8 @@
/* How to detect USB */
#define USB_PLAYERSTYLE 1
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging */
+#define CONFIG_CHARGING CHARGING_SIMPLE
/* The start address index for ROM builds */
/* #define ROM_START 0xD010 for behind original Archos */
diff --git a/firmware/export/config-recorder.h b/firmware/export/config-recorder.h
index 92dd07695d..854b1c1ade 100644
--- a/firmware/export/config-recorder.h
+++ b/firmware/export/config-recorder.h
@@ -45,9 +45,6 @@
/* Define this if you have a SH7034 */
#define CONFIG_CPU SH7034
-/* Define this if you have charging control */
-#define HAVE_CHARGE_CTRL
-
/* Define this if you have ATA power-off control */
#define HAVE_ATA_POWER_OFF
@@ -80,8 +77,8 @@
/* How to detect USB */
#define USB_RECORDERSTYLE 1
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Software controlled charging */
+#define CONFIG_CHARGING CHARGING_CONTROL
/* The start address index for ROM builds */
/* #define ROM_START 0x11010 for behind original Archos */
diff --git a/firmware/export/config-recorderv2.h b/firmware/export/config-recorderv2.h
index b508836080..09823cffb2 100644
--- a/firmware/export/config-recorderv2.h
+++ b/firmware/export/config-recorderv2.h
@@ -90,8 +90,8 @@
/* How to detect USB */
#define USB_FMRECORDERSTYLE 1
-/* Define this if the platform can charge batteries */
-#define HAVE_CHARGING 1
+/* Hardware controlled charging with monitoring */
+#define CONFIG_CHARGING CHARGING_MONITOR
/* The start address index for ROM builds */
/* #define ROM_START 0x12010 for behind original Archos */
diff --git a/firmware/export/config.h b/firmware/export/config.h
index d919b8b4f6..910aeca4eb 100644
--- a/firmware/export/config.h
+++ b/firmware/export/config.h
@@ -68,6 +68,11 @@
#define BATT_3AAA 1000 /* Ondio */
#define BATT_LIPOL1300 1300 /* the type used in iRiver h1x0 models */
+/* CONFIG_CHARGING */
+#define CHARGING_SIMPLE 1 /* Simple, hardware controlled charging */
+#define CHARGING_MONITOR 2 /* Hardware controlled charging with monitoring */
+#define CHARGING_CONTROL 3 /* Software controlled charging */
+
/* CONFIG_LCD */
#define LCD_GMINI100 0
#define LCD_SSD1815 1 /* as used by Archos Recorders and Ondios */
diff --git a/firmware/export/power.h b/firmware/export/power.h
index be8ebda5b0..dc6c09d9f9 100644
--- a/firmware/export/power.h
+++ b/firmware/export/power.h
@@ -19,12 +19,12 @@
#ifndef _POWER_H_
#define _POWER_H_
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
extern bool charger_enabled;
void charger_enable(bool on);
#endif
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
bool charger_inserted(void);
#endif
@@ -35,7 +35,7 @@ void ide_power_enable(bool on);
void power_init(void);
-# ifdef HAVE_CHARGE_STATE
+# if CONFIG_CHARGING == CHARGING_MONITOR
bool charging_state(void);
# endif
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h
index 6c31aeec52..30fe60c293 100644
--- a/firmware/export/powermgmt.h
+++ b/firmware/export/powermgmt.h
@@ -28,7 +28,7 @@
#ifndef SIMULATOR
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
#define START_TOPOFF_CHG 85 /* Battery % to start at top-off */
#define START_TRICKLE_CHG 95 /* Battery % to start at trickle */
@@ -59,23 +59,21 @@ extern int pid_p; /* PID proportional term */
extern int pid_i; /* PID integral term */
extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */
-#endif /* HAVE_CHARGE_CTRL */
+#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
-#if defined(HAVE_CHARGE_CTRL) || \
- (CONFIG_BATTERY == BATT_LIION2200) || \
- defined(HAVE_CHARGE_STATE)
-typedef enum {
- DISCHARGING,
- CHARGING,
- TOPOFF,
- TRICKLE
+#if CONFIG_CHARGING >= CHARGING_MONITOR
+typedef enum { /* sorted by increasing charging current */
+ DISCHARGING = 0,
+ TRICKLE, /* Can occur for CONFIG_CHARGING >= CHARGING_MONITOR */
+ TOPOFF, /* Can occur for CONFIG_CHARGING == CHARGING_CONTROL */
+ CHARGING /* Can occur for all CONFIG_CHARGING options */
} charge_state_type;
/* tells what the charger is doing */
extern charge_state_type charge_state;
-#endif /* defined(HAVE_CHARGE_CTRL) || (CONFIG_BATTERY == BATT_LIION2200) */
+#endif /* CONFIG_CHARGING >= CHARGING_MONITOR */
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
/*
* Flag that the charger has been plugged in/removed: this is set for exactly
* one time through the power loop when the charger has been plugged in.
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 15977caed6..ee01fd862d 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -64,7 +64,7 @@
* in it (one sample per minute). This is only for very low level debug.
*/
#undef DEBUG_FILE
-#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
+#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
#include "file.h"
#define DEBUG_FILE_NAME "/powermgmt.csv"
#define DEBUG_MESSAGE_LEN 133
@@ -190,7 +190,7 @@ static const short percent_to_volt_discharge[BATTERY_TYPES_COUNT][11] =
#endif
};
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
charger_input_state_type charger_input_state IDATA_ATTR;
/* voltages (centivolt) of 0%, 10%, ... 100% when charging enabled */
@@ -207,15 +207,13 @@ static const short percent_to_volt_charge[11] =
476, 544, 551, 556, 561, 564, 566, 576, 582, 584, 585 /* NiMH */
#endif
};
-#endif /* HAVE_CHARGING */
+#endif /* CONFIG_CHARGING */
-#if defined(HAVE_CHARGE_CTRL) || \
- CONFIG_BATTERY == BATT_LIION2200 || \
- defined(HAVE_CHARGE_STATE)
+#if CONFIG_CHARGING >= CHARGING_MONITOR
charge_state_type charge_state; /* charging mode */
#endif
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
int long_delta; /* long term delta battery voltage */
int short_delta; /* short term delta battery voltage */
bool disk_activity_last_cycle = false; /* flag set to aid charger time
@@ -235,7 +233,7 @@ int trickle_sec = 0; /* how many seconds should the
charging? */
int pid_p = 0; /* PID proportional term */
int pid_i = 0; /* PID integral term */
-#endif /* HAVE_CHARGE_CTRL */
+#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
/*
* Average battery voltage and charger voltage, filtered via a digital
@@ -366,7 +364,7 @@ static void battery_status_update(void)
{
int level;
-#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)
+#if CONFIG_CHARGING >= CHARGING_MONITOR
if (charge_state == DISCHARGING) {
level = voltage_to_percent(battery_centivolts,
percent_to_volt_discharge[battery_type]);
@@ -397,7 +395,7 @@ static void battery_status_update(void)
/* calculate estimated remaining running time */
/* discharging: remaining running time */
/* charging: remaining charging time */
-#if defined(HAVE_CHARGE_CTRL) || defined(HAVE_CHARGE_STATE)
+#if CONFIG_CHARGING >= CHARGING_MONITOR
if (charge_state == CHARGING) {
powermgmt_est_runningtime_min = (100 - level) * battery_capacity / 100
* 60 / (CURRENT_MAX_CHG - runcurrent());
@@ -425,7 +423,7 @@ static void handle_auto_poweroff(void)
long timeout = poweroff_idle_timeout_value[poweroff_timeout]*60*HZ;
int audio_stat = audio_status();
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
/*
* Inhibit shutdown as long as the charger is plugged in. If it is
* unplugged, wait for a timeout period and then shut down.
@@ -458,7 +456,7 @@ static void handle_auto_poweroff(void)
if(TIME_AFTER(current_tick, sleeptimer_endtick))
{
audio_stop();
-#if defined(HAVE_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
+#if defined(CONFIG_CHARGING) && !defined(HAVE_POWEROFF_WHILE_CHARGING)
if((charger_input_state == CHARGER) ||
(charger_input_state == CHARGER_PLUGGED))
{
@@ -538,7 +536,7 @@ static void power_thread_sleep(int ticks)
while (ticks > 0) {
-#ifdef HAVE_CHARGING
+#ifdef CONFIG_CHARGING
/*
* Detect charger plugged/unplugged transitions. On a plugged or
* unplugged event, we return immediately, run once through the main
@@ -577,7 +575,7 @@ static void power_thread_sleep(int ticks)
}
}
#endif
-#ifdef HAVE_CHARGE_STATE
+#if CONFIG_CHARGING == CHARGING_MONITOR
switch (charger_input_state) {
case CHARGER_UNPLUGGED:
case NO_CHARGER:
@@ -593,7 +591,7 @@ static void power_thread_sleep(int ticks)
break;
}
-#endif /* HAVE_CHARGE_STATE */
+#endif /* CONFIG_CHARGING == CHARGING_MONITOR */
small_ticks = MIN(HZ/2, ticks);
sleep(small_ticks);
@@ -628,13 +626,13 @@ static void power_thread_sleep(int ticks)
battery_status_update();
}
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
if (ata_disk_is_active()) {
/* flag hdd use for charging calculation */
disk_activity_last_cycle = true;
}
#endif
-#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
+#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
/*
* If we have a lot of pending writes or if the disk is spining,
* fsync the debug log file.
@@ -660,7 +658,7 @@ static void power_thread(void)
{
int i;
short *phps, *phpd; /* power history rotation pointers */
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
unsigned int target_voltage = TRICKLE_VOLTAGE; /* desired topoff/trickle
* voltage level */
int charge_max_time_idle = 0; /* max. charging duration, calculated at
@@ -678,7 +676,7 @@ static void power_thread(void)
BATT_AVE_SAMPLES;
battery_centivolts = avgbat / BATT_AVE_SAMPLES / 10000;
-#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
+#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
fd = -1;
wrcount = 0;
#endif
@@ -694,25 +692,7 @@ static void power_thread(void)
/* insert new value at the start, in centivolts 8-) */
power_history[0] = battery_centivolts;
-#if CONFIG_BATTERY == BATT_LIION2200
- /* We use the information from the ADC_EXT_POWER ADC channel, which
- tells us the charging current from the LTC1734. When DC is
- connected (either via the external adapter, or via USB), we try
- to determine if it is actively charging or only maintaining the
- charge. My tests show that ADC readings below about 0x80 means
- that the LTC1734 is only maintaining the charge. */
- if(charger_inserted()) {
- if(adc_read(ADC_EXT_POWER) < 0x80) {
- charge_state = TRICKLE;
- } else {
- charge_state = CHARGING;
- }
- } else {
- charge_state = DISCHARGING;
- }
-#endif /* # if CONFIG_BATTERY == BATT_LIION2200 */
-
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
if (charger_input_state == CHARGER_PLUGGED) {
pid_p = 0;
pid_i = 0;
@@ -876,7 +856,7 @@ static void power_thread(void)
}
}
}
- else if (charge_state > CHARGING) /* top off or trickle */
+ else if (charge_state != DISCHARGING) /* top off or trickle */
{
/*
*Time to switch from topoff to trickle?
@@ -946,11 +926,11 @@ static void power_thread(void)
snprintf(power_message, POWER_MESSAGE_LEN, "Charger: discharge");
}
-#endif /* end HAVE_CHARGE_CTRL */
+#endif /* CONFIG_CHARGING == CHARGING_CONTROL */
/* sleep for a minute */
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
if(trickle_sec > 0) {
charger_enable(true);
power_thread_sleep(HZ * trickle_sec);
@@ -962,7 +942,7 @@ static void power_thread(void)
power_thread_sleep(HZ * 60);
#endif
-#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
+#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
if(usb_inserted()) {
if(fd >= 0) {
/* It is probably too late to close the file but we can try...*/
@@ -992,7 +972,7 @@ static void power_thread(void)
#endif
handle_auto_poweroff();
-#ifdef HAVE_CHARGE_CTRL
+#if CONFIG_CHARGING == CHARGING_CONTROL
powermgmt_last_cycle_startstop_min++;
#endif
}
@@ -1029,7 +1009,7 @@ void cancel_shutdown(void)
void shutdown_hw(void)
{
#ifndef SIMULATOR
-#if defined(DEBUG_FILE) && defined(HAVE_CHARGE_CTRL)
+#if defined(DEBUG_FILE) && (CONFIG_CHARGING == CHARGING_CONTROL)
if(fd >= 0) {
close(fd);
fd = -1;