* WiP: new module interface * WiP: softserial timer DMA * WiP: setup() and send() in one step and remove methods specific to internal or external module * fixes and extra port config * horus targets * module ports have moved * T8 support (only internal module) * fix nv14 * stupid GCC.... * disable BT * remove nv14 telem driver * remove old aux serial driver * Move module buffers out of pulses.h * Soft serial fixes and PXX1 support * Fixed PPM module output * Fixed CLI * compilation fixes * Ported bluetooth and flysky gimbal to new serial driver * Re-enable soft-serial RX * fixes and cleanup * nv14 fixes * Fix flysky gimbals * Ghost module * 16 bytes of RAM * Remove getByte from module API * Ghost cleanup * fix: _half_duplex_input() must be called after usart init * WiP * more cleanup * Remove board specific settings from PXX1 / PXX2 drivers * A bit of PXX2 header cleanup * Add support for OVER8 and ONEBIT * Add some support for inverters (NV14 / EL18) * Support NV14 power fixes in generic board * Fix polarity handling * Fix RX DMA * Fix mixer not running * Add soft-serial polarity control * Quick fix for telemetry polling while module port is changed * Fix bootloader DEBUG * Fix MPM telemetry * Fix pulse start * DSM2 soft-serial fallback * DSMP async module restart * Fix CRSF LUA upstream * Remove global variable telemetryProtocol * Use HAL/LL constants * Fix various issue with AFHDS3 and NV14/EL18 internal module * Fixed S.PORT unit tests * fix: update widx after writing at current index * fix: init error condition * Fix: possible infinite loop in _find_port() * Add support for bidir S.PORT init * Add support for "getLastByte" in HW serial driver * PXX1: Add support for S.PORT based on IDLE callback * Fix rebase error * Fix softserial _rx_fifo_push() * Add softserial support for waitForTxCompleted() * Fix MPM flashing (internal / external) * Fixed external MPM * Activate RX DMA on internal module Seems to work with serial passthrough without issues, at least on the L3R PRO. * Fix softserial DMA on stdlcd F4 targets * Add softserial support for 32bit timers (mostly TIM2) * More precise soft-serial * Fix MPM update using inverters & HW uart * Raise S.PORT DMA/USART IRQ prio to achieve faster switching to input * Remove useless delays * Fix flashing external ELRS module * Added a retry mechanism for FrSky S.PORT update * Remove useless enableRx() * External FrSky modules are all flashed via S.PORT * Remove power management unit update This was only used on the first batch of X-lite.
149 lines
3.9 KiB
C++
149 lines
3.9 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/serial_port.h"
|
|
#include "stm32_serial_driver.h"
|
|
|
|
#include "board.h"
|
|
#include "dataconstants.h"
|
|
|
|
#define AUX_SERIAL_TX_BUFFER 512
|
|
#if defined(SDRAM)
|
|
#define AUX_SERIAL_RX_BUFFER 512
|
|
#else
|
|
#define AUX_SERIAL_RX_BUFFER 32
|
|
#endif
|
|
|
|
#if defined(AUX_SERIAL_PWR_GPIO) || defined(AUX2_SERIAL_PWR_GPIO)
|
|
static void _aux_pwr(GPIO_TypeDef *GPIOx, uint32_t pin, uint8_t on)
|
|
{
|
|
LL_GPIO_InitTypeDef pinInit;
|
|
LL_GPIO_StructInit(&pinInit);
|
|
pinInit.Pin = pin;
|
|
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
|
|
pinInit.Pull = LL_GPIO_PULL_UP;
|
|
LL_GPIO_Init(GPIOx, &pinInit);
|
|
|
|
if (on) {
|
|
LL_GPIO_SetOutputPin(GPIOx, pin);
|
|
} else {
|
|
LL_GPIO_ResetOutputPin(GPIOx, pin);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
#if defined(AUX_SERIAL)
|
|
|
|
#if !defined(AUX_SERIAL_DMA_TX)
|
|
#define AUX_SERIAL_DMA_TX nullptr
|
|
#define AUX_SERIAL_DMA_Stream_TX nullptr
|
|
#define AUX_SERIAL_DMA_Stream_TX_LL 0
|
|
#define AUX_SERIAL_DMA_Channel_TX 0
|
|
#endif
|
|
|
|
static const stm32_usart_t auxUSART = {
|
|
.USARTx = AUX_SERIAL_USART,
|
|
.GPIOx = AUX_SERIAL_GPIO,
|
|
.GPIO_Pin = AUX_SERIAL_GPIO_PIN_TX | AUX_SERIAL_GPIO_PIN_RX,
|
|
.IRQn = AUX_SERIAL_USART_IRQn,
|
|
.IRQ_Prio = 7, // TODO: define constant
|
|
.txDMA = AUX_SERIAL_DMA_TX,
|
|
.txDMA_Stream = AUX_SERIAL_DMA_Stream_TX_LL,
|
|
.txDMA_Channel = AUX_SERIAL_DMA_Channel_TX,
|
|
.rxDMA = AUX_SERIAL_DMA_RX,
|
|
.rxDMA_Stream = AUX_SERIAL_DMA_Stream_RX_LL,
|
|
.rxDMA_Channel = AUX_SERIAL_DMA_Channel_RX,
|
|
};
|
|
|
|
DEFINE_STM32_SERIAL_PORT(Aux, auxUSART, AUX_SERIAL_RX_BUFFER, AUX_SERIAL_TX_BUFFER);
|
|
|
|
#if defined(AUX_SERIAL_PWR_GPIO)
|
|
void set_aux_pwr(uint8_t on)
|
|
{
|
|
_aux_pwr(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN, on);
|
|
}
|
|
#define AUX_PWR_FCT set_aux_pwr
|
|
#else
|
|
#define AUX_PWR_FCT nullptr
|
|
#endif
|
|
|
|
const etx_serial_port_t auxSerialPort = {
|
|
.name = "AUX1",
|
|
.uart = &STM32SerialDriver,
|
|
.hw_def = REF_STM32_SERIAL_PORT(Aux),
|
|
AUX_PWR_FCT
|
|
};
|
|
#define AUX_SERIAL_PORT &auxSerialPort
|
|
#else
|
|
#define AUX_SERIAL_PORT nullptr
|
|
#endif
|
|
|
|
#if defined(AUX2_SERIAL)
|
|
|
|
static const stm32_usart_t aux2USART = {
|
|
.USARTx = AUX2_SERIAL_USART,
|
|
.GPIOx = AUX2_SERIAL_GPIO,
|
|
.GPIO_Pin = AUX2_SERIAL_GPIO_PIN_TX | AUX2_SERIAL_GPIO_PIN_RX,
|
|
.IRQn = AUX2_SERIAL_USART_IRQn,
|
|
.IRQ_Prio = 7, // TODO: define constant
|
|
.txDMA = nullptr,
|
|
.txDMA_Stream = 0,
|
|
.txDMA_Channel = 0,
|
|
.rxDMA = AUX2_SERIAL_DMA_RX,
|
|
.rxDMA_Stream = AUX2_SERIAL_DMA_Stream_RX_LL,
|
|
.rxDMA_Channel = AUX2_SERIAL_DMA_Channel_RX,
|
|
};
|
|
|
|
DEFINE_STM32_SERIAL_PORT(Aux2, aux2USART, AUX_SERIAL_RX_BUFFER, AUX_SERIAL_TX_BUFFER);
|
|
|
|
#if defined(AUX2_SERIAL_PWR_GPIO)
|
|
void set_aux2_pwr(uint8_t on)
|
|
{
|
|
_aux_pwr(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN, on);
|
|
}
|
|
#define AUX2_PWR_FCT set_aux2_pwr
|
|
#else
|
|
#define AUX2_PWR_FCT nullptr
|
|
#endif
|
|
|
|
const etx_serial_port_t aux2SerialPort = {
|
|
.name = "AUX2",
|
|
.uart = &STM32SerialDriver,
|
|
.hw_def = REF_STM32_SERIAL_PORT(Aux2),
|
|
AUX2_PWR_FCT
|
|
};
|
|
#define AUX2_SERIAL_PORT &aux2SerialPort
|
|
#else
|
|
#define AUX2_SERIAL_PORT nullptr
|
|
#endif
|
|
|
|
static const etx_serial_port_t* serialPorts[MAX_AUX_SERIAL] = {
|
|
AUX_SERIAL_PORT,
|
|
AUX2_SERIAL_PORT,
|
|
};
|
|
|
|
const etx_serial_port_t* auxSerialGetPort(int port_nr)
|
|
{
|
|
if (port_nr >= MAX_AUX_SERIAL) return nullptr;
|
|
return serialPorts[port_nr];
|
|
}
|
|
|