From 4f34822db21daac6aab1457895c5d96f7daf61b1 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Mon, 21 Dec 2020 12:55:34 +0100 Subject: [PATCH] Implemented backlight dimming for GD77 and DM-1801 targets --- platform/targets/DM-1801/platform.c | 26 +++++++++++++++++--------- platform/targets/GD77/platform.c | 26 +++++++++++++++++--------- 2 files changed, 34 insertions(+), 18 deletions(-) diff --git a/platform/targets/DM-1801/platform.c b/platform/targets/DM-1801/platform.c index 0b7fda89..83168f1d 100644 --- a/platform/targets/DM-1801/platform.c +++ b/platform/targets/DM-1801/platform.c @@ -32,6 +32,22 @@ void platform_init() gpio_clearPin(LCD_BKLIGHT); gpio_setMode(PTT_SW, INPUT); + + /* + * Configure backlight PWM: 58.5kHz, 8 bit resolution + */ + SIM->SCGC6 |= SIM_SCGC6_FTM0(1); /* Enable clock */ + + FTM0->CONTROLS[3].CnSC = FTM_CnSC_MSB(1) + | FTM_CnSC_ELSB(1); /* Edge-aligned PWM, clear on match */ + FTM0->CONTROLS[3].CnV = 0; + + FTM0->MOD = 0xFF; /* Reload value */ + FTM0->SC = FTM_SC_PS(3) /* Prescaler divide by 8 */ + | FTM_SC_CLKS(1); /* Enable timer */ + + gpio_setMode(LCD_BKLIGHT, OUTPUT); + gpio_setAlternateFunction(LCD_BKLIGHT, 2); } void platform_terminate() @@ -119,13 +135,5 @@ void platform_beepStop() void platform_setBacklightLevel(uint8_t level) { - /* TODO: backlight dimming */ - if(level > 1) - { - gpio_setPin(LCD_BKLIGHT); - } - else - { - gpio_clearPin(LCD_BKLIGHT); - } + FTM0->CONTROLS[3].CnV = level; } diff --git a/platform/targets/GD77/platform.c b/platform/targets/GD77/platform.c index 0b7fda89..83168f1d 100644 --- a/platform/targets/GD77/platform.c +++ b/platform/targets/GD77/platform.c @@ -32,6 +32,22 @@ void platform_init() gpio_clearPin(LCD_BKLIGHT); gpio_setMode(PTT_SW, INPUT); + + /* + * Configure backlight PWM: 58.5kHz, 8 bit resolution + */ + SIM->SCGC6 |= SIM_SCGC6_FTM0(1); /* Enable clock */ + + FTM0->CONTROLS[3].CnSC = FTM_CnSC_MSB(1) + | FTM_CnSC_ELSB(1); /* Edge-aligned PWM, clear on match */ + FTM0->CONTROLS[3].CnV = 0; + + FTM0->MOD = 0xFF; /* Reload value */ + FTM0->SC = FTM_SC_PS(3) /* Prescaler divide by 8 */ + | FTM_SC_CLKS(1); /* Enable timer */ + + gpio_setMode(LCD_BKLIGHT, OUTPUT); + gpio_setAlternateFunction(LCD_BKLIGHT, 2); } void platform_terminate() @@ -119,13 +135,5 @@ void platform_beepStop() void platform_setBacklightLevel(uint8_t level) { - /* TODO: backlight dimming */ - if(level > 1) - { - gpio_setPin(LCD_BKLIGHT); - } - else - { - gpio_clearPin(LCD_BKLIGHT); - } + FTM0->CONTROLS[3].CnV = level; }