fix: Internal PXX exclusive S.PORT (#3822)
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include "storage/storage.h"
|
||||
#include "globals.h"
|
||||
#include "MultiProtoDefs.h"
|
||||
#include "hal/module_port.h"
|
||||
|
||||
#if defined(MULTIMODULE)
|
||||
#include "telemetry/multi.h"
|
||||
@@ -728,25 +729,13 @@ inline bool isBindCh9To16Allowed(uint8_t moduleIndex)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
inline bool isSportLineUsedByInternalModule()
|
||||
{
|
||||
return g_model.moduleData[INTERNAL_MODULE].type == MODULE_TYPE_XJT_PXX1;
|
||||
}
|
||||
#else
|
||||
inline bool isSportLineUsedByInternalModule()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
inline bool isTelemAllowedOnBind(uint8_t moduleIndex)
|
||||
{
|
||||
#if defined(HARDWARE_INTERNAL_MODULE)
|
||||
if (moduleIndex == INTERNAL_MODULE)
|
||||
return true;
|
||||
|
||||
if (isSportLineUsedByInternalModule())
|
||||
if (!modulePortIsPortUsedByModule(moduleIndex, ETX_MOD_PORT_SPORT))
|
||||
return false;
|
||||
#endif
|
||||
|
||||
|
||||
@@ -139,8 +139,8 @@ static void setupPulsesMulti(uint8_t*& p_buf, uint8_t module)
|
||||
}
|
||||
|
||||
// Invert telemetry if needed
|
||||
if (invert[module] & 0x80 &&
|
||||
!g_model.moduleData[module].multi.disableTelemetry) {
|
||||
uint8_t disableTelemetry = modulePortIsPortUsedByModule(module, ETX_MOD_PORT_SPORT) ? 0 : 1;
|
||||
if (invert[module] & 0x80 && !disableTelemetry) {
|
||||
if (getMultiModuleStatus(module).isValid()) {
|
||||
invert[module] &= 0x08; // Telemetry received, stop searching
|
||||
} else if (counter[module] % 100 == 0) {
|
||||
@@ -170,7 +170,7 @@ static void setupPulsesMulti(uint8_t*& p_buf, uint8_t module)
|
||||
| (g_model.header.modelId[module] & 0x30)
|
||||
| (invert[module] & 0x08)
|
||||
//| 0x04 // Future use
|
||||
| (g_model.moduleData[module].multi.disableTelemetry << 1)
|
||||
| (disableTelemetry << 1)
|
||||
| g_model.moduleData[module].multi.disableMapping));
|
||||
}
|
||||
|
||||
|
||||
@@ -21,23 +21,6 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "pulses_common.h"
|
||||
#include "hal/serial_driver.h"
|
||||
#include "hal/module_driver.h"
|
||||
|
||||
class UartMultiPulses: public DataBuffer<uint8_t, 64>
|
||||
{
|
||||
public:
|
||||
void initFrame()
|
||||
{
|
||||
initBuffer();
|
||||
}
|
||||
|
||||
void sendByte(uint8_t b)
|
||||
{
|
||||
if (getSize() < 64)
|
||||
*ptr++ = b;
|
||||
}
|
||||
};
|
||||
|
||||
extern const etx_proto_driver_t MultiDriver;
|
||||
|
||||
@@ -111,6 +111,19 @@ void restartModule(uint8_t module)
|
||||
mixerTaskStart();
|
||||
}
|
||||
|
||||
void pulsesRestartModuleUnsafe(uint8_t module)
|
||||
{
|
||||
if (module >= MAX_MODULES)
|
||||
return;
|
||||
|
||||
auto mod_drv = pulsesGetModuleDriver(module);
|
||||
if (!mod_drv->drv) return;
|
||||
|
||||
auto drv = mod_drv->drv;
|
||||
drv->deinit(mod_drv->ctx);
|
||||
mod_drv->ctx = drv->init(module);
|
||||
}
|
||||
|
||||
#if !defined(SIMU)
|
||||
#include <FreeRTOS/include/FreeRTOS.h>
|
||||
#include <FreeRTOS/include/timers.h>
|
||||
|
||||
@@ -175,6 +175,12 @@ void pulsesSetModuleDeInitCb(module_deinit_cb_t cb);
|
||||
void restartModule(uint8_t module);
|
||||
bool restartModuleAsync(uint8_t module, uint8_t cnt_delay);
|
||||
|
||||
// Re-Init module
|
||||
//
|
||||
// Note: this can only be used from within
|
||||
// module init.
|
||||
void pulsesRestartModuleUnsafe(uint8_t module);
|
||||
|
||||
void pulsesModuleSettingsUpdate(uint8_t module);
|
||||
|
||||
void setupPulsesPPMTrainer();
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* 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 "pxx.h"
|
||||
#include "hal/module_port.h"
|
||||
|
||||
bool pxxClearSPort()
|
||||
{
|
||||
auto sport_module = modulePortGetModuleForPort(ETX_MOD_PORT_SPORT);
|
||||
if (sport_module >= 0) {
|
||||
// verify S.PORT is not used for TX (otherwise fail early)
|
||||
auto mod_st = modulePortGetState(sport_module);
|
||||
if (mod_st && mod_st->tx.port &&
|
||||
mod_st->tx.port->port == ETX_MOD_PORT_SPORT) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
// S.PORT soft-serial cannot be used for sending
|
||||
sport_module = modulePortGetModuleForPort(ETX_MOD_PORT_SPORT_INV);
|
||||
}
|
||||
|
||||
if (sport_module >= 0) {
|
||||
auto mod_st = modulePortGetState(sport_module);
|
||||
if (mod_st) modulePortDeInitRxPort(mod_st);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -45,3 +45,7 @@
|
||||
|
||||
#define EXTMODULE_PXX1_SERIAL_PERIOD 4000/*us*/
|
||||
#define EXTMODULE_PXX1_SERIAL_BAUDRATE 420000
|
||||
|
||||
// Releases S.PORT usage from
|
||||
// the module driver using it.
|
||||
bool pxxClearSPort();
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#include "dataconstants.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "heartbeat_driver.h"
|
||||
#include "mixer_scheduler.h"
|
||||
@@ -69,14 +70,17 @@ void Pxx1Pulses<PxxTransport>::addExtraFlags(uint8_t module)
|
||||
extraFlags |= (g_model.moduleData[module].pxx.receiverTelemetryOff << 1);
|
||||
extraFlags |= (g_model.moduleData[module].pxx.receiverHigherChannels << 2);
|
||||
if (isModuleR9MNonAccess(module)) {
|
||||
extraFlags |= (min<uint8_t>(g_model.moduleData[module].pxx.power, isModuleR9M_FCC_VARIANT(module) ? (uint8_t)R9M_FCC_POWER_MAX : (uint8_t)R9M_LBT_POWER_MAX) << 3);
|
||||
if (isModuleR9M_EUPLUS(module))
|
||||
extraFlags |= (1 << 6);
|
||||
extraFlags |= (min<uint8_t>(g_model.moduleData[module].pxx.power,
|
||||
isModuleR9M_FCC_VARIANT(module)
|
||||
? (uint8_t)R9M_FCC_POWER_MAX
|
||||
: (uint8_t)R9M_LBT_POWER_MAX)
|
||||
<< 3);
|
||||
if (isModuleR9M_EUPLUS(module)) extraFlags |= (1 << 6);
|
||||
}
|
||||
|
||||
#if defined(HARDWARE_EXTERNAL_MODULE) && defined(HARDWARE_INTERNAL_MODULE)
|
||||
// Disable S.PORT if internal module is active
|
||||
if (module == EXTERNAL_MODULE && isSportLineUsedByInternalModule()) {
|
||||
// Disable S.PORT if port is not used (might be used by the internal module)
|
||||
if (module == EXTERNAL_MODULE && !modulePortIsPortUsedByModule(module, ETX_MOD_PORT_SPORT)) {
|
||||
extraFlags |= (1 << 5);
|
||||
}
|
||||
#endif
|
||||
@@ -284,6 +288,8 @@ static void* pxx1Init(uint8_t module)
|
||||
|
||||
if (module == INTERNAL_MODULE) {
|
||||
|
||||
if (!pxxClearSPort()) return nullptr;
|
||||
|
||||
txCfg.baudrate = _pxx1_internal_baudrate;
|
||||
mod_st = modulePortInitSerial(module, ETX_MOD_PORT_UART, &txCfg, false);
|
||||
|
||||
@@ -361,7 +367,12 @@ static void* pxx1Init(uint8_t module)
|
||||
static void pxx1DeInit(void* ctx)
|
||||
{
|
||||
auto mod_st = (etx_module_state_t*)ctx;
|
||||
auto module = modulePortGetModule(mod_st);
|
||||
modulePortDeInit(mod_st);
|
||||
|
||||
if (module == INTERNAL_MODULE) {
|
||||
pulsesRestartModuleUnsafe(EXTERNAL_MODULE);
|
||||
}
|
||||
}
|
||||
|
||||
static void pxx1SendPulses(void* ctx, uint8_t* buffer, int16_t* channels, uint8_t nChannels)
|
||||
|
||||
Reference in New Issue
Block a user