summaryrefslogtreecommitdiff
path: root/firmware/target/arm/s5l8700/yps3/backlight-yps3.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/arm/s5l8700/yps3/backlight-yps3.c')
-rw-r--r--firmware/target/arm/s5l8700/yps3/backlight-yps3.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/firmware/target/arm/s5l8700/yps3/backlight-yps3.c b/firmware/target/arm/s5l8700/yps3/backlight-yps3.c
new file mode 100644
index 0000000000..0a9cf3cc9a
--- /dev/null
+++ b/firmware/target/arm/s5l8700/yps3/backlight-yps3.c
@@ -0,0 +1,78 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2009 by Bertrik Sikken
11 *
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.
16 *
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
19 *
20 ****************************************************************************/
21#include <stdbool.h>
22
23#include "config.h"
24#include "backlight.h"
25#include "backlight-target.h"
26#include "system.h"
27
28/*
29 Backlight driver using the PWM mode of a hardware timer.
30
31 The PWM duty cycle depends exponentially on the configured brightness
32 level. This makes the brightness curve more linear to the human eye.
33 */
34
35void _backlight_set_brightness(int brightness)
36{
37 /* pwm = (sqrt(2)**x)-1, where brightness level x = 0..16 */
38 static const unsigned char logtable[] =
39 {0, 1, 2, 3, 5, 7, 10, 15, 22, 31, 44, 63, 90, 127, 180, 255};
40
41 /* set PWM width */
42 TADATA0 = 255 - logtable[brightness];
43}
44
45void _backlight_on(void)
46{
47 _backlight_set_brightness(backlight_brightness);
48}
49
50void _backlight_off(void)
51{
52 _backlight_set_brightness(MIN_BRIGHTNESS_SETTING);
53}
54
55bool _backlight_init(void)
56{
57 /* enable backlight pin as timer output */
58 PCON0 = ((PCON0 & ~(3 << 0)) | (2 << 0));
59
60 /* enable timer clock */
61 PWRCON &= ~(1 << 4);
62
63 /* configure timer */
64 TACMD = (1 << 1); /* TC_CLR */
65 TACON = (0 << 13) | /* TC_INT1_EN */
66 (0 << 12) | /* TC_INT0_EN */
67 (0 << 11) | /* TC_START */
68 (3 << 8) | /* TC_CS = PCLK / 64 */
69 (1 << 4); /* TC_MODE_SEL = PWM mode */
70 TADATA1 = 255; /* set PWM period */
71 TAPRE = 20; /* prescaler */
72 TACMD = (1 << 0); /* TC_EN */
73
74 _backlight_on();
75
76 return true;
77}
78