Skip to content

Commit

Permalink
Merge pull request #42 from kamilsss655/rc16.5
Browse files Browse the repository at this point in the history
Rc16.5
  • Loading branch information
kamilsss655 authored Jan 5, 2024
2 parents 9a9393d + 71d0d8f commit eb784cd
Show file tree
Hide file tree
Showing 13 changed files with 65 additions and 78 deletions.
2 changes: 1 addition & 1 deletion app/aircopy.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ void AIRCOPY_StorePacket(void)
pData = &g_FSK_Buffer[2];
for (i = 0; i < 8; i++)
{
EEPROM_WriteBuffer(Offset, pData);
EEPROM_WriteBuffer(Offset, pData, true);
pData += 4;
Offset += 8;
}
Expand Down
45 changes: 13 additions & 32 deletions app/app.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,42 +257,23 @@ static void HandleReceive(void)
goto Skip;
}

switch (gCurrentCodeType)
{
default:
case CODE_TYPE_OFF:
break;

case CODE_TYPE_CONTINUOUS_TONE:
if (gFoundCTCSS && gFoundCTCSSCountdown_10ms == 0)
{
gFoundCTCSS = false;
gFoundCDCSS = false;
Mode = END_OF_RX_MODE_END;
goto Skip;
}
break;

case CODE_TYPE_DIGITAL:
case CODE_TYPE_REVERSE_DIGITAL:
if (gFoundCDCSS && gFoundCDCSSCountdown_10ms == 0)
{
gFoundCTCSS = false;
gFoundCDCSS = false;
Mode = END_OF_RX_MODE_END;
goto Skip;
}
break;
if (gCurrentCodeType != CODE_TYPE_OFF
&& ((gFoundCTCSS && gFoundCTCSSCountdown_10ms == 0)
|| (gFoundCDCSS && gFoundCDCSSCountdown_10ms == 0))
){
gFoundCTCSS = false;
gFoundCDCSS = false;
Mode = END_OF_RX_MODE_END;
goto Skip;
}

if (g_SquelchLost)
{
#ifdef ENABLE_NOAA
if (!gEndOfRxDetectedMaybe && !IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE))
#else
if (!gEndOfRxDetectedMaybe)
#endif
{
if (!gEndOfRxDetectedMaybe
#ifdef ENABLE_NOAA
&& !IS_NOAA_CHANNEL(gRxVfo->CHANNEL_SAVE)
#endif
){
switch (gCurrentCodeType)
{
case CODE_TYPE_OFF:
Expand Down
2 changes: 1 addition & 1 deletion app/fm.c
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void FM_EraseChannels(void)

memset(Template, 0xFF, sizeof(Template));
for (i = 0; i < 5; i++)
EEPROM_WriteBuffer(0x0E40 + (i * 8), Template);
EEPROM_WriteBuffer(0x0E40 + (i * 8), Template, true);

memset(gFM_Channels, 0xFF, sizeof(gFM_Channels));
}
Expand Down
2 changes: 1 addition & 1 deletion app/generic.c
Original file line number Diff line number Diff line change
Expand Up @@ -238,5 +238,5 @@ void GENERIC_Key_PTT(bool bKeyPressed)
gUpdateDisplay = true;

//done tx - restore squelch here
gVfoConfigureMode = VFO_CONFIGURE_RELOAD;
gVfoConfigureMode = VFO_CONFIGURE;
}
2 changes: 1 addition & 1 deletion app/menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ uint8_t gUnlockAllTxConfCnt;
//
EEPROM_ReadBuffer(0x1F88, &misc, 8);
misc.BK4819_XtalFreqLow = value;
EEPROM_WriteBuffer(0x1F88, &misc);
EEPROM_WriteBuffer(0x1F88, &misc, true);
}
}
#endif
Expand Down
16 changes: 8 additions & 8 deletions app/spectrum.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ struct FrequencyBandInfo {
Mode appMode;
//Idea - make this user adjustable to compensate for different antennas, frontends, conditions
#define UHF_NOISE_FLOOR 40
uint8_t scanChannel[MR_CHANNEL_LAST+1];
uint8_t scanChannel[MR_CHANNEL_LAST+3];
uint8_t scanChannelsCount;
void ToggleScanList();
void AutoAdjustResolution();
Expand Down Expand Up @@ -275,8 +275,7 @@ uint16_t GetStepsCount()
#ifdef ENABLE_SPECTRUM_CHANNEL_SCAN
if (appMode==CHANNEL_MODE)
{
// hack: adds 1 step count if steps > 128 to properly average and display last channel
return scanChannelsCount <= 128 ? scanChannelsCount : scanChannelsCount+1;
return scanChannelsCount;
}
#endif
#ifdef ENABLE_SCAN_RANGES
Expand Down Expand Up @@ -415,6 +414,9 @@ static void InitScan() {

scanInfo.scanStep = GetScanStep();
scanInfo.measurementsCount = GetStepsCount();
// prevents phantom channel bar
if(appMode==CHANNEL_MODE)
scanInfo.measurementsCount++;
}

static void ResetBlacklist() {
Expand All @@ -427,7 +429,6 @@ static void ResetBlacklist() {
blacklistFreqsIdx = 0;
#endif
if(appMode==CHANNEL_MODE){
scanChannelsCount = RADIO_ValidMemoryChannelsCount(true, settings.scanList);
LoadValidMemoryChannels();
AutoAdjustResolution();
}
Expand Down Expand Up @@ -844,7 +845,7 @@ static void DrawNums() {
sprintf(String, "M:%d", scanChannel[0]+1);
GUI_DisplaySmallest(String, 0, 49, false, true);

sprintf(String, "M:%d", scanChannel[scanChannelsCount-1]+1);
sprintf(String, "M:%d", scanChannel[GetStepsCount()-1]+1);
GUI_DisplaySmallest(String, 108, 49, false, true);
}
else
Expand Down Expand Up @@ -1311,7 +1312,7 @@ static void NextScanStep() {
static void UpdateScan() {
Scan();

if (scanInfo.i < scanInfo.measurementsCount) {
if (scanInfo.i < GetStepsCount()) {
NextScanStep();
return;
}
Expand Down Expand Up @@ -1519,15 +1520,14 @@ void APP_RunSpectrum() {
settings.scanList++;
}

scanChannelsCount = RADIO_ValidMemoryChannelsCount(true, settings.scanList);
LoadValidMemoryChannels();
ResetBlacklist();
AutoAdjustResolution();
}

void AutoAdjustResolution()
{
if (scanChannelsCount <= 64)
if (GetStepsCount() <= 64)
{
settings.stepsCount = STEPS_64;
}
Expand Down
2 changes: 1 addition & 1 deletion app/uart.c
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,7 @@ static void CMD_051D(const uint8_t *pBuffer)
bReloadEeprom = true;

if ((Offset < 0x0E98 || Offset >= 0x0EA0) || !bIsInLockScreen || pCmd->bAllowPassword)
EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U]);
EEPROM_WriteBuffer(Offset, &pCmd->Data[i * 8U], true);
}

if (bReloadEeprom)
Expand Down
2 changes: 1 addition & 1 deletion board.c
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,7 @@ void BOARD_FactoryReset(bool bIsAll)
))
)
{
EEPROM_WriteBuffer(i, Template);
EEPROM_WriteBuffer(i, Template, true);
}
}

