Implement software pwm to control c200v2 display brightness.
[kugel-rb.git] / firmware / target / arm / as3525 / sansa-c200v2 / backlight-c200v2.c
blobe094cca8fe047e1a12518a89eae48f7c4a562dfb
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
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 ****************************************************************************/
21 #include "config.h"
22 #include "backlight-target.h"
23 #include "system.h"
24 #include "lcd.h"
25 #include "backlight.h"
26 #include "ascodec-target.h"
27 #include "as3514.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 GPIOA_PIN(5) = 1<<5;
43 static void _ll_backlight_off(void)
45 GPIOA_PIN(5) = 0;
48 void _backlight_pwm(int on)
50 if (on) {
51 _ll_backlight_on();
52 } else {
53 _ll_backlight_off();
57 bool _backlight_init(void)
59 GPIOA_DIR |= 1<<5;
60 return true;
63 void _backlight_set_brightness(int brightness)
65 backlight_level = brightness_table[brightness];
67 if (brightness > 0)
68 _backlight_on();
69 else
70 _backlight_off();
73 void _backlight_on(void)
75 #ifdef HAVE_LCD_ENABLE
76 lcd_enable(true); /* power on lcd + visible display */
77 #endif
78 if (!backlight_is_on)
79 _ll_backlight_on();
80 _set_timer2_pwm_ratio(backlight_level);
81 backlight_is_on = 1;
84 void _backlight_off(void)
86 backlight_is_on = 0;
87 _set_timer2_pwm_ratio(0);
88 _ll_backlight_off();
89 #ifdef HAVE_LCD_ENABLE
90 lcd_enable(false); /* power off visible display */
91 #endif
94 void _buttonlight_on(void)
96 /* Needed for buttonlight and MicroSD to work at the same time */
97 /* Turn ROD control on, as the OF does */
98 GPIOD_DIR |= (1<<7);
99 SD_MCI_POWER |= (1<<7);
100 GPIOD_PIN(7) = (1<<7);
101 buttonlight_is_on = 1;
104 void _buttonlight_off(void)
106 /* Needed for buttonlight and MicroSD to work at the same time */
107 /* Turn ROD control off, as the OF does */
108 SD_MCI_POWER &= ~(1<<7);
109 GPIOD_PIN(7) = 0;
110 GPIOD_DIR &= ~(1<<7);
111 buttonlight_is_on = 0;