NV14 implementation partially merged with actual Flysky version.
This commit is contained in:
@@ -17,8 +17,9 @@
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
|
||||
#include "opentx.h"
|
||||
#include "touch.h"
|
||||
#if defined(__cplusplus) && !defined(SIMU)
|
||||
extern "C" {
|
||||
#endif
|
||||
@@ -62,8 +63,6 @@ void init1msTimer()
|
||||
NVIC_EnableIRQ(INTERRUPT_xMS_IRQn);
|
||||
NVIC_SetPriority(INTERRUPT_xMS_IRQn, 7);
|
||||
}
|
||||
|
||||
// TODO use the same than board_sky9x.cpp
|
||||
void interrupt1ms()
|
||||
{
|
||||
static uint8_t pre_scale; // Used to get 10 Hz counter
|
||||
@@ -74,7 +73,7 @@ void interrupt1ms()
|
||||
debugCounter1ms++;
|
||||
#endif
|
||||
|
||||
#if defined(HAPTIC)
|
||||
#if defined(HAPTIC) && !defined(BOOT)
|
||||
if (pre_scale == 5 || pre_scale == 10) {
|
||||
DEBUG_TIMER_START(debugTimerHaptic);
|
||||
HAPTIC_HEARTBEAT();
|
||||
@@ -85,7 +84,7 @@ void interrupt1ms()
|
||||
if (pre_scale == 10) {
|
||||
pre_scale = 0;
|
||||
#if !defined(SIMU)
|
||||
hall_stick_loop();
|
||||
if (boardState == BOARD_STARTED) hall_stick_loop();
|
||||
#endif
|
||||
DEBUG_TIMER_START(debugTimerPer10ms);
|
||||
DEBUG_TIMER_SAMPLE(debugTimerPer10msPeriod);
|
||||
@@ -96,18 +95,70 @@ void interrupt1ms()
|
||||
DEBUG_TIMER_START(debugTimerRotEnc);
|
||||
DEBUG_TIMER_STOP(debugTimerRotEnc);
|
||||
}
|
||||
|
||||
#if !defined(BOOT)
|
||||
extern "C" void INTERRUPT_xMS_IRQHandler()
|
||||
{
|
||||
INTERRUPT_xMS_TIMER->SR &= ~TIM_SR_UIF;
|
||||
interrupt1ms();
|
||||
DEBUG_INTERRUPT(INT_1MS);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(SEMIHOSTING)
|
||||
extern "C" void initialise_monitor_handles();
|
||||
#endif
|
||||
|
||||
|
||||
void delay_self(int count)
|
||||
{
|
||||
for (int i = 50000; i > 0; i--)
|
||||
{
|
||||
for (; count > 0; count--);
|
||||
}
|
||||
}
|
||||
#define RCC_AHB1PeriphMinimum (PWR_RCC_AHB1Periph |\
|
||||
LCD_RCC_AHB1Periph |\
|
||||
BACKLIGHT_RCC_AHB1Periph |\
|
||||
SDRAM_RCC_AHB1Periph \
|
||||
)
|
||||
#define RCC_AHB1PeriphOther (SD_RCC_AHB1Periph |\
|
||||
AUDIO_RCC_AHB1Periph |\
|
||||
MONITOR_RCC_AHB1Periph |\
|
||||
KEYS_RCC_AHB1Periph |\
|
||||
ADC_RCC_AHB1Periph |\
|
||||
AUX_SERIAL_RCC_AHB1Periph |\
|
||||
TELEMETRY_RCC_AHB1Periph |\
|
||||
TRAINER_RCC_AHB1Periph |\
|
||||
AUDIO_RCC_AHB1Periph |\
|
||||
HAPTIC_RCC_AHB1Periph |\
|
||||
INTMODULE_RCC_AHB1Periph |\
|
||||
INTMODULE_RCC_AHB1Periph|\
|
||||
EXTMODULE_RCC_AHB1Periph\
|
||||
)
|
||||
#define RCC_AHB3PeriphMinimum (SDRAM_RCC_AHB3Periph)
|
||||
|
||||
#define RCC_APB1PeriphMinimum (INTERRUPT_xMS_RCC_APB1Periph |\
|
||||
TIMER_2MHz_RCC_APB1Periph |\
|
||||
BACKLIGHT_RCC_APB1Periph \
|
||||
)
|
||||
|
||||
#define RCC_APB1PeriphOther (TELEMETRY_RCC_APB1Periph |\
|
||||
TRAINER_RCC_APB1Periph |\
|
||||
INTMODULE_RCC_APB1Periph |\
|
||||
HALL_RCC_APB1Periph |\
|
||||
EXTMODULE_RCC_APB1Periph |\
|
||||
INTMODULE_RCC_APB1Periph |\
|
||||
AUX_SERIAL_RCC_APB1Periph \
|
||||
)
|
||||
#define RCC_APB2PeriphMinimum (LCD_RCC_APB2Periph)
|
||||
|
||||
#define RCC_APB2PeriphOther (ADC_RCC_APB2Periph |\
|
||||
HAPTIC_RCC_APB2Periph |\
|
||||
AUX_SERIAL_RCC_APB2Periph |\
|
||||
AUDIO_RCC_APB2Periph |\
|
||||
EXTMODULE_RCC_APB2Periph \
|
||||
)
|
||||
|
||||
void boardInit()
|
||||
{
|
||||
#if defined(SEMIHOSTING)
|
||||
@@ -115,51 +166,15 @@ void boardInit()
|
||||
#endif
|
||||
|
||||
#if !defined(SIMU)
|
||||
RCC_AHB1PeriphClockCmd(PWR_RCC_AHB1Periph |
|
||||
LCD_RCC_AHB1Periph |
|
||||
BACKLIGHT_RCC_AHB1Periph |
|
||||
SD_RCC_AHB1Periph |
|
||||
SDRAM_RCC_AHB1Periph |
|
||||
AUDIO_RCC_AHB1Periph |
|
||||
MONITOR_RCC_AHB1Periph |
|
||||
KEYS_RCC_AHB1Periph |
|
||||
ADC_RCC_AHB1Periph |
|
||||
AUX_SERIAL_RCC_AHB1Periph |
|
||||
TELEMETRY_RCC_AHB1Periph |
|
||||
TRAINER_RCC_AHB1Periph |
|
||||
AUDIO_RCC_AHB1Periph |
|
||||
HAPTIC_RCC_AHB1Periph |
|
||||
INTMODULE_RCC_AHB1Periph |
|
||||
HALL_RCC_AHB1Periph |
|
||||
EXTMODULE_RCC_AHB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_AHB3PeriphClockCmd(SDRAM_RCC_AHB3Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB1PeriphClockCmd(INTERRUPT_xMS_RCC_APB1Periph |
|
||||
TIMER_2MHz_RCC_APB1Periph |
|
||||
TELEMETRY_RCC_APB1Periph |
|
||||
TRAINER_RCC_APB1Periph |
|
||||
INTMODULE_RCC_APB1Periph |
|
||||
HALL_RCC_APB1Periph |
|
||||
EXTMODULE_RCC_APB1Periph |
|
||||
BACKLIGHT_RCC_APB1Periph,
|
||||
ENABLE);
|
||||
|
||||
RCC_APB2PeriphClockCmd(LCD_RCC_APB2Periph |
|
||||
ADC_RCC_APB2Periph |
|
||||
HAPTIC_RCC_APB2Periph |
|
||||
AUX_SERIAL_RCC_APB2Periph |
|
||||
INTMODULE_RCC_APB2Periph |
|
||||
AUDIO_RCC_APB2Periph |
|
||||
EXTMODULE_RCC_APB2Periph,
|
||||
ENABLE);
|
||||
|
||||
pwrInit();
|
||||
RCC_AHB1PeriphClockCmd(RCC_AHB1PeriphMinimum | RCC_AHB1PeriphOther, ENABLE);
|
||||
RCC_AHB3PeriphClockCmd(RCC_AHB3PeriphMinimum, ENABLE);
|
||||
RCC_APB1PeriphClockCmd(RCC_APB1PeriphMinimum | RCC_APB1PeriphOther, ENABLE);
|
||||
RCC_APB2PeriphClockCmd(RCC_APB2PeriphMinimum | RCC_APB2PeriphOther, ENABLE);
|
||||
|
||||
__enable_irq();
|
||||
#endif
|
||||
#if defined(DEBUG)
|
||||
auxSerialInit(0, 0); // default serial mode (None if DEBUG nm ot defined)
|
||||
auxSerialInit(0, 0); // default serial mode (None if DEBUG not defined)
|
||||
#endif
|
||||
|
||||
__enable_irq();
|
||||
@@ -167,52 +182,83 @@ void boardInit()
|
||||
TRACE("\nNV14 board started :)");
|
||||
delay_ms(10);
|
||||
TRACE("RCC->CSR = %08x", RCC->CSR);
|
||||
audioInit();
|
||||
|
||||
// we need to initialize g_FATFS_Obj here, because it is in .ram section (because of DMA access)
|
||||
pwrInit();
|
||||
extModuleInit();
|
||||
battery_charge_init();
|
||||
init2MhzTimer();
|
||||
init1msTimer();
|
||||
TouchInit();
|
||||
uint32_t press_start = 0;
|
||||
uint32_t press_end = 0;
|
||||
if(UNEXPECTED_SHUTDOWN() || true) pwrOn();
|
||||
|
||||
while (boardState == BOARD_POWER_OFF)
|
||||
{
|
||||
uint32_t now = get_tmr10ms();
|
||||
if (pwrPressed())
|
||||
{
|
||||
press_end = now;
|
||||
if (press_start == 0) press_start = now;
|
||||
if ((now - press_start) > POWER_ON_DELAY)
|
||||
{
|
||||
pwrOn();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else {
|
||||
uint32_t press_end_touch = press_end;
|
||||
if(touchState.event == TE_UP)
|
||||
{
|
||||
touchState.event = TE_NONE;
|
||||
press_end_touch = touchState.time;
|
||||
}
|
||||
press_start = 0;
|
||||
handle_battery_charge(press_end_touch);
|
||||
delay_ms(20);
|
||||
press_end = 0;
|
||||
}
|
||||
}
|
||||
|
||||
keysInit();
|
||||
audioInit();
|
||||
// we need to initialize g_FATFS_Obj here, because it is in .ram section (because of DMA access)
|
||||
// and this section is un-initialized
|
||||
memset(&g_FATFS_Obj, 0, sizeof(g_FATFS_Obj));
|
||||
|
||||
init_battery_charge();
|
||||
monitorInit();
|
||||
keysInit();
|
||||
adcInit();
|
||||
backlightInit();
|
||||
lcdInit();
|
||||
#if defined(FLYSKY_HALL_STICKS)
|
||||
hall_stick_init(FLYSKY_HALL_BAUDRATE);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
init2MhzTimer();
|
||||
init1msTimer();
|
||||
usbInit();
|
||||
hapticInit();
|
||||
|
||||
TouchInit();
|
||||
|
||||
|
||||
boardState = BOARD_STARTED;
|
||||
#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
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
void boardOff()
|
||||
{
|
||||
BACKLIGHT_DISABLE();
|
||||
lcd->drawFilledRect(0, 0, LCD_WIDTH, LCD_HEIGHT, SOLID, HEADER_BGCOLOR);
|
||||
lcdOff();
|
||||
|
||||
while (pwrPressed()) {
|
||||
wdt_reset();
|
||||
WDG_RESET();
|
||||
}
|
||||
|
||||
|
||||
SysTick->CTRL = 0; // turn off systick
|
||||
pwrOff();
|
||||
#if !defined (SIMU)
|
||||
#if defined(HAPTIC) && !defined(BOOT)
|
||||
haptic.event(AU_ERROR);
|
||||
delay_ms(50);
|
||||
#endif
|
||||
while(1)
|
||||
{
|
||||
NVIC_SystemReset();
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void init_intmodule_heartbeat()
|
||||
{
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user