1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-23 00:05:33 +03:00
betaflight/src/main/drivers/vtx_common.c
Hydra 723831b579 SPRACINGF3NEO - Use RTC6705 clk hack.
CF/BF - Fix typo in max7456DmaInProgress.  Always define an
implementation even when there is no TX-DMA.

CF/BF - Ensure that max7456 communication does not disrupt RTC6705
communication when using the same SPI port for both.

CF/BF - Port RTC6705 to use the VTX API.

* Support VTX channel/band/power on OSD for ALL vtx APIs - previously it only supported RTC6705.
* Remove all FEATURE_VTX usage.
* Remove all `#define VTX` usage.

Note that due to the async nature of tramp/smartaudio it's not possible
to know the current band/channel after requesting a change (as the
request hasn't been processed) so it makes no sense to try and save the
config - and on the tramp/smartaudio vtx the vtx maintains it's state.
So on an RTX6705 equipped FC the user should now MANUALLY save the
config using the save config stick position.

CF/BF - Move CMS for RTC6705 into vtx_rtc6705.c for consistency with
other VTX CMS menus.

CF/BF - Update RTC6705 via SOFT SPI to use VTX API.

* Achieved by simply aligning the API at the driver level and removing
all legacy conditional compilation checks.

CF/BF - Use new IO for RTC6705 CLK Hack

CF/BF - Port VTX button from CF v1.x.

Features:
* Channel Cycle
* Band Cycle
* Power Cycle
* Save Settings
* Works with any VTX using VTX API.

CF/BF - Allow support for Internal and External VTX - External takes
precedence when configured.

CF/BF - Fix display of VTX power in CMS.

* Issue occured when CMS was transitioned from integer to list of
strings.

CF/BF - Disable SMARTAUDIO and TRAMP on the SPRacingF3NEO due to flash
size.

CF/BF - Cleanup const usage of bass-by-value parameters.  Cleanup
naming.

CF/BF - Cleanup naming.  Removing noise-words. Improving consistency.

CF/BF - Improve readability by further naming cleanups.

CF/BF - Remove some magic numbers in the RTC6705 VTX code.

CF/BF - Use braces on some procedural macros.

CF/BF - Improve code readability by renaming rtc6705SetChannel to
rtc6705SetBandAndChannel.

CF/BF - Remove editor mishap.

CF/BF - Make the rtc6705Dev variable static.

CF/BF - remove duplicate state variablertc6705Dev_t - vtxDevice_t had
all we needed.  Use brackets on some procedural style macros.  Make all
the vtx vtable static const.

CF/BF - making some declarations const.

CF/BF - Fix vtx_power maximum value (out by one).
2017-04-21 11:49:31 +12:00

139 lines
3.1 KiB
C

/*
* This file is part of Cleanflight.
*
* Cleanflight is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Cleanflight is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
*/
/* Created by jflyper */
#include <stdbool.h>
#include <stdint.h>
#include <ctype.h>
#include <string.h>
#include "platform.h"
#include "build/debug.h"
#if defined(VTX_COMMON)
#include "vtx_common.h"
vtxDevice_t *vtxDevice = NULL;
void vtxCommonInit(void)
{
}
// Whatever registered last will win
void vtxCommonRegisterDevice(vtxDevice_t *pDevice)
{
vtxDevice = pDevice;
}
void vtxCommonProcess(uint32_t currentTimeUs)
{
if (!vtxDevice)
return;
if (vtxDevice->vTable->process)
vtxDevice->vTable->process(currentTimeUs);
}
vtxDevType_e vtxCommonGetDeviceType(void)
{
if (!vtxDevice || !vtxDevice->vTable->getDeviceType)
return VTXDEV_UNKNOWN;
return vtxDevice->vTable->getDeviceType();
}
// band and channel are 1 origin
void vtxCommonSetBandAndChannel(uint8_t band, uint8_t channel)
{
if (!vtxDevice)
return;
if ((band > vtxDevice->capability.bandCount) || (channel > vtxDevice->capability.channelCount))
return;
if (vtxDevice->vTable->setBandAndChannel)
vtxDevice->vTable->setBandAndChannel(band, channel);
}
// index is zero origin, zero = power off completely
void vtxCommonSetPowerByIndex(uint8_t index)
{
if (!vtxDevice)
return;
if (index > vtxDevice->capability.powerCount)
return;
if (vtxDevice->vTable->setPowerByIndex)
vtxDevice->vTable->setPowerByIndex(index);
}
// on = 1, off = 0
void vtxCommonSetPitMode(uint8_t onoff)
{
if (!vtxDevice)
return;
if (vtxDevice->vTable->setPitMode)
vtxDevice->vTable->setPitMode(onoff);
}
bool vtxCommonGetBandAndChannel(uint8_t *pBand, uint8_t *pChannel)
{
if (!vtxDevice)
return false;
if (vtxDevice->vTable->getBandAndChannel)
return vtxDevice->vTable->getBandAndChannel(pBand, pChannel);
else
return false;
}
bool vtxCommonGetPowerIndex(uint8_t *pIndex)
{
if (!vtxDevice)
return false;
if (vtxDevice->vTable->getPowerIndex)
return vtxDevice->vTable->getPowerIndex(pIndex);
else
return false;
}
bool vtxCommonGetPitMode(uint8_t *pOnOff)
{
if (!vtxDevice)
return false;
if (vtxDevice->vTable->getPitMode)
return vtxDevice->vTable->getPitMode(pOnOff);
else
return false;
}
bool vtxCommonGetDeviceCapability(vtxDeviceCapability_t *pDeviceCapability)
{
if (!vtxDevice)
return false;
memcpy(pDeviceCapability, &vtxDevice->capability, sizeof(vtxDeviceCapability_t));
return true;
}
#endif