1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2002 by Linus Nielsen Feltzing
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 ****************************************************************************/
34 #include "backlight.h"
35 #include "backlight-target.h"
37 static int brightness
= 1; /* 1 to 32 */
38 static int current_dim
= 16; /* default after enabling the backlight dimmer */
39 static bool enabled
= false;
41 void _backlight_set_brightness(int val
)
45 if (current_dim
< val
)
49 oldlevel
= disable_irq_save();
50 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
52 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
53 restore_irq(oldlevel
);
56 while (++current_dim
< val
);
58 else if (current_dim
> val
)
62 oldlevel
= disable_irq_save();
63 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
65 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
66 restore_irq(oldlevel
);
69 while (--current_dim
> val
);
74 void _backlight_hw_enable(bool on
)
78 /* If the fade-out is interrupted, enabled will be true, but
79 lcd_awake() needs to be called anyways because the LCD
90 GPIO_SET_BITWISE(GPIOB_OUTPUT_VAL
, 0x08);
91 GPIO_SET_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
94 _backlight_set_brightness(brightness
);
98 GPIO_CLEAR_BITWISE(GPIOD_OUTPUT_VAL
, 0x80);
99 GPIO_CLEAR_BITWISE(GPIOB_OUTPUT_VAL
, 0x08);
105 /* Switch the backlight on. Works only if the backlight circuit is enabled.
106 * Called in ISR context for fading, so it must be fast. */
107 void _backlight_led_on(void)
109 GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL
, 0x80);
112 /* Switch the backlight off. Keeps the backlight circuit enabled.
113 * Called in ISR context for fading, so it must be fast. */
114 void _backlight_led_off(void)
116 GPIO_CLEAR_BITWISE(GPIOL_OUTPUT_VAL
, 0x80);
119 bool _backlight_init(void)
121 GPIO_SET_BITWISE(GPIOB_ENABLE
, 0x08);
122 GPIO_SET_BITWISE(GPIOB_OUTPUT_EN
, 0x08);
123 GPIO_SET_BITWISE(GPIOD_ENABLE
, 0x80);
124 GPIO_SET_BITWISE(GPIOD_OUTPUT_EN
, 0x80);
125 _backlight_hw_enable(true);
126 GPIO_SET_BITWISE(GPIOL_ENABLE
, 0x80);
127 GPIO_SET_BITWISE(GPIOL_OUTPUT_EN
, 0x80);
128 GPIO_SET_BITWISE(GPIOL_OUTPUT_VAL
, 0x80);