This commit is contained in:
Raphael Coeffic
2022-03-20 16:22:14 +01:00
parent da59fca1bc
commit 530d395204
66 changed files with 1267 additions and 1081 deletions
@@ -29,7 +29,6 @@ set(STM32USB_SRC
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
../common/arm/stm32/rtc_driver.cpp
${AUX_SERIAL_DRIVER}
../common/arm/stm32/delays_driver.cpp
../common/arm/stm32/usb_bsp.c
../common/arm/stm32/usbd_desc.c
@@ -40,6 +39,18 @@ set(FIRMWARE_TARGET_SRC
../common/arm/stm32/usbd_hid_joystick.c
)
if(AUX_SERIAL OR AUX2_SERIAL)
set(FIRMWARE_TARGET_SRC ${FIRMWARE_TARGET_SRC}
../common/arm/stm32/aux_serial_driver.cpp
)
if(AUX_SERIAL)
add_definitions(-DAUX_SERIAL)
endif()
if(AUX2_SERIAL)
add_definitions(-DAUX2_SERIAL)
endif()
endif()
if(DEBUG OR CLI OR USB_SERIAL)
set(STM32USB_SRC
${STM32USB_SRC}
@@ -70,7 +81,6 @@ endif()
set(FIRMWARE_SRC
${FIRMWARE_SRC}
serial.cpp
syscalls.c
)
@@ -26,8 +26,71 @@
#include "targets/horus/board.h"
#include "aux_serial_driver.h"
#include "fifo.h"
#include "dmafifo.h"
typedef DMAFifo<32> AuxSerialRxFifo;
struct AuxSerialState
{
Fifo<uint8_t, 512>* txFifo;
AuxSerialRxFifo* rxFifo;
const stm32_usart_t* usart;
};
static void* aux_serial_init(struct AuxSerialState* st, const etx_serial_init* params)
{
stm32_usart_init(st->usart, params);
if (params->rx_enable && st->usart->rxDMA && !params->on_receive) {
st->rxFifo->clear();
stm32_usart_init_rx_dma(st->usart, st->rxFifo->buffer(), st->rxFifo->size());
}
return st;
}
static void aux_serial_putc(void* ctx, uint8_t c)
{
AuxSerialState* st = (AuxSerialState*)ctx;
if (st->txFifo->isFull()) return;
st->txFifo->push(c);
// Send is based on IRQ, so that this
// only enables the corresponding IRQ
stm32_usart_send_buffer(st->usart, &c, 1);
}
static void aux_serial_send_buffer(void* ctx, const uint8_t* data, uint8_t size)
{
while(size > 0) {
aux_serial_putc(ctx, *data++);
size--;
}
}
static void aux_wait_tx_completed(void* ctx)
{
// TODO
(void)ctx;
}
static int aux_get_byte(void* ctx, uint8_t* data)
{
AuxSerialState* st = (AuxSerialState*)ctx;
if (!st->rxFifo) return -1;
return st->rxFifo->pop(*data);
}
void aux_serial_deinit(void* ctx)
{
AuxSerialState* st = (AuxSerialState*)ctx;
stm32_usart_deinit(st->usart);
}
#if defined(AUX_SERIAL)
uint8_t auxSerialMode = UART_MODE_COUNT; // Prevent debug output before port is setup
Fifo<uint8_t, 512> auxSerialTxFifo;
#if defined(AUX_SERIAL_DMA_Stream_RX)
@@ -65,166 +128,53 @@ const stm32_usart_t auxUSART = {
#endif
};
static bool auxSerialOnSend(uint8_t& data)
AuxSerialState auxSerialState = {
.txFifo = &auxSerialTxFifo,
.rxFifo = &auxSerialRxFifo,
.usart = &auxUSART,
};
// TODO: grab context to get buffer
static bool auxSerialOnSend(uint8_t* data)
{
return auxSerialTxFifo.pop(data);
return auxSerialTxFifo.pop(*data);
}
// TODO: add to state
static etx_serial_callbacks_t auxSerialCb = {
.on_send = auxSerialOnSend,
.on_receive = nullptr,
.on_error = nullptr,
};
void auxSerialSetup(unsigned int baudrate, bool rx_enable, uint8_t word_length,
uint8_t parity, uint8_t stop_bits)
static void* auxSerialInit(const etx_serial_init* params)
{
#if defined(AUX_SERIAL_PWR_GPIO)
LL_GPIO_InitTypeDef pinInit;
LL_GPIO_StructInit(&pinInit);
pinInit.Pin = AUX_SERIAL_PWR_GPIO_PIN;
pinInit.Mode = LL_GPIO_MODE_OUTPUT;
pinInit.Pull = LL_GPIO_PULL_UP;
LL_GPIO_Init(AUX_SERIAL_PWR_GPIO, &pinInit);
#endif
#if defined(AUX_SERIAL_TX_INVERT_GPIO_PIN) // NV14
// TODO
GPIO_InitStructure.GPIO_Pin = AUX_SERIAL_TX_INVERT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(AUX_SERIAL_TX_INVERT_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUX_SERIAL_TX_INVERT_GPIO, AUX_SERIAL_TX_INVERT_GPIO_PIN);
#endif
#if defined(AUX_SERIAL_RX_INVERT_GPIO_PIN) // NV14
// TODO
GPIO_InitStructure.GPIO_Pin = AUX_SERIAL_RX_INVERT_GPIO_PIN;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
GPIO_Init(AUX_SERIAL_RX_INVERT_GPIO, &GPIO_InitStructure);
GPIO_ResetBits(AUX_SERIAL_RX_INVERT_GPIO, AUX_SERIAL_RX_INVERT_GPIO_PIN);
#endif
etx_serial_init serialInit = {
.baudrate = baudrate,
.parity = parity,
.stop_bits = stop_bits,
.word_length = word_length,
.rx_enable = rx_enable,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = nullptr, // TODO
.on_error = nullptr, // TODO
};
#if defined(AUX_SERIAL_DMA_Stream_RX)
if (rx_enable) {
auxSerialRxFifo.clear();
serialInit.rx_dma_buf = auxSerialRxFifo.buffer();
serialInit.rx_dma_buf_len = auxSerialRxFifo.size();
}
#endif
stm32_usart_init(&auxUSART, &serialInit);
return aux_serial_init(&auxSerialState, params);
}
const etx_serial_driver_t AuxSerialDriver = {
.init = auxSerialInit,
.deinit = aux_serial_deinit,
.sendByte = aux_serial_putc,
.sendBuffer = aux_serial_send_buffer,
.waitForTxCompleted = aux_wait_tx_completed,
.getByte = aux_get_byte,
.setReceiveCb = nullptr,
.setOnErrorCb = nullptr,
};
extern "C" void AUX_SERIAL_USART_IRQHandler(void)
{
DEBUG_INTERRUPT(INT_SER2);
stm32_usart_isr(&auxUSART, &auxSerialCb);
}
void auxSerialPutc(uint8_t c)
{
if (auxSerialTxFifo.isFull()) return;
auxSerialTxFifo.push(c);
stm32_usart_send_buffer(&auxUSART, &c, 1);
}
void auxSerialStop()
{
stm32_usart_deinit(&auxUSART);
}
static void serialPushLua(uint8_t data)
{
// TODO: this should be set by LUA instead of
// including some LUA header here.
//
// if (luaRxFifo)
// luaRxFifo->push(data);
}
void auxSerialInit(unsigned int mode, unsigned int protocol)
{
auxSerialStop();
auxSerialMode = mode;
auxSerialCb.on_receive = nullptr;
switch (mode) {
case UART_MODE_TELEMETRY_MIRROR:
// TODO: add a setting for the telemetry protocol ???
// -> how do we know the baudrate?
#if defined(CROSSFIRE)
if (protocol == PROTOCOL_TELEMETRY_CROSSFIRE) {
auxSerialSetup(CROSSFIRE_TELEM_MIRROR_BAUDRATE, false);
AUX_SERIAL_POWER_ON();
break;
}
#endif
auxSerialSetup(FRSKY_TELEM_MIRROR_BAUDRATE, false);
AUX_SERIAL_POWER_ON();
break;
#if defined(DEBUG) || defined(CLI)
case UART_MODE_DEBUG:
auxSerialSetup(DEBUG_BAUDRATE, false);
AUX_SERIAL_POWER_OFF();
break;
#endif
case UART_MODE_TELEMETRY:
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
auxSerialSetup(FRSKY_D_BAUDRATE, true);
AUX_SERIAL_POWER_ON();
}
break;
case UART_MODE_SBUS_TRAINER:
auxSerialSetup(
SBUS_BAUDRATE, true, ETX_WordLength_9, ETX_Parity_Even,
ETX_StopBits_Two); // USART_WordLength_9b due to parity bit
AUX_SERIAL_POWER_ON();
break;
#if defined(LUA)
case UART_MODE_LUA:
auxSerialSetup(LUA_DEFAULT_BAUDRATE, false);
auxSerialCb.on_receive = serialPushLua;
AUX_SERIAL_POWER_ON();
break;
#endif
}
}
void auxSerialSbusInit()
{
auxSerialInit(UART_MODE_SBUS_TRAINER, 0);
}
uint8_t auxSerialTracesEnabled()
{
#if defined(DEBUG)
return (auxSerialMode == UART_MODE_DEBUG);
#else
return false;
#endif
}
#endif // AUX_SERIAL
#if defined(AUX2_SERIAL)
uint8_t aux2SerialMode = UART_MODE_COUNT; // Prevent debug output before port is setup
Fifo<uint8_t, 512> aux2SerialTxFifo;
AuxSerialRxFifo aux2SerialRxFifo __DMA (AUX2_SERIAL_DMA_Stream_RX);
const LL_GPIO_InitTypeDef aux2USARTPinInit = {
@@ -250,9 +200,15 @@ const stm32_usart_t aux2USART = {
.rxDMA_Channel = AUX2_SERIAL_DMA_Channel_RX,
};
static bool aux2SerialOnSend(uint8_t& data)
AuxSerialState aux2SerialState = {
.txFifo = &aux2SerialTxFifo,
.rxFifo = &aux2SerialRxFifo,
.usart = &aux2USART,
};
static bool aux2SerialOnSend(uint8_t* data)
{
return aux2SerialTxFifo.pop(data);
return aux2SerialTxFifo.pop(*data);
}
static etx_serial_callbacks_t aux2SerialCb = {
@@ -261,35 +217,9 @@ static etx_serial_callbacks_t aux2SerialCb = {
.on_error = nullptr,
};
void aux2SerialSetup(unsigned int baudrate, bool rx_enable, uint8_t word_length,
uint8_t parity, uint8_t stop_bits)
void* aux2SerialInit(const etx_serial_init* params)
{
etx_serial_init serialInit = {
.baudrate = baudrate,
.parity = parity,
.stop_bits = stop_bits,
.word_length = word_length,
.rx_enable = rx_enable,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = nullptr, // TODO
.on_error = nullptr, // TODO
};
if (rx_enable) {
aux2SerialRxFifo.clear();
serialInit.rx_dma_buf = aux2SerialRxFifo.buffer();
serialInit.rx_dma_buf_len = aux2SerialRxFifo.size();
}
stm32_usart_init(&aux2USART, &serialInit);
// #if defined(AUX2_SERIAL_PWR_GPIO)
// GPIO_InitStructure.GPIO_Mode = GPIO_Mode_OUT;
// GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_UP;
// GPIO_InitStructure.GPIO_Pin = AUX2_SERIAL_PWR_GPIO_PIN;
// GPIO_Init(AUX2_SERIAL_PWR_GPIO, &GPIO_InitStructure);
// #endif
return aux_serial_init(&aux2SerialState, params);
}
extern "C" void AUX2_SERIAL_USART_IRQHandler(void)
@@ -298,81 +228,15 @@ extern "C" void AUX2_SERIAL_USART_IRQHandler(void)
stm32_usart_isr(&aux2USART, &aux2SerialCb);
}
void aux2SerialPutc(uint8_t c)
{
if (aux2SerialTxFifo.isFull()) return;
aux2SerialTxFifo.push(c);
stm32_usart_send_buffer(&aux2USART, &c, 1);
}
void aux2SerialStop()
{
stm32_usart_deinit(&aux2USART);
}
void aux2SerialInit(unsigned int mode, unsigned int protocol)
{
aux2SerialStop();
aux2SerialMode = mode;
aux2SerialCb.on_receive = nullptr;
switch (mode) {
case UART_MODE_TELEMETRY_MIRROR:
#if defined(CROSSFIRE)
if (protocol == PROTOCOL_TELEMETRY_CROSSFIRE) {
aux2SerialSetup(CROSSFIRE_TELEM_MIRROR_BAUDRATE, false);
AUX2_SERIAL_POWER_ON();
break;
}
#endif
aux2SerialSetup(FRSKY_TELEM_MIRROR_BAUDRATE, false);
AUX2_SERIAL_POWER_ON();
break;
#if defined(DEBUG) || defined(CLI)
case UART_MODE_DEBUG:
aux2SerialSetup(DEBUG_BAUDRATE, false);
AUX2_SERIAL_POWER_OFF();
break;
#endif
case UART_MODE_TELEMETRY:
if (protocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
aux2SerialSetup(FRSKY_D_BAUDRATE, true);
AUX2_SERIAL_POWER_ON();
}
break;
case UART_MODE_SBUS_TRAINER:
aux2SerialSetup(
SBUS_BAUDRATE, true, ETX_WordLength_9, ETX_Parity_Even,
ETX_StopBits_Two); // 2 stop bits requires USART_WordLength_9b
AUX2_SERIAL_POWER_ON();
break;
#if defined(LUA)
case UART_MODE_LUA:
aux2SerialSetup(LUA_DEFAULT_BAUDRATE, false);
aux2SerialCb.on_receive = serialPushLua;
AUX2_SERIAL_POWER_ON();
break;
#endif
}
}
void aux2SerialSbusInit()
{
aux2SerialInit(UART_MODE_SBUS_TRAINER, 0);
}
uint8_t aux2SerialTracesEnabled()
{
#if defined(DEBUG)
return (aux2SerialMode == UART_MODE_DEBUG);
#else
return false;
#endif
}
const etx_serial_driver_t Aux2SerialDriver = {
.init = aux2SerialInit,
.deinit = aux_serial_deinit,
.sendByte = aux_serial_putc,
.sendBuffer = aux_serial_send_buffer,
.waitForTxCompleted = aux_wait_tx_completed,
.getByte = aux_get_byte,
.setReceiveCb = nullptr,
.setOnErrorCb = nullptr,
};
#endif // AUX2_SERIAL
@@ -24,28 +24,12 @@
#include "hal/serial_driver.h"
#if defined(AUX_SERIAL)
extern uint8_t auxSerialMode;
void auxSerialSetup(unsigned int baudrate, bool rx_enable,
uint8_t word_length = ETX_WordLength_8,
uint8_t parity = ETX_Parity_None,
uint8_t stop_bits = ETX_StopBits_One);
void auxSerialInit(unsigned int mode, unsigned int protocol);
void auxSerialPutc(uint8_t c);
void auxSerialSbusInit();
void auxSerialStop();
uint8_t auxSerialTracesEnabled();
extern const etx_serial_driver_t AuxSerialDriver;
#endif
#if defined(AUX2_SERIAL)
extern uint8_t aux2SerialMode;
void aux2SerialSetup(unsigned int baudrate, bool rx_enable,
uint8_t word_length = ETX_WordLength_8,
uint8_t parity = ETX_Parity_None,
uint8_t stop_bits = ETX_StopBits_One);
void aux2SerialInit(unsigned int mode, unsigned int protocol);
void aux2SerialPutc(uint8_t c);
void aux2SerialSbusInit();
void aux2SerialStop();
uint8_t aux2SerialTracesEnabled();
extern const etx_serial_driver_t Aux2SerialDriver;
#endif
@@ -144,6 +144,7 @@ if(PCB STREQUAL X10 OR PCB STREQUAL X12S OR PCB STREQUAL NV14)
../../../../../${STM32LIB_DIR}/STM32F4xx_StdPeriph_Driver/src/stm32f4xx_usart.c
../../../../../serial.cpp
../../../../../targets/common/arm/stm32/aux_serial_driver.cpp
../../../../../targets/common/arm/stm32/stm32_usart_driver.cpp
)
endif()
else()
@@ -244,12 +244,9 @@ int main()
#endif
delaysInit(); // needed for lcdInit()
#if defined(DEBUG) && defined(AUX_SERIAL)
auxSerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif
#if defined(DEBUG) && defined(AUX2_SERIAL)
aux2SerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#if defined(DEBUG)
initSerialPorts();
#endif
__enable_irq();
@@ -49,8 +49,6 @@ static const etx_serial_init extmoduleSerialParams = {
.stop_bits = ETX_StopBits_One,
.word_length = ETX_WordLength_8,
.rx_enable = true,
.rx_dma_buf = nullptr,
.rx_dma_buf_len = 0,
.on_receive = extmoduleFifoReceive,
.on_error = extmoduleFifoError,
};
@@ -78,9 +76,9 @@ static const stm32_usart_t extmoduleUSART = {
.rxDMA_Channel = 0,
};
static void extmoduleSerialStart(const etx_serial_init* params)
static void* extmoduleSerialStart(const etx_serial_init* params)
{
if (!params) return;
if (!params) return nullptr;
extmodule_driver.on_receive = params->on_receive;
extmodule_driver.on_error = params->on_error;
@@ -88,6 +86,8 @@ static void extmoduleSerialStart(const etx_serial_init* params)
// UART config
stm32_usart_init(&extmoduleUSART, params);
extmoduleFifo.clear();
return nullptr;
}
void extmoduleInvertedSerialStart(uint32_t baudrate)
@@ -108,7 +108,7 @@ void extmodulePxx1SerialStart()
}
#endif
void extmoduleSerialStop()
void extmoduleSerialStop(void*)
{
stm32_usart_deinit(&extmoduleUSART);
@@ -117,18 +117,18 @@ void extmoduleSerialStop()
extmodule_driver.on_error = nullptr;
}
static void extmoduleSendByte(uint8_t byte)
static void extmoduleSendByte(void*, uint8_t byte)
{
stm32_usart_send_byte(&extmoduleUSART, byte);
}
static void extmoduleSendBuffer(const uint8_t * data, uint8_t size)
static void extmoduleSendBuffer(void*, const uint8_t * data, uint8_t size)
{
if (size == 0) return;
stm32_usart_send_buffer(&extmoduleUSART, data, size);
}
static void extmoduleWaitForTxCompleted()
static void extmoduleWaitForTxCompleted(void*)
{
stm32_usart_wait_for_tx_dma(&extmoduleUSART);
}
@@ -20,6 +20,7 @@ target_include_directories(stm32cube_ll PRIVATE
${THIRDPARTY_DIR}/CMSIS/Include)
set(FIRMWARE_SRC ${FIRMWARE_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
set(BOOTLOADER_SRC ${BOOTLOADER_SRC} $<TARGET_OBJECTS:stm32cube_ll>)
# StdPeriph library
set(STM32LIB_DIR ${THIRDPARTY_DIR}/STM32F4xx_DSP_StdPeriph_Lib_V1.8.0/Libraries)
@@ -28,13 +28,13 @@
ModuleFifo intmoduleFifo;
#if !defined(INTMODULE_DMA_STREAM)
uint8_t * intmoduleTxBufferData;
volatile uint8_t intmoduleTxBufferRemaining;
static uint8_t * intmoduleTxBufferData;
static volatile uint8_t intmoduleTxBufferRemaining;
bool intmoduleTxBufferSend(uint8_t& data)
bool intmoduleTxBufferSend(uint8_t* data)
{
if (intmoduleTxBufferRemaining) {
data = *(intmoduleTxBufferData++);
*data = *(intmoduleTxBufferData++);
intmoduleTxBufferRemaining--;
return true;
}
@@ -96,9 +96,15 @@ void intmoduleStop()
intmodule_driver.on_error = nullptr;
}
void intmoduleSerialStart(const etx_serial_init* params)
static void intmoduleStop(void* ctx)
{
if (!params) return;
(void)ctx;
intmoduleStop();
}
void* intmoduleSerialStart(const etx_serial_init* params)
{
if (!params) return nullptr;
// TODO: sanity check parameters
// - the UART seems to block when initialised with baudrate = 0
@@ -108,6 +114,7 @@ void intmoduleSerialStart(const etx_serial_init* params)
intmodule_driver.on_error = params->on_error;
stm32_usart_init(&intmoduleUSART, params);
return nullptr;
}
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
@@ -116,13 +123,15 @@ extern "C" void INTMODULE_USART_IRQHandler(void)
stm32_usart_isr(&intmoduleUSART, &intmodule_driver);
}
void intmoduleSendByte(uint8_t byte)
void intmoduleSendByte(void* ctx, uint8_t byte)
{
(void)ctx;
stm32_usart_send_byte(&intmoduleUSART, byte);
}
void intmoduleSendBuffer(const uint8_t * data, uint8_t size)
void intmoduleSendBuffer(void* ctx, const uint8_t * data, uint8_t size)
{
(void)ctx;
if (size == 0)
return;
@@ -133,8 +142,9 @@ void intmoduleSendBuffer(const uint8_t * data, uint8_t size)
stm32_usart_send_buffer(&intmoduleUSART, data, size);
}
void intmoduleWaitForTxCompleted()
void intmoduleWaitForTxCompleted(void* ctx)
{
(void)ctx;
#if defined(INTMODULE_DMA_STREAM)
stm32_usart_wait_for_tx_dma(&intmoduleUSART);
#else
@@ -22,8 +22,16 @@
#include "stm32_usart_driver.h"
#include <string.h>
static void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length)
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length)
{
// Disable IRQ based RX
LL_USART_DisableIT_RXNE(usart->USARTx);
// In case TX DMA is used, disable the ISR completely
if (usart->txDMA) {
NVIC_DisableIRQ(usart->IRQn);
}
LL_DMA_InitTypeDef dmaInit;
LL_DMA_StructInit(&dmaInit);
dmaInit.Channel = usart->rxDMA_Channel;
@@ -47,6 +55,8 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
LL_GPIO_Init(usart->GPIOx, (LL_GPIO_InitTypeDef*)usart->pinInit);
LL_USART_InitTypeDef usartInit;
LL_USART_StructInit(&usartInit);
usartInit.BaudRate = params->baudrate;
uint32_t parity = LL_USART_PARITY_NONE;
@@ -96,14 +106,8 @@ void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params)
// Enable RX IRQ
if (params->rx_enable) {
if (usart->rxDMA) {
// RX DMA
stm32_usart_init_rx_dma(usart, params->rx_dma_buf,
params->rx_dma_buf_len);
} else {
// IRQ based RX
LL_USART_EnableIT_RXNE(usart->USARTx);
}
// IRQ based RX
LL_USART_EnableIT_RXNE(usart->USARTx);
}
if (!usart->txDMA || (params->rx_enable && !usart->rxDMA)) {
@@ -159,7 +163,7 @@ void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, u
return;
} else {
// Please note that we don't use the buffer:
// it should set internally by the driver user
// it should be set internally by the driver user
// and each byte is returned individually by on_send()
LL_USART_EnableIT_TXE(usart->USARTx);
}
@@ -204,7 +208,7 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
uint32_t status = LL_USART_ReadReg(usart->USARTx, SR);
// Receive: do it first as it is more time critical
if (LL_USART_IsEnabledIT_TXE(usart->USARTx)) {
if (LL_USART_IsEnabledIT_RXNE(usart->USARTx)) {
// Drain RX
while (status & (LL_USART_SR_RXNE | USART_FLAG_ERRORS)) {
@@ -229,7 +233,7 @@ void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb)
if (LL_USART_IsEnabledIT_TXE(usart->USARTx) && (status & LL_USART_SR_TXE)) {
uint8_t data;
if (cb->on_send && cb->on_send(data)) {
if (cb->on_send && cb->on_send(&data)) {
LL_USART_TransmitData8(usart->USARTx, data);
} else {
LL_USART_DisableIT_TXE(usart->USARTx);
@@ -48,10 +48,10 @@ struct stm32_usart_t {
};
void stm32_usart_init(const stm32_usart_t* usart, const etx_serial_init* params);
void stm32_usart_init_rx_dma(const stm32_usart_t* usart, void* buffer, uint32_t length);
void stm32_usart_deinit(const stm32_usart_t* usart);
void stm32_usart_send_byte(const stm32_usart_t* usart, uint8_t byte);
void stm32_usart_send_buffer(const stm32_usart_t* usart, const uint8_t * data, uint32_t size);
void stm32_usart_wait_for_tx_dma(const stm32_usart_t* usart);
void stm32_usart_isr(const stm32_usart_t* usart, etx_serial_callbacks_t* cb);
@@ -51,7 +51,7 @@ int getSelectedUsbMode();
void setSelectedUsbMode(int mode);
uint32_t usbSerialFreeSpace();
void usbSerialPutc(uint8_t c);
void usbSerialPutc(void*, uint8_t c);
uint32_t usbSerialBaudRate(void);
@@ -94,6 +94,7 @@ static uint16_t VCP_Init(void)
cdcConnected = true;
ctrlLineStateCb = NULL;
baudRateCb = NULL;
return USBD_OK;
}
@@ -205,7 +206,7 @@ uint32_t usbSerialFreeSpace()
1;
}
void usbSerialPutc(uint8_t c)
void usbSerialPutc(void*, uint8_t c)
{
/*
Apparently there is no reliable way to tell if the
@@ -253,21 +254,8 @@ void usbSerialPutc(uint8_t c)
*/
static uint16_t VCP_DataRx (uint8_t* Buf, uint32_t Len)
{
if (receiveDataCb)
receiveDataCb(Buf, Len);
// #if defined(CLI)
// // pass data to CLI
// cliReceiveData(Buf, Len);
// #elif defined(LUA)
// // copy data to the LUA FIFO
// if (luaRxFifo) {
// for (uint32_t i = 0; i < Len; i++) {
// luaRxFifo->push(Buf[i]);
// }
// }
// #endif
auto _rxCb = receiveDataCb;
if (_rxCb) _rxCb(Buf, Len);
return USBD_OK;
}
-11
View File
@@ -245,16 +245,6 @@ if(BLUETOOTH)
add_definitions(-DHARDWARE_TRAINER_BLUETOOTH)
endif()
if (AUX_SERIAL)
add_definitions(-DAUX_SERIAL)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
endif()
if (AUX2_SERIAL)
add_definitions(-DAUX2_SERIAL)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
endif()
if (SBUS_TRAINER)
add_definitions(-DSBUS_TRAINER)
set(SRC
@@ -266,7 +256,6 @@ endif()
set(FIRMWARE_TARGET_SRC
${FIRMWARE_TARGET_SRC}
${LCD_DRIVER}
${AUX_SERIAL_DRIVER}
${FLYSKY_HALL_STICKS_DRIVER}
${IMU_LSM6DS33_DRIVER}
${TOUCH_DRIVER}
+72 -32
View File
@@ -19,13 +19,21 @@
* GNU General Public License for more details.
*/
#include "stm32_hal_ll.h"
#include "opentx.h"
#include "hal/adc_driver.h"
#include "../common/arm/stm32/timers_driver.h"
#include "hal/serial_driver.h"
#include "hal/serial_port.h"
#include "timers_driver.h"
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
#include "aux_serial_driver.h"
#endif
#if !defined(PCBX12S)
#include "../common/arm/stm32/stm32_hal_adc.h"
#include "stm32_hal_adc.h"
#define ADC_DRIVER stm32_hal_adc_driver
#else
#include "x12s_adc_driver.h"
@@ -58,30 +66,6 @@ void watchdogInit(unsigned int duration)
IWDG->KR = 0xCCCC; // start
}
#if defined(AUX_SERIAL_PWR_GPIO)
void auxSerialPowerOn()
{
GPIO_SetBits(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN);
}
void auxSerialPowerOff()
{
GPIO_ResetBits(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN);
}
#endif
#if defined(AUX2_SERIAL_PWR_GPIO)
void aux2SerialPowerOn()
{
GPIO_SetBits(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN);
}
void aux2SerialPowerOff()
{
GPIO_ResetBits(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN);
}
#endif
#if HAS_SPORT_UPDATE_CONNECTOR()
void sportUpdateInit()
{
@@ -193,12 +177,7 @@ void boardInit()
__enable_irq();
#if defined(DEBUG) && defined(AUX_SERIAL)
auxSerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif
#if defined(DEBUG) && defined(AUX2_SERIAL)
aux2SerialInit(UART_MODE_DEBUG, 0); // default serial mode (None if DEBUG not defined)
#endif
initSerialPorts();
TRACE("\nHorus board started :)");
TRACE("RCC->CSR = %08x", RCC->CSR);
@@ -359,3 +338,64 @@ bool isBacklightEnabled()
return true;
return boardBacklightOn;
}
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);
}
}
#if defined(AUX_SERIAL)
void set_aux_pwr(uint8_t on)
{
#if defined(AUX_SERIAL_PWR_GPIO)
_aux_pwr(AUX_SERIAL_PWR_GPIO, AUX_SERIAL_PWR_GPIO_PIN, on);
#endif
}
const etx_serial_port_t auxSerialPort = {
&AuxSerialDriver,
set_aux_pwr,
};
#define AUX_SERIAL_PORT &auxSerialPort
#else
#define AUX_SERIAL_PORT nullptr
#endif
#if defined(AUX2_SERIAL)
void set_aux2_pwr(uint8_t on)
{
#if defined(AUX2_SERIAL_PWR_GPIO)
_aux_pwr(AUX2_SERIAL_PWR_GPIO, AUX2_SERIAL_PWR_GPIO_PIN, on);
#endif
}
const etx_serial_port_t aux2SerialPort = {
&Aux2SerialDriver,
set_aux2_pwr,
};
#define AUX2_SERIAL_PORT &aux2SerialPort
#else
#define AUX2_SERIAL_PORT nullptr
#endif // AUX2_SERIAL
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];
}
+3 -39
View File
@@ -26,6 +26,7 @@
#include "opentx_constants.h"
#include "board_common.h"
#include "hal.h"
#include "hal/serial_port.h"
#include "watchdog_driver.h"
@@ -198,9 +199,6 @@ void stop_trainer_ppm();
void init_trainer_capture();
void stop_trainer_capture();
// SBUS
int sbusGetByte(uint8_t * byte);
// Keys driver
enum EnumKeys
{
@@ -623,7 +621,7 @@ void telemetryPortSetDirectionInput();
void telemetryPortSetDirectionOutput();
void sportSendByte(uint8_t byte);
void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte);
bool sportGetByte(uint8_t * byte);
void telemetryClearFifo();
extern uint32_t telemetryErrors;
@@ -654,32 +652,8 @@ void sportUpdatePowerInit();
#define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200
#endif
#if defined(AUX_SERIAL)
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
void auxSerialPowerOn();
void auxSerialPowerOff();
#if defined(AUX_SERIAL_PWR_GPIO)
#define AUX_SERIAL_POWER_ON() auxSerialPowerOn()
#define AUX_SERIAL_POWER_OFF() auxSerialPowerOff()
#else
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL_POWER_OFF()
#endif
#endif
// Aux2 serial port driver
#if defined(AUX2_SERIAL)
#define aux2SerialTelemetryInit(protocol) aux2SerialInit(UART_MODE_TELEMETRY, protocol)
void aux2SerialPowerOn();
void aux2SerialPowerOff();
#if defined(AUX2_SERIAL_PWR_GPIO)
#define AUX2_SERIAL_POWER_ON() aux2SerialPowerOn()
#define AUX2_SERIAL_POWER_OFF() aux2SerialPowerOff()
#else
#define AUX2_SERIAL_POWER_ON()
#define AUX2_SERIAL_POWER_OFF()
#endif
#endif
const etx_serial_port_t* auxSerialGetPort(int port_nr);
// Haptic driver
void hapticInit();
@@ -711,14 +685,4 @@ void bluetoothWriteWakeup();
uint8_t bluetoothIsWriting();
void bluetoothDisable();
#if defined(__cplusplus)
#include "fifo.h"
#include "dmafifo.h"
extern DMAFifo<512> telemetryFifo;
typedef DMAFifo<32> AuxSerialRxFifo;
extern AuxSerialRxFifo auxSerialRxFifo;
extern AuxSerialRxFifo aux2SerialRxFifo;
extern volatile uint32_t externalModulePort;
#endif
#endif // _BOARD_H_
@@ -22,6 +22,9 @@
#include "opentx.h"
#include "flyskyHallStick_driver.h"
#include "fifo.h"
#include "dmafifo.h"
DMAFifo<HALLSTICK_BUFF_SIZE> hallDMAFifo __DMA (FLYSKY_HALL_DMA_Stream_RX);
Fifo<uint8_t, HALLSTICK_BUFF_SIZE> hallStickTxFifo;
unsigned char HallCmd[264] __DMA;
+4 -1
View File
@@ -21,6 +21,9 @@
#include "opentx.h"
#include "fifo.h"
#include "dmafifo.h"
Fifo<uint8_t, TELEMETRY_FIFO_SIZE> telemetryNoDMAFifo;
uint32_t telemetryErrors = 0;
@@ -415,7 +418,7 @@ extern "C" void TELEMETRY_TIMER_IRQHandler()
}
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
bool telemetryGetByte(uint8_t * byte)
bool sportGetByte(uint8_t * byte)
{
#if defined(PCBX12S)
if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA)
@@ -142,22 +142,3 @@ extern "C" void TRAINER_TIMER_IRQHandler()
}
}
}
int sbusGetByte(uint8_t * byte)
{
switch (currentTrainerMode) {
#if defined(AUX_SERIAL) || defined(AUX2_SERIAL)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
#if defined(AUX_SERIAL)
if (auxSerialMode == UART_MODE_SBUS_TRAINER)
return auxSerialRxFifo.pop(*byte);
#endif
#if defined(AUX2_SERIAL)
if (aux2SerialMode == UART_MODE_SBUS_TRAINER)
return aux2SerialRxFifo.pop(*byte);
#endif
#endif
default:
return false;
}
}
+7 -2
View File
@@ -23,8 +23,8 @@
#include "touch.h"
#include "hal/adc_driver.h"
#include "../common/arm/stm32/stm32_hal_adc.h"
#include "../common/arm/stm32/timers_driver.h"
#include "stm32_hal_adc.h"
#include "timers_driver.h"
#if defined(__cplusplus) && !defined(SIMU)
extern "C" {
@@ -242,3 +242,8 @@ void boardOff()
}
}
const etx_serial_port_t* auxSerialGetPort(int port_nr)
{
return nullptr;
}
+4 -21
View File
@@ -26,6 +26,7 @@
#include "opentx_constants.h"
#include "board_common.h"
#include "hal.h"
#include "hal/serial_port.h"
#if !defined(LUA_EXPORT_GENERATION)
#include "stm32f4xx_sdio.h"
@@ -390,9 +391,8 @@ bool pwrPressed();
#endif
uint32_t pwrPressedDuration();;
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL_POWER_OFF()
const etx_serial_port_t* auxSerialGetPort(int port_nr);
// LCD driver
#define LCD_W 320
#define LCD_H 480
@@ -483,7 +483,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode);
void telemetryPortSetDirectionOutput();
void telemetryPortSetDirectionInput();
void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte);
bool sportGetByte(uint8_t * byte);
void telemetryClearFifo();
void sportSendByte(uint8_t byte);
extern uint32_t telemetryErrors;
@@ -507,27 +507,10 @@ void hapticOn(uint32_t pwmPercent);
//#define AUX_SERIAL
#define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
#if defined(AUX_SERIAL_PWR_GPIO)
#define AUX_SERIAL_POWER_ON() auxSerialPowerOn()
#define AUX_SERIAL__POWER_OFF() auxSerialPowerOff()
#else
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL__POWER_OFF()
#endif
extern uint8_t currentTrainerMode;
void checkTrainerSettings();
#if defined(__cplusplus)
#include "fifo.h"
#include "dmafifo.h"
extern DMAFifo<512> telemetryFifo;
typedef Fifo<uint8_t, 32> AuxSerialRxFifo;
extern AuxSerialRxFifo auxSerialRxFifo;
#endif
// Touch panel driver
bool touchPanelEventOccured();
struct TouchState touchPanelRead();
+1 -1
View File
@@ -215,7 +215,7 @@ extern "C" void TELEMETRY_USART_IRQHandler(void)
}
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
bool telemetryGetByte(uint8_t * byte)
bool sportGetByte(uint8_t * byte)
{
#if defined(PCBX12S)
if (telemetryFifoMode & TELEMETRY_SERIAL_WITHOUT_DMA)
+8 -5
View File
@@ -63,11 +63,12 @@ void stop_trainer_module_sbus() {}
void init_intmodule_heartbeat() {}
void stop_intmodule_heartbeat() {}
static void init(const etx_serial_init*) {}
static void deinit() {}
static void sendByte(uint8_t) {}
static void sendBuffer(const uint8_t*, uint8_t) {}
static void waitForTxCompleted() {}
static void* init(const etx_serial_init*) { return nullptr; }
static void deinit(void*) {}
static void sendByte(void*, uint8_t) {}
static void sendBuffer(void*, const uint8_t*, uint8_t) {}
static void waitForTxCompleted(void*) {}
static int getByte(void*,uint8_t*) { return -1; }
const etx_serial_driver_t IntmoduleSerialDriver = {
.init = init,
@@ -75,6 +76,7 @@ const etx_serial_driver_t IntmoduleSerialDriver = {
.sendByte = sendByte,
.sendBuffer = sendBuffer,
.waitForTxCompleted = waitForTxCompleted,
.getByte = getByte,
.setReceiveCb = nullptr,
.setOnErrorCb = nullptr,
};
@@ -85,6 +87,7 @@ const etx_serial_driver_t ExtmoduleSerialDriver = {
.sendByte = sendByte,
.sendBuffer = sendBuffer,
.waitForTxCompleted = waitForTxCompleted,
.getByte = getByte,
.setReceiveCb = nullptr,
.setOnErrorCb = nullptr,
};
+3 -55
View File
@@ -429,7 +429,7 @@ void telemetryPortInit(uint32_t baudrate, uint8_t mode)
{
}
bool telemetryGetByte(uint8_t * byte)
bool sportGetByte(uint8_t * byte)
{
return false;
}
@@ -732,6 +732,7 @@ void disableSpeaker()
}
#endif
int trainerModuleSbusGetByte(unsigned char*) { return 0; }
void rtcInit()
{
@@ -751,60 +752,7 @@ void usbSerialPutc(uint8_t c)
}
#endif
#if defined(AUX_SERIAL)
#if defined(AUX_SERIAL_DMA_Stream_RX)
AuxSerialRxFifo auxSerialRxFifo(nullptr);
#else
AuxSerialRxFifo auxSerialRxFifo;
#endif
uint8_t auxSerialMode;
void auxSerialSetup(unsigned int baudrate, bool dma, uint8_t length, uint8_t parity, uint8_t stop)
{
}
void auxSerialInit(unsigned int mode, unsigned int protocol)
{
}
void auxSerialPutc(uint8_t c)
{
}
void auxSerialSbusInit()
{
}
void auxSerialStop()
{
}
#endif
#if defined(AUX2_SERIAL)
AuxSerialRxFifo aux2SerialRxFifo(nullptr);
uint8_t aux2SerialMode;
void aux2SerialSetup(unsigned int baudrate, bool dma, uint8_t length, uint8_t parity, uint8_t stop)
{
}
void aux2SerialInit(unsigned int mode, unsigned int protocol)
{
}
void aux2SerialPutc(uint8_t c)
{
}
void aux2SerialSbusInit()
{
}
void aux2SerialStop()
{
}
#endif
const etx_serial_port_t* auxSerialGetPort(int port_nr) { return nullptr; }
#if defined(HARDWARE_TOUCH)
struct TouchState simTouchState = {};
+4 -4
View File
@@ -31,7 +31,7 @@ if(PCB STREQUAL X9E)
top_lcd_driver.cpp
startup_stm32f40_41xxx.s
)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
set(AUX_SERIAL ON)
if(STICKS STREQUAL HORUS)
add_definitions(-DHORUS_STICKS)
endif()
@@ -90,7 +90,7 @@ elseif(PCB STREQUAL X9D+)
set(CPU_TYPE_FULL STM32F205xE) # for size report
add_definitions(-DSTM32F205xx)
set(LINKER_SCRIPT targets/taranis/stm32f2_flash.ld)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
set(AUX_SERIAL ON)
set(STATUS_LEDS NO)
endif()
elseif(PCB STREQUAL X9D)
@@ -110,7 +110,7 @@ elseif(PCB STREQUAL X9D)
set(BITMAPS_TARGET taranis_bitmaps)
set(FONTS_TARGET taranis_fonts)
set(LCD_DRIVER lcd_driver_aspi.cpp)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
set(AUX_SERIAL ON)
set(GVAR_SCREEN model_gvars.cpp)
set(STATUS_LEDS NO)
add_definitions(-DMANUFACTURER_FRSKY)
@@ -207,7 +207,7 @@ elseif(PCB STREQUAL X7)
set(LUA_EXPORT lua_export_zorro)
set(BLUETOOTH NO)
set(USB_CHARGER YES)
set(AUX_SERIAL_DRIVER ../common/arm/stm32/aux_serial_driver.cpp)
set(AUX_SERIAL ON)
add_definitions(-DRADIO_ZORRO)
add_definitions(-DEEPROM_VARIANT=0x4006)
add_definitions(-DMANUFACTURER_RADIOMASTER)
+28 -4
View File
@@ -26,6 +26,10 @@
#include "../common/arm/stm32/timers_driver.h"
#if defined(AUX_SERIAL)
#include "aux_serial_driver.h"
#endif
#if defined(__cplusplus)
extern "C" {
#endif
@@ -223,10 +227,7 @@ void boardInit()
i2cInit();
usbInit();
#if defined(DEBUG) && defined(AUX_SERIAL_GPIO)
auxSerialInit(0, 0); // default serial mode (None if DEBUG not defined)
TRACE("\nTaranis board started :)");
#endif
initSerialPorts();
#if defined(HAPTIC)
hapticInit();
@@ -415,3 +416,26 @@ void initJackDetect(void)
GPIO_Init(JACK_DETECT_GPIO, &GPIO_InitStructure);
}
#endif
#if defined(AUX_SERIAL)
const etx_serial_port_t auxSerialPort = {
&AuxSerialDriver,
nullptr
};
#define AUX_SERIAL_PORT &auxSerialPort
#else
#define AUX_SERIAL_PORT nullptr
#endif
#define AUX2_SERIAL_PORT nullptr
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];
}
+7 -17
View File
@@ -27,6 +27,7 @@
#include "opentx_constants.h"
#include "board_common.h"
#include "hal.h"
#include "hal/serial_port.h"
#include "watchdog_driver.h"
@@ -164,26 +165,20 @@ uint32_t isBootloaderStart(const uint8_t * buffer);
#define init_trainer_capture()
#define stop_trainer_capture()
#endif
#if defined(TRAINER_MODULE_CPPM)
void init_trainer_module_cppm();
void stop_trainer_module_cppm();
#else
#define init_trainer_module_cppm()
#define stop_trainer_module_cppm()
#endif
#if defined(TRAINER_MODULE_SBUS)
void init_trainer_module_sbus();
void stop_trainer_module_sbus();
#else
#define init_trainer_module_sbus()
#define stop_trainer_module_sbus()
int trainerModuleSbusGetByte(uint8_t* byte);
#endif
void check_telemetry_exti();
// SBUS
int sbusGetByte(uint8_t * byte);
// Keys driver
enum EnumKeys
{
@@ -775,7 +770,7 @@ void sportSendByte(uint8_t byte);
void sportSendByteLoop(uint8_t byte);
void sportStopSendByteLoop();
void sportSendBuffer(const uint8_t * buffer, uint32_t count);
bool telemetryGetByte(uint8_t * byte);
bool sportGetByte(uint8_t * byte);
void telemetryClearFifo();
extern uint32_t telemetryErrors;
@@ -860,15 +855,10 @@ void hapticOff();
void hapticOn();
#endif
// Aux serial port driver
#if defined(AUX_SERIAL_GPIO)
#define DEBUG_BAUDRATE 115200
#define LUA_DEFAULT_BAUDRATE 115200
#define AUX_SERIAL
#define auxSerialTelemetryInit(protocol) auxSerialInit(UART_MODE_TELEMETRY, protocol)
#define AUX_SERIAL_POWER_ON()
#define AUX_SERIAL_POWER_OFF()
#endif
const etx_serial_port_t* auxSerialGetPort(int port_nr);
// BT driver
#define BLUETOOTH_BOOTLOADER_BAUDRATE 230400
+8 -8
View File
@@ -1929,14 +1929,14 @@
#define TRAINER_MODULE_CPPM_TIMER_IRQn TRAINER_TIMER_IRQn
#define TRAINER_MODULE_CPPM_GPIO_AF GPIO_AF_TIM3
// Trainer SBUS input on heartbeat pin
#define TRAINER_MODULE_SBUS
#define TRAINER_MODULE_SBUS_GPIO_AF GPIO_AF_USART6
#define TRAINER_MODULE_SBUS_USART USART6
#define TRAINER_MODULE_SBUS_GPIO INTMODULE_HEARTBEAT_GPIO
#define TRAINER_MODULE_SBUS_GPIO_PIN INTMODULE_HEARTBEAT_GPIO_PIN
#define TRAINER_MODULE_SBUS_GPIO_PinSource INTMODULE_HEARTBEAT_EXTI_PinSource
#define TRAINER_MODULE_SBUS_DMA_STREAM DMA2_Stream1
#define TRAINER_MODULE_SBUS_DMA_CHANNEL DMA_Channel_5
// #define TRAINER_MODULE_SBUS
// #define TRAINER_MODULE_SBUS_GPIO_AF GPIO_AF_USART6
// #define TRAINER_MODULE_SBUS_USART USART6
// #define TRAINER_MODULE_SBUS_GPIO INTMODULE_HEARTBEAT_GPIO
// #define TRAINER_MODULE_SBUS_GPIO_PIN INTMODULE_HEARTBEAT_GPIO_PIN
// #define TRAINER_MODULE_SBUS_GPIO_PinSource INTMODULE_HEARTBEAT_EXTI_PinSource
// #define TRAINER_MODULE_SBUS_DMA_STREAM DMA2_Stream1
// #define TRAINER_MODULE_SBUS_DMA_CHANNEL DMA_Channel_5
#else
// TODO: replace SBUS trainer with S.PORT pin
#define TRAINER_MODULE_RCC_AHB1Periph 0
+4 -14
View File
@@ -393,22 +393,12 @@ extern "C" void TELEMETRY_TIMER_IRQHandler()
telemetryPortInvertedRxBit();
}
// TODO we should have telemetry in an higher layer, functions above should move to a sport_driver.cpp
bool telemetryGetByte(uint8_t * byte)
// TODO: we should have telemetry in an higher layer,
// functions above should move to a sport_driver.cpp
//
bool sportGetByte(uint8_t * byte)
{
#if defined(AUX_SERIAL)
if (telemetryProtocol == PROTOCOL_TELEMETRY_FRSKY_D_SECONDARY) {
if (auxSerialMode == UART_MODE_TELEMETRY)
return auxSerialRxFifo.pop(*byte);
else
return false;
}
else {
return telemetryFifo.pop(*byte);
}
#else
return telemetryFifo.pop(*byte);
#endif
}
void telemetryClearFifo()
+6 -19
View File
@@ -21,10 +21,6 @@
#include "opentx.h"
#if defined(TRAINER_MODULE_SBUS_USART)
DMAFifo<32> trainerSbusFifo __DMA (TRAINER_MODULE_SBUS_DMA_STREAM);
#endif
void trainerSendNextFrame();
#if defined(TRAINER_GPIO)
@@ -267,7 +263,11 @@ void stop_trainer_module_cppm()
}
#endif
// TODO: use external module serial driver
#if defined(TRAINER_MODULE_SBUS)
static DMAFifo<32> trainerSbusFifo __DMA (TRAINER_MODULE_SBUS_DMA_STREAM);
void init_trainer_module_sbus()
{
EXTERNAL_MODULE_ON();
@@ -328,22 +328,9 @@ void stop_trainer_module_sbus()
EXTERNAL_MODULE_OFF();
}
}
#endif
#if defined(SBUS_TRAINER)
int sbusGetByte(uint8_t * byte)
int trainerModuleSbusGetByte(uint8_t* byte)
{
switch (currentTrainerMode) {
#if defined(TRAINER_MODULE_SBUS_USART)
case TRAINER_MODE_MASTER_SBUS_EXTERNAL_MODULE:
return trainerSbusFifo.pop(*byte);
#endif
#if defined(AUX_SERIAL_USART)
case TRAINER_MODE_MASTER_BATTERY_COMPARTMENT:
return auxSerialRxFifo.pop(*byte);
#endif
default:
return false;
}
return trainerSbusFifo.pop(*byte);
}
#endif