summaryrefslogtreecommitdiffstats
path: root/firmware/target/hosted/ibasso/backlight-ibasso.c
blob: 907980e01a70c653b8cf7ca6ca0ead97d927e627 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/***************************************************************************
 *             __________               __   ___
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 *
 * Copyright (C) 2014 by Ilia Sergachev: Initial Rockbox port to iBasso DX50
 * Copyright (C) 2014 by Mario Basister: iBasso DX90 port
 * Copyright (C) 2014 by Simon Rothen: Initial Rockbox repository submission, additional features
 * Copyright (C) 2014 by Udo Schläpfer: Code clean up, additional features
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/


#include <stdbool.h>

#include "config.h"
#include "debug.h"
#include "lcd.h"
#include "panic.h"

#include "debug-ibasso.h"
#include "sysfs-ibasso.h"


/*
    Prevent excessive backlight_hw_on usage.
    Required for proper seeking.
*/
static bool _backlight_enabled = false;


bool backlight_hw_init(void)
{
    TRACE;

    /*
        /sys/devices/platform/rk29_backlight/backlight/rk28_bl/bl_power
        0: backlight on
    */
    if(! sysfs_set_int(SYSFS_BACKLIGHT_POWER, 0))
    {
        DEBUGF("ERROR %s: Can not enable backlight.", __func__);
        panicf("ERROR %s: Can not enable backlight.", __func__);
        return false;
    }

    _backlight_enabled = true;

    return true;
}


void backlight_hw_on(void)
{
    if(! _backlight_enabled)
    {
        backlight_hw_init();
        lcd_enable(true);
    }
}


void backlight_hw_off(void)
{
    TRACE;

    /*
        /sys/devices/platform/rk29_backlight/backlight/rk28_bl/bl_power
        1: backlight off
    */
    if(! sysfs_set_int(SYSFS_BACKLIGHT_POWER, 1))
    {
        DEBUGF("ERROR %s: Can not disable backlight.", __func__);
        return;
    }

    lcd_enable(false);

    _backlight_enabled = false;
}


/*
    Prevent excessive backlight_hw_brightness usage.
    Required for proper seeking.
*/
static int _current_brightness = -1;


void backlight_hw_brightness(int brightness)
{
    if(brightness > MAX_BRIGHTNESS_SETTING)
    {
        DEBUGF("DEBUG %s: Adjusting brightness from %d to MAX.", __func__, brightness);
        brightness = MAX_BRIGHTNESS_SETTING;
    }
    if(brightness < MIN_BRIGHTNESS_SETTING)
    {
        DEBUGF("DEBUG %s: Adjusting brightness from %d to MIN.", __func__, brightness);
        brightness = MIN_BRIGHTNESS_SETTING;
    }

    if(_current_brightness == brightness)
    {
        return;
    }

    TRACE;

    _current_brightness = brightness;

    /*
        /sys/devices/platform/rk29_backlight/backlight/rk28_bl/max_brightness
        0 ... 255
    */
    if(! sysfs_set_int(SYSFS_BACKLIGHT_BRIGHTNESS, _current_brightness))
    {
        DEBUGF("ERROR %s: Can not set brightness.", __func__);
        return;
    }
}