Add T16 support

Added support for:
- T16 radio
- internal multi-protocol module.
- flashing internal and external multi-protocol modules.

Many thx to:
- goebish, for the hardware support.
- qba667, for the original patches for the internal multi-protocol support (UI and serial com).
This commit is contained in:
Raphael Coeffic
2019-09-24 22:12:13 +02:00
committed by Raphael Coeffic
parent 4a618f1317
commit 6b12010473
98 changed files with 4585 additions and 481 deletions
+1 -1
View File
@@ -143,7 +143,7 @@ endif()
if(MULTIMODULE)
add_definitions(-DMULTIMODULE)
set(SRC ${SRC} pulses/multi.cpp telemetry/spektrum.cpp telemetry/flysky_ibus.cpp telemetry/multi.cpp)
set(SRC ${SRC} pulses/multi.cpp telemetry/spektrum.cpp telemetry/flysky_ibus.cpp telemetry/multi.cpp io/multi_firmware_update.cpp)
endif()
if(CROSSFIRE)
@@ -22,8 +22,10 @@
#if defined(SIMU)
// not needed
#elif defined(RADIO_T16)
const int8_t adcDirection[NUM_ANALOGS] = {1,-1,1,-1, 1,1,1, -1,1, -1,1};
#elif defined(PCBX10)
const int8_t adcDirection[NUM_ANALOGS] = {1,-1,1,-1, -1,1,-1, 1,1, 1, -1};
const int8_t adcDirection[NUM_ANALOGS] = {1,-1,1,-1, -1,1,-1, 1,1, 1, -1};
#elif defined(PCBX9E)
#if defined(HORUS_STICKS)
const int8_t adcDirection[NUM_ANALOGS] = {1,-1,1,-1, -1,-1,-1,1, -1,1,-1, -1,-1,-1};
@@ -95,8 +95,14 @@ void audioConsumeCurrentBuffer()
nextBuffer = audioQueue.buffersFifo.getNextFilledBuffer();
if (nextBuffer) {
#if defined(AUDIO_MUTE_GPIO_PIN)
// un-mute
GPIO_ResetBits(AUDIO_MUTE_GPIO, 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);
#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
@@ -20,6 +20,7 @@
#include "opentx.h"
#if defined(AUX_SERIAL)
uint8_t auxSerialMode = 0;
Fifo<uint8_t, 512> auxSerialTxFifo;
AuxSerialRxFifo auxSerialRxFifo __DMA (AUX_SERIAL_DMA_Stream_RX);
@@ -183,4 +184,5 @@ extern "C" void AUX_SERIAL_USART_IRQHandler(void)
}
#endif
}
#endif
#endif
#endif // AUX_SERIAL
@@ -39,14 +39,20 @@ void intmoduleStop()
USART_DeInit(INTMODULE_USART);
GPIO_ResetBits(INTMODULE_GPIO, INTMODULE_TX_GPIO_PIN | INTMODULE_RX_GPIO_PIN);
#if defined(INTERNAL_MODULE_MULTI)
// stop pulses timer
INTMODULE_TIMER->DIER &= ~TIM_DIER_CC2IE;
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
#endif
}
void intmodulePxx1SerialStart()
{
intmoduleSerialStart(INTMODULE_PXX1_SERIAL_BAUDRATE, false);
intmoduleSerialStart(INTMODULE_PXX1_SERIAL_BAUDRATE, false, USART_Parity_No, USART_StopBits_1, USART_WordLength_8b);
}
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable)
void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable, uint16_t parity, uint16_t stopBits, uint16_t wordLength)
{
INTERNAL_MODULE_ON();
@@ -71,9 +77,9 @@ void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable)
USART_DeInit(INTMODULE_USART);
USART_InitTypeDef USART_InitStructure;
USART_InitStructure.USART_BaudRate = baudrate;
USART_InitStructure.USART_Parity = USART_Parity_No;
USART_InitStructure.USART_StopBits = USART_StopBits_1;
USART_InitStructure.USART_WordLength = USART_WordLength_8b;
USART_InitStructure.USART_Parity = parity;
USART_InitStructure.USART_StopBits = stopBits;
USART_InitStructure.USART_WordLength = wordLength;
USART_InitStructure.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
USART_InitStructure.USART_Mode = USART_Mode_Tx | USART_Mode_Rx;
USART_Init(INTMODULE_USART, &USART_InitStructure);
@@ -87,6 +93,28 @@ void intmoduleSerialStart(uint32_t baudrate, uint8_t rxEnable)
}
}
#if defined(INTERNAL_MODULE_MULTI)
void intmoduleTimerStart(uint32_t periodMs)
{
// Timer
INTMODULE_TIMER->CR1 &= ~TIM_CR1_CEN;
INTMODULE_TIMER->PSC = INTMODULE_TIMER_FREQ / 2000000 - 1; // 0.5uS (2Mhz)
INTMODULE_TIMER->ARR = periodMs * 2000;
INTMODULE_TIMER->CCR2 = (periodMs - 1) * 2000;
INTMODULE_TIMER->CCER = TIM_CCER_CC3E;
INTMODULE_TIMER->CCMR2 = 0;
INTMODULE_TIMER->EGR = 1; // Restart
INTMODULE_TIMER->CCMR2 = TIM_CCMR2_OC3M_1 | TIM_CCMR2_OC3M_0; // Toggle CC1 o/p
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // Clear flag
INTMODULE_TIMER->DIER |= TIM_DIER_CC2IE; // Enable this interrupt
INTMODULE_TIMER->CR1 |= TIM_CR1_CEN;
NVIC_EnableIRQ(INTMODULE_TIMER_IRQn);
NVIC_SetPriority(INTMODULE_TIMER_IRQn, 7);
}
#endif
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
extern "C" void INTMODULE_USART_IRQHandler(void)
{
@@ -98,7 +126,6 @@ extern "C" void INTMODULE_USART_IRQHandler(void)
intmoduleFifo.errors++;
}
else {
hardwareOptions.pxx2Enabled = true;
intmoduleFifo.push(data);
}
status = INTMODULE_USART->SR;
@@ -152,5 +179,20 @@ void intmoduleSendNextFrame()
intmoduleSendBuffer(intmodulePulsesData.pxx_uart.getData(), intmodulePulsesData.pxx_uart.getSize());
break;
#endif
#if defined(INTERNAL_MODULE_MULTI)
case PROTOCOL_CHANNELS_MULTIMODULE:
intmoduleSendBuffer(intmodulePulsesData.multi.getData(), intmodulePulsesData.multi.getSize());
break;
#endif
}
}
#if defined(INTERNAL_MODULE_MULTI)
extern "C" void INTMODULE_TIMER_IRQHandler()
{
INTMODULE_TIMER->SR &= ~TIM_SR_CC2IF; // clear flag
setupPulsesInternalModule();
intmoduleSendNextFrame();
}
#endif
@@ -71,6 +71,27 @@ void rotaryEncoderInit()
void rotaryEncoderCheck()
{
#if defined(RADIO_T16)
static uint8_t state = 0;
uint8_t pins = ROTARY_ENCODER_POSITION();
if (pins != (state & 0x03) && !(readKeys() & (1 << KEY_ENTER))) {
if ((pins & 0x01) ^ ((pins & 0x02) >> 1)) {
if ((state & 0x03) == 3)
++rotencValue;
else
--rotencValue;
}
else
{
if ((state & 0x03) == 3)
--rotencValue;
else if ((state & 0x03) == 0)
++rotencValue;
}
state &= ~0x03 ;
state |= pins ;
#else
uint8_t newPosition = ROTARY_ENCODER_POSITION();
if (newPosition != rotencPosition && !(readKeys() & (1 << KEY_ENTER))) {
if ((rotencPosition & 0x01) ^ ((newPosition & 0x02) >> 1)) {
@@ -80,6 +101,7 @@ void rotaryEncoderCheck()
++rotencValue;
}
rotencPosition = newPosition;
#endif
#if !defined(BOOT)
if (g_eeGeneral.backlightMode & e_backlight_mode_keys) {
backlightOn();
@@ -127,4 +149,4 @@ extern "C" void ROTARY_ENCODER_TIMER_IRQHandler(void)
ROTARY_ENCODER_TIMER->SR &= ~TIM_SR_UIF;
ROTARY_ENCODER_TIMER->CR1 = 0;
rotaryEncoderCheck();
}
}