2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
18 /* Created by jflyper */
20 #include "common/time.h"
22 #define VTX_SETTINGS_MIN_BAND 1
23 #define VTX_SETTINGS_MAX_BAND 5
24 #define VTX_SETTINGS_MIN_CHANNEL 1
25 #define VTX_SETTINGS_MAX_CHANNEL 8
27 #define VTX_SETTINGS_BAND_COUNT (VTX_SETTINGS_MAX_BAND - VTX_SETTINGS_MIN_BAND + 1)
28 #define VTX_SETTINGS_CHANNEL_COUNT (VTX_SETTINGS_MAX_CHANNEL - VTX_SETTINGS_MIN_CHANNEL + 1)
30 #define VTX_SETTINGS_DEFAULT_BAND 4
31 #define VTX_SETTINGS_DEFAULT_CHANNEL 1
32 #define VTX_SETTINGS_DEFAULT_PITMODE_CHANNEL 1
33 #define VTX_SETTINGS_DEFAULT_LOW_POWER_DISARM 0
35 #if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP) || defined(USE_VTX_MSP)
37 #define VTX_SETTINGS_POWER_COUNT 8
38 #define VTX_SETTINGS_DEFAULT_POWER 1
39 #define VTX_SETTINGS_MIN_POWER 1
40 #define VTX_SETTINGS_MIN_USER_FREQ 5000
41 #define VTX_SETTINGS_MAX_USER_FREQ 5999
42 #define VTX_SETTINGS_FREQCMD
43 #define VTX_SETTINGS_MAX_POWER (VTX_SETTINGS_POWER_COUNT - VTX_SETTINGS_MIN_POWER + 1)
47 #define VTX_SETTINGS_DEFAULT_POWER 0
51 // check value for MSP_SET_VTX_CONFIG to determine if value is encoded
52 // band/channel or frequency in MHz (3 bits for band and 3 bits for channel)
53 #define VTXCOMMON_MSP_BANDCHAN_CHKVAL ((uint16_t)((7 << 3) + 7))
56 VTXDEV_UNSUPPORTED
= 0, // reserved for MSP
57 VTXDEV_RTC6705
= 1, // deprecated
59 VTXDEV_SMARTAUDIO
= 3,
63 VTXDEV_UNKNOWN
= 0xFF,
67 FREQUENCYGROUP_5G8
= 0,
68 FREQUENCYGROUP_2G4
= 1,
69 FREQUENCYGROUP_1G3
= 2,
70 } vtxFrequencyGroups_e
;
74 typedef struct vtxDeviceCapability_s
{
81 } vtxDeviceCapability_t
;
83 typedef struct vtxDeviceOsdInfo_s
{
90 const char * bandName
;
91 const char * channelName
;
92 char powerIndexLetter
;
95 typedef struct vtxDevice_s
{
96 const struct vtxVTable_s
* const vTable
;
98 vtxDeviceCapability_t capability
;
100 uint8_t band
; // Band = 1, 1-based
101 uint8_t channel
; // CH1 = 1, 1-based
102 uint8_t powerIndex
; // Lowest/Off = 0
103 uint8_t pitMode
; // 0 = non-PIT, 1 = PIT
106 // {set,get}BandAndChannel: band and channel are 1 origin
107 // {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent
108 // {set,get}PitMode: 0 = OFF, 1 = ON
110 typedef struct vtxVTable_s
{
111 void (*process
)(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
);
112 vtxDevType_e (*getDeviceType
)(const vtxDevice_t
*vtxDevice
);
113 bool (*isReady
)(const vtxDevice_t
*vtxDevice
);
115 void (*setBandAndChannel
)(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
);
116 void (*setPowerByIndex
)(vtxDevice_t
*vtxDevice
, uint8_t level
);
117 void (*setPitMode
)(vtxDevice_t
*vtxDevice
, uint8_t onoff
);
119 bool (*getBandAndChannel
)(const vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
);
120 bool (*getPowerIndex
)(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
);
121 bool (*getPitMode
)(const vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
);
122 bool (*getFrequency
)(const vtxDevice_t
*vtxDevice
, uint16_t *pFreq
);
124 bool (*getPower
)(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
, uint16_t *pPowerMw
);
125 bool (*getOsdInfo
)(const vtxDevice_t
*vtxDevice
, vtxDeviceOsdInfo_t
* pOsdInfo
);
129 // PIT mode is defined as LOWEST POSSIBLE RF POWER.
130 // - It can be a dedicated mode, or lowest RF power possible.
131 // - It is *NOT* RF on/off control ?
133 void vtxCommonInit(void);
134 void vtxCommonSetDevice(vtxDevice_t
*vtxDevice
);
135 vtxDevice_t
*vtxCommonDevice(void);
138 void vtxCommonProcess(vtxDevice_t
*vtxDevice
, timeUs_t currentTimeUs
);
139 vtxDevType_e
vtxCommonGetDeviceType(vtxDevice_t
*vtxDevice
);
140 bool vtxCommonDeviceIsReady(vtxDevice_t
*vtxDevice
);
141 void vtxCommonSetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t band
, uint8_t channel
);
142 void vtxCommonSetPowerByIndex(vtxDevice_t
*vtxDevice
, uint8_t index
);
143 void vtxCommonSetPitMode(vtxDevice_t
*vtxDevice
, uint8_t onoff
);
144 bool vtxCommonGetBandAndChannel(vtxDevice_t
*vtxDevice
, uint8_t *pBand
, uint8_t *pChannel
);
145 bool vtxCommonGetPowerIndex(vtxDevice_t
*vtxDevice
, uint8_t *pIndex
);
146 bool vtxCommonGetPitMode(vtxDevice_t
*vtxDevice
, uint8_t *pOnOff
);
147 bool vtxCommonGetFrequency(const vtxDevice_t
*vtxDevice
, uint16_t *pFreq
);
148 bool vtxCommonGetDeviceCapability(vtxDevice_t
*vtxDevice
, vtxDeviceCapability_t
*pDeviceCapability
);
149 bool vtxCommonGetPower(const vtxDevice_t
*vtxDevice
, uint8_t *pIndex
, uint16_t *pPowerMw
);
150 bool vtxCommonGetOsdInfo(vtxDevice_t
*vtxDevice
, vtxDeviceOsdInfo_t
* pOsdInfo
);