diff options
Diffstat (limited to 'firmware/backlight.c')
-rw-r--r-- | firmware/backlight.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/firmware/backlight.c b/firmware/backlight.c index 4dcdea917c..8a7c4ceb76 100644 --- a/firmware/backlight.c +++ b/firmware/backlight.c | |||
@@ -25,6 +25,7 @@ | |||
25 | #include "debug.h" | 25 | #include "debug.h" |
26 | #include "rtc.h" | 26 | #include "rtc.h" |
27 | #include "usb.h" | 27 | #include "usb.h" |
28 | #include "power.h" | ||
28 | 29 | ||
29 | #define BACKLIGHT_ON 1 | 30 | #define BACKLIGHT_ON 1 |
30 | #define BACKLIGHT_OFF 2 | 31 | #define BACKLIGHT_OFF 2 |
@@ -34,6 +35,11 @@ static char backlight_stack[DEFAULT_STACK_SIZE]; | |||
34 | static char backlight_thread_name[] = "backlight"; | 35 | static char backlight_thread_name[] = "backlight"; |
35 | static struct event_queue backlight_queue; | 36 | static struct event_queue backlight_queue; |
36 | 37 | ||
38 | #ifdef HAVE_CHARGE_CTRL | ||
39 | static bool charger_was_inserted = 0; | ||
40 | static bool backlight_on_when_charging = 0; | ||
41 | #endif | ||
42 | |||
37 | static int backlight_timer; | 43 | static int backlight_timer; |
38 | static int backlight_timeout = 5; | 44 | static int backlight_timeout = 5; |
39 | 45 | ||
@@ -52,9 +58,22 @@ void backlight_thread(void) | |||
52 | switch(ev.id) | 58 | switch(ev.id) |
53 | { | 59 | { |
54 | case BACKLIGHT_ON: | 60 | case BACKLIGHT_ON: |
61 | #ifdef HAVE_CHARGE_CTRL | ||
62 | if( backlight_on_when_charging && charger_inserted() ) | ||
63 | { | ||
64 | /* Forcing to zero keeps the lights on */ | ||
65 | backlight_timer = 0; | ||
66 | } | ||
67 | else | ||
68 | { | ||
69 | backlight_timer = HZ*timeout_value[backlight_timeout]; | ||
70 | } | ||
71 | #else | ||
55 | backlight_timer = HZ*timeout_value[backlight_timeout]; | 72 | backlight_timer = HZ*timeout_value[backlight_timeout]; |
73 | #endif | ||
56 | if(backlight_timer < 0) | 74 | if(backlight_timer < 0) |
57 | { | 75 | { |
76 | backlight_timer = 0; /* timer value 0 will not get ticked */ | ||
58 | #ifdef HAVE_RTC | 77 | #ifdef HAVE_RTC |
59 | /* Disable square wave */ | 78 | /* Disable square wave */ |
60 | rtc_write(0x0a, rtc_read(0x0a) & ~0x40); | 79 | rtc_write(0x0a, rtc_read(0x0a) & ~0x40); |
@@ -62,7 +81,8 @@ void backlight_thread(void) | |||
62 | PADR |= 0x4000; | 81 | PADR |= 0x4000; |
63 | #endif | 82 | #endif |
64 | } | 83 | } |
65 | else if(backlight_timer) | 84 | /* else if(backlight_timer) */ |
85 | else | ||
66 | { | 86 | { |
67 | #ifdef HAVE_RTC | 87 | #ifdef HAVE_RTC |
68 | /* Enable square wave */ | 88 | /* Enable square wave */ |
@@ -105,14 +125,28 @@ void backlight_off(void) | |||
105 | queue_post(&backlight_queue, BACKLIGHT_OFF, NULL); | 125 | queue_post(&backlight_queue, BACKLIGHT_OFF, NULL); |
106 | } | 126 | } |
107 | 127 | ||
108 | void backlight_time(int value) | 128 | void backlight_set_timeout(int seconds) |
129 | { | ||
130 | backlight_timeout = seconds; | ||
131 | backlight_on(); | ||
132 | } | ||
133 | |||
134 | void backlight_set_on_when_charging(bool yesno) | ||
109 | { | 135 | { |
110 | backlight_timeout = value; | 136 | backlight_on_when_charging = yesno; |
111 | backlight_on(); | 137 | backlight_on(); |
112 | } | 138 | } |
113 | 139 | ||
114 | void backlight_tick(void) | 140 | void backlight_tick(void) |
115 | { | 141 | { |
142 | #ifdef HAVE_CHARGE_CTRL | ||
143 | bool charger_is_inserted = charger_inserted(); | ||
144 | if( backlight_on_when_charging && (charger_was_inserted != charger_is_inserted) ) | ||
145 | { | ||
146 | backlight_on(); | ||
147 | } | ||
148 | charger_was_inserted = charger_is_inserted; | ||
149 | #endif | ||
116 | if(backlight_timer) | 150 | if(backlight_timer) |
117 | { | 151 | { |
118 | backlight_timer--; | 152 | backlight_timer--; |