From 80c1cfa6dba3bb212f36efde57677eccd89d4660 Mon Sep 17 00:00:00 2001 From: jflyper Date: Thu, 17 Jan 2019 02:40:14 +0900 Subject: [PATCH] Call vtxInit after device parameters are initialized --- src/main/drivers/vtx_common.c | 2 +- src/main/fc/init.c | 1 - src/main/io/vtx.c | 10 +++++++++- src/main/io/vtx_rtc6705.c | 3 +++ src/main/io/vtx_smartaudio.c | 2 ++ src/main/io/vtx_tramp.c | 4 ++++ 6 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/main/drivers/vtx_common.c b/src/main/drivers/vtx_common.c index 56c611393b..55381e8459 100644 --- a/src/main/drivers/vtx_common.c +++ b/src/main/drivers/vtx_common.c @@ -168,7 +168,7 @@ bool vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_ // Returns frequency value (in MHz), or 0 if band/channel out of range. uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel) { - if (band > 0 && band <= vtxDevice->capability.bandCount && + if (vtxDevice && band > 0 && band <= vtxDevice->capability.bandCount && channel > 0 && channel <= vtxDevice->capability.channelCount) { return vtxDevice->frequencyTable[(band - 1) * vtxDevice->capability.channelCount + (channel - 1)]; diff --git a/src/main/fc/init.c b/src/main/fc/init.c index 5b27214fdd..b12adff4be 100644 --- a/src/main/fc/init.c +++ b/src/main/fc/init.c @@ -710,7 +710,6 @@ void init(void) #if defined(USE_VTX_COMMON) vtxCommonInit(); - vtxInit(); #endif #ifdef USE_VTX_SMARTAUDIO diff --git a/src/main/io/vtx.c b/src/main/io/vtx.c index 15c8f004e8..24fe44aa79 100644 --- a/src/main/io/vtx.c +++ b/src/main/io/vtx.c @@ -69,8 +69,16 @@ void vtxInit(void) { bool settingsUpdated = false; + vtxDevice_t *vtxDevice = vtxCommonDevice(); + + if (!vtxDevice) { + // If a device is not registered, we don't have any table to refer. + // Don't manipulate settings and just return in this case. + return; + } + // sync frequency in parameter group when band/channel are specified - const uint16_t freq = vtxCommonLookupFrequency(vtxCommonDevice(), vtxSettingsConfig()->band, vtxSettingsConfig()->channel); + const uint16_t freq = vtxCommonLookupFrequency(vtxDevice, vtxSettingsConfig()->band, vtxSettingsConfig()->channel); if (vtxSettingsConfig()->band && freq != vtxSettingsConfig()->freq) { vtxSettingsConfigMutable()->freq = freq; settingsUpdated = true; diff --git a/src/main/io/vtx_rtc6705.c b/src/main/io/vtx_rtc6705.c index cb2a372643..2ed249692a 100644 --- a/src/main/io/vtx_rtc6705.c +++ b/src/main/io/vtx_rtc6705.c @@ -36,6 +36,7 @@ #include "drivers/time.h" #include "drivers/vtx_rtc6705.h" +#include "io/vtx.h" #include "io/vtx_rtc6705.h" #include "io/vtx_string.h" @@ -69,6 +70,8 @@ bool vtxRTC6705Init(void) vtxCommonSetDevice(&vtxRTC6705); + vtxInit(); + return true; } diff --git a/src/main/io/vtx_smartaudio.c b/src/main/io/vtx_smartaudio.c index d0b5f797c6..fa810b79c8 100644 --- a/src/main/io/vtx_smartaudio.c +++ b/src/main/io/vtx_smartaudio.c @@ -706,6 +706,8 @@ bool vtxSmartAudioInit(void) vtxCommonSetDevice(&vtxSmartAudio); + vtxInit(); + return true; } diff --git a/src/main/io/vtx_tramp.c b/src/main/io/vtx_tramp.c index 5dabda3c20..ec6bcab19f 100644 --- a/src/main/io/vtx_tramp.c +++ b/src/main/io/vtx_tramp.c @@ -614,6 +614,7 @@ bool vtxTrampInit(void) return false; } + // XXX Effect of USE_VTX_COMMON should be reviewed, as following call to vtxInit will do nothing if vtxCommonSetDevice is not called. #if defined(USE_VTX_COMMON) vtxTramp.capability.bandCount = VTX_TRAMP_BAND_COUNT; vtxTramp.capability.channelCount = VTX_TRAMP_CHANNEL_COUNT; @@ -626,8 +627,11 @@ bool vtxTrampInit(void) vtxTramp.powerValues = trampPowerTable; vtxCommonSetDevice(&vtxTramp); + #endif + vtxInit(); + return true; }