mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-23 08:15:30 +03:00
VTX abstraction (experimental)
This commit is contained in:
parent
2d6b718896
commit
cdd0cd4528
9 changed files with 573 additions and 24 deletions
140
src/main/drivers/vtx_common.c
Normal file
140
src/main/drivers/vtx_common.c
Normal file
|
@ -0,0 +1,140 @@
|
|||
/*
|
||||
* 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"
|
||||
#include "vtx_var.h"
|
||||
|
||||
vtxDevice_t *vtxDevice = NULL;
|
||||
|
||||
void vtxCommonInit(void)
|
||||
{
|
||||
}
|
||||
|
||||
// Whatever registered last will win
|
||||
|
||||
void vtxCommonRegisterDevice(vtxDevice_t *pDevice)
|
||||
{
|
||||
vtxDevice = pDevice;
|
||||
}
|
||||
|
||||
vtxDevType_e vtxCommonGetDeviceType(void)
|
||||
{
|
||||
if (!vtxDevice)
|
||||
return VTXDEV_UNKNOWN;
|
||||
|
||||
return vtxDevice->devtype;
|
||||
}
|
||||
|
||||
// band and chan are 1 origin
|
||||
void vtxCommonSetBandChan(uint8_t band, uint8_t chan)
|
||||
{
|
||||
if (!vtxDevice)
|
||||
return;
|
||||
|
||||
if (vtxDevice->vTable->setBandChan)
|
||||
vtxDevice->vTable->setBandChan(band, chan);
|
||||
}
|
||||
|
||||
// index is zero origin, zero = power off completely
|
||||
void vtxCommonSetPowerByIndex(uint8_t index)
|
||||
{
|
||||
if (!vtxDevice)
|
||||
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 vtxCommonGetBandChan(uint8_t *pBand, uint8_t *pChan)
|
||||
{
|
||||
if (!vtxDevice)
|
||||
return false;
|
||||
|
||||
if (vtxDevice->vTable->getBandChan)
|
||||
return vtxDevice->vTable->getBandChan(pBand, pChan);
|
||||
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;
|
||||
}
|
||||
|
||||
// Utilities
|
||||
|
||||
bool vtx58_Freq2Bandchan(uint16_t freq, uint8_t *pBand, uint8_t *pChan)
|
||||
{
|
||||
uint8_t band;
|
||||
uint8_t chan;
|
||||
|
||||
for (band = 0 ; band < 5 ; band++) {
|
||||
for (chan = 0 ; chan < 8 ; chan++) {
|
||||
if (vtx58FreqTable[band][chan] == freq) {
|
||||
*pBand = band + 1;
|
||||
*pChan = chan + 1;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*pBand = 0;
|
||||
*pChan = 0;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue