1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2006 by Barry Wardell
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include "backlight-target.h"
25 #include "backlight.h"
26 #include "ascodec-target.h"
29 int buttonlight_is_on
= 0;
30 int backlight_is_on
= 0;
31 static int backlight_level
= 0;
33 /* logarithmic lookup table for brightness s*/
34 static const int brightness_table
[MAX_BRIGHTNESS_SETTING
+1] = {
35 0, 21, 47, 78, 118, 165, 224, 296, 386, 495, 630, 796, 1000
38 static void _ll_backlight_on(void)
40 if (c200v2_variant
== 0) {
47 static void _ll_backlight_off(void)
49 if (c200v2_variant
== 0) {
56 static void _ll_buttonlight_on(void)
58 if (c200v2_variant
== 1) {
59 /* Main buttonlight is on A5 */
62 /* Needed for buttonlight and MicroSD to work at the same time */
63 /* Turn ROD control on, as the OF does */
65 SD_MCI_POWER
|= (1<<7);
66 GPIOD_PIN(7) = (1<<7);
70 static void _ll_buttonlight_off(void)
72 if (c200v2_variant
== 1) {
73 /* Main buttonlight is on A5 */
76 /* Needed for buttonlight and MicroSD to work at the same time */
77 /* Turn ROD control off, as the OF does */
78 SD_MCI_POWER
&= ~(1<<7);
84 void _backlight_pwm(int on
)
90 if (buttonlight_is_on
)
96 if (buttonlight_is_on
)
97 _ll_buttonlight_off();
101 bool _backlight_init(void)
104 if (c200v2_variant
== 1) {
105 /* On this variant A7 is the backlight and
106 * A5 is the buttonlight */
112 void _backlight_set_brightness(int brightness
)
114 backlight_level
= brightness_table
[brightness
];
122 static void _pwm_on(void)
124 _set_timer2_pwm_ratio(backlight_level
);
127 static void _pwm_off(void)
129 if (buttonlight_is_on
== 0 && backlight_is_on
== 0)
130 _set_timer2_pwm_ratio(0);
133 void _backlight_on(void)
135 if (backlight_is_on
== 1) {
136 /* Update pwm ratio in case user changed the brightness */
141 #ifdef HAVE_LCD_ENABLE
142 lcd_enable(true); /* power on lcd + visible display */
149 void _backlight_off(void)
151 if (backlight_is_on
== 0)
157 #ifdef HAVE_LCD_ENABLE
158 lcd_enable(false); /* power off visible display */
162 void _buttonlight_on(void)
164 if (buttonlight_is_on
== 1)
167 _ll_buttonlight_on();
169 buttonlight_is_on
= 1;
172 void _buttonlight_off(void)
174 if (buttonlight_is_on
== 0)
177 buttonlight_is_on
= 0;
179 _ll_buttonlight_off();