kamilsss655/misc.h

363 lines
11 KiB
C
Raw Permalink Normal View History

2024-02-04 12:32:49 +00:00
/* Original work Copyright 2023 Dual Tachyon
2023-09-09 07:03:56 +00:00
* https://github.com/DualTachyon
*
2024-02-04 12:32:49 +00:00
* Modified work Copyright 2024 kamilsss655
* https://github.com/kamilsss655
*
2023-09-09 07:03:56 +00:00
* 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
2023-12-16 13:46:01 +00:00
#ifndef SWAP
#define SWAP(a, b) ({ __typeof__ (a) _c = (a); a = b; b = _c; })
#endif
2023-10-16 15:17:17 +00:00
#define IS_MR_CHANNEL(x) ((x) <= MR_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)
2023-09-09 07:03:56 +00:00
2023-10-05 15:28:20 +00:00
enum {
MR_CHANNEL_FIRST = 0,
2023-09-15 11:31:30 +00:00
MR_CHANNEL_LAST = 199u,
FREQ_CHANNEL_FIRST = 200u,
FREQ_CHANNEL_LAST = 206u,
NOAA_CHANNEL_FIRST = 207u,
NOAA_CHANNEL_LAST = 216u,
LAST_CHANNEL
2023-10-05 15:28:20 +00:00
};
2023-09-09 07:03:56 +00:00
2024-01-13 15:42:19 +00:00
#ifdef ENABLE_PWRON_PASSWORD
enum {
PASSWORD_OFF = 10000u
};
#define PASSWORD_MAX_RETRIES 3
2024-01-13 15:42:19 +00:00
#endif
2023-09-09 07:03:56 +00:00
enum {
2023-09-10 23:02:57 +00:00
FLASHLIGHT_OFF = 0,
FLASHLIGHT_ON,
2023-10-15 21:54:14 +00:00
FLASHLIGHT_BLINK,
FLASHLIGHT_SOS
2023-09-09 07:03:56 +00:00
};
enum {
VFO_CONFIGURE_NONE = 0,
VFO_CONFIGURE,
2023-09-10 23:02:57 +00:00
VFO_CONFIGURE_RELOAD
2023-09-09 07:03:56 +00:00
};
enum AlarmState_t {
2023-09-10 23:02:57 +00:00
ALARM_STATE_OFF = 0,
ALARM_STATE_TXALARM,
ALARM_STATE_ALARM,
ALARM_STATE_TX1750
2023-09-09 07:03:56 +00:00
};
typedef enum AlarmState_t AlarmState_t;
enum ReceptionMode_t {
2023-09-21 22:06:47 +00:00
RX_MODE_NONE = 0, // squelch close ?
RX_MODE_DETECTED, // signal detected
RX_MODE_LISTENING //
2023-09-09 07:03:56 +00:00
};
typedef enum ReceptionMode_t ReceptionMode_t;
2023-10-22 00:12:07 +00:00
enum BacklightOnRxTx_t {
BACKLIGHT_ON_TR_OFF,
BACKLIGHT_ON_TR_TX,
BACKLIGHT_ON_TR_RX,
BACKLIGHT_ON_TR_TXRX
};
2023-09-17 08:54:24 +00:00
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;
2023-09-25 12:27:52 +00:00
extern const uint16_t fm_restore_countdown_10ms;
2023-09-17 08:54:24 +00:00
extern const uint8_t vfo_state_resume_countdown_500ms;
extern const uint8_t menu_timeout_500ms;
extern const uint16_t menu_timeout_long_500ms;
2023-09-29 19:48:23 +00:00
extern const uint8_t DTMF_RX_live_timeout_500ms;
#ifdef ENABLE_DTMF_CALLING
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;
#endif
2023-09-16 16:16:36 +00:00
extern const uint8_t key_input_timeout_500ms;
2023-09-16 16:16:36 +00:00
extern const uint16_t key_repeat_delay_10ms;
extern const uint16_t key_repeat_10ms;
extern const uint16_t key_debounce_10ms;
2023-09-14 18:38:28 +00:00
2023-09-16 16:16:36 +00:00
extern const uint8_t scan_delay_10ms;
2023-09-10 23:02:57 +00:00
2023-09-16 16:16:36 +00:00
extern const uint16_t battery_save_count_10ms;
2023-09-21 22:06:47 +00:00
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
2023-09-25 12:27:52 +00:00
extern const uint16_t NOAA_countdown_10ms;
extern const uint16_t NOAA_countdown_2_10ms;
extern const uint16_t NOAA_countdown_3_10ms;
2023-09-16 16:16:36 +00:00
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
2023-09-11 11:09:05 +00:00
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 uint16_t gMax_bat_v;
//extern const uint16_t gMin_bat_v;
2023-09-09 09:17:58 +00:00
2023-09-13 08:20:09 +00:00
extern const uint8_t gMicGain_dB2[5];
2023-09-11 11:09:05 +00:00
2023-09-13 08:20:09 +00:00
extern bool gSetting_350TX;
#ifdef ENABLE_DTMF_CALLING
2023-09-13 08:20:09 +00:00
extern bool gSetting_KILLED;
#endif
2023-09-13 08:20:09 +00:00
extern bool gSetting_200TX;
extern bool gSetting_500TX;
extern bool gSetting_350EN;
extern uint8_t gSetting_F_LOCK;
extern bool gSetting_ScrambleEnable;
2023-09-09 07:03:56 +00:00
2023-10-04 15:37:11 +00:00
extern uint8_t gSetting_backlight_on_tx_rx;
extern bool gSetting_live_DTMF_decoder;
extern uint8_t gSetting_battery_text;
extern bool gMonitor;
2023-09-13 08:20:09 +00:00
extern const uint32_t gDefaultAesKey[4];
extern uint32_t gCustomAesKey[4];
extern bool bHasCustomAesKey;
2023-09-13 08:20:09 +00:00
extern uint32_t gChallenge[4];
extern uint8_t gTryCount;
2023-09-09 07:03:56 +00:00
2023-10-16 10:22:56 +00:00
extern uint16_t gEEPROM_RSSI_CALIB[7][4];
2023-09-09 07:03:56 +00:00
2023-09-13 08:20:09 +00:00
extern uint16_t gEEPROM_1F8A;
extern uint16_t gEEPROM_1F8C;
2023-09-09 07:03:56 +00:00
2023-11-22 20:30:54 +00:00
typedef union {
struct {
uint8_t
band : 4,
compander : 2,
scanlist2 : 1,
scanlist1 : 1;
};
uint8_t __val;
} ChannelAttributes_t;
2023-12-16 13:48:38 +00:00
#ifdef ENABLE_SPECTRUM_SHOW_CHANNEL_NAME
typedef struct
{
uint32_t Frequency;
char Name[12];
} __attribute__((packed)) ChannelFrequencyAttributes;
extern ChannelFrequencyAttributes gMR_ChannelFrequencyAttributes[200];
#endif
2023-11-22 20:30:54 +00:00
extern ChannelAttributes_t gMR_ChannelAttributes[207];
2023-09-09 07:03:56 +00:00
typedef struct
{
uint8_t sLevel; // S-level value
uint8_t over; // over S9 value
int dBmRssi; // RSSI in dBm
bool overSquelch; // determines whether signal is over squelch open threshold
} __attribute__((packed)) sLevelAttributes;
extern volatile uint16_t gBatterySaveCountdown_10ms;
2023-09-21 22:06:47 +00:00
extern volatile bool gPowerSaveCountdownExpired;
extern volatile bool gSchedulePowerSave;
extern volatile bool gScheduleDualWatch;
extern volatile uint16_t gDualWatchCountdown_10ms;
extern bool gDualWatchActive;
extern volatile uint8_t gSerialConfigCountDown_500ms;
2023-09-28 16:39:45 +00:00
extern volatile bool gNextTimeslice_500ms;
extern volatile uint16_t gTxTimerCountdown_500ms;
extern volatile bool gTxTimeoutReached;
extern volatile uint16_t gTailNoteEliminationCountdown_10ms;
2023-09-28 16:39:45 +00:00
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
2023-09-17 08:54:24 +00:00
extern volatile uint16_t gFmPlayCountdown_10ms;
2023-09-14 08:56:30 +00:00
#endif
#ifdef ENABLE_NOAA
extern volatile uint16_t gNOAA_Countdown_10ms;
2023-09-09 07:03:56 +00:00
#endif
2023-09-13 08:20:09 +00:00
extern bool gEnableSpeaker;
extern uint8_t gKeyInputCountdown;
2023-09-13 08:20:09 +00:00
extern uint8_t gKeyLockCountdown;
extern bool bIsInLockScreen;
extern uint8_t gUpdateStatus;
extern uint8_t gFoundCTCSS;
extern uint8_t gFoundCDCSS;
extern bool gEndOfRxDetectedMaybe;
2023-09-17 14:36:23 +00:00
extern int16_t gVFO_RSSI[2];
extern uint8_t gVFO_RSSI_bar_level[2];
2023-09-17 14:36:23 +00:00
2023-10-27 18:11:22 +00:00
// battery critical, limit functionality to minimum
2023-09-13 08:20:09 +00:00
extern uint8_t gReducedService;
extern uint8_t gBatteryVoltageIndex;
2023-10-27 18:11:22 +00:00
// we are searching CTCSS/DCS inside RX ctcss/dcs menu
extern bool gCssBackgroundScan;
enum
{
SCAN_REV = -1,
SCAN_OFF = 0,
SCAN_FWD = +1
};
extern volatile bool gScheduleScanListen;
extern volatile uint16_t gScanPauseDelayIn_10ms;
2023-09-13 08:20:09 +00:00
extern bool gUpdateRSSI;
extern AlarmState_t gAlarmState;
extern uint16_t gMenuCountdown;
2023-09-13 08:20:09 +00:00
extern bool gPttWasReleased;
extern bool gPttWasPressed;
extern bool gFlagReconfigureVfos;
extern uint8_t gVfoConfigureMode;
extern bool gFlagResetVfos;
extern bool gRequestSaveVFO;
extern uint8_t gRequestSaveChannel;
extern bool gRequestSaveSettings;
extern uint8_t gKeypadLocked;
extern bool gFlagPrepareTX;
extern bool gFlagAcceptSetting; // accept menu setting
extern bool gFlagRefreshSetting; // refresh menu display
2023-09-13 08:20:09 +00:00
extern bool gFlagSaveVfo;
extern bool gFlagSaveSettings;
extern bool gFlagSaveChannel;
extern bool g_CDCSS_Lost;
extern uint8_t gCDCSSCodeType;
extern bool g_CTCSS_Lost;
extern bool g_CxCSS_TAIL_Found;
#ifdef ENABLE_VOX
extern bool g_VOX_Lost;
extern bool gVOX_NoiseDetected;
extern uint16_t gVoxResumeCountdown;
extern uint16_t gVoxPauseCountdown;
#endif
2023-10-27 18:11:22 +00:00
// true means we are receiving signal
2023-09-13 08:20:09 +00:00
extern bool g_SquelchLost;
extern uint8_t gFlashLightState;
extern volatile uint16_t gFlashLightBlinkCounter;
extern bool gFlagEndTransmission;
extern uint8_t gNextMrChannel;
extern ReceptionMode_t gRxReceptionMode;
2023-10-19 19:42:56 +00:00
//TRUE when dual watch is momentarly suspended and RX_VFO is locked to either last TX or RX
extern bool gRxVfoIsActive;
2023-09-13 08:20:09 +00:00
extern uint8_t gAlarmToneCounter;
extern uint16_t gAlarmRunningCounter;
extern bool gKeyBeingHeld;
extern bool gPttIsPressed;
extern uint8_t gPttDebounceCounter;
extern uint8_t gMenuListCount;
extern uint8_t gBackup_CROSS_BAND_RX_TX;
extern uint8_t gScanDelay_10ms;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_AIRCOPY
2023-09-13 08:20:09 +00:00
extern uint8_t gAircopySendCountdown;
2023-09-09 07:03:56 +00:00
#endif
2023-09-13 08:20:09 +00:00
extern uint8_t gFSKWriteIndex;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
2023-09-13 08:20:09 +00:00
extern bool gIsNoaaMode;
extern uint8_t gNoaaChannel;
#endif
extern volatile bool gNextTimeslice;
extern bool gUpdateDisplay;
extern bool gF_LOCK;
2023-09-13 08:20:09 +00:00
extern uint8_t gShowChPrefix;
extern volatile uint8_t gFoundCDCSSCountdown_10ms;
extern volatile uint8_t gFoundCTCSSCountdown_10ms;
#ifdef ENABLE_VOX
extern volatile uint16_t gVoxStopCountdown_10ms;
#endif
2023-09-13 08:20:09 +00:00
extern volatile bool gNextTimeslice40ms;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_NOAA
extern volatile uint16_t gNOAACountdown_10ms;
2023-09-13 08:20:09 +00:00
extern volatile bool gScheduleNOAA;
2023-09-09 07:03:56 +00:00
#endif
extern volatile bool gFlagTailNoteEliminationComplete;
extern volatile uint8_t gVFOStateResumeCountdown_500ms;
2023-09-14 08:56:30 +00:00
#ifdef ENABLE_FMRADIO
extern volatile bool gScheduleFM;
#endif
2023-09-24 08:00:34 +00:00
extern int16_t gCurrentRSSI[2]; // now one per VFO
extern uint8_t gIsLocked;
2023-09-18 10:54:42 +00:00
extern volatile uint8_t boot_counter_10ms;
2023-09-09 07:03:56 +00:00
int32_t NUMBER_AddWithWraparound(int32_t Base, int32_t Add, int32_t LowerLimit, int32_t UpperLimit);
2023-10-19 22:15:11 +00:00
unsigned long StrToUL(const char * str);
2023-09-09 07:03:56 +00:00
bool IsValueInArray(int val, const int *arr, const int size);
sLevelAttributes GetSLevelAttributes (const int16_t rssi, const uint32_t frequency);
2024-01-01 13:29:28 +00:00
int Rssi2DBm(const uint16_t rssi);
2023-09-09 07:03:56 +00:00
#endif