Merge pull request #2452 from opentx/frsky_2.1

Frsky 2.1
This commit is contained in:
Bertrand Songis
2015-07-11 10:49:47 +02:00
18 changed files with 282 additions and 115 deletions
+5 -2
View File
@@ -1191,9 +1191,12 @@ void lcdRefresh()
#if defined(PCBTARANIS)
void pwrInit() { }
uint32_t pwrCheck() { return true; }
void pwrOff() { }
uint32_t pwrPressedDuration() { return 0; }
#if defined(REV9E)
uint32_t pwrPressed() { return false; }
#else
uint32_t pwrCheck() { return true; }
#endif
void usbStart() { }
int usbPlugged() { return false; }
void USART_DeInit(USART_TypeDef* ) { }
+57 -5
View File
@@ -112,6 +112,23 @@ extern "C" void INTERRUPT_5MS_IRQHandler()
interrupt5ms() ;
}
#if defined(REV9E)
#define PWR_PRESS_DURATION_MIN 80 // 800ms
#define PWR_PRESS_DURATION_MAX 300 // 3s
const pm_uchar bmp_startup[] PROGMEM = {
#include "../../bitmaps/Taranis/startup.lbm"
};
const pm_uchar bmp_lock[] PROGMEM = {
#include "../../bitmaps/Taranis/lock.lbm"
};
const pm_uchar bmp_sleep[] PROGMEM = {
#include "../../bitmaps/Taranis/sleep.lbm"
};
#endif
void boardInit()
{
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph | KEYS_RCC_AHB1Periph | LCD_RCC_AHB1Periph | BACKLIGHT_RCC_AHB1Periph | ADC_RCC_AHB1Periph | I2C_RCC_AHB1Periph | SD_RCC_AHB1Periph | HAPTIC_RCC_AHB1Periph | INTMODULE_RCC_AHB1Periph | EXTMODULE_RCC_AHB1Periph | TELEMETRY_RCC_AHB1Periph | SERIAL_RCC_AHB1Periph | TRAINER_RCC_AHB1Periph | HEARTBEAT_RCC_AHB1Periph, ENABLE);
@@ -123,11 +140,6 @@ void boardInit()
adcInit();
delaysInit();
lcdInit(); // delaysInit() must be called before
#if defined(REV9E)
topLcdInit();
#endif
audioInit();
init2MhzTimer();
init5msTimer();
@@ -146,6 +158,46 @@ void boardInit()
#if defined(DEBUG)
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
#endif
#if defined(REV9E)
if (!(RCC->CSR & (RCC_CSR_SFTRSTF | RCC_CSR_WDGRSTF))) {
tmr10ms_t start = get_tmr10ms();
tmr10ms_t duration = 0;
uint8_t pwr_on = 0;
while (pwrPressed()) {
duration = get_tmr10ms() - start;
lcd_clear();
if (duration < PWR_PRESS_DURATION_MIN) {
lcd_bmp(76, 0, bmp_lock, 0, 60);
}
else if (duration >= PWR_PRESS_DURATION_MAX) {
lcd_bmp(76, 0, bmp_sleep, 0, 60);
turnBacklightOff();
}
else {
unsigned index = (duration - PWR_PRESS_DURATION_MIN) / ((PWR_PRESS_DURATION_MAX-PWR_PRESS_DURATION_MIN) / 4);
lcd_bmp(76, 0, bmp_startup, index*60, 60);
if (pwr_on != 1) {
backlightInit();
pwr_on = 1;
}
}
lcdRefresh();
}
if (duration < PWR_PRESS_DURATION_MIN || duration >= PWR_PRESS_DURATION_MAX) {
pwrOff();
}
else {
lcdRefreshWait();
}
}
else {
backlightInit();
}
topLcdInit();
#else
backlightInit();
#endif
}
#endif
+8 -1
View File
@@ -254,6 +254,7 @@ extern "C" {
// Power driver
void pwrInit(void);
uint32_t pwrCheck(void);
void pwrOn(void);
void pwrOff(void);
#if defined(REV9E)
uint32_t pwrPressed(void);
@@ -262,6 +263,7 @@ uint32_t pwrPressedDuration(void);
#define UNEXPECTED_SHUTDOWN() (g_eeGeneral.unexpectedShutdown)
// Backlight driver
void backlightInit(void);
#if defined(REVPLUS)
void turnBacklightOn(uint8_t level, uint8_t color);
void turnBacklightOff(void);
@@ -331,13 +333,18 @@ void uart3Stop(void);
// BT driver
#define BLUETOOTH_DEFAULT_BAUDRATE 115200
#define BLUETOOTH_FACTORY_BAUDRATE 9600
uint8_t bluetoothReady();
uint8_t bluetoothReady(void);
void bluetoothInit(uint32_t baudrate);
void bluetoothWrite(const void * buffer, int len);
void bluetoothWriteString(const char * str);
int bluetoothRead(void * buffer, int len);
void bluetoothWakeup(void);
// LCD driver
void lcdInit(void);
void lcdInitFinish(void);
void lcdOff(void);
// Top LCD driver
#if defined(REV9E)
void topLcdInit(void);
+1 -25
View File
@@ -398,45 +398,21 @@ int main()
#endif
pwrInit();
#if defined(PCBSKY9X)
MATRIX->CCFG_SYSIO |= 0x000000F0L; // Disable syspins, enable B4,5,6,7
#endif
#if defined(PCBSKY9X)
init_SDcard();
PIOC->PIO_PER = PIO_PC25; // Enable bit C25 (USB-detect)
start_timer0();
#endif
#if defined(PCBTARANIS)
delaysInit(); //needed for lcdInit()
#endif
lcdInit();
backlightInit();
#if defined(PCBSKY9X)
extern uint8_t OptrexDisplay;
OptrexDisplay = 1;
#endif
lcd_clear();
lcd_putsLeft(0, BOOTLOADER_TITLE);
lcd_invert_line(0);
lcdRefresh();
#if defined(REVPLUS)
turnBacklightOn(0, 0);
#endif
keysInit();
i2cInit();
__enable_irq();
init10msTimer();
#if defined(PCBSKY9X)
EblockAddress = -1;
init_spi();
#endif
#if defined(PCBTARANIS)
// SD card detect pin
sdInit();
+4 -6
View File
@@ -251,8 +251,7 @@ void lcdRefresh()
}
#endif
/**Init the Backlight GPIO */
static void LCD_BL_Config()
void backlightInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
@@ -269,8 +268,8 @@ static void LCD_BL_Config()
BACKLIGHT_TIMER->PSC = (PERI2_FREQUENCY * TIMER_MULT_APB2) / 50000 - 1; // 20us * 100 = 2ms => 500Hz
BACKLIGHT_TIMER->CCMR1 = TIM_CCMR1_OC1M_1 | TIM_CCMR1_OC1M_2 | TIM_CCMR1_OC2M_1 | TIM_CCMR1_OC2M_2 ; // PWM
BACKLIGHT_TIMER->CCER = TIM_CCER_CC1E | TIM_CCER_CC2E ;
BACKLIGHT_TIMER->CCR1 = 0 ;
BACKLIGHT_TIMER->CCR2 = 80 ;
BACKLIGHT_TIMER->CCR2 = 0 ;
BACKLIGHT_TIMER->CCR1 = 100 ;
BACKLIGHT_TIMER->EGR = 0 ;
BACKLIGHT_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable
#elif defined(REVPLUS)
@@ -288,7 +287,7 @@ static void LCD_BL_Config()
BACKLIGHT_TIMER->CCMR2 = TIM_CCMR2_OC4M_1 | TIM_CCMR2_OC4M_2 ; // PWM
BACKLIGHT_TIMER->CCER = TIM_CCER_CC4E | TIM_CCER_CC2E ;
BACKLIGHT_TIMER->CCR2 = 0 ;
BACKLIGHT_TIMER->CCR4 = 80 ;
BACKLIGHT_TIMER->CCR4 = 100 ;
BACKLIGHT_TIMER->EGR = 0 ;
BACKLIGHT_TIMER->CR1 = TIM_CR1_CEN ; // Counter enable
#else
@@ -362,7 +361,6 @@ void lcdOff()
*/
void lcdInit()
{
LCD_BL_Config();
LCD_Hardware_Init();
if (WAS_RESET_BY_WATCHDOG()|WAS_RESET_BY_SOFTWARE()) return; //no need to reset LCD module
+8 -34
View File
@@ -72,17 +72,18 @@ void pwrInit()
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(TRAINER_GPIO_DETECT, &GPIO_InitStructure);
// Soft power ON
GPIO_SetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
pwrOn();
}
#if defined(REV9E)
while (pwrPressed()) ;
#endif
void pwrOn()
{
GPIO_SetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
}
void pwrOff()
{
GPIO_ResetBits(PWR_GPIO, PWR_GPIO_PIN_ON);
#if defined(REV9E)
// 9E needs watchdog reset because CPU is still running while the power
// key is held pressed by the user
@@ -107,36 +108,9 @@ uint32_t pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_GPIO, PWR_GPIO_PIN_SWITCH) == Bit_RESET;
}
#if !defined(BOOT)
uint32_t pwrPressTime = 0;
uint32_t pwrPressedDuration()
{
if (pwrPressTime == 0) {
return 0;
}
else {
return get_tmr10ms() - pwrPressTime;
}
}
uint32_t pwrCheck()
{
if (pwrPressed()) {
if (pwrPressTime == 0) {
pwrPressTime = get_tmr10ms();
}
else {
if (get_tmr10ms() - pwrPressTime > 250) {
return e_power_off;
}
}
}
else {
pwrPressTime = 0;
}
return e_power_on;
}
#endif
#else
#if !defined(REV9E)
uint32_t pwrCheck()
{
#if defined(SIMU)