Tidy of VTX common

This commit is contained in:
Martin Budden 2017-11-09 21:05:36 +00:00
parent 39727ce384
commit 3c12367c84
10 changed files with 95 additions and 81 deletions

View File

@ -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)

View File

@ -23,13 +23,13 @@
#include <string.h>
#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,9 +84,10 @@ 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,33 +98,38 @@ 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;

View File

@ -19,8 +19,11 @@
#pragma once
#include <stdint.h>
#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.

View File

@ -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"

View File

@ -15,13 +15,24 @@
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#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,11 +75,10 @@ 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)
{
switch (currentSchedule) {
case VTX_PARAM_BANDCHAN:
if (vtxSettingsConfig()->band) {
uint8_t vtxBand;

View File

@ -17,10 +17,11 @@
#pragma once
#include "drivers/vtx_common.h"
#include <stdint.h>
#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);

View File

@ -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,

View File

@ -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

View File

@ -3,15 +3,13 @@
#include <stdint.h>
#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

View File

@ -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"