Expand Down
11 changes: 8 additions & 3 deletions driver/eeprom.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,17 @@ void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size)
I2C_Stop();
}

void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer)
/*
Writes to EEPROM
Address: EEPROM address
pBuffer: value
safe: if set to false will allow overwriting calibration data
*/
void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer, const bool safe)
{
if (pBuffer == NULL || Address >= EEPROM_WRITE_MAX_ADDR)
if (pBuffer == NULL || (safe && Address >= EEPROM_WRITE_MAX_ADDR))
return;


uint8_t buffer[8];
EEPROM_ReadBuffer(Address, buffer, 8);
if (memcmp(pBuffer, buffer, 8) != 0)
Expand Down
3 changes: 2 additions & 1 deletion driver/eeprom.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@
#define DRIVER_EEPROM_H

#include <stdint.h>
#include <stdbool.h>

void EEPROM_ReadBuffer(uint16_t Address, void *pBuffer, uint8_t Size);
void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer);
void EEPROM_WriteBuffer(uint16_t Address, const void *pBuffer, const bool safe);

#endif

40 changes: 20 additions & 20 deletions settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ EEPROM_Config_t gEeprom;
State.Frequency = gEeprom.FM_SelectedFrequency;
State.IsChannelSelected = gEeprom.FM_IsMrMode;

