Merge with latest 2.3

This commit is contained in:
Bertrand Songis
2020-01-08 16:35:30 +01:00
91 changed files with 1139 additions and 860 deletions
@@ -3,6 +3,7 @@ set_property(CACHE TIMERS PROPERTY STRINGS 2 3)
option(CLI "Command Line Interface" OFF)
option(DEBUG "Debug mode" OFF)
option(LOG_TELEMETRY "Telemetry Logs on SD card" OFF)
option(LOG_BLUETOOTH "Bluetooth Logs on SD card" OFF)
option(TRACE_SD_CARD "Traces SD enabled" OFF)
option(TRACE_FATFS "Traces FatFS enabled" OFF)
option(TRACE_AUDIO "Traces audio enabled" OFF)
@@ -32,6 +33,10 @@ if(LOG_TELEMETRY)
add_definitions(-DLOG_TELEMETRY)
endif()
if(LOG_BLUETOOTH)
add_definitions(-DLOG_BLUETOOTH)
endif()
if(TRACE_SD_CARD)
add_definitions(-DTRACE_SD_CARD)
set(DEBUG ON)
@@ -88,33 +88,61 @@ void dacInit()
NVIC_SetPriority(AUDIO_DMA_Stream_IRQn, 7);
}
#if defined(AUDIO_MUTE_GPIO_PIN)
void audioMute()
{
#if defined(AUDIO_UNMUTE_DELAY)
tmr10ms_t now = get_tmr10ms();
if (!audioQueue.lastAudioPlayTime) {
// we start the mute delay now
audioQueue.lastAudioPlayTime = now;
}
else if (now - audioQueue.lastAudioPlayTime > AUDIO_MUTE_DELAY / 10) {
// delay expired, we may mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
}
#else
// mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
}
void audioUnmute()
{
#if defined(AUDIO_UNMUTE_DELAY)
// if muted
if (GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN)) {
// ..un-mute
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
}
// reset the mute delay
audioQueue.lastAudioPlayTime = 0;
#else
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#endif
}
#endif
void audioConsumeCurrentBuffer()
{
if (!nextBuffer) {
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (nextBuffer) {
#if defined(AUDIO_MUTE_GPIO_PIN)
// if muted
if (GPIO_ReadOutputDataBit(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN)) {
// ..un-mute
GPIO_ResetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
#if defined(AUDIO_UNMUTE_DELAY)
RTOS_WAIT_MS(AUDIO_UNMUTE_DELAY);
audioUnmute();
#endif
}
#endif
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN ; // Disable DMA channel
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5 ; // Write ones to clear bits
AUDIO_DMA_Stream->CR &= ~DMA_SxCR_EN; // Disable DMA channel
AUDIO_DMA->HIFCR = DMA_HIFCR_CTCIF5 | DMA_HIFCR_CHTIF5 | DMA_HIFCR_CTEIF5 | DMA_HIFCR_CDMEIF5 | DMA_HIFCR_CFEIF5; // Write ones to clear bits
AUDIO_DMA_Stream->M0AR = CONVERT_PTR_UINT(nextBuffer->data);
AUDIO_DMA_Stream->NDTR = nextBuffer->size;
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE ; // Enable DMA channel and interrupt
DAC->SR = DAC_SR_DMAUDR1 ; // Write 1 to clear flag
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1 ; // Enable DAC
AUDIO_DMA_Stream->CR |= DMA_SxCR_EN | DMA_SxCR_TCIE; // Enable DMA channel and interrupt
DAC->SR = DAC_SR_DMAUDR1; // Write 1 to clear flag
DAC->CR |= DAC_CR_EN1 | DAC_CR_DMAEN1; // Enable DAC
}
#if defined(AUDIO_MUTE_GPIO_PIN)
else {
// mute
GPIO_SetBits(AUDIO_MUTE_GPIO, AUDIO_MUTE_GPIO_PIN);
audioMute();
}
#endif
}
@@ -107,6 +107,12 @@ void bluetoothInit(uint32_t baudrate, bool enable)
void bluetoothDisable()
{
GPIO_SetBits(BT_EN_GPIO, BT_EN_GPIO_PIN); // close bluetooth (recent modules will go to bootloader mode)
USART_ITConfig(BT_USART, USART_IT_RXNE, DISABLE);
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = BT_RX_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
GPIO_Init(BT_USART_GPIO, &GPIO_InitStructure);
USART_DeInit(BT_USART);
}
extern "C" void BT_USART_IRQHandler(void)
@@ -74,7 +74,7 @@ set(BOOTLOADER_SRC
../../../../../targets/${TARGET_DIR}/keys_driver.cpp
../../../../../targets/${TARGET_DIR}/diskio.cpp
../../../../../targets/${TARGET_DIR}/board.cpp
../../../../../targets/${TARGET_DIR}/pwr_driver.cpp
../pwr_driver.cpp
../../../../../targets/${TARGET_DIR}/bootloader/boot_menu.cpp
../usbd_usr.cpp
../usbd_storage_msd.cpp
@@ -142,6 +142,7 @@ remove_definitions(-DDEBUG)
remove_definitions(-DDISK_CACHE)
remove_definitions(-DLUA)
remove_definitions(-DCLI)
remove_definitions(-DSEMIHOSTING)
remove_definitions(-DUSB_SERIAL)
remove_definitions(-DWATCHDOG)
@@ -0,0 +1,119 @@
/*
* Copyright (C) OpenTX
*
* Based on code named
* 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 "opentx.h"
void pwrInit()
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
#if defined(INTMODULE_BOOTCMD_GPIO)
INIT_INTMODULE_BOOTCMD_PIN();
GPIO_InitStructure.GPIO_Pin = INTMODULE_BOOTCMD_GPIO_PIN;
GPIO_Init(INTMODULE_BOOTCMD_GPIO, &GPIO_InitStructure);
#endif
// Internal module power
GPIO_ResetBits(INTMODULE_PWR_GPIO, INTMODULE_PWR_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = INTMODULE_PWR_GPIO_PIN;
GPIO_Init(INTMODULE_PWR_GPIO, &GPIO_InitStructure);
// External module power
EXTERNAL_MODULE_PWR_OFF();
GPIO_InitStructure.GPIO_Pin = EXTMODULE_PWR_GPIO_PIN;
GPIO_Init(EXTMODULE_PWR_GPIO, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN;
// PWR switch
GPIO_InitStructure.GPIO_Pin = PWR_SWITCH_GPIO_PIN;
GPIO_Init(PWR_SWITCH_GPIO, &GPIO_InitStructure);
#if defined(PCBREV_HARDCODED)
hardwareOptions.pcbrev = PCBREV_HARDCODED;
#elif defined(PCBREV_GPIO_PIN)
GPIO_ResetBits(PCBREV_GPIO, PCBREV_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = PCBREV_GPIO_PIN;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_DOWN;
GPIO_Init(PCBREV_GPIO, &GPIO_InitStructure);
hardwareOptions.pcbrev = PCBREV_VALUE();
#endif
#if defined(TRAINER_DETECT_GPIO_PIN)
GPIO_InitStructure.GPIO_Pin = TRAINER_DETECT_GPIO_PIN;
GPIO_Init(TRAINER_DETECT_GPIO, &GPIO_InitStructure);
#endif
#if defined(SD_PRESENT_GPIO_PIN)
GPIO_ResetBits(SD_PRESENT_GPIO, SD_PRESENT_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = SD_PRESENT_GPIO_PIN;
GPIO_Init(SD_PRESENT_GPIO, &GPIO_InitStructure);
#endif
#if defined(INTMODULE_USART) && defined(TRAINER_MODULE_CPPM_GPIO_PIN)
GPIO_SetBits(TRAINER_MODULE_CPPM_GPIO, TRAINER_MODULE_CPPM_GPIO_PIN);
GPIO_InitStructure.GPIO_Pin = TRAINER_MODULE_CPPM_GPIO_PIN;
GPIO_Init(TRAINER_MODULE_CPPM_GPIO, &GPIO_InitStructure);
#endif
}
void pwrOn()
{
// we keep the init of the PIN to have pwrOn as quick as possible
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = PWR_ON_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_2MHz;
GPIO_InitStructure.GPIO_OType = GPIO_OType_PP;
GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
GPIO_Init(PWR_ON_GPIO, &GPIO_InitStructure);
GPIO_SetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
}
void pwrOff()
{
GPIO_ResetBits(PWR_ON_GPIO, PWR_ON_GPIO_PIN);
}
bool pwrPressed()
{
return GPIO_ReadInputDataBit(PWR_SWITCH_GPIO, PWR_SWITCH_GPIO_PIN) == Bit_RESET;
}
void pwrResetHandler()
{
RCC->AHB1ENR |= PWR_RCC_AHB1Periph;
// these two NOPs are needed (see STM32F errata sheet) before the peripheral
// register can be written after the peripheral clock was enabled
__ASM volatile ("nop");
__ASM volatile ("nop");
if (WAS_RESET_BY_WATCHDOG_OR_SOFTWARE()) {
pwrOn();
}
}