2 * This file is part of Cleanflight and Betaflight.
4 * Cleanflight and Betaflight are free software. You can redistribute
5 * this software and/or modify this software under the terms of the
6 * GNU General Public License as published by the Free Software
7 * Foundation, either version 3 of the License, or (at your option)
10 * Cleanflight and Betaflight are distributed in the hope that they
11 * will be useful, but WITHOUT ANY WARRANTY; without even the implied
12 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13 * See the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this software.
18 * If not, see <http://www.gnu.org/licenses/>.
21 /* Created by jflyper */
28 #include "common/time.h"
30 #define VTX_SETTINGS_NO_BAND 0 // used for custom frequency selection mode
31 #define VTX_SETTINGS_MIN_BAND 1
32 #define VTX_SETTINGS_MAX_BAND 5
33 #define VTX_SETTINGS_MIN_CHANNEL 1
34 #define VTX_SETTINGS_MAX_CHANNEL 8
36 #define VTX_SETTINGS_BAND_COUNT (VTX_SETTINGS_MAX_BAND - VTX_SETTINGS_MIN_BAND + 1)
37 #define VTX_SETTINGS_CHANNEL_COUNT (VTX_SETTINGS_MAX_CHANNEL - VTX_SETTINGS_MIN_CHANNEL + 1)
39 #define VTX_SETTINGS_DEFAULT_BAND 4
40 #define VTX_SETTINGS_DEFAULT_CHANNEL 1
41 #define VTX_SETTINGS_DEFAULT_FREQ 5740
42 #define VTX_SETTINGS_DEFAULT_PITMODE_FREQ 0
44 #define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
46 #if defined(USE_VTX_RTC6705)
48 #include "drivers/vtx_rtc6705.h"
52 #if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)
54 #define VTX_SETTINGS_POWER_COUNT 5
55 #define VTX_SETTINGS_DEFAULT_POWER 1
56 #define VTX_SETTINGS_MIN_POWER 0
57 #define VTX_SETTINGS_MIN_USER_FREQ 5000
58 #define VTX_SETTINGS_MAX_USER_FREQ 5999
59 #define VTX_SETTINGS_FREQCMD
61 #elif defined(USE_VTX_RTC6705)
63 #define VTX_SETTINGS_POWER_COUNT VTX_RTC6705_POWER_COUNT
64 #define VTX_SETTINGS_DEFAULT_POWER VTX_RTC6705_DEFAULT_POWER
65 #define VTX_SETTINGS_MIN_POWER VTX_RTC6705_MIN_POWER
69 // check value for MSP_SET_VTX_CONFIG to determine if value is encoded
70 // band/channel or frequency in MHz (3 bits for band and 3 bits for channel)
71 #define VTXCOMMON_MSP_BANDCHAN_CHKVAL ((uint16_t)((7 << 3) + 7))
74 VTXDEV_UNSUPPORTED
= 0, // reserved for MSP
77 VTXDEV_SMARTAUDIO
= 3,
79 VTXDEV_UNKNOWN
= 0xFF,
83 #define VTX_COMMON_BAND_USER 0
84 #define VTX_COMMON_BAND_A 1
85 #define VTX_COMMON_BAND_B 2
86 #define VTX_COMMON_BAND_E 3
87 #define VTX_COMMON_BAND_FS 4
88 #define VTX_COMMON_BAND_RACE 5
90 // RTC6705 RF Power index "---", 25 or 200 mW
91 #define VTX_6705_POWER_OFF 0
92 #define VTX_6705_POWER_25 1
93 #define VTX_6705_POWER_200 2
95 // SmartAudio "---", 25, 200, 500, 800 mW
96 #define VTX_SA_POWER_OFF 0
97 #define VTX_SA_POWER_25 1
98 #define VTX_SA_POWER_200 2
99 #define VTX_SA_POWER_500 3
100 #define VTX_SA_POWER_800 4
102 // Tramp "---", 25, 100, 200, 400, 600 mW
103 #define VTX_TRAMP_POWER_OFF 0
104 #define VTX_TRAMP_POWER_25 1
105 #define VTX_TRAMP_POWER_100 2
106 #define VTX_TRAMP_POWER_200 3
107 #define VTX_TRAMP_POWER_400 4
108 #define VTX_TRAMP_POWER_600 5
111 typedef struct vtxDeviceCapability_s
{
113 uint8_t channelCount
;
116 } vtxDeviceCapability_t
;
119 typedef struct vtxDevice_s
{
120 const struct vtxVTable_s
* const vTable
;
122 vtxDeviceCapability_t capability
;
124 const uint16_t *frequencyTable
; // Array of [bandCount][channelCount]
125 const char **bandNames
; // char *bandNames[bandCount + 1]
126 const char **channelNames
; // char *channelNames[channelCount + 1]
127 const char *bandLetters
; // char bandLetters[bandCount + 1]
128 const uint16_t *powerValues
; // uint16 powerValues[powerCount]
129 const char **powerNames
; // char *powerNames[powerCount + 1]
132 uint8_t band
; // Band = 1, 1-based
133 uint8_t channel
; // CH1 = 1, 1-based
134 uint8_t powerIndex
; // Lowest/Off = 0
135 uint8_t pitMode
; // 0 = non-PIT, 1 = PIT
139 // {set,get}BandAndChannel: band and channel are 1 origin
140 // {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent
141 // {set,get}PitMode: 0 = OFF, 1 = ON
143 typedef struct vtxVTable_s
{
144 void (*process
)(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
);
145 vtxDevType_e (*getDeviceType
)(const vtxDevice_t
*vtxDevice
);
146 bool (*isReady
)(const vtxDevice_t
*vtxDevice
);
148 void (*setBandAndChannel
)(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
);
149 void (*setPowerByIndex
)(vtxDevice_t
*vtxDevice
, uint8_t level
);
150 void (*setPitMode
)(vtxDevice_t
*vtxDevice
, uint8_t onoff
);
151 void (*setFrequency
)(vtxDevice_t
*vtxDevice
, uint16_t freq
);
153 bool (*getBandAndChannel
)(const vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
);
154 bool (*getPowerIndex
)(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
);
155 bool (*getPitMode
)(const vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
);
156 bool (*getFrequency
)(const vtxDevice_t
*vtxDevice
, uint16_t *pFreq
);
160 // PIT mode is defined as LOWEST POSSIBLE RF POWER.
161 // - It can be a dedicated mode, or lowest RF power possible.
162 // - It is *NOT* RF on/off control ?
164 void vtxCommonInit(void);
165 void vtxCommonSetDevice(vtxDevice_t
*vtxDevice
);
166 vtxDevice_t
*vtxCommonDevice(void);
169 void vtxCommonProcess(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
);
170 vtxDevType_e
vtxCommonGetDeviceType(const vtxDevice_t
*vtxDevice
);
171 bool vtxCommonDeviceIsReady(const vtxDevice_t
*vtxDevice
);
172 void vtxCommonSetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
);
173 void vtxCommonSetPowerByIndex(vtxDevice_t
*vtxDevice
, uint8_t level
);
174 void vtxCommonSetPitMode(vtxDevice_t
*vtxDevice
, uint8_t onoff
);
175 void vtxCommonSetFrequency(vtxDevice_t
*vtxDevice
, uint16_t freq
);
176 bool vtxCommonGetBandAndChannel(const vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
);
177 bool vtxCommonGetPowerIndex(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
);
178 bool vtxCommonGetPitMode(const vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
);
179 bool vtxCommonGetFrequency(const vtxDevice_t
*vtxDevice
, uint16_t *pFreq
);
180 bool vtxCommonGetDeviceCapability(const vtxDevice_t
*vtxDevice
, vtxDeviceCapability_t
*pDeviceCapability
);
181 const char *vtxCommonLookupBandName(const vtxDevice_t
*vtxDevice
, int band
);
182 char vtxCommonLookupBandLetter(const vtxDevice_t
*vtxDevice
, int band
);
183 char vtxCommonGetBandLetter(const vtxDevice_t
*vtxDevice
, int band
);
184 const char *vtxCommonLookupChannelName(const vtxDevice_t
*vtxDevice
, int channel
);
185 uint16_t vtxCommonLookupFrequency(const vtxDevice_t
*vtxDevice
, int band
, int channel
);
186 bool vtxCommonLookupBandChan(const vtxDevice_t
*vtxDevice
, uint16_t freq
, uint8_t *pBand
, uint8_t *pChannel
);
187 const char *vtxCommonLookupPowerName(const vtxDevice_t
*vtxDevice
, int index
);
188 uint16_t vtxCommonLookupPowerValue(const vtxDevice_t
*vtxDevice
, int index
);