diff options
Diffstat (limited to 'firmware/target/hosted/ibasso/backlight-ibasso.c')
-rw-r--r-- | firmware/target/hosted/ibasso/backlight-ibasso.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/firmware/target/hosted/ibasso/backlight-ibasso.c b/firmware/target/hosted/ibasso/backlight-ibasso.c new file mode 100644 index 0000000000..907980e01a --- /dev/null +++ b/firmware/target/hosted/ibasso/backlight-ibasso.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___ | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * | ||
9 | * Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50 | ||
10 | * Copyright (C) 2014 by Mario Basister: iBasso DX90 port | ||
11 | * Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features | ||
12 | * Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features | ||
13 | * | ||
14 | * This program is free software; you can redistribute it and/or | ||
15 | * modify it under the terms of the GNU General Public License | ||
16 | * as published by the Free Software Foundation; either version 2 | ||
17 | * of the License, or (at your option) any later version. | ||
18 | * | ||
19 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
20 | * KIND, either express or implied. | ||
21 | * | ||
22 | ****************************************************************************/ | ||
23 | |||
24 | |||
25 | #include <stdbool.h> | ||
26 | |||
27 | #include "config.h" | ||
28 | #include "debug.h" | ||
29 | #include "lcd.h" | ||
30 | #include "panic.h" | ||
31 | |||
32 | #include "debug-ibasso.h" | ||
33 | #include "sysfs-ibasso.h" | ||
34 | |||
35 | |||
36 | /* | ||
37 | Prevent excessive backlight_hw_on usage. | ||
38 | Required for proper seeking. | ||
39 | */ | ||
40 | static bool _backlight_enabled = false; | ||
41 | |||
42 | |||
43 | bool backlight_hw_init(void) | ||
44 | { | ||
45 | TRACE; | ||
46 | |||
47 | /* | ||
48 | /sys/devices/platform/rk29_backlight/backlight/rk28_bl/bl_power | ||
49 | 0: backlight on | ||
50 | */ | ||
51 | if(! sysfs_set_int(SYSFS_BACKLIGHT_POWER, 0)) | ||
52 | { | ||
53 | DEBUGF("ERROR %s: Can not enable backlight.", __func__); | ||
54 | panicf("ERROR %s: Can not enable backlight.", __func__); | ||
55 | return false; | ||
56 | } | ||
57 | |||
58 | _backlight_enabled = true; | ||
59 | |||
60 | return true; | ||
61 | } | ||
62 | |||
63 | |||
64 | void backlight_hw_on(void) | ||
65 | { | ||
66 | if(! _backlight_enabled) | ||
67 | { | ||
68 | backlight_hw_init(); | ||
69 | lcd_enable(true); | ||
70 | } | ||
71 | } | ||
72 | |||
73 | |||
74 | void backlight_hw_off(void) | ||
75 | { | ||
76 | TRACE; | ||
77 | |||
78 | /* | ||
79 | /sys/devices/platform/rk29_backlight/backlight/rk28_bl/bl_power | ||
80 | 1: backlight off | ||
81 | */ | ||
82 | if(! sysfs_set_int(SYSFS_BACKLIGHT_POWER, 1)) | ||
83 | { | ||
84 | DEBUGF("ERROR %s: Can not disable backlight.", __func__); | ||
85 | return; | ||
86 | } | ||
87 | |||
88 | lcd_enable(false); | ||
89 | |||
90 | _backlight_enabled = false; | ||
91 | } | ||
92 | |||
93 | |||
94 | /* | ||
95 | Prevent excessive backlight_hw_brightness usage. | ||
96 | Required for proper seeking. | ||
97 | */ | ||
98 | static int _current_brightness = -1; | ||
99 | |||
100 | |||
101 | void backlight_hw_brightness(int brightness) | ||
102 | { | ||
103 | if(brightness > MAX_BRIGHTNESS_SETTING) | ||
104 | { | ||
105 | DEBUGF("DEBUG %s: Adjusting brightness from %d to MAX.", __func__, brightness); | ||
106 | brightness = MAX_BRIGHTNESS_SETTING; | ||
107 | } | ||
108 | if(brightness < MIN_BRIGHTNESS_SETTING) | ||
109 | { | ||
110 | DEBUGF("DEBUG %s: Adjusting brightness from %d to MIN.", __func__, brightness); | ||
111 | brightness = MIN_BRIGHTNESS_SETTING; | ||
112 | } | ||
113 | |||
114 | if(_current_brightness == brightness) | ||
115 | { | ||
116 | return; | ||
117 | } | ||
118 | |||
119 | TRACE; | ||
120 | |||
121 | _current_brightness = brightness; | ||
122 | |||
123 | /* | ||
124 | /sys/devices/platform/rk29_backlight/backlight/rk28_bl/max_brightness | ||
125 | 0 ... 255 | ||
126 | */ | ||
127 | if(! sysfs_set_int(SYSFS_BACKLIGHT_BRIGHTNESS, _current_brightness)) | ||
128 | { | ||
129 | DEBUGF("ERROR %s: Can not set brightness.", __func__); | ||
130 | return; | ||
131 | } | ||
132 | } | ||