From 06346ac827407c4eb18e30e8829e090702edf7b2 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Thu, 22 Oct 2020 14:54:09 +0200 Subject: [PATCH] Moving function for setting display backlight level from display driver to 'platform.c' file --- openrtx/include/interfaces/display.h | 7 --- openrtx/src/.keep | 1 - platform/drivers/display/HX83XX_md380.c | 29 ------------ platform/targets/.keep | 1 - platform/targets/MD380/platform.c | 59 +++++++++++++++++++++++++ 5 files changed, 59 insertions(+), 38 deletions(-) delete mode 100644 openrtx/src/.keep delete mode 100644 platform/targets/.keep create mode 100644 platform/targets/MD380/platform.c diff --git a/openrtx/include/interfaces/display.h b/openrtx/include/interfaces/display.h index 6eebde12..311c88b0 100644 --- a/openrtx/include/interfaces/display.h +++ b/openrtx/include/interfaces/display.h @@ -87,13 +87,6 @@ uint16_t display_screenWidth(); */ uint16_t display_screenHeight(); -/** - * Set screen backlight to a given level. - * @param level: backlight level, from 0 (backlight off) to 255 (backlight at - * full brightness). - */ -void display_setBacklightLevel(uint8_t level); - /** * Copy a given section, between two given rows, of framebuffer content to the * display. diff --git a/openrtx/src/.keep b/openrtx/src/.keep deleted file mode 100644 index 8d1c8b69..00000000 --- a/openrtx/src/.keep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/platform/drivers/display/HX83XX_md380.c b/platform/drivers/display/HX83XX_md380.c index f5da1453..99955dd0 100644 --- a/platform/drivers/display/HX83XX_md380.c +++ b/platform/drivers/display/HX83XX_md380.c @@ -144,29 +144,6 @@ void display_init() /* Clear framebuffer, setting all pixels to 0xFFFF makes the screen white */ memset(frameBuffer, 0xFF, fbSize); - /* - * Configure TIM8 for backlight PWM: Fpwm = 100kHz, 8 bit of resolution - * APB2 freq. is 84MHz, then: PSC = 327 to have Ftick = 256.097kHz - * With ARR = 256, Fpwm is 100kHz; - */ - RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; - TIM8->ARR = 255; - TIM8->PSC = 327; - TIM8->CNT = 0; - TIM8->CR1 |= TIM_CR1_ARPE; /* LCD backlight is on PC6, TIM8-CH1 */ - TIM8->CCMR1 |= TIM_CCMR1_OC1M_2 - | TIM_CCMR1_OC1M_1 - | TIM_CCMR1_OC1PE; - TIM8->CCER |= TIM_CCER_CC1E; - TIM8->BDTR |= TIM_BDTR_MOE; - TIM8->CCR1 = 0; - TIM8->EGR = TIM_EGR_UG; /* Update registers */ - TIM8->CR1 |= TIM_CR1_CEN; /* Start timer */ - - /* Configure backlight GPIO, TIM8 is on AF3 */ - gpio_setMode(GPIOC, 6, ALTERNATE); - gpio_setAlternateFunction(GPIOC, 6, 3); - /* * Turn on DMA2 and configure its interrupt. DMA is used to transfer the * framebuffer content to the screen without using CPU. @@ -368,7 +345,6 @@ void display_terminate() /* Shut off backlight, FSMC and deallocate framebuffer */ gpio_setMode(GPIOC, 6, OUTPUT); gpio_clearPin(GPIOC, 6); - RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN; RCC->AHB3ENR &= ~RCC_AHB3ENR_FSMCEN; if(frameBuffer != NULL) { @@ -386,11 +362,6 @@ uint16_t display_screenHeight() return SCREEN_HEIGHT; } -void display_setBacklightLevel(uint8_t level) -{ - TIM8->CCR1 = level; -} - void display_renderRows(uint8_t startRow, uint8_t endRow) { /* diff --git a/platform/targets/.keep b/platform/targets/.keep deleted file mode 100644 index 8d1c8b69..00000000 --- a/platform/targets/.keep +++ /dev/null @@ -1 +0,0 @@ - diff --git a/platform/targets/MD380/platform.c b/platform/targets/MD380/platform.c new file mode 100644 index 00000000..932c077a --- /dev/null +++ b/platform/targets/MD380/platform.c @@ -0,0 +1,59 @@ +/*************************************************************************** + * Copyright (C) 2020 by Federico Amedeo Izzo IU2NUO, * + * Niccolò Izzo IU2KIN * + * Silvano Seva IU2KWO * + * * + * 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 3 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, see * + ***************************************************************************/ + +#include +#include "platform.h" +#include "gpio.h" + +void platform_init() +{ + /* + * Configure TIM8 for backlight PWM: Fpwm = 100kHz, 8 bit of resolution + * APB2 freq. is 84MHz, then: PSC = 327 to have Ftick = 256.097kHz + * With ARR = 256, Fpwm is 100kHz; + */ + RCC->APB2ENR |= RCC_APB2ENR_TIM8EN; + TIM8->ARR = 255; + TIM8->PSC = 327; + TIM8->CNT = 0; + TIM8->CR1 |= TIM_CR1_ARPE; /* LCD backlight is on PC6, TIM8-CH1 */ + TIM8->CCMR1 |= TIM_CCMR1_OC1M_2 + | TIM_CCMR1_OC1M_1 + | TIM_CCMR1_OC1PE; + TIM8->CCER |= TIM_CCER_CC1E; + TIM8->BDTR |= TIM_BDTR_MOE; + TIM8->CCR1 = 0; + TIM8->EGR = TIM_EGR_UG; /* Update registers */ + TIM8->CR1 |= TIM_CR1_CEN; /* Start timer */ + + /* Configure backlight GPIO, TIM8 is on AF3 */ + gpio_setMode(GPIOC, 6, ALTERNATE); + gpio_setAlternateFunction(GPIOC, 6, 3); +} + +void platform_terminate() +{ + /* Shut off backlight */ + RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN; +} + +void platform_setBacklightLevel(uint8_t level) +{ + TIM8->CCR1 = level; +}