summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c88
1 files changed, 88 insertions, 0 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c
new file mode 100644
index 0000000000..f02fcaaee8
--- /dev/null
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/backlight-fiiom3k.c
@@ -0,0 +1,88 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2021 Aidan MacDonald
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
22#include "backlight.h"
23#include "backlight-target.h"
24#include "lcd.h"
25#include "pwm-x1000.h"
26
27#define BL_LCD_CHN 0
28#define BL_LCD_PERIOD 33000
29
30#define BL_BTN_CHN 4
31#define BL_BTN_PERIOD 100000
32
33static int backlight_calc_duty(int period, int min_duty, int brightness)
34{
35 return min_duty + (period - min_duty) * brightness / MAX_BRIGHTNESS_SETTING;
36}
37
38bool backlight_hw_init(void)
39{
40 pwm_init(BL_LCD_CHN);
41 pwm_init(BL_BTN_CHN);
42 pwm_enable(BL_LCD_CHN);
43 pwm_enable(BL_BTN_CHN);
44 backlight_hw_brightness(MAX_BRIGHTNESS_SETTING);
45 buttonlight_hw_brightness(MAX_BRIGHTNESS_SETTING);
46 /* TODO: avoid buttonlight flicker when powering up the machine */
47 return true;
48}
49
50void backlight_hw_on(void)
51{
52 pwm_enable(BL_LCD_CHN);
53#ifdef HAVE_LCD_ENABLE
54 lcd_enable(true);
55#endif
56}
57
58void backlight_hw_off(void)
59{
60 pwm_disable(BL_LCD_CHN);
61#ifdef HAVE_LCD_ENABLE
62 lcd_enable(false);
63#endif
64}
65
66void backlight_hw_brightness(int brightness)
67{
68 int duty_ns = backlight_calc_duty(BL_LCD_PERIOD, 0, brightness);
69 pwm_set_period(BL_LCD_CHN, BL_LCD_PERIOD, duty_ns);
70}
71
72void buttonlight_hw_on(void)
73{
74 pwm_enable(BL_BTN_CHN);
75}
76
77void buttonlight_hw_off(void)
78{
79 pwm_disable(BL_BTN_CHN);
80}
81
82void buttonlight_hw_brightness(int brightness)
83{
84 /* Duty cycle below 11% seems to turn the buttonlight off entirely,
85 * so we need to rescale the range */
86 int duty_ns = backlight_calc_duty(BL_BTN_PERIOD, BL_BTN_PERIOD*11/100, brightness);
87 pwm_set_period(BL_BTN_CHN, BL_BTN_PERIOD, duty_ns);
88}