From 3c12367c8409853ad041b9bea3a6c18ac178a991 Mon Sep 17 00:00:00 2001 From: Martin Budden Date: Thu, 9 Nov 2017 21:05:36 +0000 Subject: [PATCH] Tidy of VTX common --- src/main/cms/cms_menu_vtx_rtc6705.c | 2 +- src/main/drivers/vtx_common.c | 38 +++++++++------- src/main/drivers/vtx_common.h | 42 +++++++++--------- src/main/fc/settings.c | 1 + src/main/io/vtx.c | 68 +++++++++++++++++------------ src/main/io/vtx.h | 7 +-- src/main/io/vtx_rtc6705.c | 4 +- src/main/io/vtx_rtc6705.h | 7 --- src/main/io/vtx_string.h | 6 +-- src/main/rx/spektrum.c | 1 + 10 files changed, 95 insertions(+), 81 deletions(-) diff --git a/src/main/cms/cms_menu_vtx_rtc6705.c b/src/main/cms/cms_menu_vtx_rtc6705.c index 733cef5a5..34d642169 100644 --- a/src/main/cms/cms_menu_vtx_rtc6705.c +++ b/src/main/cms/cms_menu_vtx_rtc6705.c @@ -50,7 +50,7 @@ static const char * const rtc6705BandNames[] = { }; static OSD_TAB_t entryVtxBand = {&cmsx_vtxBand, ARRAYLEN(rtc6705BandNames) - 1, &rtc6705BandNames[0]}; -static OSD_UINT8_t entryVtxChannel = {&cmsx_vtxChannel, 1, VTX_RTC6705_CHANNEL_COUNT, 1}; +static OSD_UINT8_t entryVtxChannel = {&cmsx_vtxChannel, 1, VTX_SETTINGS_CHANNEL_COUNT, 1}; static OSD_TAB_t entryVtxPower = {&cmsx_vtxPower, VTX_RTC6705_POWER_COUNT - 1 - VTX_RTC6705_MIN_POWER, &rtc6705PowerNames[VTX_RTC6705_MIN_POWER]}; static void cmsx_Vtx_ConfigRead(void) diff --git a/src/main/drivers/vtx_common.c b/src/main/drivers/vtx_common.c index eb71bb260..5ba697e65 100644 --- a/src/main/drivers/vtx_common.c +++ b/src/main/drivers/vtx_common.c @@ -23,13 +23,13 @@ #include #include "platform.h" -#include "build/debug.h" -#include "common/time.h" -#include "drivers/vtx_common.h" -#include "fc/config.h" #if defined(VTX_COMMON) +#include "common/time.h" +#include "drivers/vtx_common.h" + + vtxDevice_t *vtxDevice = NULL; void vtxCommonInit(void) @@ -48,8 +48,9 @@ bool vtxCommonDeviceRegistered(void) vtxDevType_e vtxCommonGetDeviceType(void) { - if (!vtxDevice || !vtxDevice->vTable->getDeviceType) + if (!vtxDevice || !vtxDevice->vTable->getDeviceType) { return VTXDEV_UNKNOWN; + } return vtxDevice->vTable->getDeviceType(); } @@ -83,8 +84,9 @@ void vtxCommonSetPowerByIndex(uint8_t index) // on = 1, off = 0 void vtxCommonSetPitMode(uint8_t onoff) { - if (vtxDevice->vTable->setPitMode) + if (vtxDevice->vTable->setPitMode) { vtxDevice->vTable->setPitMode(onoff); + } } void vtxCommonSetFrequency(uint16_t freq) @@ -96,32 +98,37 @@ void vtxCommonSetFrequency(uint16_t freq) bool vtxCommonGetBandAndChannel(uint8_t *pBand, uint8_t *pChannel) { - if (vtxDevice->vTable->getBandAndChannel) + if (vtxDevice->vTable->getBandAndChannel) { return vtxDevice->vTable->getBandAndChannel(pBand, pChannel); - else + } else { return false; + } } bool vtxCommonGetPowerIndex(uint8_t *pIndex) { - if (!vtxDevice) + if (!vtxDevice) { return false; + } - if (vtxDevice->vTable->getPowerIndex) + if (vtxDevice->vTable->getPowerIndex) { return vtxDevice->vTable->getPowerIndex(pIndex); - else + } else { return false; + } } bool vtxCommonGetPitMode(uint8_t *pOnOff) { - if (!vtxDevice) + if (!vtxDevice) { return false; + } - if (vtxDevice->vTable->getPitMode) + if (vtxDevice->vTable->getPitMode) { return vtxDevice->vTable->getPitMode(pOnOff); - else + } else { return false; + } } bool vtxCommonGetFrequency(uint16_t *pFreq) @@ -138,8 +145,9 @@ bool vtxCommonGetFrequency(uint16_t *pFreq) bool vtxCommonGetDeviceCapability(vtxDeviceCapability_t *pDeviceCapability) { - if (!vtxDevice) + if (!vtxDevice) { return false; + } memcpy(pDeviceCapability, &vtxDevice->capability, sizeof(vtxDeviceCapability_t)); return true; diff --git a/src/main/drivers/vtx_common.h b/src/main/drivers/vtx_common.h index aea9e7fd0..634b5f184 100644 --- a/src/main/drivers/vtx_common.h +++ b/src/main/drivers/vtx_common.h @@ -19,8 +19,11 @@ #pragma once +#include + +#include "platform.h" #include "common/time.h" -#include "io/vtx.h" + #define VTX_SETTINGS_MIN_BAND 1 #define VTX_SETTINGS_MAX_BAND 5 @@ -94,7 +97,6 @@ typedef enum { #define VTX_TRAMP_POWER_400 4 #define VTX_TRAMP_POWER_600 5 -struct vtxVTable_s; typedef struct vtxDeviceCapability_s { uint8_t bandCount; @@ -102,29 +104,12 @@ typedef struct vtxDeviceCapability_s { uint8_t powerCount; } vtxDeviceCapability_t; -typedef struct vtxDevice_s { - const struct vtxVTable_s * const vTable; - - vtxDeviceCapability_t capability; - - uint16_t *frequencyTable; // Array of [bandCount][channelCount] - char **bandNames; // char *bandNames[bandCount] - char **channelNames; // char *channelNames[channelCount] - char **powerNames; // char *powerNames[powerCount] - - uint8_t band; // Band = 1, 1-based - uint8_t channel; // CH1 = 1, 1-based - uint8_t powerIndex; // Lowest/Off = 0 - uint8_t pitMode; // 0 = non-PIT, 1 = PIT - -} vtxDevice_t; - // {set,get}BandAndChannel: band and channel are 1 origin // {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent // {set,get}PitMode: 0 = OFF, 1 = ON typedef struct vtxVTable_s { - void (*process)(uint32_t currentTimeUs); + void (*process)(timeUs_t currentTimeUs); vtxDevType_e (*getDeviceType)(void); bool (*isReady)(void); @@ -139,6 +124,23 @@ typedef struct vtxVTable_s { bool (*getFrequency)(uint16_t *pFreq); } vtxVTable_t; +typedef struct vtxDevice_s { + const vtxVTable_t * const vTable; + + vtxDeviceCapability_t capability; + + uint16_t *frequencyTable; // Array of [bandCount][channelCount] + char **bandNames; // char *bandNames[bandCount] + char **channelNames; // char *channelNames[channelCount] + char **powerNames; // char *powerNames[powerCount] + + uint8_t band; // Band = 1, 1-based + uint8_t channel; // CH1 = 1, 1-based + uint8_t powerIndex; // Lowest/Off = 0 + uint8_t pitMode; // 0 = non-PIT, 1 = PIT +} vtxDevice_t; + + // 3.1.0 // PIT mode is defined as LOWEST POSSIBLE RF POWER. // - It can be a dedicated mode, or lowest RF power possible. diff --git a/src/main/fc/settings.c b/src/main/fc/settings.c index 8847524d9..5316c9761 100644 --- a/src/main/fc/settings.c +++ b/src/main/fc/settings.c @@ -64,6 +64,7 @@ #include "io/gps.h" #include "io/ledstrip.h" #include "io/osd.h" +#include "io/vtx.h" #include "io/vtx_control.h" #include "io/vtx_rtc6705.h" diff --git a/src/main/io/vtx.c b/src/main/io/vtx.c index 1e87f43e3..e1ca7afec 100644 --- a/src/main/io/vtx.c +++ b/src/main/io/vtx.c @@ -15,13 +15,24 @@ * along with Cleanflight. If not, see . */ +#include + +#include "platform.h" + +#if defined(VTX_COMMON) + #include "common/time.h" + +#include "config/parameter_group.h" +#include "config/parameter_group_ids.h" + #include "drivers/vtx_common.h" + #include "fc/config.h" + #include "io/vtx.h" #include "io/vtx_string.h" -#if defined(VTX_COMMON) PG_REGISTER_WITH_RESET_TEMPLATE(vtxSettingsConfig_t, vtxSettingsConfig, PG_VTX_SETTINGS_CONFIG, 0); @@ -64,41 +75,40 @@ void vtxProcess(timeUs_t currentTimeUs) static uint8_t scheduleIndex; if (vtxCommonDeviceRegistered()) { - uint8_t currentSchedule = vtxParamSchedule[scheduleIndex]; + const uint8_t currentSchedule = vtxParamSchedule[scheduleIndex]; // Process VTX changes from the parameter group at 10Hz if (currentTimeUs > lastCycleTimeUs + VTX_PARAM_CYCLE_TIME_US) { - switch (currentSchedule) - { - case VTX_PARAM_BANDCHAN: - if (vtxSettingsConfig()->band) { - uint8_t vtxBand; - uint8_t vtxChan; - if (vtxCommonGetBandAndChannel(&vtxBand, &vtxChan)) { - if (vtxSettingsConfig()->band != vtxBand || vtxSettingsConfig()->channel != vtxChan) { - vtxCommonSetBandAndChannel(vtxSettingsConfig()->band, vtxSettingsConfig()->channel); - } + switch (currentSchedule) { + case VTX_PARAM_BANDCHAN: + if (vtxSettingsConfig()->band) { + uint8_t vtxBand; + uint8_t vtxChan; + if (vtxCommonGetBandAndChannel(&vtxBand, &vtxChan)) { + if (vtxSettingsConfig()->band != vtxBand || vtxSettingsConfig()->channel != vtxChan) { + vtxCommonSetBandAndChannel(vtxSettingsConfig()->band, vtxSettingsConfig()->channel); } + } #if defined(VTX_SETTINGS_FREQCMD) - } else { - uint16_t vtxFreq; - if (vtxCommonGetFrequency(&vtxFreq)) { - if (vtxSettingsConfig()->freq != vtxFreq) { - vtxCommonSetFrequency(vtxSettingsConfig()->freq); - } + } else { + uint16_t vtxFreq; + if (vtxCommonGetFrequency(&vtxFreq)) { + if (vtxSettingsConfig()->freq != vtxFreq) { + vtxCommonSetFrequency(vtxSettingsConfig()->freq); } + } #endif + } + break; + case VTX_PARAM_POWER: ; + uint8_t vtxPower; + if (vtxCommonGetPowerIndex(&vtxPower)) { + if (vtxSettingsConfig()->power != vtxPower) { + vtxCommonSetPowerByIndex(vtxSettingsConfig()->power); } - break; - case VTX_PARAM_POWER: ; - uint8_t vtxPower; - if (vtxCommonGetPowerIndex(&vtxPower)) { - if (vtxSettingsConfig()->power != vtxPower) { - vtxCommonSetPowerByIndex(vtxSettingsConfig()->power); - } - } - break; - default: - break; + } + break; + default: + break; } lastCycleTimeUs = currentTimeUs; scheduleIndex = (scheduleIndex + 1) % vtxParamScheduleCount; diff --git a/src/main/io/vtx.h b/src/main/io/vtx.h index ee32a401f..3029011af 100644 --- a/src/main/io/vtx.h +++ b/src/main/io/vtx.h @@ -17,10 +17,11 @@ #pragma once -#include "drivers/vtx_common.h" +#include +#include "platform.h" +#include "common/time.h" #include "config/parameter_group.h" -#include "config/parameter_group_ids.h" typedef struct vtxSettingsConfig_s { uint8_t band; // 1=A, 2=B, 3=E, 4=F(Airwaves/Fatshark), 5=Raceband @@ -32,4 +33,4 @@ typedef struct vtxSettingsConfig_s { PG_DECLARE(vtxSettingsConfig_t, vtxSettingsConfig); void vtxInit(void); -void vtxProcess(uint32_t currentTimeUs); +void vtxProcess(timeUs_t currentTimeUs); diff --git a/src/main/io/vtx_rtc6705.c b/src/main/io/vtx_rtc6705.c index ec24ae424..5dae83b65 100644 --- a/src/main/io/vtx_rtc6705.c +++ b/src/main/io/vtx_rtc6705.c @@ -62,8 +62,8 @@ const char * const rtc6705PowerNames[VTX_RTC6705_POWER_COUNT] = { static vtxVTable_t rtc6705VTable; // Forward static vtxDevice_t vtxRTC6705 = { .vTable = &rtc6705VTable, - .capability.bandCount = VTX_RTC6705_BAND_COUNT, - .capability.channelCount = VTX_RTC6705_CHANNEL_COUNT, + .capability.bandCount = VTX_SETTINGS_BAND_COUNT, + .capability.channelCount = VTX_SETTINGS_CHANNEL_COUNT, .capability.powerCount = VTX_RTC6705_POWER_COUNT, .bandNames = (char **)vtx58BandNames, .channelNames = (char **)vtx58ChannelNames, diff --git a/src/main/io/vtx_rtc6705.h b/src/main/io/vtx_rtc6705.h index 5e8157e69..00bc26917 100644 --- a/src/main/io/vtx_rtc6705.h +++ b/src/main/io/vtx_rtc6705.h @@ -22,13 +22,6 @@ #include "platform.h" -#define VTX_RTC6705_MIN_BAND 1 -#define VTX_RTC6705_MAX_BAND 5 -#define VTX_RTC6705_MIN_CHANNEL 1 -#define VTX_RTC6705_MAX_CHANNEL 8 - -#define VTX_RTC6705_BAND_COUNT (VTX_RTC6705_MAX_BAND - VTX_RTC6705_MIN_BAND + 1) -#define VTX_RTC6705_CHANNEL_COUNT (VTX_RTC6705_MAX_CHANNEL - VTX_RTC6705_MIN_CHANNEL + 1) #define VTX_RTC6705_POWER_COUNT 3 #define VTX_RTC6705_DEFAULT_POWER 1 diff --git a/src/main/io/vtx_string.h b/src/main/io/vtx_string.h index 44854128c..3325c4333 100644 --- a/src/main/io/vtx_string.h +++ b/src/main/io/vtx_string.h @@ -3,15 +3,13 @@ #include #include "platform.h" +#include "drivers/vtx_common.h" -#if defined(VTX_COMMON) -extern const uint16_t vtx58frequencyTable[5][8]; +extern const uint16_t vtx58frequencyTable[VTX_SETTINGS_BAND_COUNT][VTX_SETTINGS_CHANNEL_COUNT]; extern const char * const vtx58BandNames[]; extern const char * const vtx58ChannelNames[]; extern const char vtx58BandLetter[]; bool vtx58_Freq2Bandchan(uint16_t freq, uint8_t *pBand, uint8_t *pChannel); uint16_t vtx58_Bandchan2Freq(uint8_t band, uint8_t channel); - -#endif diff --git a/src/main/rx/spektrum.c b/src/main/rx/spektrum.c index 4a9b40688..05e8c6830 100644 --- a/src/main/rx/spektrum.c +++ b/src/main/rx/spektrum.c @@ -34,6 +34,7 @@ #include "drivers/vtx_common.h" #include "io/serial.h" +#include "io/vtx.h" #include "io/vtx_string.h" #include "fc/config.h"