EEPROM_WriteBuffer(0x0E88, &State);
EEPROM_WriteBuffer(0x0E88, &State, true);
for (i = 0; i < 5; i++)
EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4]);
EEPROM_WriteBuffer(0x0E40 + (i * 8), &gFM_Channels[i * 4], true);
}
#endif

Expand All @@ -70,7 +70,7 @@ void SETTINGS_SaveVfoIndices(void)
State[7] = gEeprom.NoaaChannel[1];
#endif

EEPROM_WriteBuffer(0x0E80, State);
EEPROM_WriteBuffer(0x0E80, State, true);
}

void SETTINGS_SaveSettings(void)
Expand All @@ -94,7 +94,7 @@ void SETTINGS_SaveSettings(void)
State[6] = 0;
#endif
State[7] = gEeprom.MIC_SENSITIVITY;
EEPROM_WriteBuffer(0x0E70, State);
EEPROM_WriteBuffer(0x0E70, State, true);

State[0] = (gEeprom.BACKLIGHT_MIN << 4) + gEeprom.BACKLIGHT_MAX;
State[1] = gEeprom.CHANNEL_DISPLAY_MODE;
Expand All @@ -104,7 +104,7 @@ void SETTINGS_SaveSettings(void)
State[5] = gEeprom.BACKLIGHT_TIME;
State[6] = gEeprom.TAIL_TONE_ELIMINATION;
State[7] = gEeprom.VFO_OPEN;
EEPROM_WriteBuffer(0x0E78, State);
EEPROM_WriteBuffer(0x0E78, State, true);

State[0] = gEeprom.BEEP_CONTROL;
State[0] |= gEeprom.KEY_M_LONG_PRESS_ACTION << 1;
Expand All @@ -115,7 +115,7 @@ void SETTINGS_SaveSettings(void)
State[5] = gEeprom.SCAN_RESUME_MODE;
State[6] = gEeprom.AUTO_KEYPAD_LOCK;
State[7] = gEeprom.POWER_ON_DISPLAY_MODE;
EEPROM_WriteBuffer(0x0E90, State);
EEPROM_WriteBuffer(0x0E90, State, true);

// 0x0E98..0x0E9F
memset(State, 0xFF, sizeof(State));
Expand All @@ -124,12 +124,12 @@ void SETTINGS_SaveSettings(void)
memcpy(&State[0], &gEeprom.POWER_ON_PASSWORD, 4);
#endif
memcpy(&State[4], &gEeprom.RX_OFFSET, 4);
EEPROM_WriteBuffer(0x0E98, State);
EEPROM_WriteBuffer(0x0E98, State, true);

memset(State, 0xFF, sizeof(State));
#ifdef ENABLE_VOX
State[0] = gEeprom.VOX_DELAY;
EEPROM_WriteBuffer(0x0EA0, State);
EEPROM_WriteBuffer(0x0EA0, State, true);
#endif

#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
Expand All @@ -141,7 +141,7 @@ void SETTINGS_SaveSettings(void)
State[2] = gEeprom.REPEATER_TAIL_TONE_ELIMINATION;
State[3] = gEeprom.TX_VFO;
State[4] = gEeprom.BATTERY_TYPE;
EEPROM_WriteBuffer(0x0EA8, State);
EEPROM_WriteBuffer(0x0EA8, State, true);

State[0] = gEeprom.DTMF_SIDE_TONE;
#ifdef ENABLE_DTMF_CALLING
Expand All @@ -153,15 +153,15 @@ void SETTINGS_SaveSettings(void)
State[5] = gEeprom.DTMF_PRELOAD_TIME / 10U;
State[6] = gEeprom.DTMF_FIRST_CODE_PERSIST_TIME / 10U;
State[7] = gEeprom.DTMF_HASH_CODE_PERSIST_TIME / 10U;
EEPROM_WriteBuffer(0x0ED0, State);
EEPROM_WriteBuffer(0x0ED0, State, true);

