kopia lustrzana https://github.com/OpenRTX/OpenRTX
Created low-level driver for backlight level management
rodzic
d70e0bc60a
commit
56c598da7e
|
@ -32,9 +32,9 @@ openrtx_inc = ['openrtx/include',
|
|||
'platform/drivers/NVM',
|
||||
'platform/drivers/GPS',
|
||||
'platform/drivers/tones',
|
||||
'openrtx/include/fonts/adafruit',
|
||||
'platform/drivers/tones',
|
||||
'platform/drivers/baseband']
|
||||
'platform/drivers/baseband',
|
||||
'platform/drivers/backlight',
|
||||
'openrtx/include/fonts/adafruit']
|
||||
|
||||
# Add to sources either the main executable or a platform test
|
||||
if get_option('test') != ''
|
||||
|
@ -79,6 +79,7 @@ def = {'DONT_USE_CMSIS_INIT': ''}
|
|||
mdx_src = ['platform/drivers/ADC/ADC1_MDx.c',
|
||||
'platform/drivers/GPS/GPS_MDx.cpp',
|
||||
'platform/drivers/NVM/W25Qx.c',
|
||||
'platform/drivers/backlight/backlight_MDx.c',
|
||||
'platform/drivers/tones/toneGenerator_MDx.cpp']
|
||||
|
||||
##
|
||||
|
@ -90,6 +91,7 @@ gdx_src = ['platform/drivers/NVM/W25Qx.c',
|
|||
'platform/drivers/NVM/spiFlash_GDx.c',
|
||||
'platform/drivers/NVM/nvmem_GDx.c',
|
||||
'platform/drivers/ADC/ADC0_GDx.c',
|
||||
'platform/drivers/backlight/backlight_GDx.c',
|
||||
'platform/drivers/baseband/radio_GDx.c',
|
||||
'platform/drivers/baseband/AT1846S.c',
|
||||
'platform/drivers/baseband/HR_C6000.c',
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* 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 <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#ifndef BACKLIGHT_H
|
||||
#define BACKLIGHT_H
|
||||
|
||||
/**
|
||||
* Low-level driver for backlight dimming control.
|
||||
* This header file only provides the API for driver initialisation and shutdown,
|
||||
* while effective setting of backlight level is provided by target-specific
|
||||
* sources by implementating platform_setBacklightLevel().
|
||||
*/
|
||||
|
||||
/**
|
||||
* Initialise backlight driver.
|
||||
*/
|
||||
void backlight_init();
|
||||
|
||||
/**
|
||||
* Terminate backlight driver.
|
||||
*/
|
||||
void backlight_terminate();
|
||||
|
||||
#endif /* BACKLIGHT_H */
|
|
@ -0,0 +1,57 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* 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 <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <interfaces/platform.h>
|
||||
#include <interfaces/gpio.h>
|
||||
#include <hwconfig.h>
|
||||
#include "backlight.h"
|
||||
|
||||
void backlight_init()
|
||||
{
|
||||
/*
|
||||
* 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 backlight_terminate()
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
SIM->SCGC6 &= ~SIM_SCGC6_FTM0(1);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is defined in platform.h
|
||||
*/
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
FTM0->CONTROLS[3].CnV = level;
|
||||
}
|
|
@ -0,0 +1,168 @@
|
|||
/***************************************************************************
|
||||
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||
* Niccolò Izzo IU2KIN *
|
||||
* Frederik Saraci IU2NRO *
|
||||
* 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 <http://www.gnu.org/licenses/> *
|
||||
***************************************************************************/
|
||||
|
||||
#include <interfaces/platform.h>
|
||||
#include <interfaces/gpio.h>
|
||||
#include <hwconfig.h>
|
||||
#include "backlight.h"
|
||||
|
||||
#ifndef PLATFORM_MDUV3x0 /* MD-3x0 and MD-9600 */
|
||||
|
||||
void backlight_init()
|
||||
{
|
||||
gpio_setMode(LCD_BKLIGHT, ALTERNATE);
|
||||
gpio_setAlternateFunction(LCD_BKLIGHT, 3);
|
||||
|
||||
/*
|
||||
* Configure TIM8 for backlight PWM: Fpwm = 1kHz with 8 bit of resolution.
|
||||
* APB2 freq. is 84MHz, but timer runs at twice this frequency.
|
||||
* Then: PSC = 655 to have Ftick = 256.097kHz
|
||||
* With ARR = 256, Fpwm is 1kHz;
|
||||
* Backlight pin is connected to TIM8 CR1.
|
||||
*/
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
|
||||
TIM8->ARR = 255;
|
||||
TIM8->PSC = 654;
|
||||
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 */
|
||||
}
|
||||
|
||||
void backlight_terminate()
|
||||
{
|
||||
/* Shut down backlight */
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
/* Shut down timer */
|
||||
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is defined in platform.h
|
||||
*/
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
TIM8->CCR1 = level;
|
||||
}
|
||||
|
||||
#elif defined(ENABLE_BKLIGHT_DIMMING) /* MD-UV3x0 AND dimming enabled */
|
||||
|
||||
/*
|
||||
* Interrupt-based software PWM for backlight dimming on MD-UV3x0.
|
||||
* On this family of devices the GPIO for backlight control is not connected to
|
||||
* any of the available timer compare output channels, thus making impossible to
|
||||
* implement an hardware-based PWM.
|
||||
* However, we provide a software-base backlight dimming for experimental purposes.
|
||||
*/
|
||||
|
||||
/* Name of interrupt handler is mangled for C++ compatibility */
|
||||
void _Z29TIM1_TRG_COM_TIM11_IRQHandlerv()
|
||||
{
|
||||
if(TIM11->SR & TIM_SR_CC1IF)
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT); /* Clear pin on compare match */
|
||||
}
|
||||
|
||||
if(TIM11->SR & TIM_SR_UIF)
|
||||
{
|
||||
gpio_setPin(LCD_BKLIGHT); /* Set pin on counter reload */
|
||||
}
|
||||
|
||||
TIM11->SR = 0;
|
||||
}
|
||||
|
||||
void backlight_init()
|
||||
{
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
/*
|
||||
* Configure TIM11 for backlight PWM: Fpwm = 256Hz, 8 bit of resolution.
|
||||
* APB2 freq. is 84MHz but timer runs at twice this frequency, then:
|
||||
* PSC = 2564 to have Ftick = 65.52kHz
|
||||
* With ARR = 256, Fpwm is 256Hz;
|
||||
*/
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
|
||||
__DSB();
|
||||
|
||||
TIM11->ARR = 255;
|
||||
TIM11->PSC = 2563;
|
||||
TIM11->CNT = 0;
|
||||
TIM11->CR1 |= TIM_CR1_ARPE;
|
||||
TIM11->CCMR1 |= TIM_CCMR1_OC1M_2
|
||||
| TIM_CCMR1_OC1M_1
|
||||
| TIM_CCMR1_OC1PE;
|
||||
TIM11->CCER |= TIM_CCER_CC1E;
|
||||
TIM11->CCR1 = 0;
|
||||
TIM11->EGR = TIM_EGR_UG; /* Update registers */
|
||||
TIM11->SR = 0; /* Clear interrupt flags */
|
||||
TIM11->DIER = TIM_DIER_CC1IE /* Interrupt on compare match */
|
||||
| TIM_DIER_UIE; /* Interrupt on counter reload */
|
||||
TIM11->CR1 |= TIM_CR1_CEN; /* Start timer */
|
||||
|
||||
NVIC_ClearPendingIRQ(TIM1_TRG_COM_TIM11_IRQn);
|
||||
NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn,15);
|
||||
NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
|
||||
}
|
||||
|
||||
void backlight_terminate()
|
||||
{
|
||||
/* Shut down backlight */
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
/* Shut down timer */
|
||||
RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN;
|
||||
__DSB();
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is defined in platform.h
|
||||
*/
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
/*
|
||||
* Little workaround for the following nasty behaviour: if CCR1 value is
|
||||
* zero, a waveform with 99% duty cycle is generated. This is because we are
|
||||
* emulating pwm with interrupts.
|
||||
*/
|
||||
if(level > 1)
|
||||
{
|
||||
TIM11->CCR1 = level;
|
||||
TIM11->CR1 |= TIM_CR1_CEN;
|
||||
}
|
||||
else
|
||||
{
|
||||
TIM11->CR1 &= ~TIM_CR1_CEN;
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
#include <I2C0.h>
|
||||
#include <pthread.h>
|
||||
#include <backlight.h>
|
||||
#include "hwconfig.h"
|
||||
|
||||
/* Mutex for concurrent access to ADC0 */
|
||||
|
@ -40,28 +41,14 @@ void platform_init()
|
|||
gpio_setMode(GREEN_LED, OUTPUT);
|
||||
gpio_setMode(RED_LED, OUTPUT);
|
||||
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
gpio_setMode(PTT_SW, INPUT);
|
||||
|
||||
gpio_setMode(PWR_SW, OUTPUT);
|
||||
|
||||
/*
|
||||
* Configure backlight PWM: 58.5kHz, 8 bit resolution
|
||||
* Initialise backlight driver
|
||||
*/
|
||||
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);
|
||||
backlight_init();
|
||||
|
||||
/*
|
||||
* Initialise ADC
|
||||
|
@ -100,7 +87,9 @@ void platform_init()
|
|||
|
||||
void platform_terminate()
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
/* Shut down backlight */
|
||||
backlight_terminate();
|
||||
|
||||
gpio_clearPin(RED_LED);
|
||||
gpio_clearPin(GREEN_LED);
|
||||
|
||||
|
@ -197,11 +186,6 @@ void platform_beepStop()
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
FTM0->CONTROLS[3].CnV = level;
|
||||
}
|
||||
|
||||
const void *platform_getCalibrationData()
|
||||
{
|
||||
/* The first time this function is called, load calibration data from flash */
|
||||
|
@ -217,3 +201,10 @@ const hwInfo_t *platform_getHwInfo()
|
|||
{
|
||||
return &hwInfo;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NOTE: implementation of this API function is provided in
|
||||
* platform/drivers/backlight/backlight_GDx.c
|
||||
*/
|
||||
// void platform_setBacklightLevel(uint8_t level)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <string.h>
|
||||
#include <I2C0.h>
|
||||
#include <pthread.h>
|
||||
#include <backlight.h>
|
||||
#include "hwconfig.h"
|
||||
|
||||
pthread_mutex_t adc_mutex;
|
||||
|
@ -39,28 +40,14 @@ void platform_init()
|
|||
gpio_setMode(GREEN_LED, OUTPUT);
|
||||
gpio_setMode(RED_LED, OUTPUT);
|
||||
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
gpio_setMode(PTT_SW, INPUT);
|
||||
|
||||
gpio_setMode(PWR_SW, OUTPUT);
|
||||
|
||||
/*
|
||||
* Configure backlight PWM: 58.5kHz, 8 bit resolution
|
||||
* Initialise backlight driver
|
||||
*/
|
||||
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);
|
||||
backlight_init();
|
||||
|
||||
/*
|
||||
* Initialise ADC
|
||||
|
@ -99,7 +86,9 @@ void platform_init()
|
|||
|
||||
void platform_terminate()
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
/* Shut down backlight */
|
||||
backlight_terminate();
|
||||
|
||||
gpio_clearPin(RED_LED);
|
||||
gpio_clearPin(GREEN_LED);
|
||||
|
||||
|
@ -196,11 +185,6 @@ void platform_beepStop()
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
FTM0->CONTROLS[3].CnV = level;
|
||||
}
|
||||
|
||||
const void *platform_getCalibrationData()
|
||||
{
|
||||
/* The first time this function is called, load calibration data from flash */
|
||||
|
@ -216,3 +200,10 @@ const hwInfo_t *platform_getHwInfo()
|
|||
{
|
||||
return &hwInfo;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NOTE: implementation of this API function is provided in
|
||||
* platform/drivers/backlight/backlight_GDx.c
|
||||
*/
|
||||
// void platform_setBacklightLevel(uint8_t level)
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <hwconfig.h>
|
||||
#include <string.h>
|
||||
#include <ADC1_MDx.h>
|
||||
#include <backlight.h>
|
||||
#include <calibInfo_MDx.h>
|
||||
#include <toneGenerator_MDx.h>
|
||||
#include <interfaces/rtc.h>
|
||||
|
@ -62,45 +63,18 @@ void platform_init()
|
|||
nvm_loadHwInfo(&hwInfo); /* Load hardware information data */
|
||||
toneGen_init(); /* Initialise tone generator */
|
||||
rtc_init(); /* Initialise RTC */
|
||||
|
||||
/*
|
||||
* Configure TIM8 for backlight PWM: Fpwm = 100kHz with 8 bit of resolution.
|
||||
* APB2 freq. is 84MHz, but timer runs at twice this frequency.
|
||||
* Then: PSC = 655 to have Ftick = 256.097kHz
|
||||
* With ARR = 256, Fpwm is 100kHz;
|
||||
* Backlight pin is connected to TIM8 CR1.
|
||||
*/
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
|
||||
TIM8->ARR = 255;
|
||||
TIM8->PSC = 654;
|
||||
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 */
|
||||
backlight_init(); /* Initialise backlight driver */
|
||||
}
|
||||
|
||||
void platform_terminate()
|
||||
{
|
||||
/* Shut down backlight */
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
backlight_terminate();
|
||||
|
||||
/* Shut down LEDs */
|
||||
gpio_clearPin(GREEN_LED);
|
||||
gpio_clearPin(RED_LED);
|
||||
|
||||
/* Shut down timer */
|
||||
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
|
||||
/* Shut down all the modules */
|
||||
adc1_terminate();
|
||||
nvm_terminate();
|
||||
|
@ -193,11 +167,6 @@ void platform_beepStop()
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
TIM8->CCR1 = level;
|
||||
}
|
||||
|
||||
const void *platform_getCalibrationData()
|
||||
{
|
||||
return ((const void *) &calibration);
|
||||
|
@ -207,3 +176,9 @@ const hwInfo_t *platform_getHwInfo()
|
|||
{
|
||||
return &hwInfo;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: implementation of this API function is provided in
|
||||
* platform/drivers/backlight/backlight_MDx.c
|
||||
*/
|
||||
// void platform_setBacklightLevel(uint8_t level)
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <interfaces/platform.h>
|
||||
#include <hwconfig.h>
|
||||
#include <string.h>
|
||||
#include <backlight.h>
|
||||
#include <ADC1_MDx.h>
|
||||
#include <calibInfo_MDx.h>
|
||||
#include <toneGenerator_MDx.h>
|
||||
|
@ -32,9 +33,6 @@ hwInfo_t hwInfo;
|
|||
|
||||
void platform_init()
|
||||
{
|
||||
gpio_setMode(LCD_BKLIGHT, ALTERNATE);
|
||||
gpio_setAlternateFunction(LCD_BKLIGHT, 3);
|
||||
|
||||
gpio_setMode(CH_SELECTOR_0, INPUT_PULL_UP);
|
||||
gpio_setMode(CH_SELECTOR_1, INPUT_PULL_UP);
|
||||
|
||||
|
@ -77,40 +75,13 @@ void platform_init()
|
|||
nvm_init(); /* Initialise non volatile memory manager */
|
||||
toneGen_init(); /* Initialise tone generator */
|
||||
rtc_init(); /* Initialise RTC */
|
||||
|
||||
/*
|
||||
* Configure TIM8 for backlight PWM: Fpwm = 100kHz with 8 bit of resolution.
|
||||
* APB2 freq. is 84MHz, but timer runs at twice this frequency.
|
||||
* Then: PSC = 655 to have Ftick = 256.097kHz
|
||||
* With ARR = 256, Fpwm is 100kHz;
|
||||
* Backlight pin is connected to TIM8 CR1.
|
||||
*/
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
|
||||
TIM8->ARR = 255;
|
||||
TIM8->PSC = 654;
|
||||
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 */
|
||||
backlight_init(); /* Initialise backlight driver */
|
||||
}
|
||||
|
||||
void platform_terminate()
|
||||
{
|
||||
/* Shut down backlight */
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
/* Shut down timer */
|
||||
RCC->APB2ENR &= ~RCC_APB2ENR_TIM8EN;
|
||||
__DSB();
|
||||
backlight_terminate();
|
||||
|
||||
/* Shut down all the modules */
|
||||
adc1_terminate();
|
||||
|
@ -179,11 +150,6 @@ void platform_beepStop()
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
TIM8->CCR1 = level;
|
||||
}
|
||||
|
||||
const void *platform_getCalibrationData()
|
||||
{
|
||||
return NULL;
|
||||
|
@ -193,3 +159,10 @@ const hwInfo_t *platform_getHwInfo()
|
|||
{
|
||||
return &hwInfo;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: implementation of this API function is provided in
|
||||
* platform/drivers/backlight/backlight_MDx.c
|
||||
*/
|
||||
// void platform_setBacklightLevel(uint8_t level)
|
||||
|
||||
|
|
|
@ -27,27 +27,14 @@
|
|||
#include <interfaces/rtc.h>
|
||||
#include <qdec.h>
|
||||
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
#include <backlight.h>
|
||||
#endif
|
||||
|
||||
mduv3x0Calib_t calibration;
|
||||
hwInfo_t hwInfo;
|
||||
static int8_t knob_pos = 0;
|
||||
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
void _Z29TIM1_TRG_COM_TIM11_IRQHandlerv()
|
||||
{
|
||||
if(TIM11->SR & TIM_SR_CC1IF)
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT); /* Clear pin on compare match */
|
||||
}
|
||||
|
||||
if(TIM11->SR & TIM_SR_UIF)
|
||||
{
|
||||
gpio_setPin(LCD_BKLIGHT); /* Set pin on counter reload */
|
||||
}
|
||||
|
||||
TIM11->SR = 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Note that this interrupt handler currently assumes only the encoder will
|
||||
* ever cause this interrupt to fire
|
||||
|
@ -90,9 +77,6 @@ void platform_init()
|
|||
gpio_setMode(GREEN_LED, OUTPUT);
|
||||
gpio_setMode(RED_LED, OUTPUT);
|
||||
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
gpio_setMode(CH_SELECTOR_0, INPUT_PULL_UP);
|
||||
gpio_setMode(CH_SELECTOR_1, INPUT_PULL_UP);
|
||||
|
||||
|
@ -126,44 +110,20 @@ void platform_init()
|
|||
rtc_init(); /* Initialise RTC */
|
||||
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
/*
|
||||
* Configure TIM11 for backlight PWM: Fpwm = 256Hz, 8 bit of resolution.
|
||||
* APB2 freq. is 84MHz but timer runs at twice this frequency, then:
|
||||
* PSC = 2564 to have Ftick = 65.52kHz
|
||||
* With ARR = 256, Fpwm is 256Hz;
|
||||
*/
|
||||
RCC->APB2ENR |= RCC_APB2ENR_TIM11EN;
|
||||
__DSB();
|
||||
|
||||
TIM11->ARR = 255;
|
||||
TIM11->PSC = 2563;
|
||||
TIM11->CNT = 0;
|
||||
TIM11->CR1 |= TIM_CR1_ARPE;
|
||||
TIM11->CCMR1 |= TIM_CCMR1_OC1M_2
|
||||
| TIM_CCMR1_OC1M_1
|
||||
| TIM_CCMR1_OC1PE;
|
||||
TIM11->CCER |= TIM_CCER_CC1E;
|
||||
TIM11->CCR1 = 0;
|
||||
TIM11->EGR = TIM_EGR_UG; /* Update registers */
|
||||
TIM11->SR = 0; /* Clear interrupt flags */
|
||||
TIM11->DIER = TIM_DIER_CC1IE /* Interrupt on compare match */
|
||||
| TIM_DIER_UIE; /* Interrupt on counter reload */
|
||||
TIM11->CR1 |= TIM_CR1_CEN; /* Start timer */
|
||||
|
||||
NVIC_ClearPendingIRQ(TIM1_TRG_COM_TIM11_IRQn);
|
||||
NVIC_SetPriority(TIM1_TRG_COM_TIM11_IRQn,15);
|
||||
NVIC_EnableIRQ(TIM1_TRG_COM_TIM11_IRQn);
|
||||
backlight_init(); /* Initialise backlight driver */
|
||||
#else
|
||||
gpio_setMode(LCD_BKLIGHT, OUTPUT);
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
#endif
|
||||
}
|
||||
|
||||
void platform_terminate()
|
||||
{
|
||||
/* Shut down backlight */
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
RCC->APB2ENR &= ~RCC_APB2ENR_TIM11EN;
|
||||
__DSB();
|
||||
backlight_terminate();
|
||||
#else
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
#endif
|
||||
|
||||
/* Shut down LEDs */
|
||||
|
@ -259,31 +219,6 @@ void platform_beepStop()
|
|||
/* TODO */
|
||||
}
|
||||
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
/*
|
||||
* Little workaround for the following nasty behaviour: if CCR1 value is
|
||||
* zero, a waveform with 99% duty cycle is generated. This is because we are
|
||||
* emulating pwm with interrupts.
|
||||
*/
|
||||
if(level > 1)
|
||||
{
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
TIM11->CCR1 = level;
|
||||
TIM11->CR1 |= TIM_CR1_CEN;
|
||||
#else
|
||||
gpio_setPin(LCD_BKLIGHT);
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#ifdef ENABLE_BKLIGHT_DIMMING
|
||||
TIM11->CR1 &= ~TIM_CR1_CEN;
|
||||
#endif
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
}
|
||||
}
|
||||
|
||||
const void *platform_getCalibrationData()
|
||||
{
|
||||
return ((const void *) &calibration);
|
||||
|
@ -293,3 +228,22 @@ const hwInfo_t *platform_getHwInfo()
|
|||
{
|
||||
return &hwInfo;
|
||||
}
|
||||
|
||||
/*
|
||||
* NOTE: when backligth dimming is enabled, the implementation of this API
|
||||
* function is provided in platform/drivers/backlight/backlight_MDx.c to avoid
|
||||
* an useless function call.
|
||||
*/
|
||||
#ifndef ENABLE_BKLIGHT_DIMMING
|
||||
void platform_setBacklightLevel(uint8_t level)
|
||||
{
|
||||
if(level > 1)
|
||||
{
|
||||
gpio_setPin(LCD_BKLIGHT);
|
||||
}
|
||||
else
|
||||
{
|
||||
gpio_clearPin(LCD_BKLIGHT);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Ładowanie…
Reference in New Issue