forked from mirror/uv-k5-firmware
Several cleanups.
This commit is contained in:
parent
bc10f1ed6b
commit
2e813a4460
@ -120,7 +120,7 @@ void ACTION_Scan(bool bRestart)
|
||||
FUN_0000773c();
|
||||
gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
|
||||
} else {
|
||||
APP_SetStepDirection(true, 1);
|
||||
CHANNEL_Next(true, 1);
|
||||
AUDIO_SetVoiceID(0, VOICE_ID_SCANNING_BEGIN);
|
||||
AUDIO_PlaySingleVoice(true);
|
||||
}
|
||||
|
20
app/app.c
20
app/app.c
@ -395,7 +395,7 @@ void APP_SetFrequencyByStep(VFO_Info_t *pInfo, int8_t Step)
|
||||
}
|
||||
}
|
||||
|
||||
void APP_MoreRadioStuff(void)
|
||||
static void FREQ_NextChannel(void)
|
||||
{
|
||||
APP_SetFrequencyByStep(gRxVfo, gScanState);
|
||||
RADIO_ApplyOffset(gRxVfo);
|
||||
@ -406,7 +406,7 @@ void APP_MoreRadioStuff(void)
|
||||
g_20000413 = false;
|
||||
}
|
||||
|
||||
void FUN_00007dd4(void)
|
||||
static void MR_NextChannel(void)
|
||||
{
|
||||
uint8_t Ch1 = gEeprom.SCANLIST_PRIORITY_CH1[gEeprom.SCAN_LIST_DEFAULT];
|
||||
uint8_t Ch2 = gEeprom.SCANLIST_PRIORITY_CH2[gEeprom.SCAN_LIST_DEFAULT];
|
||||
@ -574,7 +574,7 @@ void APP_CheckRadioInterrupts(void)
|
||||
}
|
||||
}
|
||||
|
||||
void TalkRelatedCode(void)
|
||||
void APP_EndTransmission(void)
|
||||
{
|
||||
RADIO_SendEndOfTransmission();
|
||||
RADIO_EnableCxCSS();
|
||||
@ -603,7 +603,7 @@ static void FUN_00008334(void)
|
||||
if (gFlagEndTransmission) {
|
||||
FUNCTION_Select(FUNCTION_0);
|
||||
} else {
|
||||
TalkRelatedCode();
|
||||
APP_EndTransmission();
|
||||
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) {
|
||||
FUNCTION_Select(FUNCTION_0);
|
||||
} else {
|
||||
@ -639,7 +639,7 @@ void APP_Update(void)
|
||||
if (gCurrentFunction == FUNCTION_TRANSMIT && gTxTimeoutReached) {
|
||||
gTxTimeoutReached = false;
|
||||
gFlagEndTransmission = true;
|
||||
TalkRelatedCode();
|
||||
APP_EndTransmission();
|
||||
AUDIO_PlayBeep(BEEP_500HZ_60MS_DOUBLE_BEEP);
|
||||
RADIO_SetVfoState(VFO_STATE_TIMEOUT);
|
||||
GUI_DisplayScreen();
|
||||
@ -660,13 +660,13 @@ void APP_Update(void)
|
||||
if (gCurrentFunction == FUNCTION_3) {
|
||||
APP_StartListening(FUNCTION_RECEIVE);
|
||||
} else {
|
||||
APP_MoreRadioStuff();
|
||||
FREQ_NextChannel();
|
||||
}
|
||||
} else {
|
||||
if (gCopyOfCodeType == CODE_TYPE_OFF && gCurrentFunction == FUNCTION_3) {
|
||||
APP_StartListening(FUNCTION_RECEIVE);
|
||||
} else {
|
||||
FUN_00007dd4();
|
||||
MR_NextChannel();
|
||||
}
|
||||
}
|
||||
gScanPauseMode = false;
|
||||
@ -1267,7 +1267,7 @@ void FUN_000075b0(void)
|
||||
gScanProgressIndicator = 0;
|
||||
}
|
||||
|
||||
void APP_SetStepDirection(bool bFlag, int8_t Direction)
|
||||
void CHANNEL_Next(bool bFlag, int8_t Direction)
|
||||
{
|
||||
RADIO_SelectVfos();
|
||||
gNextMrChannel = gRxVfo->CHANNEL_SAVE;
|
||||
@ -1277,12 +1277,12 @@ void APP_SetStepDirection(bool bFlag, int8_t Direction)
|
||||
if (bFlag) {
|
||||
gRestoreMrChannel = gNextMrChannel;
|
||||
}
|
||||
FUN_00007dd4();
|
||||
MR_NextChannel();
|
||||
} else {
|
||||
if (bFlag) {
|
||||
gRestoreFrequency = gRxVfo->ConfigRX.Frequency;
|
||||
}
|
||||
APP_MoreRadioStuff();
|
||||
FREQ_NextChannel();
|
||||
}
|
||||
ScanPauseDelayIn10msec = 50;
|
||||
gScheduleScanListen = false;
|
||||
|
@ -21,7 +21,8 @@
|
||||
#include "functions.h"
|
||||
|
||||
void FUN_0000773c(void);
|
||||
void APP_SetStepDirection(bool bFlag, int8_t Direction);
|
||||
void APP_EndTransmission(void);
|
||||
void CHANNEL_Next(bool bFlag, int8_t Direction);
|
||||
void APP_StartListening(FUNCTION_Type_t Function);
|
||||
|
||||
void APP_Update(void);
|
||||
|
64
app/fm.c
64
app/fm.c
@ -153,41 +153,43 @@ void FM_PlayAndUpdate(void)
|
||||
|
||||
int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
|
||||
{
|
||||
uint16_t SNR;
|
||||
int16_t Deviation;
|
||||
uint16_t RSSI;
|
||||
uint16_t Test2;
|
||||
uint16_t Deviation;
|
||||
int ret = -1;
|
||||
|
||||
SNR = BK1080_ReadRegister(BK1080_REG_07);
|
||||
// This cast fails to extend the sign because ReadReg is guaranteed to be U16.
|
||||
Deviation = (int16_t)SNR >> 4;
|
||||
if ((SNR & 0xF) < 2) {
|
||||
goto Bail;
|
||||
}
|
||||
Test2 = BK1080_ReadRegister(BK1080_REG_07);
|
||||
// This is supposed to be a signed value, but above function is unsigned
|
||||
Deviation = BK1080_REG_07_GET_FREQD(Test2);
|
||||
|
||||
RSSI = BK1080_ReadRegister(BK1080_REG_10);
|
||||
if (RSSI & 0x1000 || (RSSI & 0xFF) < 10) {
|
||||
goto Bail;
|
||||
}
|
||||
if (BK1080_REG_07_GET_SNR(Test2) >= 2) {
|
||||
uint16_t Status;
|
||||
|
||||
if (Deviation < 280 || Deviation > 3815) {
|
||||
if ((LowerLimit < Frequency) && (Frequency - BK1080_BaseFrequency) == 1) {
|
||||
if (BK1080_FrequencyDeviation & 0x800) {
|
||||
goto Bail;
|
||||
}
|
||||
if (BK1080_FrequencyDeviation < 20) {
|
||||
goto Bail;
|
||||
Status = BK1080_ReadRegister(BK1080_REG_10);
|
||||
if ((Status & BK1080_REG_10_MASK_AFCRL) == BK1080_REG_10_AFCRL_NOT_RAILED && BK1080_REG_10_GET_RSSI(Status) >= 10) {
|
||||
// if (Deviation > -281 && Deviation < 280)
|
||||
if (Deviation < 280 || Deviation > 3815) {
|
||||
// not BLE(less than or equal)
|
||||
if (Frequency > LowerLimit && (Frequency - BK1080_BaseFrequency) == 1) {
|
||||
if (BK1080_FrequencyDeviation & 0x800) {
|
||||
goto Bail;
|
||||
}
|
||||
if (BK1080_FrequencyDeviation < 20) {
|
||||
goto Bail;
|
||||
}
|
||||
}
|
||||
// not BLT(less than)
|
||||
if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1) {
|
||||
if ((BK1080_FrequencyDeviation & 0x800) == 0) {
|
||||
goto Bail;
|
||||
}
|
||||
// if (BK1080_FrequencyDeviation > -21) {
|
||||
if (BK1080_FrequencyDeviation > 4075) {
|
||||
goto Bail;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
}
|
||||
if ((LowerLimit <= Frequency) && (BK1080_BaseFrequency - Frequency) == 1) {
|
||||
if ((BK1080_FrequencyDeviation & 0x800) == 0) {
|
||||
goto Bail;
|
||||
}
|
||||
if (4075 < BK1080_FrequencyDeviation) {
|
||||
goto Bail;
|
||||
}
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
|
||||
Bail:
|
||||
@ -292,9 +294,9 @@ static void FM_Key_DIGITS(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
|
||||
if (!FM_ConfigureChannelState()) {
|
||||
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
|
||||
gRequestSaveFM = true;
|
||||
return;
|
||||
} else {
|
||||
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
|
||||
}
|
||||
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
|
||||
break;
|
||||
|
||||
case KEY_2:
|
||||
|
2
app/fm.h
2
app/fm.h
@ -34,7 +34,7 @@ extern volatile int8_t gFM_ScanState;
|
||||
extern bool gFM_AutoScan;
|
||||
extern uint8_t gFM_ChannelPosition;
|
||||
// Doubts about whether this should be signed or not.
|
||||
extern int16_t gFM_FrequencyDeviation;
|
||||
extern uint16_t gFM_FrequencyDeviation;
|
||||
extern bool gFM_FoundFrequency;
|
||||
extern bool gFM_AutoScan;
|
||||
extern uint8_t gFM_ResumeCountdown;
|
||||
|
@ -14,6 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include "app/app.h"
|
||||
#include "app/fm.h"
|
||||
#include "app/generic.h"
|
||||
#include "app/scanner.h"
|
||||
@ -27,10 +28,6 @@
|
||||
#include "ui/inputbox.h"
|
||||
#include "ui/ui.h"
|
||||
|
||||
extern void FUN_0000773c(void);
|
||||
extern void PlayFMRadio(void);
|
||||
extern void TalkRelatedCode(void);
|
||||
|
||||
void GENERIC_Key_F(bool bKeyPressed, bool bKeyHeld)
|
||||
{
|
||||
if (gInputBoxIndex) {
|
||||
@ -87,7 +84,7 @@ void GENERIC_Key_PTT(bool bKeyPressed)
|
||||
if (gFlagEndTransmission) {
|
||||
FUNCTION_Select(FUNCTION_0);
|
||||
} else {
|
||||
TalkRelatedCode();
|
||||
APP_EndTransmission();
|
||||
if (gEeprom.REPEATER_TAIL_TONE_ELIMINATION == 0) {
|
||||
FUNCTION_Select(FUNCTION_0);
|
||||
} else {
|
||||
|
@ -407,7 +407,7 @@ static void MAIN_Key_UP_DOWN(bool bKeyPressed, bool bKeyHeld, int8_t Direction)
|
||||
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
|
||||
return;
|
||||
}
|
||||
APP_SetStepDirection(false, Direction);
|
||||
CHANNEL_Next(false, Direction);
|
||||
gPttWasReleased = true;
|
||||
}
|
||||
|
||||
|
@ -29,5 +29,29 @@ enum BK1080_Register_t {
|
||||
|
||||
typedef enum BK1080_Register_t BK1080_Register_t;
|
||||
|
||||
// REG 07
|
||||
|
||||
#define BK1080_REG_07_SHIFT_FREQD 4
|
||||
#define BK1080_REG_07_SHIFT_SNR 0
|
||||
|
||||
#define BK1080_REG_07_MASK_FREQD (0xFFFU << BK1080_REG_07_SHIFT_FREQD)
|
||||
#define BK1080_REG_07_MASK_SNR (0x00FU << BK1080_REG_07_SHIFT_SNR)
|
||||
|
||||
#define BK1080_REG_07_GET_FREQD(x) (((x) & BK1080_REG_07_MASK_FREQD) >> BK1080_REG_07_SHIFT_FREQD)
|
||||
#define BK1080_REG_07_GET_SNR(x) (((x) & BK1080_REG_07_MASK_SNR) >> BK1080_REG_07_SHIFT_SNR)
|
||||
|
||||
// REG 10
|
||||
|
||||
#define BK1080_REG_10_SHIFT_AFCRL 12
|
||||
#define BK1080_REG_10_SHIFT_RSSI 0
|
||||
|
||||
#define BK1080_REG_10_MASK_AFCRL (0x01U << BK1080_REG_10_SHIFT_AFCRL)
|
||||
#define BK1080_REG_10_MASK_RSSI (0xFFU << BK1080_REG_10_SHIFT_RSSI)
|
||||
|
||||
#define BK1080_REG_10_AFCRL_NOT_RAILED (0U << BK1080_REG_10_SHIFT_AFCRL)
|
||||
#define BK1080_REG_10_AFCRL_RAILED (1U << BK1080_REG_10_SHIFT_AFCRL)
|
||||
|
||||
#define BK1080_REG_10_GET_RSSI(x) (((x) & BK1080_REG_10_MASK_RSSI) >> BK1080_REG_10_SHIFT_RSSI)
|
||||
|
||||
#endif
|
||||
|
||||
|
@ -38,7 +38,7 @@ static const uint16_t BK1080_RegisterTable[] = {
|
||||
static bool gIsInitBK1080;
|
||||
|
||||
uint16_t BK1080_BaseFrequency;
|
||||
int16_t BK1080_FrequencyDeviation;
|
||||
uint16_t BK1080_FrequencyDeviation;
|
||||
|
||||
void BK1080_Init(uint16_t Frequency, bool bDoScan)
|
||||
{
|
||||
@ -110,7 +110,6 @@ void BK1080_SetFrequency(uint16_t Frequency)
|
||||
void BK1080_GetFrequencyDeviation(uint16_t Frequency)
|
||||
{
|
||||
BK1080_BaseFrequency = Frequency;
|
||||
// Doubts whether this register is signed or not
|
||||
BK1080_FrequencyDeviation = (int16_t)BK1080_ReadRegister(BK1080_REG_07) / 16;
|
||||
BK1080_FrequencyDeviation = BK1080_ReadRegister(BK1080_REG_07) / 16;
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@
|
||||
#include "driver/bk1080-regs.h"
|
||||
|
||||
extern uint16_t BK1080_BaseFrequency;
|
||||
extern int16_t BK1080_FrequencyDeviation;
|
||||
extern uint16_t BK1080_FrequencyDeviation;
|
||||
|
||||
void BK1080_Init(uint16_t Frequency, bool bDoScan);
|
||||
uint16_t BK1080_ReadRegister(BK1080_Register_t Register);
|
||||
|
Loading…
Reference in New Issue
Block a user