memset(State, 0xFF, sizeof(State));
State[0] = gEeprom.DTMF_CODE_PERSIST_TIME / 10U;
State[1] = gEeprom.DTMF_CODE_INTERVAL_TIME / 10U;
#ifdef ENABLE_DTMF_CALLING
State[2] = gEeprom.PERMIT_REMOTE_KILL;
#endif
EEPROM_WriteBuffer(0x0ED8, State);
EEPROM_WriteBuffer(0x0ED8, State, true);

State[0] = gEeprom.SCAN_LIST_DEFAULT;
State[1] = gEeprom.SCAN_LIST_ENABLED[0];
Expand All @@ -171,7 +171,7 @@ void SETTINGS_SaveSettings(void)
State[5] = gEeprom.SCANLIST_PRIORITY_CH1[1];
State[6] = gEeprom.SCANLIST_PRIORITY_CH2[1];
State[7] = 0xFF;
EEPROM_WriteBuffer(0x0F18, State);
EEPROM_WriteBuffer(0x0F18, State, true);

memset(State, 0xFF, sizeof(State));
State[0] = gSetting_F_LOCK;
Expand All @@ -194,7 +194,7 @@ void SETTINGS_SaveSettings(void)
#endif
State[7] = (State[7] & ~(3u << 6)) | ((gSetting_backlight_on_tx_rx & 3u) << 6);

EEPROM_WriteBuffer(0x0F40, State);
EEPROM_WriteBuffer(0x0F40, State, true);
}

void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode)
Expand All @@ -218,7 +218,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,

((uint32_t *)State)[0] = pVFO->freq_config_RX.Frequency;
((uint32_t *)State)[1] = pVFO->TX_OFFSET_FREQUENCY;
EEPROM_WriteBuffer(OffsetVFO + 0, State);
EEPROM_WriteBuffer(OffsetVFO + 0, State, true);

State[0] = pVFO->freq_config_RX.Code;
State[1] = pVFO->freq_config_TX.Code;
Expand All @@ -236,7 +236,7 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
;
State[6] = pVFO->STEP_SETTING;
State[7] = pVFO->SCRAMBLING_TYPE;
EEPROM_WriteBuffer(OffsetVFO + 8, State);
EEPROM_WriteBuffer(OffsetVFO + 8, State, true);

SETTINGS_UpdateChannel(Channel, pVFO, true);

Expand Down Expand Up @@ -264,11 +264,11 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO,
void SETTINGS_SaveBatteryCalibration(const uint16_t * batteryCalibration)
{
uint16_t buf[4];
EEPROM_WriteBuffer(0x1F40, batteryCalibration);
EEPROM_WriteBuffer(0x1F40, batteryCalibration, false);
EEPROM_ReadBuffer( 0x1F48, buf, sizeof(buf));
buf[0] = batteryCalibration[4];
buf[1] = batteryCalibration[5];
EEPROM_WriteBuffer(0x1F48, buf);
EEPROM_WriteBuffer(0x1F48, buf, false);
}

void SETTINGS_SaveChannelName(uint8_t channel, const char * name)
Expand All @@ -277,8 +277,8 @@ void SETTINGS_SaveChannelName(uint8_t channel, const char * name)
uint8_t buf[16];
memset(&buf, 0x00, sizeof(buf));
memcpy(buf, name, MIN(strlen(name),10u));
EEPROM_WriteBuffer(0x0F50 + offset, buf);
EEPROM_WriteBuffer(0x0F58 + offset, buf + 8);
EEPROM_WriteBuffer(0x0F50 + offset, buf, true);
EEPROM_WriteBuffer(0x0F58 + offset, buf + 8, true);
}

void SETTINGS_FetchChannelName(char *s, const int channel)
Expand Down Expand Up @@ -337,7 +337,7 @@ void SETTINGS_UpdateChannel(uint8_t channel, const VFO_Info_t *pVFO, bool keep)
}

state[channel & 7u] = att.__val;
EEPROM_WriteBuffer(offset, state);
EEPROM_WriteBuffer(offset, state, true);

gMR_ChannelAttributes[channel] = att;

Expand Down
Loading

0 comments on commit eb784cd

Please sign in to comment.