1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2009 by Bertrik Sikken
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 ****************************************************************************/
24 #include "backlight.h"
25 #include "backlight-target.h"
29 Backlight driver using the PWM mode of a hardware timer.
31 The PWM duty cycle depends exponentially on the configured brightness
32 level. This makes the brightness curve more linear to the human eye.
35 void _backlight_set_brightness(int brightness
)
37 /* pwm = round(sqrt(2)**x), where brightness level x = 1..16 */
38 static const unsigned int logtable
[] =
39 {1, 2, 3, 4, 6, 8, 11, 16, 23, 32, 45, 64, 91, 128, 181, 256};
42 TCDATA0
= logtable
[brightness
];
45 void _backlight_on(void)
47 /* configure backlight pin P0.2 as timer PWM output */
48 PCON0
= ((PCON0
& ~(3 << 4)) | (2 << 4));
49 _backlight_set_brightness(backlight_brightness
);
52 void _backlight_off(void)
54 /* configure backlight pin P0.2 as GPIO and switch off */
55 PCON0
= ((PCON0
& ~(3 << 4)) | (1 << 4));
59 bool _backlight_init(void)
61 /* enable timer clock */
65 TCCMD
= (1 << 1); /* TC_CLR */
66 TCCON
= (0 << 13) | /* TC_INT1_EN */
67 (0 << 12) | /* TC_INT0_EN */
68 (1 << 11) | /* TC_START */
69 (3 << 8) | /* TC_CS = PCLK / 64 */
70 (1 << 4); /* TC_MODE_SEL = PWM mode */
71 TCDATA1
= 256; /* set PWM period */
72 TCPRE
= 20; /* prescaler */
73 TCCMD
= (1 << 0); /* TC_EN */