Internal and external module buffers are now private
This commit is contained in:
committed by
Raphael Coeffic
parent
ab6033e4d5
commit
f952c5f7c7
@@ -25,9 +25,16 @@
|
||||
|
||||
#if defined(EXTMODULE_USART)
|
||||
#include "stm32_usart_driver.h"
|
||||
#include "fifo.h"
|
||||
|
||||
#include "io/frsky_pxx2.h"
|
||||
ModuleFifo extmoduleFifo;
|
||||
typedef Fifo<uint8_t, INTMODULE_FIFO_SIZE> RxFifo;
|
||||
static RxFifo extmoduleFifo;
|
||||
|
||||
struct ExtmoduleCtx
|
||||
{
|
||||
RxFifo* rxFifo;
|
||||
const stm32_usart_t* usart;
|
||||
};
|
||||
|
||||
static etx_serial_callbacks_t extmodule_driver = {
|
||||
nullptr, nullptr, nullptr
|
||||
@@ -69,6 +76,11 @@ static const stm32_usart_t extmoduleUSART = {
|
||||
.rxDMA_Channel = 0,
|
||||
};
|
||||
|
||||
static const ExtmoduleCtx extmoduleCtx = {
|
||||
.rxFifo = &extmoduleFifo,
|
||||
.usart = &extmoduleUSART,
|
||||
};
|
||||
|
||||
static void* extmoduleSerialStart(const etx_serial_init* params)
|
||||
{
|
||||
if (!params) return nullptr;
|
||||
@@ -78,9 +90,9 @@ static void* extmoduleSerialStart(const etx_serial_init* params)
|
||||
|
||||
// UART config
|
||||
stm32_usart_init(&extmoduleUSART, params);
|
||||
extmoduleFifo.clear();
|
||||
extmoduleCtx.rxFifo->clear();
|
||||
|
||||
return nullptr;
|
||||
return (void*)&extmoduleCtx;
|
||||
}
|
||||
|
||||
void extmoduleInvertedSerialStart(uint32_t baudrate)
|
||||
@@ -91,16 +103,6 @@ void extmoduleInvertedSerialStart(uint32_t baudrate)
|
||||
extmoduleSerialStart(¶ms);
|
||||
}
|
||||
|
||||
#if defined(PXX1)
|
||||
void extmodulePxx1SerialStart()
|
||||
{
|
||||
EXTERNAL_MODULE_ON();
|
||||
etx_serial_init params(extmoduleSerialParams);
|
||||
params.baudrate = EXTMODULE_PXX1_SERIAL_BAUDRATE;
|
||||
ExtmoduleSerialDriver.init(¶ms);
|
||||
}
|
||||
#endif
|
||||
|
||||
void extmoduleSerialStop(void*)
|
||||
{
|
||||
stm32_usart_deinit(&extmoduleUSART);
|
||||
@@ -110,20 +112,37 @@ void extmoduleSerialStop(void*)
|
||||
extmodule_driver.on_error = nullptr;
|
||||
}
|
||||
|
||||
static void extmoduleSendByte(void*, uint8_t byte)
|
||||
static void extmoduleSendByte(void* ctx, uint8_t byte)
|
||||
{
|
||||
stm32_usart_send_byte(&extmoduleUSART, byte);
|
||||
auto modCtx = (ExtmoduleCtx*)ctx;
|
||||
stm32_usart_send_byte(modCtx->usart, byte);
|
||||
}
|
||||
|
||||
static void extmoduleSendBuffer(void*, const uint8_t * data, uint8_t size)
|
||||
static void extmoduleSendBuffer(void* ctx, const uint8_t * data, uint8_t size)
|
||||
{
|
||||
auto modCtx = (ExtmoduleCtx*)ctx;
|
||||
if (size == 0) return;
|
||||
stm32_usart_send_buffer(&extmoduleUSART, data, size);
|
||||
stm32_usart_send_buffer(modCtx->usart, data, size);
|
||||
}
|
||||
|
||||
static void extmoduleWaitForTxCompleted(void*)
|
||||
static void extmoduleWaitForTxCompleted(void* ctx)
|
||||
{
|
||||
stm32_usart_wait_for_tx_dma(&extmoduleUSART);
|
||||
auto modCtx = (ExtmoduleCtx*)ctx;
|
||||
stm32_usart_wait_for_tx_dma(modCtx->usart);
|
||||
}
|
||||
|
||||
static int extmoduleGetByte(void* ctx, uint8_t* data)
|
||||
{
|
||||
auto modCtx = (ExtmoduleCtx*)ctx;
|
||||
if (!modCtx->rxFifo) return -1;
|
||||
return modCtx->rxFifo->pop(*data);
|
||||
}
|
||||
|
||||
static void extmoduleClearRxBuffer(void* ctx)
|
||||
{
|
||||
auto modCtx = (ExtmoduleCtx*)ctx;
|
||||
if (!modCtx->rxFifo) return;
|
||||
modCtx->rxFifo->clear();
|
||||
}
|
||||
|
||||
const etx_serial_driver_t ExtmoduleSerialDriver = {
|
||||
@@ -132,7 +151,8 @@ const etx_serial_driver_t ExtmoduleSerialDriver = {
|
||||
.sendByte = extmoduleSendByte,
|
||||
.sendBuffer = extmoduleSendBuffer,
|
||||
.waitForTxCompleted = extmoduleWaitForTxCompleted,
|
||||
.getByte = nullptr,
|
||||
.getByte = extmoduleGetByte,
|
||||
.clearRxBuffer = extmoduleClearRxBuffer,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
|
||||
@@ -30,13 +30,4 @@
|
||||
void extmoduleFifoReceive(uint8_t data);
|
||||
void extmoduleFifoError();
|
||||
|
||||
// void extmoduleSerialStart();
|
||||
// void extmoduleInvertedSerialStart(uint32_t baudrate);
|
||||
// void extmoduleSendBuffer(const uint8_t * data, uint8_t size);
|
||||
// void extmoduleSendNextFrame();
|
||||
|
||||
#if defined(PXX1)
|
||||
void extmodulePxx1SerialStart();
|
||||
#endif
|
||||
|
||||
extern const etx_serial_driver_t ExtmoduleSerialDriver;
|
||||
|
||||
@@ -23,9 +23,16 @@
|
||||
#include "intmodule_serial_driver.h"
|
||||
#include "stm32_usart_driver.h"
|
||||
#include "board.h"
|
||||
#include "fifo.h"
|
||||
|
||||
Fifo<uint8_t, INTMODULE_FIFO_SIZE> intmoduleFifo;
|
||||
#include "fifo.h"
|
||||
typedef Fifo<uint8_t, INTMODULE_FIFO_SIZE> RxFifo;
|
||||
static RxFifo intmoduleFifo;
|
||||
|
||||
struct IntmoduleCtx
|
||||
{
|
||||
RxFifo* rxFifo;
|
||||
const stm32_usart_t* usart;
|
||||
};
|
||||
|
||||
#if !defined(INTMODULE_DMA_STREAM)
|
||||
static uint8_t * intmoduleTxBufferData;
|
||||
@@ -88,6 +95,11 @@ static const stm32_usart_t intmoduleUSART = {
|
||||
.rxDMA_Channel = 0,
|
||||
};
|
||||
|
||||
static const IntmoduleCtx intmoduleCtx = {
|
||||
.rxFifo = &intmoduleFifo,
|
||||
.usart = &intmoduleUSART,
|
||||
};
|
||||
|
||||
void intmoduleStop()
|
||||
{
|
||||
stm32_usart_deinit(&intmoduleUSART);
|
||||
@@ -115,7 +127,9 @@ void* intmoduleSerialStart(const etx_serial_init* params)
|
||||
intmodule_driver.on_error = nullptr;
|
||||
|
||||
stm32_usart_init(&intmoduleUSART, params);
|
||||
return nullptr;
|
||||
|
||||
intmoduleCtx.rxFifo->clear();
|
||||
return (void*)&intmoduleCtx;
|
||||
}
|
||||
|
||||
#define USART_FLAG_ERRORS (USART_FLAG_ORE | USART_FLAG_NE | USART_FLAG_FE | USART_FLAG_PE)
|
||||
@@ -126,13 +140,13 @@ extern "C" void INTMODULE_USART_IRQHandler(void)
|
||||
|
||||
void intmoduleSendByte(void* ctx, uint8_t byte)
|
||||
{
|
||||
(void)ctx;
|
||||
stm32_usart_send_byte(&intmoduleUSART, byte);
|
||||
auto modCtx = (IntmoduleCtx*)ctx;
|
||||
stm32_usart_send_byte(modCtx->usart, byte);
|
||||
}
|
||||
|
||||
void intmoduleSendBuffer(void* ctx, const uint8_t * data, uint8_t size)
|
||||
{
|
||||
(void)ctx;
|
||||
auto modCtx = (IntmoduleCtx*)ctx;
|
||||
if (size == 0)
|
||||
return;
|
||||
|
||||
@@ -140,26 +154,41 @@ void intmoduleSendBuffer(void* ctx, const uint8_t * data, uint8_t size)
|
||||
intmoduleTxBufferData = (uint8_t *)data;
|
||||
intmoduleTxBufferRemaining = size;
|
||||
#endif
|
||||
stm32_usart_send_buffer(&intmoduleUSART, data, size);
|
||||
stm32_usart_send_buffer(modCtx->usart, data, size);
|
||||
}
|
||||
|
||||
void intmoduleWaitForTxCompleted(void* ctx)
|
||||
{
|
||||
(void)ctx;
|
||||
auto modCtx = (IntmoduleCtx*)ctx;
|
||||
#if defined(INTMODULE_DMA_STREAM)
|
||||
stm32_usart_wait_for_tx_dma(&intmoduleUSART);
|
||||
stm32_usart_wait_for_tx_dma(modCtx->usart);
|
||||
#else
|
||||
while (intmoduleTxBufferRemaining > 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
static int intmoduleGetByte(void* ctx, uint8_t* data)
|
||||
{
|
||||
auto modCtx = (IntmoduleCtx*)ctx;
|
||||
if (!modCtx->rxFifo) return -1;
|
||||
return modCtx->rxFifo->pop(*data);
|
||||
}
|
||||
|
||||
static void intmoduleClearRxBuffer(void* ctx)
|
||||
{
|
||||
auto modCtx = (IntmoduleCtx*)ctx;
|
||||
if (!modCtx->rxFifo) return;
|
||||
modCtx->rxFifo->clear();
|
||||
}
|
||||
|
||||
const etx_serial_driver_t IntmoduleSerialDriver = {
|
||||
.init = intmoduleSerialStart,
|
||||
.deinit = intmoduleStop,
|
||||
.sendByte = intmoduleSendByte,
|
||||
.sendBuffer = intmoduleSendBuffer,
|
||||
.waitForTxCompleted = intmoduleWaitForTxCompleted,
|
||||
.getByte = nullptr,
|
||||
.getByte = intmoduleGetByte,
|
||||
.clearRxBuffer = intmoduleClearRxBuffer,
|
||||
.getBaudrate = nullptr,
|
||||
.setReceiveCb = nullptr,
|
||||
.setBaudrateCb = nullptr,
|
||||
|
||||
@@ -297,15 +297,16 @@ void usbSerialSetBaudRateCb(void*, void (*cb)(uint32_t))
|
||||
// }
|
||||
|
||||
static const etx_serial_driver_t usbSerialDriver = {
|
||||
nullptr,
|
||||
nullptr,
|
||||
usbSerialPutc,
|
||||
nullptr,
|
||||
nullptr,
|
||||
nullptr,
|
||||
usbSerialBaudRate,
|
||||
usbSerialSetReceiveDataCb,
|
||||
usbSerialSetBaudRateCb,
|
||||
.init = nullptr,
|
||||
.deinit = nullptr,
|
||||
.sendByte = usbSerialPutc,
|
||||
.sendBuffer = nullptr,
|
||||
.waitForTxCompleted = nullptr,
|
||||
.getByte = nullptr,
|
||||
.clearRxBuffer = nullptr,
|
||||
.getBaudrate = usbSerialBaudRate,
|
||||
.setReceiveCb = usbSerialSetReceiveDataCb,
|
||||
.setBaudrateCb = usbSerialSetBaudRateCb,
|
||||
};
|
||||
|
||||
const etx_serial_port_t UsbSerialPort = {
|
||||
|
||||
Reference in New Issue
Block a user