kopia lustrzana https://github.com/OpenRTX/OpenRTX
Fixed wrong bitmask in AT1846S::setRxAudioGain. Moved getBandFromFrequency function to a dedicated file, in common for all dual-band radio drivers.
rodzic
e7b48b14a5
commit
87d9b733e6
|
@ -215,8 +215,8 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void setRxAudioGain(const uint8_t gainWb, const uint8_t gainNb)
|
inline void setRxAudioGain(const uint8_t gainWb, const uint8_t gainNb)
|
||||||
{
|
{
|
||||||
uint16_t value = (gainWb & 0x0F) << 8;
|
uint16_t value = (gainWb & 0x0F) << 4;
|
||||||
maskSetRegister(0x44, 0x0F00, value);
|
maskSetRegister(0x44, 0x00F0, value);
|
||||||
maskSetRegister(0x44, 0x000F, ((uint16_t) gainNb));
|
maskSetRegister(0x44, 0x000F, ((uint16_t) gainNb));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -227,7 +227,7 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void setNoise1Thresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
inline void setNoise1Thresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
||||||
{
|
{
|
||||||
uint16_t value = ((highTsh & 0x1f) << 8) | (lowTsh & 0x1F);
|
uint16_t value = ((highTsh & 0x1F) << 8) | (lowTsh & 0x1F);
|
||||||
i2c_writeReg16(0x48, value);
|
i2c_writeReg16(0x48, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -238,7 +238,7 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void setNoise2Thresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
inline void setNoise2Thresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
||||||
{
|
{
|
||||||
uint16_t value = ((highTsh & 0x1f) << 8) | (lowTsh & 0x1F);
|
uint16_t value = ((highTsh & 0x1F) << 8) | (lowTsh & 0x1F);
|
||||||
i2c_writeReg16(0x60, value);
|
i2c_writeReg16(0x60, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -249,7 +249,7 @@ public:
|
||||||
*/
|
*/
|
||||||
inline void setRssiThresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
inline void setRssiThresholds(const uint8_t highTsh, const uint8_t lowTsh)
|
||||||
{
|
{
|
||||||
uint16_t value = ((highTsh & 0x1f) << 8) | (lowTsh & 0x1F);
|
uint16_t value = ((highTsh & 0x1F) << 8) | (lowTsh & 0x1F);
|
||||||
i2c_writeReg16(0x3F, value);
|
i2c_writeReg16(0x3F, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
/***************************************************************************
|
||||||
|
* Copyright (C) 2021 by Federico Amedeo Izzo IU2NUO, *
|
||||||
|
* Niccolò Izzo IU2KIN *
|
||||||
|
* Frederik Saraci IU2NRO *
|
||||||
|
* Silvano Seva IU2KWO *
|
||||||
|
* *
|
||||||
|
* This program 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. *
|
||||||
|
* *
|
||||||
|
* This program 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 this program; if not, see <http://www.gnu.org/licenses/> *
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
#ifndef RADIO_UTILS_H
|
||||||
|
#define RADIO_UTILS_H
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <datatypes.h>
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
static const freq_t BAND_VHF_LO = 136000000;
|
||||||
|
static const freq_t BAND_VHF_HI = 174000000;
|
||||||
|
static const freq_t BAND_UHF_LO = 400000000;
|
||||||
|
static const freq_t BAND_UHF_HI = 470000000;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Enumeration type for bandwidth identification.
|
||||||
|
*/
|
||||||
|
enum Band
|
||||||
|
{
|
||||||
|
BND_NONE = -1,
|
||||||
|
BND_VHF = 0,
|
||||||
|
BND_UHF = 1
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \internal
|
||||||
|
* Function to identify the current band (VHF or UHF), given an input frequency.
|
||||||
|
*
|
||||||
|
* @param freq frequency in Hz.
|
||||||
|
* @return a value from @enum Band identifying the band to which the frequency
|
||||||
|
* belong.
|
||||||
|
*/
|
||||||
|
inline Band getBandFromFrequency(const freq_t freq)
|
||||||
|
{
|
||||||
|
if((freq >= BAND_VHF_LO) && (freq <= BAND_VHF_HI)) return BND_VHF;
|
||||||
|
if((freq >= BAND_UHF_LO) && (freq <= BAND_UHF_HI)) return BND_UHF;
|
||||||
|
return BND_NONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#endif /* RADIO_UTILS_H */
|
|
@ -25,14 +25,16 @@
|
||||||
#include <calibUtils.h>
|
#include <calibUtils.h>
|
||||||
#include <hwconfig.h>
|
#include <hwconfig.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include "radioUtils.h"
|
||||||
#include "HR_C6000.h"
|
#include "HR_C6000.h"
|
||||||
#include "AT1846S.h"
|
#include "AT1846S.h"
|
||||||
|
|
||||||
|
|
||||||
const mduv3x0Calib_t *calData; // Pointer to calibration data
|
const mduv3x0Calib_t *calData; // Pointer to calibration data
|
||||||
const rtxStatus_t *config; // Pointer to data structure with radio configuration
|
const rtxStatus_t *config; // Pointer to data structure with radio configuration
|
||||||
|
|
||||||
int8_t currRxBand = -1; // Current band for RX
|
Band currRxBand = BND_NONE; // Current band for RX
|
||||||
int8_t currTxBand = -1; // Current band for TX
|
Band currTxBand = BND_NONE; // Current band for TX
|
||||||
uint8_t txpwr_lo = 0; // APC voltage for TX output power control, low power
|
uint8_t txpwr_lo = 0; // APC voltage for TX output power control, low power
|
||||||
uint8_t txpwr_hi = 0; // APC voltage for TX output power control, high power
|
uint8_t txpwr_hi = 0; // APC voltage for TX output power control, high power
|
||||||
uint8_t rxModBias = 0; // VCXO bias for RX
|
uint8_t rxModBias = 0; // VCXO bias for RX
|
||||||
|
@ -43,22 +45,6 @@ enum opstatus radioStatus; // Current operating status
|
||||||
HR_C6000& C6000 = HR_C6000::instance(); // HR_C5000 driver
|
HR_C6000& C6000 = HR_C6000::instance(); // HR_C5000 driver
|
||||||
AT1846S& at1846s = AT1846S::instance(); // AT1846S driver
|
AT1846S& at1846s = AT1846S::instance(); // AT1846S driver
|
||||||
|
|
||||||
/**
|
|
||||||
* \internal
|
|
||||||
* Function to identify the current band (VHF or UHF), given an input frequency.
|
|
||||||
*
|
|
||||||
* @param freq frequency in Hz.
|
|
||||||
* @return 0 if the frequency is in the VHF band,
|
|
||||||
* 1 if the frequency is in the UHF band,
|
|
||||||
* -1 if the band to which the frequency belongs is neither VHF nor UHF.
|
|
||||||
*/
|
|
||||||
int8_t _getBandFromFrequency(freq_t freq)
|
|
||||||
{
|
|
||||||
if((freq >= FREQ_LIMIT_VHF_LO) && (freq <= FREQ_LIMIT_VHF_HI)) return 0;
|
|
||||||
if((freq >= FREQ_LIMIT_UHF_LO) && (freq <= FREQ_LIMIT_UHF_HI)) return 1;
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
void radio_init(const rtxStatus_t *rtxState)
|
void radio_init(const rtxStatus_t *rtxState)
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
|
@ -150,13 +136,13 @@ void radio_enableRx()
|
||||||
gpio_clearPin(UHF_LNA_EN);
|
gpio_clearPin(UHF_LNA_EN);
|
||||||
DAC->DHR12R1 = 0;
|
DAC->DHR12R1 = 0;
|
||||||
|
|
||||||
if(currRxBand < 0) return;
|
if(currRxBand == BND_NONE) return;
|
||||||
|
|
||||||
C6000.setModOffset(rxModBias);
|
C6000.setModOffset(rxModBias);
|
||||||
at1846s.setFrequency(config->rxFrequency);
|
at1846s.setFrequency(config->rxFrequency);
|
||||||
at1846s.setFuncMode(AT1846S_FuncMode::RX);
|
at1846s.setFuncMode(AT1846S_FuncMode::RX);
|
||||||
|
|
||||||
if(currRxBand == 0)
|
if(currRxBand == BND_VHF)
|
||||||
{
|
{
|
||||||
gpio_setPin(VHF_LNA_EN);
|
gpio_setPin(VHF_LNA_EN);
|
||||||
}
|
}
|
||||||
|
@ -209,7 +195,7 @@ void radio_enableTx()
|
||||||
|
|
||||||
gpio_setPin(PA_EN_1);
|
gpio_setPin(PA_EN_1);
|
||||||
|
|
||||||
if(currTxBand == 0)
|
if(currTxBand == BND_VHF)
|
||||||
{
|
{
|
||||||
gpio_clearPin(PA_SEL_SW);
|
gpio_clearPin(PA_SEL_SW);
|
||||||
}
|
}
|
||||||
|
@ -249,10 +235,10 @@ void radio_disableRtx()
|
||||||
|
|
||||||
void radio_updateConfiguration()
|
void radio_updateConfiguration()
|
||||||
{
|
{
|
||||||
currRxBand = _getBandFromFrequency(config->rxFrequency);
|
currRxBand = getBandFromFrequency(config->rxFrequency);
|
||||||
currTxBand = _getBandFromFrequency(config->txFrequency);
|
currTxBand = getBandFromFrequency(config->txFrequency);
|
||||||
|
|
||||||
if((currRxBand < 0) || (currTxBand < 0)) return;
|
if((currRxBand == BND_NONE) || (currTxBand == BND_NONE)) return;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* VCXO bias voltage, separated values for TX and RX to allow for cross-band
|
* VCXO bias voltage, separated values for TX and RX to allow for cross-band
|
||||||
|
@ -260,8 +246,8 @@ void radio_updateConfiguration()
|
||||||
*/
|
*/
|
||||||
txModBias = calData->vhfCal.freqAdjustMid;
|
txModBias = calData->vhfCal.freqAdjustMid;
|
||||||
rxModBias = calData->vhfCal.freqAdjustMid;
|
rxModBias = calData->vhfCal.freqAdjustMid;
|
||||||
if(currRxBand > 0) rxModBias = calData->uhfCal.freqAdjustMid;
|
if(currRxBand == BND_UHF) rxModBias = calData->uhfCal.freqAdjustMid;
|
||||||
if(currTxBand > 0) txModBias = calData->uhfCal.freqAdjustMid;
|
if(currTxBand == BND_UHF) txModBias = calData->uhfCal.freqAdjustMid;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Discarding "const" qualifier to suppress compiler warnings.
|
* Discarding "const" qualifier to suppress compiler warnings.
|
||||||
|
@ -274,7 +260,7 @@ void radio_updateConfiguration()
|
||||||
uint8_t *hiPwrCal = cal->vhfCal.txHighPower;
|
uint8_t *hiPwrCal = cal->vhfCal.txHighPower;
|
||||||
uint8_t *qRangeCal = (config->opMode == FM) ? cal->vhfCal.analogSendQrange
|
uint8_t *qRangeCal = (config->opMode == FM) ? cal->vhfCal.analogSendQrange
|
||||||
: cal->vhfCal.sendQrange;
|
: cal->vhfCal.sendQrange;
|
||||||
if(currTxBand > 0)
|
if(currTxBand == BND_UHF)
|
||||||
{
|
{
|
||||||
calPoints = 9;
|
calPoints = 9;
|
||||||
txCalPoints = cal->uhfCal.txFreq;
|
txCalPoints = cal->uhfCal.txFreq;
|
||||||
|
|
Ładowanie…
Reference in New Issue