Merge pull request #11297 from SteveCEvans/baro_state
[betaflight.git] / src / main / drivers / vtx_common.h
blob1bd0aa7650b6aad657d3674a7afe0a0ef8b7417f
1 /*
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)
8 * any later version.
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 */
23 #pragma once
25 #include <stdint.h>
27 #include "platform.h"
28 #include "common/time.h"
29 #include "common/streambuf.h"
31 #define VTX_SETTINGS_MAX_FREQUENCY_MHZ 5999 //max freq (in MHz) for 'vtx_freq' setting
33 #if defined(USE_VTX_RTC6705)
35 #include "drivers/vtx_rtc6705.h"
37 #endif
39 #if defined(USE_VTX_SMARTAUDIO) || defined(USE_VTX_TRAMP)
41 #define VTX_SETTINGS_FREQCMD
43 #endif
45 // check value for MSP_SET_VTX_CONFIG to determine if value is encoded
46 // band/channel or frequency in MHz (3 bits for band and 3 bits for channel)
47 #define VTXCOMMON_MSP_BANDCHAN_CHKVAL ((uint16_t)((7 << 3) + 7))
49 typedef enum {
50 VTXDEV_UNSUPPORTED = 0, // reserved for MSP
51 VTXDEV_RTC6705 = 1,
52 // 2 reserved
53 VTXDEV_SMARTAUDIO = 3,
54 VTXDEV_TRAMP = 4,
55 VTXDEV_UNKNOWN = 0xFF,
56 } vtxDevType_e;
58 // VTX magic numbers used for spektrum vtx control
59 #define VTX_COMMON_BAND_USER 0
60 #define VTX_COMMON_BAND_A 1
61 #define VTX_COMMON_BAND_B 2
62 #define VTX_COMMON_BAND_E 3
63 #define VTX_COMMON_BAND_FS 4
64 #define VTX_COMMON_BAND_RACE 5
66 // RTC6705 RF Power index 25 or 200 mW
67 #define VTX_6705_POWER_25 1
68 #define VTX_6705_POWER_200 2
70 // SmartAudio "---", 25, 200, 500, 800 mW
71 #define VTX_SA_POWER_OFF 1 //1 goes to min power whereas 0 doesnt do anything (illegal index).
72 #define VTX_SA_POWER_25 1
73 #define VTX_SA_POWER_200 2
74 #define VTX_SA_POWER_500 3
75 #define VTX_SA_POWER_800 4
77 // Tramp "---", 25, 100, 200, 400, 600 mW
78 #define VTX_TRAMP_POWER_OFF 1 //same as with SmartAudio
79 #define VTX_TRAMP_POWER_25 1
80 #define VTX_TRAMP_POWER_100 2
81 #define VTX_TRAMP_POWER_200 3
82 #define VTX_TRAMP_POWER_400 4
83 #define VTX_TRAMP_POWER_600 5
85 // VTX status flags
86 enum {
87 VTX_STATUS_PIT_MODE = 1 << 0,
88 VTX_STATUS_LOCKED = 1 << 1,
91 struct vtxVTable_s;
92 typedef struct vtxDevice_s {
93 const struct vtxVTable_s *const vTable;
94 } vtxDevice_t;
97 // {set,get}BandAndChannel: band and channel are 1 origin
98 // {set,get}PowerByIndex: 0 = Power OFF, 1 = device dependent
99 // {set,get}PitMode: 0 = OFF, 1 = ON
101 typedef struct vtxVTable_s {
102 void (*process)(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs);
103 vtxDevType_e (*getDeviceType)(const vtxDevice_t *vtxDevice);
104 bool (*isReady)(const vtxDevice_t *vtxDevice);
106 void (*setBandAndChannel)(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel);
107 void (*setPowerByIndex)(vtxDevice_t *vtxDevice, uint8_t level);
108 void (*setPitMode)(vtxDevice_t *vtxDevice, uint8_t onoff);
109 void (*setFrequency)(vtxDevice_t *vtxDevice, uint16_t freq);
111 bool (*getBandAndChannel)(const vtxDevice_t *vtxDevice, uint8_t *pBand, uint8_t *pChannel);
112 bool (*getPowerIndex)(const vtxDevice_t *vtxDevice, uint8_t *pIndex);
113 bool (*getFrequency)(const vtxDevice_t *vtxDevice, uint16_t *pFreq);
114 bool (*getStatus)(const vtxDevice_t *vtxDevice, unsigned *status);
115 uint8_t (*getPowerLevels)(const vtxDevice_t *vtxDevice, uint16_t *levels, uint16_t *powers);
117 void (*serializeCustomDeviceStatus)(const vtxDevice_t *vtxDevice, sbuf_t *dst);
118 } vtxVTable_t;
120 // 3.1.0
121 // PIT mode is defined as LOWEST POSSIBLE RF POWER.
122 // - It can be a dedicated mode, or lowest RF power possible.
123 // - It is *NOT* RF on/off control ?
125 void vtxCommonInit(void);
126 void vtxCommonSetDevice(vtxDevice_t *vtxDevice);
127 vtxDevice_t *vtxCommonDevice(void);
129 // VTable functions
130 void vtxCommonProcess(vtxDevice_t *vtxDevice, timeUs_t currentTimeUs);
131 vtxDevType_e vtxCommonGetDeviceType(const vtxDevice_t *vtxDevice);
132 bool vtxCommonDeviceIsReady(const vtxDevice_t *vtxDevice);
134 void vtxCommonSetBandAndChannel(vtxDevice_t *vtxDevice, uint8_t band, uint8_t channel);
135 void vtxCommonSetPowerByIndex(vtxDevice_t *vtxDevice, uint8_t level);
136 void vtxCommonSetPitMode(vtxDevice_t *vtxDevice, uint8_t onoff);
137 void vtxCommonSetFrequency(vtxDevice_t *vtxDevice, uint16_t freq);
139 bool vtxCommonGetBandAndChannel(const vtxDevice_t *vtxDevice, uint8_t *pBand, uint8_t *pChannel);
140 bool vtxCommonGetPowerIndex(const vtxDevice_t *vtxDevice, uint8_t *pIndex);
141 bool vtxCommonGetFrequency(const vtxDevice_t *vtxDevice, uint16_t *pFreq);
142 bool vtxCommonGetStatus(const vtxDevice_t *vtxDevice, unsigned *status);
143 uint8_t vtxCommonGetVTXPowerLevels(const vtxDevice_t *vtxDevice, uint16_t *levels, uint16_t *powers);
144 // end of VTable functions
146 const char *vtxCommonLookupBandName(const vtxDevice_t *vtxDevice, int band);
147 char vtxCommonLookupBandLetter(const vtxDevice_t *vtxDevice, int band);
148 char vtxCommonGetBandLetter(const vtxDevice_t *vtxDevice, int band);
149 const char *vtxCommonLookupChannelName(const vtxDevice_t *vtxDevice, int channel);
150 uint16_t vtxCommonLookupFrequency(const vtxDevice_t *vtxDevice, int band, int channel);
151 void vtxCommonLookupBandChan(const vtxDevice_t *vtxDevice, uint16_t freq, uint8_t *pBand, uint8_t *pChannel);
152 const char *vtxCommonLookupPowerName(const vtxDevice_t *vtxDevice, int index);
153 bool vtxCommonLookupPowerValue(const vtxDevice_t *vtxDevice, int index, uint16_t *pPowerValue);
154 void vtxCommonSerializeDeviceStatus(const vtxDevice_t *vtxDevice, sbuf_t *dst);