diff options
Diffstat (limited to 'firmware')
-rw-r--r-- | firmware/drivers/power.c | 5 | ||||
-rw-r--r-- | firmware/export/powermgmt.h | 5 | ||||
-rw-r--r-- | firmware/powermgmt.c | 30 |
3 files changed, 34 insertions, 6 deletions
diff --git a/firmware/drivers/power.c b/firmware/drivers/power.c index 83300fe1d4..563ff3e25c 100644 --- a/firmware/drivers/power.c +++ b/firmware/drivers/power.c | |||
@@ -45,8 +45,9 @@ bool charger_inserted(void) | |||
45 | return adc_read(ADC_EXT_POWER) > 0x100; | 45 | return adc_read(ADC_EXT_POWER) > 0x100; |
46 | #else | 46 | #else |
47 | #ifdef HAVE_FMADC | 47 | #ifdef HAVE_FMADC |
48 | /* FM */ | 48 | /* FM or V2, can also charge from the USB port */ |
49 | return adc_read(ADC_CHARGE_REGULATOR) < 0x1FF; | 49 | return (adc_read(ADC_CHARGE_REGULATOR) < 0x1FF) || |
50 | (adc_read(ADC_USB_POWER) < 0x1FF); | ||
50 | #else | 51 | #else |
51 | /* Player */ | 52 | /* Player */ |
52 | return (PADR & 1) == 0; | 53 | return (PADR & 1) == 0; |
diff --git a/firmware/export/powermgmt.h b/firmware/export/powermgmt.h index f6b1a64b68..c772195d64 100644 --- a/firmware/export/powermgmt.h +++ b/firmware/export/powermgmt.h | |||
@@ -68,10 +68,13 @@ extern int powermgmt_last_cycle_level; /* which level had the batteries | |||
68 | extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */ | 68 | extern int battery_lazyness[20]; /* how does the battery react when plugging in/out the charger */ |
69 | void enable_trickle_charge(bool on); | 69 | void enable_trickle_charge(bool on); |
70 | extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ | 70 | extern int trickle_sec; /* trickle charge: How many seconds per minute are we charging actually? */ |
71 | extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
72 | 71 | ||
73 | #endif /* HAVE_CHARGE_CTRL */ | 72 | #endif /* HAVE_CHARGE_CTRL */ |
74 | 73 | ||
74 | #if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION) | ||
75 | extern int charge_state; /* tells what the charger is doing (for info display): 0: decharging/charger off, 1: charge, 2: top-off, 3: trickle */ | ||
76 | #endif | ||
77 | |||
75 | #define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ | 78 | #define CURRENT_NORMAL 145 /* usual current in mA when using the AJB including some disk/backlight/... activity */ |
76 | #define CURRENT_USB 500 /* usual current in mA in USB mode */ | 79 | #define CURRENT_USB 500 /* usual current in mA in USB mode */ |
77 | #define CURRENT_BACKLIGHT 30 /* additional current when backlight is always on */ | 80 | #define CURRENT_BACKLIGHT 30 /* additional current when backlight is always on */ |
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c index 374f10c8f8..c7c299092c 100644 --- a/firmware/powermgmt.c +++ b/firmware/powermgmt.c | |||
@@ -105,6 +105,11 @@ void set_battery_capacity(int capacity) | |||
105 | battery_capacity = 1500; | 105 | battery_capacity = 1500; |
106 | } | 106 | } |
107 | 107 | ||
108 | #if defined(HAVE_CHARGE_CTRL) || defined(HAVE_LIION) | ||
109 | int charge_state = 0; /* at the beginning, the | ||
110 | charger does nothing */ | ||
111 | #endif | ||
112 | |||
108 | #ifdef HAVE_CHARGE_CTRL | 113 | #ifdef HAVE_CHARGE_CTRL |
109 | 114 | ||
110 | char power_message[POWER_MESSAGE_LEN] = ""; /* message that's shown in | 115 | char power_message[POWER_MESSAGE_LEN] = ""; /* message that's shown in |
@@ -121,9 +126,6 @@ int trickle_sec = 0; /* how many seconds should the | |||
121 | charger be enabled per | 126 | charger be enabled per |
122 | minute for trickle | 127 | minute for trickle |
123 | charging? */ | 128 | charging? */ |
124 | int charge_state = 0; /* at the beginning, the | ||
125 | charger does nothing */ | ||
126 | |||
127 | static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%, | 129 | static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%, |
128 | ... 100% when charging enabled */ | 130 | ... 100% when charging enabled */ |
129 | { | 131 | { |
@@ -428,6 +430,9 @@ static void power_thread(void) | |||
428 | int i; | 430 | int i; |
429 | int avg, ok_samples, spin_samples; | 431 | int avg, ok_samples, spin_samples; |
430 | int current = 0; | 432 | int current = 0; |
433 | #ifdef HAVE_LIION | ||
434 | int charging_current; | ||
435 | #endif | ||
431 | #ifdef HAVE_CHARGE_CTRL | 436 | #ifdef HAVE_CHARGE_CTRL |
432 | int delta; | 437 | int delta; |
433 | int charged_time = 0; | 438 | int charged_time = 0; |
@@ -517,6 +522,24 @@ static void power_thread(void) | |||
517 | #endif /* MEM == 8 */ | 522 | #endif /* MEM == 8 */ |
518 | #endif /* HAVE_CHARGE_CONTROL */ | 523 | #endif /* HAVE_CHARGE_CONTROL */ |
519 | 524 | ||
525 | #ifdef HAVE_LIION | ||
526 | /* We use the information from the ADC_EXT_POWER ADC channel, which | ||
527 | tells us the charging current from the LTC1734. When DC is | ||
528 | connected (either via the external adapter, or via USB), we try | ||
529 | to determine if it is actively charging or only maintaining the | ||
530 | charge. My tests show that ADC readings is below about 0x80 means | ||
531 | that the LTC1734 is only maintaining the charge. */ | ||
532 | if(charger_inserted()) { | ||
533 | charging_current = adc_read(ADC_EXT_POWER); | ||
534 | if(charging_current < 0x80) { | ||
535 | charge_state = 2; /* Trickle */ | ||
536 | } else { | ||
537 | charge_state = 1; /* Charging */ | ||
538 | } | ||
539 | } else { | ||
540 | charge_state = 0; /* Not charging */ | ||
541 | } | ||
542 | #else | ||
520 | #ifdef HAVE_CHARGE_CTRL | 543 | #ifdef HAVE_CHARGE_CTRL |
521 | 544 | ||
522 | if (charge_pause > 0) | 545 | if (charge_pause > 0) |
@@ -754,6 +777,7 @@ static void power_thread(void) | |||
754 | powermgmt_last_cycle_startstop_min++; | 777 | powermgmt_last_cycle_startstop_min++; |
755 | 778 | ||
756 | #endif /* HAVE_CHARGE_CTRL*/ | 779 | #endif /* HAVE_CHARGE_CTRL*/ |
780 | #endif /* HAVE_LIION */ | ||
757 | 781 | ||
758 | /* sleep for roughly a minute */ | 782 | /* sleep for roughly a minute */ |
759 | #ifdef HAVE_CHARGE_CTRL | 783 | #ifdef HAVE_CHARGE_CTRL |