Commit 125fd0f2 authored by schneider's avatar schneider
Browse files

fix(display): Dim backlight in percent steps

parent 2077f3ec
......@@ -1337,7 +1337,7 @@ API(API_DISP_FRAMEBUFFER, int epic_disp_framebuffer(union disp_framebuffer *fb))
/**
* Set the backlight brightness value
*
* :param brightness: brightness from 0 - 1000
* :param brightness: brightness from 0 - 100
* :return: ``0`` on success or negative value in case of an error:
*
* - ``-EBUSY``: Display was already locked from another task.
......
......@@ -37,7 +37,7 @@ void display_init(void)
GPIO_Config(&DEV_DC_PIN);
LCD_SetBacklight(200);
LCD_SetBacklight(20);
LCD_Init();
display_screen = gfx_screen(LCD_framebuffer());
......
......@@ -76,39 +76,43 @@ void DEV_Set_BL(uint16_t _Value)
gpio_cfg_t gpio_pwm; // to configure GPIO
tmr_cfg_t tmr; // to congigure timer
tmr_pwm_cfg_t tmr_pwm; // for configure PWM
unsigned int period_ticks = PeripheralClock / FREQ;
unsigned int duty_ticks = period_ticks * _Value / 1000;
// Congfigure GPIO port and pin for PWM
gpio_pwm.func = GPIO_FUNC_ALT4;
gpio_pwm.port = PORT_PWM;
gpio_pwm.mask = PIN_PWM;
gpio_pwm.pad = GPIO_PAD_PULL_DOWN;
GPIO_Config(&gpio_pwm);
if (_Value > 100) {
_Value = 100;
}
/*
Steps for configuring a timer for PWM mode:
1. Disable the timer
2. Set the prescale value
3. Configure the timer for PWM mode
4. Set polarity, pwm parameters
5. Enable Timer
*/
unsigned int period_ticks = PeripheralClock / FREQ;
unsigned int duty_ticks = period_ticks * _Value / 100;
TMR_Disable(PWM_TIMER);
TMR_Init(PWM_TIMER, TMR_PRES_1, 0);
if (duty_ticks > 0) {
// Congfigure GPIO port and pin for PWM
gpio_pwm.func = GPIO_FUNC_ALT4;
gpio_pwm.port = PORT_PWM;
gpio_pwm.mask = PIN_PWM;
gpio_pwm.pad = GPIO_PAD_PULL_DOWN;
GPIO_Config(&gpio_pwm);
TMR_Init(PWM_TIMER, TMR_PRES_1, 0);
tmr.mode = TMR_MODE_PWM;
tmr.cmp_cnt = period_ticks;
tmr.pol = 0;
TMR_Config(PWM_TIMER, &tmr);
tmr.mode = TMR_MODE_PWM;
tmr.cmp_cnt = period_ticks;
tmr.pol = 0;
TMR_Config(PWM_TIMER, &tmr);
tmr_pwm.pol = 1;
tmr_pwm.per_cnt = period_ticks;
tmr_pwm.duty_cnt = duty_ticks;
tmr_pwm.pol = 1;
tmr_pwm.per_cnt = period_ticks;
tmr_pwm.duty_cnt = duty_ticks;
TMR_PWMConfig(PWM_TIMER, &tmr_pwm);
TMR_Enable(PWM_TIMER);
TMR_PWMConfig(PWM_TIMER, &tmr_pwm);
TMR_Enable(PWM_TIMER);
} else {
gpio_pwm.func = GPIO_FUNC_OUT;
gpio_pwm.port = PORT_PWM;
gpio_pwm.mask = PIN_PWM;
gpio_pwm.pad = GPIO_PAD_PULL_DOWN;
GPIO_Config(&gpio_pwm);
GPIO_OutClr(&gpio_pwm);
}
}
......@@ -50,7 +50,7 @@ static void LCD_Reset(void)
function:
Setting backlight
parameter :
value : Range 0~1000 Duty cycle is value/1000
value : Range 0~100 Duty cycle is value/100
*******************************************************************************/
void LCD_SetBacklight(UWORD Value)
{
......
......@@ -95,7 +95,7 @@ class Display:
"""
Set display backlight brightness
:param brightness: backlight brightness 0 <= brightness <= 1000
:param brightness: backlight brightness 0 <= brightness <= 100
"""
sys_display.backlight(brightness)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment