summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c30
1 files changed, 27 insertions, 3 deletions
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)
109int 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
110char power_message[POWER_MESSAGE_LEN] = ""; /* message that's shown in 115char 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? */
124int charge_state = 0; /* at the beginning, the
125 charger does nothing */
126
127static int percent_to_volt_charge[11] = /* voltages (centivolt) of 0%, 10%, 129static 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