AFHDS2 and PXX1 serial module drivers
This commit is contained in:
@@ -21,7 +21,18 @@
|
|||||||
|
|
||||||
#include "afhds2.h"
|
#include "afhds2.h"
|
||||||
#include "flysky.h"
|
#include "flysky.h"
|
||||||
|
|
||||||
#include "intmodule_serial_driver.h"
|
#include "intmodule_serial_driver.h"
|
||||||
|
#include "mixer_scheduler.h"
|
||||||
|
|
||||||
|
afhds2::afhds2() {
|
||||||
|
// TODO Auto-generated constructor stub
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
afhds2::~afhds2() {
|
||||||
|
// TODO Auto-generated destructor stub
|
||||||
|
}
|
||||||
|
|
||||||
etx_serial_init afhds2SerialInitParams = {
|
etx_serial_init afhds2SerialInitParams = {
|
||||||
.baudrate = INTMODULE_USART_AFHDS2_BAUDRATE,
|
.baudrate = INTMODULE_USART_AFHDS2_BAUDRATE,
|
||||||
@@ -33,12 +44,57 @@ etx_serial_init afhds2SerialInitParams = {
|
|||||||
.on_error = intmoduleFifoError,
|
.on_error = intmoduleFifoError,
|
||||||
};
|
};
|
||||||
|
|
||||||
afhds2::afhds2() {
|
static void* afhds2Init(uint8_t module)
|
||||||
// TODO Auto-generated constructor stub
|
{
|
||||||
|
(void)module;
|
||||||
|
|
||||||
|
// serial port setup
|
||||||
|
resetPulsesAFHDS2();
|
||||||
|
intmoduleFifo.clear();
|
||||||
|
IntmoduleSerialDriver.init(&afhds2SerialInitParams);
|
||||||
|
|
||||||
|
// mixer setup
|
||||||
|
mixerSchedulerSetPeriod(INTERNAL_MODULE, AFHDS2_PERIOD);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
afhds2::~afhds2() {
|
static void afhds2DeInit(void* context)
|
||||||
// TODO Auto-generated destructor stub
|
{
|
||||||
|
(void)context;
|
||||||
|
|
||||||
|
intmoduleFifo.clear();
|
||||||
|
IntmoduleSerialDriver.deinit();
|
||||||
|
|
||||||
|
// mixer setup
|
||||||
|
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void afhds2SetupPulses(void* context)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
|
||||||
|
ModuleSyncStatus& status = getModuleSyncStatus(INTERNAL_MODULE);
|
||||||
|
mixerSchedulerSetPeriod(INTERNAL_MODULE, status.isValid()
|
||||||
|
? status.getAdjustedRefreshRate()
|
||||||
|
: AFHDS2_PERIOD);
|
||||||
|
status.invalidate();
|
||||||
|
setupPulsesAFHDS2();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void afhds2SendPulses(void* context)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
|
||||||
|
uint8_t* data = (uint8_t*)intmodulePulsesData.flysky.pulses;
|
||||||
|
uint16_t size = intmodulePulsesData.flysky.ptr - data;
|
||||||
|
IntmoduleSerialDriver.sendBuffer(data, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
etx_module_driver_t Afhds2InternalDriver = {
|
||||||
|
.protocol = PROTOCOL_CHANNELS_AFHDS2A,
|
||||||
|
.init = afhds2Init,
|
||||||
|
.deinit = afhds2DeInit,
|
||||||
|
.setupPulses = afhds2SetupPulses,
|
||||||
|
.sendPulses = afhds2SendPulses,
|
||||||
|
};
|
||||||
|
|||||||
@@ -312,11 +312,8 @@ static void enablePulsesInternalModule(uint8_t protocol)
|
|||||||
|
|
||||||
#if defined(PXX1) && defined(INTMODULE_USART)
|
#if defined(PXX1) && defined(INTMODULE_USART)
|
||||||
case PROTOCOL_CHANNELS_PXX1_SERIAL:
|
case PROTOCOL_CHANNELS_PXX1_SERIAL:
|
||||||
intmodulePxx1SerialStart();
|
internalModuleContext = Pxx1InternalSerialDriver.init(INTERNAL_MODULE);
|
||||||
#if defined(INTMODULE_HEARTBEAT)
|
internalModuleDriver = &Pxx1InternalSerialDriver;
|
||||||
init_intmodule_heartbeat();
|
|
||||||
#endif
|
|
||||||
mixerSchedulerSetPeriod(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD);
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -350,13 +347,8 @@ static void enablePulsesInternalModule(uint8_t protocol)
|
|||||||
|
|
||||||
#if defined(AFHDS2)
|
#if defined(AFHDS2)
|
||||||
case PROTOCOL_CHANNELS_AFHDS2A:
|
case PROTOCOL_CHANNELS_AFHDS2A:
|
||||||
// serial port setup
|
internalModuleContext = Afhds2InternalDriver.init(INTERNAL_MODULE);
|
||||||
resetPulsesAFHDS2();
|
internalModuleDriver = &Afhds2InternalDriver;
|
||||||
intmoduleFifo.clear();
|
|
||||||
IntmoduleSerialDriver.init(&afhds2SerialInitParams);
|
|
||||||
|
|
||||||
// mixer setup
|
|
||||||
mixerSchedulerSetPeriod(INTERNAL_MODULE, AFHDS2_PERIOD);
|
|
||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
@@ -386,31 +378,12 @@ bool setupPulsesInternalModule(uint8_t protocol)
|
|||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PXX1) && defined(INTMODULE_USART)
|
|
||||||
case PROTOCOL_CHANNELS_PXX1_SERIAL:
|
|
||||||
intmodulePulsesData.pxx_uart.setupFrame(INTERNAL_MODULE);
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(PCBTARANIS) && defined(INTERNAL_MODULE_PPM)
|
#if defined(PCBTARANIS) && defined(INTERNAL_MODULE_PPM)
|
||||||
case PROTOCOL_CHANNELS_PPM:
|
case PROTOCOL_CHANNELS_PPM:
|
||||||
setupPulsesPPMInternalModule();
|
setupPulsesPPMInternalModule();
|
||||||
return true;
|
return true;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(AFHDS2)
|
|
||||||
case PROTOCOL_CHANNELS_AFHDS2A:
|
|
||||||
{
|
|
||||||
ModuleSyncStatus& status = getModuleSyncStatus(INTERNAL_MODULE);
|
|
||||||
mixerSchedulerSetPeriod(
|
|
||||||
INTERNAL_MODULE,
|
|
||||||
status.isValid() ? status.getAdjustedRefreshRate() : AFHDS2_PERIOD);
|
|
||||||
status.invalidate();
|
|
||||||
setupPulsesAFHDS2();
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -448,26 +421,11 @@ void intmoduleSendNextFrame()
|
|||||||
break;
|
break;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PXX1)
|
#if defined(PXX1) && !defined(INTMODULE_USART)
|
||||||
#if defined(INTMODULE_USART)
|
|
||||||
case PROTOCOL_CHANNELS_PXX1_SERIAL:
|
|
||||||
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.pxx_uart.getData(),
|
|
||||||
intmodulePulsesData.pxx_uart.getSize());
|
|
||||||
break;
|
|
||||||
#else
|
|
||||||
case PROTOCOL_CHANNELS_PXX1_PULSES:
|
case PROTOCOL_CHANNELS_PXX1_PULSES:
|
||||||
intmoduleSendNextFramePxx1(intmodulePulsesData.pxx.getData(),
|
intmoduleSendNextFramePxx1(intmodulePulsesData.pxx.getData(),
|
||||||
intmodulePulsesData.pxx.getSize());
|
intmodulePulsesData.pxx.getSize());
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(AFHDS2)
|
|
||||||
case PROTOCOL_CHANNELS_AFHDS2A: {
|
|
||||||
uint8_t* data = (uint8_t*)intmodulePulsesData.flysky.pulses;
|
|
||||||
uint16_t size = intmodulePulsesData.flysky.ptr - data;
|
|
||||||
IntmoduleSerialDriver.sendBuffer(data, size);
|
|
||||||
} break;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,6 +21,8 @@
|
|||||||
|
|
||||||
#include "opentx.h"
|
#include "opentx.h"
|
||||||
#include "pulses/pxx1.h"
|
#include "pulses/pxx1.h"
|
||||||
|
#include "mixer_scheduler.h"
|
||||||
|
#include "heartbeat_driver.h"
|
||||||
|
|
||||||
template <class PxxTransport>
|
template <class PxxTransport>
|
||||||
void Pxx1Pulses<PxxTransport>::addFlag1(uint8_t module, uint8_t sendFailsafe)
|
void Pxx1Pulses<PxxTransport>::addFlag1(uint8_t module, uint8_t sendFailsafe)
|
||||||
@@ -219,3 +221,67 @@ void Pxx1Pulses<PxxTransport>::setupFrame(uint8_t module)
|
|||||||
template class Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport> >;
|
template class Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport> >;
|
||||||
template class Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport> >;
|
template class Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport> >;
|
||||||
template class Pxx1Pulses<UartPxx1Transport>;
|
template class Pxx1Pulses<UartPxx1Transport>;
|
||||||
|
|
||||||
|
#if defined(INTMODULE_USART)
|
||||||
|
#include "intmodule_serial_driver.h"
|
||||||
|
|
||||||
|
static const etx_serial_init pxx1SerialInit = {
|
||||||
|
.baudrate = INTMODULE_PXX1_SERIAL_BAUDRATE,
|
||||||
|
.parity = ETX_Parity_None,
|
||||||
|
.stop_bits = ETX_StopBits_One,
|
||||||
|
.word_length = ETX_WordLength_8,
|
||||||
|
.rx_enable = false,
|
||||||
|
.on_receive = intmoduleFifoReceive,
|
||||||
|
.on_error = intmoduleFifoError,
|
||||||
|
};
|
||||||
|
|
||||||
|
static void* pxx1InitInternal(uint8_t module)
|
||||||
|
{
|
||||||
|
(void)module;
|
||||||
|
|
||||||
|
IntmoduleSerialDriver.init(&pxx1SerialInit);
|
||||||
|
|
||||||
|
#if defined(INTMODULE_HEARTBEAT)
|
||||||
|
init_intmodule_heartbeat();
|
||||||
|
#endif
|
||||||
|
mixerSchedulerSetPeriod(INTERNAL_MODULE, INTMODULE_PXX1_SERIAL_PERIOD);
|
||||||
|
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pxx1DeInitInternal(void* context)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
|
||||||
|
mixerSchedulerSetPeriod(INTERNAL_MODULE, 0);
|
||||||
|
#if defined(INTMODULE_HEARTBEAT)
|
||||||
|
stop_intmodule_heartbeat();
|
||||||
|
#endif
|
||||||
|
IntmoduleSerialDriver.deinit();
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pxx1SetupPulsesInternal(void* context, int16_t* channels, uint8_t nChannels)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
|
||||||
|
// TODO:
|
||||||
|
(void)channels;
|
||||||
|
(void)nChannels;
|
||||||
|
intmodulePulsesData.pxx_uart.setupFrame(INTERNAL_MODULE);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void pxx1SendPulsesInternal(void* context)
|
||||||
|
{
|
||||||
|
(void)context;
|
||||||
|
IntmoduleSerialDriver.sendBuffer(intmodulePulsesData.pxx_uart.getData(),
|
||||||
|
intmodulePulsesData.pxx_uart.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
const etx_module_driver_t Pxx1InternalSerialDriver = {
|
||||||
|
.init = pxx1InitInternal,
|
||||||
|
.deinit = pxx1DeInitInternal,
|
||||||
|
.setupPulses = pxx1SetupPulsesInternal,
|
||||||
|
.sendPulses = pxx1SendPulsesInternal,
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|||||||
@@ -25,6 +25,8 @@
|
|||||||
#include "pxx.h"
|
#include "pxx.h"
|
||||||
#include "crc.h"
|
#include "crc.h"
|
||||||
|
|
||||||
|
#include "hal/module_driver.h"
|
||||||
|
|
||||||
class Pxx1CrcMixin {
|
class Pxx1CrcMixin {
|
||||||
protected:
|
protected:
|
||||||
void initCrc()
|
void initCrc()
|
||||||
@@ -166,4 +168,6 @@ typedef Pxx1Pulses<UartPxx1Transport> UartPxx1Pulses;
|
|||||||
typedef Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport>> PwmPxx1Pulses;
|
typedef Pxx1Pulses<StandardPxx1Transport<PwmPxxBitTransport>> PwmPxx1Pulses;
|
||||||
typedef Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport>> SerialPxx1Pulses;
|
typedef Pxx1Pulses<StandardPxx1Transport<SerialPxxBitTransport>> SerialPxx1Pulses;
|
||||||
|
|
||||||
|
extern const etx_module_driver_t Pxx1InternalSerialDriver;
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
@@ -71,21 +71,6 @@ void intmoduleStop()
|
|||||||
intmodule_driver.on_error = nullptr;
|
intmodule_driver.on_error = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const etx_serial_init pxx1SerialInit = {
|
|
||||||
.baudrate = INTMODULE_PXX1_SERIAL_BAUDRATE,
|
|
||||||
.parity = ETX_Parity_None,
|
|
||||||
.stop_bits = ETX_StopBits_One,
|
|
||||||
.word_length = ETX_WordLength_8,
|
|
||||||
.rx_enable = false,
|
|
||||||
.on_receive = intmoduleFifoReceive,
|
|
||||||
.on_error = intmoduleFifoError,
|
|
||||||
};
|
|
||||||
|
|
||||||
void intmodulePxx1SerialStart()
|
|
||||||
{
|
|
||||||
IntmoduleSerialDriver.init(&pxx1SerialInit);
|
|
||||||
}
|
|
||||||
|
|
||||||
void intmoduleSerialStart(const etx_serial_init* params)
|
void intmoduleSerialStart(const etx_serial_init* params)
|
||||||
{
|
{
|
||||||
if (!params) return;
|
if (!params) return;
|
||||||
@@ -227,7 +212,7 @@ void intmoduleWaitForTxCompleted()
|
|||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
etx_serial_driver_t IntmoduleSerialDriver = {
|
const etx_serial_driver_t IntmoduleSerialDriver = {
|
||||||
.init = intmoduleSerialStart,
|
.init = intmoduleSerialStart,
|
||||||
.deinit = intmoduleStop,
|
.deinit = intmoduleStop,
|
||||||
.sendByte = intmoduleSendByte,
|
.sendByte = intmoduleSendByte,
|
||||||
|
|||||||
@@ -28,4 +28,4 @@
|
|||||||
void intmoduleFifoReceive(uint8_t data);
|
void intmoduleFifoReceive(uint8_t data);
|
||||||
void intmoduleFifoError();
|
void intmoduleFifoError();
|
||||||
|
|
||||||
extern etx_serial_driver_t IntmoduleSerialDriver;
|
extern const etx_serial_driver_t IntmoduleSerialDriver;
|
||||||
|
|||||||
Reference in New Issue
Block a user