New SPI API supporting DMA
[betaflight.git] / src / main / cms / cms_menu_vtx_rtc6705.c
blobe45892f16522fae61f6a066b39ea67a260e86c5e
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 #include <stdbool.h>
22 #include <stdint.h>
23 #include <ctype.h>
24 #include <drivers/vtx_table.h>
26 #include "platform.h"
28 #if defined(USE_CMS) && defined(USE_VTX_RTC6705)
30 #include "common/printf.h"
31 #include "common/utils.h"
33 #include "cms/cms.h"
34 #include "cms/cms_types.h"
36 #include "drivers/vtx_common.h"
38 #include "config/config.h"
40 #include "io/vtx_rtc6705.h"
41 #include "io/vtx.h"
43 static uint8_t cmsx_vtxBand;
44 static uint8_t cmsx_vtxChannel;
45 static uint8_t cmsx_vtxPower;
46 static uint8_t cmsx_vtxPit;
48 static OSD_TAB_t entryVtxBand;
49 static OSD_TAB_t entryVtxChannel;
50 static OSD_TAB_t entryVtxPower;
51 static const char * const cmsxCmsPitNames[] = {
52 "---",
53 "OFF",
54 "ON ",
56 static OSD_TAB_t entryVtxPit = {&cmsx_vtxPit, 2, cmsxCmsPitNames};
58 static void cmsx_Vtx_ConfigRead(void)
60 vtxCommonGetBandAndChannel(vtxCommonDevice(), &cmsx_vtxBand, &cmsx_vtxChannel);
61 vtxCommonGetPowerIndex(vtxCommonDevice(), &cmsx_vtxPower);
62 unsigned status;
63 if (vtxCommonGetStatus(vtxCommonDevice(), &status)) {
64 cmsx_vtxPit = status & VTX_STATUS_PIT_MODE ? 2 : 1;
65 } else {
66 cmsx_vtxPit = 0;
70 static void cmsx_Vtx_ConfigWriteback(void)
72 // update vtx_ settings
73 vtxSettingsConfigMutable()->band = cmsx_vtxBand;
74 vtxSettingsConfigMutable()->channel = cmsx_vtxChannel;
75 vtxSettingsConfigMutable()->power = cmsx_vtxPower;
76 vtxSettingsConfigMutable()->freq = vtxCommonLookupFrequency(vtxCommonDevice(), cmsx_vtxBand, cmsx_vtxChannel);
78 saveConfigAndNotify();
81 static const void *cmsx_Vtx_onEnter(displayPort_t *pDisp)
83 UNUSED(pDisp);
85 cmsx_Vtx_ConfigRead();
87 entryVtxBand.val = &cmsx_vtxBand;
88 entryVtxBand.max = vtxTableBandCount;
89 entryVtxBand.names = vtxTableBandNames;
91 entryVtxChannel.val = &cmsx_vtxChannel;
92 entryVtxChannel.max = vtxTableChannelCount;
93 entryVtxChannel.names = vtxTableChannelNames;
95 entryVtxPower.val = &cmsx_vtxPower;
96 entryVtxPower.max = vtxTablePowerLevels;
97 entryVtxPower.names = vtxTablePowerLabels;
99 return NULL;
102 static const void *cmsx_Vtx_onExit(displayPort_t *pDisp, const OSD_Entry *self)
104 UNUSED(pDisp);
105 UNUSED(self);
107 vtxCommonSetPitMode(vtxCommonDevice(), cmsx_vtxPit);
108 cmsx_Vtx_ConfigWriteback();
110 return NULL;
113 static const void *cmsx_Vtx_onBandChange(displayPort_t *pDisp, const void *self)
115 UNUSED(pDisp);
116 UNUSED(self);
117 if (cmsx_vtxBand == 0) {
118 cmsx_vtxBand = 1;
120 return NULL;
123 static const void *cmsx_Vtx_onChanChange(displayPort_t *pDisp, const void *self)
125 UNUSED(pDisp);
126 UNUSED(self);
127 if (cmsx_vtxChannel == 0) {
128 cmsx_vtxChannel = 1;
130 return NULL;
133 static const void *cmsx_Vtx_onPowerChange(displayPort_t *pDisp, const void *self)
135 UNUSED(pDisp);
136 UNUSED(self);
137 if (cmsx_vtxPower == 0) {
138 cmsx_vtxPower = 1;
140 return NULL;
143 static const void *cmsx_Vtx_onPitChange(displayPort_t *pDisp, const void *self)
145 UNUSED(pDisp);
146 UNUSED(self);
147 if (cmsx_vtxPit == 0) {
148 cmsx_vtxPit = 1;
150 return NULL;
153 static const OSD_Entry cmsx_menuVtxEntries[] = {
154 {"--- VTX ---", OME_Label, NULL, NULL, 0},
155 {"BAND", OME_TAB, cmsx_Vtx_onBandChange, &entryVtxBand, 0},
156 {"CHANNEL", OME_TAB, cmsx_Vtx_onChanChange, &entryVtxChannel, 0},
157 {"POWER", OME_TAB, cmsx_Vtx_onPowerChange, &entryVtxPower, 0},
158 {"PIT", OME_TAB, cmsx_Vtx_onPitChange, &entryVtxPit, 0},
159 {"BACK", OME_Back, NULL, NULL, 0},
160 {NULL, OME_END, NULL, NULL, 0}
163 CMS_Menu cmsx_menuVtxRTC6705 = {
164 #ifdef CMS_MENU_DEBUG
165 .GUARD_text = "MENUVTX",
166 .GUARD_type = OME_MENU,
167 #endif
168 .onEnter = cmsx_Vtx_onEnter,
169 .onExit = cmsx_Vtx_onExit,
170 .onDisplayUpdate = NULL,
171 .entries = cmsx_menuVtxEntries
174 #endif // CMS