summaryrefslogtreecommitdiff
path: root/firmware
diff options
context:
space:
mode:
Diffstat (limited to 'firmware')
-rw-r--r--firmware/export/kernel.h2
-rw-r--r--firmware/powermgmt.c56
2 files changed, 4 insertions, 54 deletions
diff --git a/firmware/export/kernel.h b/firmware/export/kernel.h
index 6f2df802be..7b76e74e18 100644
--- a/firmware/export/kernel.h
+++ b/firmware/export/kernel.h
@@ -43,6 +43,8 @@
43#define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27))) 43#define SYS_MMC_EXTRACTED ((SYS_EVENT | ((long)7 << 27)))
44#define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27))) 44#define SYS_POWEROFF ((SYS_EVENT | ((long)8 << 27)))
45#define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27))) 45#define SYS_FS_CHANGED ((SYS_EVENT | ((long)9 << 27)))
46#define SYS_CHARGER_CONNECTED ((SYS_EVENT | ((long)10 << 27)))
47#define SYS_CHARGER_DISCONNECTED ((SYS_EVENT | ((long)11 << 27)))
46 48
47struct event 49struct event
48{ 50{
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index 9cfacad9b0..5a1639ca1c 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -89,11 +89,6 @@ void set_battery_capacity(int capacity)
89 (void)capacity; 89 (void)capacity;
90} 90}
91 91
92void set_car_adapter_mode(bool setting)
93{
94 (void)setting;
95}
96
97void reset_poweroff_timer(void) 92void reset_poweroff_timer(void)
98{ 93{
99} 94}
@@ -150,9 +145,6 @@ static enum {
150 CHARGER_PLUGGED, /* transient state */ 145 CHARGER_PLUGGED, /* transient state */
151 CHARGER 146 CHARGER
152} charger_input_state; 147} charger_input_state;
153
154static bool waiting_to_resume_play = false;
155static long play_resume_time;
156#endif 148#endif
157 149
158#ifdef HAVE_CHARGE_CTRL 150#ifdef HAVE_CHARGE_CTRL
@@ -192,8 +184,6 @@ static int battery_type = 0;
192/* Power history: power_history[0] is the newest sample */ 184/* Power history: power_history[0] is the newest sample */
193unsigned short power_history[POWER_HISTORY_LEN]; 185unsigned short power_history[POWER_HISTORY_LEN];
194 186
195static bool car_adapter_mode_enabled = false;
196
197static char power_stack[DEFAULT_STACK_SIZE + DEBUG_STACK]; 187static char power_stack[DEFAULT_STACK_SIZE + DEBUG_STACK];
198static const char power_thread_name[] = "power"; 188static const char power_thread_name[] = "power";
199 189
@@ -401,47 +391,6 @@ static void handle_auto_poweroff(void)
401 } 391 }
402} 392}
403 393
404void set_car_adapter_mode(bool setting)
405{
406 car_adapter_mode_enabled = setting;
407}
408
409#ifdef HAVE_CHARGING
410static void car_adapter_mode_processing(void)
411{
412 if (car_adapter_mode_enabled) {
413
414 if (waiting_to_resume_play) {
415 if (TIME_AFTER(current_tick, play_resume_time)) {
416 if (audio_status() & AUDIO_STATUS_PAUSE) {
417 audio_resume();
418 }
419 waiting_to_resume_play = false;
420 }
421 } else {
422 if (charger_input_state == CHARGER_UNPLUGGED) {
423 /*
424 * Just got unplugged, pause if playing
425 */
426 if ((audio_status() & AUDIO_STATUS_PLAY) &&
427 !(audio_status() & AUDIO_STATUS_PAUSE)) {
428 audio_pause();
429 }
430 } else if(charger_input_state == CHARGER_PLUGGED) {
431 /*
432 * Just got plugged in, delay & resume if we were playing
433 */
434 if (audio_status() & AUDIO_STATUS_PAUSE) {
435 /* delay resume a bit while the engine is cranking */
436 play_resume_time = current_tick + HZ*5;
437 waiting_to_resume_play = true;
438 }
439 }
440 }
441 }
442}
443#endif
444
445/* 394/*
446 * Estimate how much current we are drawing just to run. 395 * Estimate how much current we are drawing just to run.
447 */ 396 */
@@ -507,6 +456,7 @@ static void power_thread_sleep(int ticks)
507 charger_input_state = CHARGER_PLUGGED; 456 charger_input_state = CHARGER_PLUGGED;
508 return; 457 return;
509 case CHARGER_PLUGGED: 458 case CHARGER_PLUGGED:
459 queue_broadcast(SYS_CHARGER_CONNECTED, NULL);
510 charger_input_state = CHARGER; 460 charger_input_state = CHARGER;
511 break; 461 break;
512 case CHARGER: 462 case CHARGER:
@@ -517,6 +467,7 @@ static void power_thread_sleep(int ticks)
517 case NO_CHARGER: 467 case NO_CHARGER:
518 break; 468 break;
519 case CHARGER_UNPLUGGED: 469 case CHARGER_UNPLUGGED:
470 queue_broadcast(SYS_CHARGER_DISCONNECTED, NULL);
520 charger_input_state = NO_CHARGER; 471 charger_input_state = NO_CHARGER;
521 break; 472 break;
522 case CHARGER_PLUGGED: 473 case CHARGER_PLUGGED:
@@ -531,9 +482,6 @@ static void power_thread_sleep(int ticks)
531 sleep(small_ticks); 482 sleep(small_ticks);
532 ticks -= small_ticks; 483 ticks -= small_ticks;
533 484
534#ifdef HAVE_CHARGING
535 car_adapter_mode_processing();
536#endif
537#ifdef HAVE_ALARM_MOD 485#ifdef HAVE_ALARM_MOD
538 power_thread_rtc_process(); 486 power_thread_rtc_process();
539#endif 487#endif