222 lines
6.2 KiB
C++
222 lines
6.2 KiB
C++
/*
|
|
* Copyright (C) EdgeTX
|
|
*
|
|
* Based on code named
|
|
* opentx - https://github.com/opentx/opentx
|
|
* th9x - http://code.google.com/p/th9x
|
|
* er9x - http://code.google.com/p/er9x
|
|
* gruvin9x - http://code.google.com/p/gruvin9x
|
|
*
|
|
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*
|
|
* 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.
|
|
*/
|
|
|
|
#include "hal/adc_driver.h"
|
|
#include "hal/trainer_driver.h"
|
|
#include "hal/switch_driver.h"
|
|
#include "hal/rotary_encoder.h"
|
|
#include "hal/usb_driver.h"
|
|
|
|
#include "board.h"
|
|
#include "boards/generic_stm32/module_ports.h"
|
|
#include "boards/generic_stm32/intmodule_heartbeat.h"
|
|
#include "boards/generic_stm32/analog_inputs.h"
|
|
|
|
#include "timers_driver.h"
|
|
#include "dataconstants.h"
|
|
#include "opentx_types.h"
|
|
#include "globals.h"
|
|
#include "sdcard.h"
|
|
#include "debug.h"
|
|
|
|
#include <string.h>
|
|
|
|
#if defined(FLYSKY_GIMBAL)
|
|
#include "flysky_gimbal_driver.h"
|
|
#endif
|
|
|
|
HardwareOptions hardwareOptions;
|
|
bool boardBacklightOn = false;
|
|
|
|
#if !defined(BOOT)
|
|
#include "opentx.h"
|
|
|
|
void boardInit()
|
|
{
|
|
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph |
|
|
PCBREV_RCC_AHB1Periph |
|
|
LED_RCC_AHB1Periph |
|
|
LCD_RCC_AHB1Periph |
|
|
BACKLIGHT_RCC_AHB1Periph |
|
|
KEYS_BACKLIGHT_RCC_AHB1Periph |
|
|
SD_RCC_AHB1Periph |
|
|
AUDIO_RCC_AHB1Periph |
|
|
TELEMETRY_RCC_AHB1Periph |
|
|
BT_RCC_AHB1Periph |
|
|
AUDIO_RCC_AHB1Periph |
|
|
HAPTIC_RCC_AHB1Periph |
|
|
INTMODULE_RCC_AHB1Periph |
|
|
EXTMODULE_RCC_AHB1Periph |
|
|
SPORT_UPDATE_RCC_AHB1Periph,
|
|
ENABLE);
|
|
|
|
RCC_APB1PeriphClockCmd(ROTARY_ENCODER_RCC_APB1Periph |
|
|
AUDIO_RCC_APB1Periph |
|
|
TELEMETRY_RCC_APB1Periph |
|
|
AUDIO_RCC_APB1Periph |
|
|
BACKLIGHT_RCC_APB1Periph,
|
|
ENABLE);
|
|
|
|
RCC_APB2PeriphClockCmd(RCC_APB2Periph_SYSCFG |
|
|
LCD_RCC_APB2Periph |
|
|
HAPTIC_RCC_APB2Periph |
|
|
TELEMETRY_RCC_APB2Periph |
|
|
BT_RCC_APB2Periph |
|
|
BACKLIGHT_RCC_APB2Periph,
|
|
ENABLE);
|
|
|
|
#if defined(RADIO_FAMILY_T16)
|
|
void board_set_bor_level();
|
|
board_set_bor_level();
|
|
#endif
|
|
|
|
pwrInit();
|
|
boardInitModulePorts();
|
|
|
|
#if defined(INTMODULE_HEARTBEAT) && \
|
|
(defined(INTERNAL_MODULE_PXX1) || defined(INTERNAL_MODULE_PXX2))
|
|
pulsesSetModuleInitCb(_intmodule_heartbeat_init);
|
|
pulsesSetModuleDeInitCb(_intmodule_heartbeat_deinit);
|
|
trainerSetChangeCb(_intmodule_heartbeat_trainer_hook);
|
|
#endif
|
|
|
|
board_trainer_init();
|
|
pwrOn();
|
|
delaysInit();
|
|
|
|
__enable_irq();
|
|
|
|
#if defined(DEBUG) && defined(AUX_SERIAL)
|
|
serialSetMode(SP_AUX1, UART_MODE_DEBUG); // indicate AUX1 is used
|
|
serialInit(SP_AUX1, UART_MODE_DEBUG); // early AUX1 init
|
|
#endif
|
|
|
|
TRACE("\nHorus board started :)");
|
|
TRACE("RCC->CSR = %08x", RCC->CSR);
|
|
|
|
audioInit();
|
|
|
|
keysInit();
|
|
switchInit();
|
|
rotaryEncoderInit();
|
|
|
|
#if defined(PWM_STICKS)
|
|
sticksPwmDetect();
|
|
#endif
|
|
|
|
#if defined(FLYSKY_GIMBAL)
|
|
flysky_gimbal_init();
|
|
#endif
|
|
|
|
if (!adcInit(&_adc_driver))
|
|
TRACE("adcInit failed");
|
|
|
|
timersInit();
|
|
|
|
usbInit();
|
|
hapticInit();
|
|
|
|
#if defined(BLUETOOTH)
|
|
bluetoothInit(BLUETOOTH_DEFAULT_BAUDRATE, true);
|
|
#endif
|
|
|
|
|
|
#if defined(DEBUG)
|
|
DBGMCU_APB1PeriphConfig(DBGMCU_IWDG_STOP|DBGMCU_TIM1_STOP|DBGMCU_TIM2_STOP|DBGMCU_TIM3_STOP|DBGMCU_TIM4_STOP|DBGMCU_TIM5_STOP|DBGMCU_TIM6_STOP|DBGMCU_TIM7_STOP|DBGMCU_TIM8_STOP|DBGMCU_TIM9_STOP|DBGMCU_TIM10_STOP|DBGMCU_TIM11_STOP|DBGMCU_TIM12_STOP|DBGMCU_TIM13_STOP|DBGMCU_TIM14_STOP, ENABLE);
|
|
#endif
|
|
|
|
ledInit();
|
|
|
|
#if defined(USB_CHARGER)
|
|
usbChargerInit();
|
|
#endif
|
|
|
|
#if defined(RTCLOCK)
|
|
ledRed();
|
|
rtcInit(); // RTC must be initialized before rambackupRestore() is called
|
|
#endif
|
|
|
|
ledBlue();
|
|
#if !defined(LCD_VERTICAL_INVERT)
|
|
lcdSetInitalFrameBuffer(lcdFront->getData());
|
|
#endif
|
|
}
|
|
#endif
|
|
|
|
extern void rtcDisableBackupReg();
|
|
|
|
void boardOff()
|
|
{
|
|
ledOff();
|
|
backlightEnable(0);
|
|
|
|
while (pwrPressed()) {
|
|
WDG_RESET();
|
|
}
|
|
|
|
SysTick->CTRL = 0; // turn off systick
|
|
|
|
#if defined(PCBX12S)
|
|
// Shutdown the Audio amp
|
|
GPIO_InitTypeDef GPIO_InitStructure;
|
|
GPIO_InitStructure.GPIO_Pin = AUDIO_SHUTDOWN_GPIO_PIN;
|
|
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
|
|
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_25MHz;
|
|
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
|
|
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
|
|
GPIO_Init(AUDIO_SHUTDOWN_GPIO, &GPIO_InitStructure);
|
|
GPIO_ResetBits(AUDIO_SHUTDOWN_GPIO, AUDIO_SHUTDOWN_GPIO_PIN);
|
|
#endif
|
|
|
|
// Shutdown the Haptic
|
|
hapticDone();
|
|
|
|
rtcDisableBackupReg();
|
|
// RTC->BKP0R = SHUTDOWN_REQUEST;
|
|
|
|
pwrOff();
|
|
|
|
// We reach here only in forced power situations, such as hw-debugging with external power
|
|
// Enter STM32 stop mode / deep-sleep
|
|
// Code snippet from ST Nucleo PWR_EnterStopMode example
|
|
#define PDMode 0x00000000U
|
|
#if defined(PWR_CR_MRUDS) && defined(PWR_CR_LPUDS) && defined(PWR_CR_FPDS)
|
|
MODIFY_REG(PWR->CR, (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_FPDS | PWR_CR_LPUDS | PWR_CR_MRUDS), PDMode);
|
|
#elif defined(PWR_CR_MRLVDS) && defined(PWR_CR_LPLVDS) && defined(PWR_CR_FPDS)
|
|
MODIFY_REG(PWR->CR, (PWR_CR_PDDS | PWR_CR_LPDS | PWR_CR_FPDS | PWR_CR_LPLVDS | PWR_CR_MRLVDS), PDMode);
|
|
#else
|
|
MODIFY_REG(PWR->CR, (PWR_CR_PDDS| PWR_CR_LPDS), PDMode);
|
|
#endif /* PWR_CR_MRUDS && PWR_CR_LPUDS && PWR_CR_FPDS */
|
|
|
|
/* Set SLEEPDEEP bit of Cortex System Control Register */
|
|
SET_BIT(SCB->SCR, ((uint32_t)SCB_SCR_SLEEPDEEP_Msk));
|
|
|
|
// To avoid HardFault at return address, end in an endless loop
|
|
while (1) {
|
|
|
|
}
|
|
}
|
|
|
|
bool isBacklightEnabled()
|
|
{
|
|
return boardBacklightOn;
|
|
}
|