From 01c749720f42f7d1da468ce8457ad06f50acf38d Mon Sep 17 00:00:00 2001 From: 3djc Date: Wed, 28 Aug 2024 04:59:26 +0200 Subject: [PATCH] fix: xjt lite telem binding (#5468) --- radio/src/pulses/modules_helpers.h | 2 +- radio/src/tests/module_ports.cpp | 38 ++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/radio/src/pulses/modules_helpers.h b/radio/src/pulses/modules_helpers.h index b9d90ae5c3c..56b21751c1c 100644 --- a/radio/src/pulses/modules_helpers.h +++ b/radio/src/pulses/modules_helpers.h @@ -669,7 +669,7 @@ inline bool isTelemAllowedOnBind(uint8_t moduleIndex) if (moduleIndex == INTERNAL_MODULE) return true; - if (!modulePortIsPortUsedByModule(moduleIndex, ETX_MOD_PORT_SPORT)) + if (modulePortIsPortUsedByModule(INTERNAL_MODULE, ETX_MOD_PORT_SPORT)) return false; #endif diff --git a/radio/src/tests/module_ports.cpp b/radio/src/tests/module_ports.cpp index 5a6ebdc5bfe..e24fcc4048b 100644 --- a/radio/src/tests/module_ports.cpp +++ b/radio/src/tests/module_ports.cpp @@ -238,4 +238,42 @@ TEST(ports, boot_pxx1_multi) _deinitModuleDrv(EXTERNAL_MODULE); EXPECT_FALSE(modulePortIsPortUsed(ETX_MOD_PORT_SPORT)); } + +TEST(ports, isTelemAllowedOnBind) +{ + modulePortInit(); + + void* int_ctx = Pxx1Driver.init(INTERNAL_MODULE); + EXPECT_TRUE(int_ctx != nullptr); + if (!int_ctx) return; + _setModuleDrv(INTERNAL_MODULE, &Pxx1Driver, int_ctx); + + // Telem always has priority on internal + EXPECT_TRUE(isTelemAllowedOnBind(INTERNAL_MODULE)); + + // When internal uses SPORT, you cannot bind FRSKY with telem on external module + EXPECT_FALSE(isTelemAllowedOnBind(EXTERNAL_MODULE)); + + // but you can when internal is disabled + _deinitModuleDrv(INTERNAL_MODULE); + EXPECT_TRUE(isTelemAllowedOnBind(EXTERNAL_MODULE)); +} +#elif !defined(PCBFLYSKY) //defined(INTERNAL_MODULE_PXX1) && defined(HARDWARE_EXTERNAL_MODULE) +TEST(ports, isTelemAllowedOnBind) +{ + modulePortInit(); + + const etx_serial_init serialCfg = { + .baudrate = 921000, + .encoding = ETX_Encoding_8N1, + .direction = ETX_Dir_TX_RX, + .polarity = ETX_Pol_Normal, + }; + + auto mod_st = modulePortInitSerial(INTERNAL_MODULE, ETX_MOD_PORT_UART, &serialCfg, false); + EXPECT_TRUE(mod_st != nullptr); + + // Since internal module doesn't use SPORT, you should be able to bind FrSky with telem + EXPECT_TRUE(isTelemAllowedOnBind(EXTERNAL_MODULE)); +} #endif