forked from spm81/MCFW_UV-K5_Open_Source_Firmware
-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions.c
192 lines (176 loc) · 4.8 KB
/
functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
/* Copyright 2023 Dual Tachyon
* https://github.com/DualTachyon
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "main/dtmf.h"
#include <string.h>
#if defined(ENABLE_FMRADIO)
#include "main/fm.h"
#endif
#ifdef ENABLE_MESSENGER
#include "apps/messenger.h"
#endif
#include "bsp/dp32g030/gpio.h"
#include "dcs.h"
#if defined(ENABLE_FMRADIO)
#include "driver/bk1080.h"
#endif
#include "driver/bk4819.h"
#include "driver/gpio.h"
#include "driver/system.h"
#include "functions.h"
#include "helper/battery.h"
#include "misc.h"
#include "radio.h"
#include "settings.h"
#include "ui/status.h"
#include "ui/ui.h"
FUNCTION_Type_t gCurrentFunction;
void FUNCTION_Init(void) {
if (IS_NOT_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)) {
gCurrentCodeType = gSelectedCodeType;
if (gCssScanMode == CSS_SCAN_MODE_OFF) {
if (gRxVfo->ModulationType) {
gCurrentCodeType = CODE_TYPE_OFF;
} else {
gCurrentCodeType = gRxVfo->pRX->CodeType;
}
}
} else {
gCurrentCodeType = CODE_TYPE_CONTINUOUS_TONE;
}
#ifdef ENABLE_DTMF_CALLING
gDTMF_RequestPending = false;
gDTMF_WriteIndex = 0;
memset(gDTMF_Received, 0, sizeof(gDTMF_Received));
#endif
g_CxCSS_TAIL_Found = false;
g_CDCSS_Lost = false;
g_CTCSS_Lost = false;
g_VOX_Lost = false;
g_SquelchLost = false;
gTailNoteEliminationCountdown = 0;
gFlagTteComplete = false;
gFoundCTCSS = false;
gFoundCDCSS = false;
gFoundCTCSSCountdown = 0;
gFoundCDCSSCountdown = 0;
gEndOfRxDetectedMaybe = false;
gSystickCountdown2 = 0;
}
void FUNCTION_Select(FUNCTION_Type_t Function) {
FUNCTION_Type_t PreviousFunction;
bool bWasPowerSave;
PreviousFunction = gCurrentFunction;
bWasPowerSave = (PreviousFunction == FUNCTION_POWER_SAVE);
gCurrentFunction = Function;
if (bWasPowerSave) {
if (Function != FUNCTION_POWER_SAVE) {
BK4819_Conditional_RX_TurnOn_and_GPIO6_Enable();
gRxIdleMode = false;
UI_DisplayStatus();
}
}
switch (Function) {
case FUNCTION_FOREGROUND:
#ifdef ENABLE_DTMF_CALLING
if (gDTMF_ReplyState != DTMF_REPLY_NONE) {
RADIO_PrepareCssTX();
}
#endif
if (PreviousFunction == FUNCTION_TRANSMIT) {
gVFO_RSSI_Level[0] = 0;
gVFO_RSSI_Level[1] = 0;
} else if (PreviousFunction != FUNCTION_RECEIVE) {
break;
}
#if defined(ENABLE_FMRADIO)
if (gFmRadioMode) {
#if defined(ENABLE_FMRADIO_FAST_RESTORE)
gFM_RestoreCountdown = 100;
#else
gFM_RestoreCountdown = 500;
#endif
}
#endif
#ifdef ENABLE_DTMF_CALLING
if (gDTMF_CallState == DTMF_CALL_STATE_CALL_OUT ||
gDTMF_CallState == DTMF_CALL_STATE_RECEIVED) {
gDTMF_AUTO_RESET_TIME = 1 + (gEeprom.DTMF_AUTO_RESET_TIME * 2);
}
#endif
return;
case FUNCTION_MONITOR:
case FUNCTION_INCOMING:
case FUNCTION_RECEIVE:
break;
case FUNCTION_POWER_SAVE:
gBatterySave = gEeprom.BATTERY_SAVE * 10;
gRxIdleMode = true;
BK4819_DisableVox();
BK4819_Sleep();
BK4819_ToggleGpioOut(BK4819_GPIO6_PIN2, false);
gBatterySaveCountdownExpired = false;
gUpdateStatus = true;
GUI_SelectNextDisplay(DISPLAY_MAIN);
return;
case FUNCTION_TRANSMIT:
#if defined(ENABLE_FMRADIO)
if (gFmRadioMode) {
BK1080_Init(0, false);
}
#endif
#ifdef ENABLE_MESSENGER
MSG_EnableRX(false);
#endif
GUI_DisplayScreen();
RADIO_SetTxParameters();
BK4819_ToggleGpioOut(BK4819_GPIO1_PIN29_RED, true);
#ifdef ENABLE_CW
if (gRxVfo->ModulationType == MOD_CW) {
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
gEnableSpeaker = true;
BK4819_TransmitTone(true, 641);
SYSTEM_DelayMs(2);
} else
#endif
{
#ifdef ENABLE_DTMF_CALLING
DTMF_Reply();
#endif
#if defined(ENABLE_TX1750)
if (gAlarmState != ALARM_STATE_OFF) {
if (gAlarmState == ALARM_STATE_TX1750) {
BK4819_TransmitTone(true, 1750);
}
SYSTEM_DelayMs(2);
GPIO_SetBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
gEnableSpeaker = true;
break;
}
#endif
if (gCurrentVfo->SCRAMBLING_TYPE && gSetting_ScrambleEnable) {
BK4819_EnableScramble(gCurrentVfo->SCRAMBLING_TYPE - 1U);
} else {
BK4819_DisableScramble();
}
}
break;
}
gBatterySaveCountdown = 1000;
gSchedulePowerSave = false;
#if defined(ENABLE_FMRADIO)
gFM_RestoreCountdown = 0;
#endif
}