forked from OneOfEleven/uv-k5-firmware-custom
-
Notifications
You must be signed in to change notification settings - Fork 26
/
misc.h
340 lines (282 loc) · 11.6 KB
/
misc.h
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* 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.
*/
#ifndef MISC_H
#define MISC_H
#include <stdbool.h>
#include <stdint.h>
#ifndef ARRAY_SIZE
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#endif
#ifndef MAX
// #define MAX(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a > _b ? _a : _b; })
#endif
#ifndef MIN
// #define MIN(a, b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); _a < _b ? _a : _b; })
#endif
//#define IS_USER_CHANNEL(x) ((x) >= USER_CHANNEL_FIRST && (x) <= USER_CHANNEL_LAST)
#define IS_USER_CHANNEL(x) ((x) <= USER_CHANNEL_LAST)
#define IS_FREQ_CHANNEL(x) ((x) >= FREQ_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
#define IS_VALID_CHANNEL(x) ((x) < LAST_CHANNEL)
#define IS_NOAA_CHANNEL(x) ((x) >= NOAA_CHANNEL_FIRST && (x) <= NOAA_CHANNEL_LAST)
//#define IS_NOT_NOAA_CHANNEL(x) ((x) >= USER_CHANNEL_FIRST && (x) <= FREQ_CHANNEL_LAST)
#define IS_NOT_NOAA_CHANNEL(x) ((x) <= FREQ_CHANNEL_LAST)
// PTT key-up/key-down audio tone freq's used in NASA's apollo rides to the moon
#define APOLLO_TONE_MS 200 // slightly shorter tone length
//#define APOLLO_TONE_MS 250 // NASA tone length
#define APOLLO_TONE1_HZ 2525
#define APOLLO_TONE2_HZ 2475
enum {
USER_CHANNEL_FIRST = 0,
USER_CHANNEL_LAST = 199u,
FREQ_CHANNEL_FIRST = 200u,
FREQ_CHANNEL_LAST = 206u,
NOAA_CHANNEL_FIRST = 207u,
NOAA_CHANNEL_LAST = 216u,
LAST_CHANNEL
};
enum {
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
FLASHLIGHT_BLINK
};
enum {
VFO_CONFIGURE_NONE = 0,
VFO_CONFIGURE,
VFO_CONFIGURE_RELOAD
};
enum alarm_state_e {
ALARM_STATE_OFF = 0,
ALARM_STATE_TXALARM,
ALARM_STATE_ALARM,
ALARM_STATE_TX1750
};
typedef enum alarm_state_e alarm_state_t;
enum reception_mode_e {
RX_MODE_NONE = 0, // squelch close ?
RX_MODE_DETECTED, // signal detected
RX_MODE_LISTENING //
};
typedef enum reception_mode_e reception_mode_t;
enum css_scan_mode_e
{
CSS_SCAN_MODE_OFF = 0,
CSS_SCAN_MODE_SCANNING,
CSS_SCAN_MODE_FOUND,
};
typedef enum css_scan_mode_e css_scan_mode_t;
enum scan_next_chan_e {
SCAN_NEXT_CHAN_SCANLIST1 = 0,
SCAN_NEXT_CHAN_SCANLIST2,
SCAN_NEXT_CHAN_DUAL_WATCH,
SCAN_NEXT_CHAN_USER,
SCAN_NEXT_NUM
};
typedef enum scan_next_chan_e scan_next_chan_t;
extern const uint8_t fm_resume_countdown_500ms;
extern const uint8_t fm_radio_countdown_500ms;
extern const uint16_t fm_play_countdown_scan_10ms;
extern const uint16_t fm_play_countdown_noscan_10ms;
extern const uint16_t fm_restore_countdown_10ms;
extern const uint8_t menu_timeout_500ms;
extern const uint16_t menu_timeout_long_500ms;
extern const uint8_t dtmf_rx_live_timeout_500ms;
extern const uint8_t dtmf_rx_timeout_500ms;
extern const uint8_t dtmf_decode_ring_countdown_500ms;
extern const uint8_t dtmf_txstop_countdown_500ms;
extern const uint8_t serial_config_count_down_500ms;
extern const uint8_t key_input_timeout_500ms;
extern const uint8_t key_lock_timeout_500ms;
extern const uint8_t key_debounce_10ms;
extern const uint8_t key_long_press_10ms;
extern const uint8_t key_repeat_10ms;
extern const uint16_t scan_freq_css_timeout_10ms;
extern const uint8_t scan_freq_css_delay_10ms;
extern const uint16_t battery_save_count_10ms;
extern const uint16_t power_save1_10ms;
extern const uint16_t power_save2_10ms;
#ifdef ENABLE_VOX
extern const uint16_t vox_stop_count_down_10ms;
#endif
extern const uint16_t noaa_count_down_10ms;
extern const uint16_t noaa_count_down_2_10ms;
extern const uint16_t noaa_count_down_3_10ms;
extern const uint16_t dual_watch_count_after_tx_10ms;
extern const uint16_t dual_watch_count_after_rx_10ms;
extern const uint16_t dual_watch_count_after_1_10ms;
extern const uint16_t dual_watch_count_after_2_10ms;
extern const uint16_t dual_watch_count_toggle_10ms;
extern const uint16_t dual_watch_count_noaa_10ms;
#ifdef ENABLE_VOX
extern const uint16_t dual_watch_count_after_vox_10ms;
#endif
extern const uint16_t scan_pause_delay_in_1_10ms;
extern const uint16_t scan_pause_delay_in_2_10ms;
extern const uint16_t scan_pause_delay_in_3_10ms;
extern const uint16_t scan_pause_delay_in_4_10ms;
extern const uint16_t scan_pause_delay_in_5_10ms;
extern const uint16_t scan_pause_delay_in_6_10ms;
extern const uint16_t scan_pause_delay_in_7_10ms;
extern const uint8_t g_mic_gain_dB_2[5];
extern bool g_setting_350_tx_enable;
extern bool g_setting_killed;
extern bool g_setting_200_tx_enable;
extern bool g_setting_500_tx_enable;
extern bool g_setting_350_enable;
extern bool g_setting_tx_enable;
extern uint8_t g_setting_freq_lock;
extern bool g_setting_scramble_enable;
extern uint8_t g_setting_backlight_on_tx_rx;
#ifdef ENABLE_AM_FIX
extern bool g_setting_am_fix;
#endif
#ifdef ENABLE_AM_FIX_TEST1
extern uint8_t g_setting_am_fix_test1;
#endif
#ifdef ENABLE_AUDIO_BAR
extern bool g_setting_mic_bar;
#endif
extern bool g_setting_live_dtmf_decoder;
extern uint8_t g_setting_battery_text;
extern uint8_t g_setting_contrast;
extern uint8_t g_setting_side1_short;
extern uint8_t g_setting_side1_long;
extern uint8_t g_setting_side2_short;
extern uint8_t g_setting_side2_long;
extern bool g_monitor_enabled;
extern const uint32_t g_default_aes_key[4];
extern uint32_t g_custom_aes_key[4];
extern bool g_has_custom_aes_key;
extern uint32_t g_challenge[4];
extern uint8_t g_eeprom_1EC0_0[8];
extern uint8_t g_eeprom_1EC0_1[8];
extern uint8_t g_eeprom_1EC0_2[8];
extern uint8_t g_eeprom_1EC0_3[8];
extern uint16_t g_eeprom_rssi_calib[2][4];
extern uint16_t g_eeprom_1F8A;
extern uint16_t g_eeprom_1F8C;
extern uint8_t g_user_channel_attributes[207];
extern volatile uint16_t g_battery_save_count_down_10ms;
extern volatile bool g_power_save_expired;
extern volatile bool g_schedule_power_save;
extern volatile bool g_schedule_dual_watch;
extern volatile uint16_t g_dual_watch_count_down_10ms;
extern volatile bool g_dual_watch_count_down_expired;
extern bool g_dual_watch_active;
extern volatile uint8_t g_serial_config_count_down_500ms;
extern volatile bool g_next_time_slice_500ms;
extern volatile uint16_t g_tx_timer_count_down_500ms;
extern volatile bool g_tx_timeout_reached;
extern volatile uint16_t g_tail_tone_elimination_count_down_10ms;
#ifdef ENABLE_FMRADIO
extern volatile uint16_t g_fm_play_count_down_10ms;
#endif
#ifdef ENABLE_NOAA
extern volatile uint16_t g_noaa_count_down_10ms;
#endif
extern bool g_enable_speaker;
extern uint8_t g_key_input_count_down;
extern uint8_t g_key_lock_count_down_500ms;
extern uint8_t g_rtte_count_down;
extern bool g_password_locked;
extern uint8_t g_update_status;
extern uint8_t g_found_CTCSS;
extern uint8_t g_found_CDCSS;
extern bool g_end_of_rx_detected_maybe;
extern int16_t g_vfo_rssi[2];
extern uint8_t g_vfo_rssi_bar_level[2];
extern uint8_t g_reduced_service;
extern uint8_t g_battery_voltage_index;
extern css_scan_mode_t g_css_scan_mode;
extern bool g_update_rssi;
extern alarm_state_t g_alarm_state;
extern uint16_t g_menu_count_down;
extern bool g_flag_reconfigure_vfos;
extern uint8_t g_vfo_configure_mode;
extern bool g_flag_reset_vfos;
extern bool g_request_save_vfo;
extern uint8_t g_request_save_channel;
extern bool g_request_save_settings;
#ifdef ENABLE_FMRADIO
extern bool g_request_save_fm;
#endif
extern bool g_flag_prepare_tx;
extern bool g_flag_AcceptSetting; // accept menu setting
extern bool g_flag_refresh_menu; // refresh menu display
extern bool g_flag_SaveVfo;
extern bool g_flag_SaveSettings;
extern bool g_flag_save_channel;
#ifdef ENABLE_FMRADIO
extern bool g_flag_SaveFM;
#endif
extern bool g_CDCSS_lost;
extern uint8_t g_CDCSS_code_type;
extern bool g_CTCSS_lost;
extern bool g_CxCSS_tail_found;
#ifdef ENABLE_VOX
extern bool g_vox_lost;
extern bool g_vox_noise_detected;
extern uint16_t g_vox_resume_count_down;
extern uint16_t g_vox_pause_count_down;
#endif
extern bool g_squelch_lost;
extern uint8_t g_flash_light_state;
extern volatile uint16_t g_flash_light_blink_counter;
extern bool g_flag_end_tx;
extern uint16_t g_low_batteryCountdown;
extern uint8_t g_next_channel;
extern reception_mode_t g_rx_reception_mode;
extern uint8_t g_restore_channel;
extern scan_next_chan_t g_current_scan_list;
extern uint32_t g_restore_frequency;
extern bool g_rx_vfo_is_active;
extern uint8_t g_alarm_tone_counter;
extern uint16_t g_alarm_running_counter;
extern uint8_t g_menu_list_count;
extern uint8_t g_backup_cross_vfo_rx_tx;
extern uint8_t g_scan_delay_10ms;
#ifdef ENABLE_NOAA
extern bool g_is_noaa_mode;
extern uint8_t g_noaa_channel;
#endif
extern volatile bool g_next_time_slice;
extern bool g_update_display;
extern bool g_unhide_hidden;
#ifdef ENABLE_FMRADIO
extern uint8_t g_fm_channel_position;
#endif
extern uint8_t g_show_chan_prefix;
extern volatile uint8_t g_found_CDCSS_count_down_10ms;
extern volatile uint8_t g_found_CTCSS_count_down_10ms;
#ifdef ENABLE_VOX
extern volatile uint16_t g_vox_stop_count_down_10ms;
#endif
extern volatile bool g_next_time_slice_40ms;
#ifdef ENABLE_NOAA
extern volatile uint16_t g_noaa_count_down_10ms;
extern volatile bool g_schedule_noaa;
#endif
extern volatile bool g_flag_tail_tone_elimination_complete;
#ifdef ENABLE_FMRADIO
extern volatile bool g_schedule_fm;
#endif
extern int16_t g_current_rssi[2]; // now one per VFO
extern volatile uint8_t g_boot_counter_10ms;
unsigned int get_TX_VFO(void);
unsigned int get_RX_VFO(void);
void NUMBER_Get(char *pDigits, uint32_t *pInteger);
void NUMBER_ToDigits(uint32_t Value, char *pDigits);
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit);
#endif