This commit is contained in:
Krzysiek Egzmont
2024-01-14 19:35:59 +01:00
parent f8ff71aaa3
commit adbc466c49
8 changed files with 152 additions and 213 deletions

View File

@@ -346,9 +346,8 @@ void ACTION_FM(void)
static void ACTION_Scan_FM(bool bRestart) static void ACTION_Scan_FM(bool bRestart)
{ {
if (FUNCTION_IsRx()) { if (FUNCTION_IsRx())
return; return;
}
GUI_SelectNextDisplay(DISPLAY_FM); GUI_SelectNextDisplay(DISPLAY_FM);
@@ -363,21 +362,21 @@ static void ACTION_Scan_FM(bool bRestart)
return; return;
} }
uint16_t Frequency; uint16_t freq;
if (bRestart) { if (bRestart) {
gFM_AutoScan = true; gFM_AutoScan = true;
gFM_ChannelPosition = 0; gFM_ChannelPosition = 0;
FM_EraseChannels(); FM_EraseChannels();
Frequency = gEeprom.FM_LowerLimit; freq = gEeprom.FM_LowerLimit;
} else { } else {
gFM_AutoScan = false; gFM_AutoScan = false;
gFM_ChannelPosition = 0; gFM_ChannelPosition = 0;
Frequency = gEeprom.FM_FrequencyPlaying; freq = gEeprom.FM_FrequencyPlaying;
} }
BK1080_GetFrequencyDeviation(Frequency); BK1080_GetFrequencyDeviation(freq);
FM_Tune(Frequency, 1, bRestart); FM_Tune(freq, 1, bRestart);
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_BEGIN; gAnotherVoiceID = VOICE_ID_SCANNING_BEGIN;

250
app/fm.c
View File

@@ -67,14 +67,10 @@ bool FM_CheckValidChannel(uint8_t Channel)
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction) uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction)
{ {
unsigned int i; for (unsigned i = 0; i < ARRAY_SIZE(gFM_Channels); i++) {
for (i = 0; i < ARRAY_SIZE(gFM_Channels); i++)
{
if (Channel == 0xFF) if (Channel == 0xFF)
Channel = ARRAY_SIZE(gFM_Channels) - 1; Channel = ARRAY_SIZE(gFM_Channels) - 1;
else else if (Channel >= ARRAY_SIZE(gFM_Channels))
if (Channel >= ARRAY_SIZE(gFM_Channels))
Channel = 0; Channel = 0;
if (FM_CheckValidChannel(Channel)) if (FM_CheckValidChannel(Channel))
return Channel; return Channel;
@@ -88,11 +84,9 @@ int FM_ConfigureChannelState(void)
{ {
gEeprom.FM_FrequencyPlaying = gEeprom.FM_SelectedFrequency; gEeprom.FM_FrequencyPlaying = gEeprom.FM_SelectedFrequency;
if (gEeprom.FM_IsMrMode) if (gEeprom.FM_IsMrMode) {
{
const uint8_t Channel = FM_FindNextChannel(gEeprom.FM_SelectedChannel, FM_CHANNEL_UP); const uint8_t Channel = FM_FindNextChannel(gEeprom.FM_SelectedChannel, FM_CHANNEL_UP);
if (Channel == 0xFF) if (Channel == 0xFF) {
{
gEeprom.FM_IsMrMode = false; gEeprom.FM_IsMrMode = false;
return -1; return -1;
} }
@@ -110,7 +104,6 @@ void FM_TurnOff(void)
gFM_RestoreCountdown_10ms = 0; gFM_RestoreCountdown_10ms = 0;
AUDIO_AudioPathOff(); AUDIO_AudioPathOff();
gEnableSpeaker = false; gEnableSpeaker = false;
BK1080_Init(0, false); BK1080_Init(0, false);
@@ -120,11 +113,10 @@ void FM_TurnOff(void)
void FM_EraseChannels(void) void FM_EraseChannels(void)
{ {
unsigned int i;
uint8_t Template[8]; uint8_t Template[8];
memset(Template, 0xFF, sizeof(Template)); memset(Template, 0xFF, sizeof(Template));
for (i = 0; i < 5; i++)
for (unsigned i = 0; i < 5; i++)
EEPROM_WriteBuffer(0x0E40 + (i * 8), Template); EEPROM_WriteBuffer(0x0E40 + (i * 8), Template);
memset(gFM_Channels, 0xFF, sizeof(gFM_Channels)); memset(gFM_Channels, 0xFF, sizeof(gFM_Channels));
@@ -144,13 +136,11 @@ void FM_Tune(uint16_t Frequency, int8_t Step, bool bFlag)
gAskToDelete = false; gAskToDelete = false;
gEeprom.FM_FrequencyPlaying = Frequency; gEeprom.FM_FrequencyPlaying = Frequency;
if (!bFlag) if (!bFlag) {
{
Frequency += Step; Frequency += Step;
if (Frequency < gEeprom.FM_LowerLimit) if (Frequency < gEeprom.FM_LowerLimit)
Frequency = gEeprom.FM_UpperLimit; Frequency = gEeprom.FM_UpperLimit;
else else if (Frequency > gEeprom.FM_UpperLimit)
if (Frequency > gEeprom.FM_UpperLimit)
Frequency = gEeprom.FM_LowerLimit; Frequency = gEeprom.FM_LowerLimit;
gEeprom.FM_FrequencyPlaying = Frequency; gEeprom.FM_FrequencyPlaying = Frequency;
@@ -165,8 +155,7 @@ void FM_PlayAndUpdate(void)
{ {
gFM_ScanState = FM_SCAN_OFF; gFM_ScanState = FM_SCAN_OFF;
if (gFM_AutoScan) if (gFM_AutoScan) {
{
gEeprom.FM_IsMrMode = true; gEeprom.FM_IsMrMode = true;
gEeprom.FM_SelectedChannel = 0; gEeprom.FM_SelectedChannel = 0;
} }
@@ -193,7 +182,7 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
// This is supposed to be a signed value, but above function is unsigned // This is supposed to be a signed value, but above function is unsigned
const uint16_t Deviation = BK1080_REG_07_GET_FREQD(Test2); const uint16_t Deviation = BK1080_REG_07_GET_FREQD(Test2);
if (BK1080_REG_07_GET_SNR(Test2) <= 2){ if (BK1080_REG_07_GET_SNR(Test2) <= 2) {
goto Bail; goto Bail;
} }
@@ -219,7 +208,6 @@ int FM_CheckFrequencyLock(uint16_t Frequency, uint16_t LowerLimit)
if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1) { if (Frequency >= LowerLimit && (BK1080_BaseFrequency - Frequency) == 1) {
if ((BK1080_FrequencyDeviation & 0x800) == 0 || (BK1080_FrequencyDeviation > 4075)) if ((BK1080_FrequencyDeviation & 0x800) == 0 || (BK1080_FrequencyDeviation > 4075))
goto Bail; goto Bail;
} }
ret = 0; ret = 0;
@@ -236,93 +224,93 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state)
enum { STATE_FREQ_MODE, STATE_MR_MODE, STATE_SAVE }; enum { STATE_FREQ_MODE, STATE_MR_MODE, STATE_SAVE };
if (state == BUTTON_EVENT_SHORT && !gWasFKeyPressed) { if (state == BUTTON_EVENT_SHORT && !gWasFKeyPressed) {
uint8_t State; uint8_t State;
if (gAskToDelete) { if (gAskToDelete) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
if (gAskToSave) {
State = STATE_SAVE;
}
else {
if (gFM_ScanState != FM_SCAN_OFF) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
if (gAskToSave) { State = gEeprom.FM_IsMrMode ? STATE_MR_MODE : STATE_FREQ_MODE;
State = STATE_SAVE; }
INPUTBOX_Append(Key);
gRequestDisplayScreen = DISPLAY_FM;
if (State == STATE_FREQ_MODE) {
if (gInputBoxIndex == 1) {
if (gInputBox[0] > 1) {
gInputBox[1] = gInputBox[0];
gInputBox[0] = 0;
gInputBoxIndex = 2;
}
} }
else { else if (gInputBoxIndex > 3) {
if (gFM_ScanState != FM_SCAN_OFF) { uint32_t Frequency;
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gInputBoxIndex = 0;
Frequency = StrToUL(INPUTBOX_GetAscii());
if (Frequency < gEeprom.FM_LowerLimit || gEeprom.FM_UpperLimit < Frequency) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gRequestDisplayScreen = DISPLAY_FM;
return; return;
} }
State = gEeprom.FM_IsMrMode ? STATE_MR_MODE : STATE_FREQ_MODE; gEeprom.FM_SelectedFrequency = (uint16_t)Frequency;
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
gEeprom.FM_FrequencyPlaying = gEeprom.FM_SelectedFrequency;
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
gRequestSaveFM = true;
return;
} }
}
else if (gInputBoxIndex == 2) {
uint8_t Channel;
INPUTBOX_Append(Key); gInputBoxIndex = 0;
Channel = ((gInputBox[0] * 10) + gInputBox[1]) - 1;
gRequestDisplayScreen = DISPLAY_FM; if (State == STATE_MR_MODE) {
if (FM_CheckValidChannel(Channel)) {
if (State == STATE_FREQ_MODE) {
if (gInputBoxIndex == 1) {
if (gInputBox[0] > 1) {
gInputBox[1] = gInputBox[0];
gInputBox[0] = 0;
gInputBoxIndex = 2;
}
}
else if (gInputBoxIndex > 3) {
uint32_t Frequency;
gInputBoxIndex = 0;
Frequency = StrToUL(INPUTBOX_GetAscii());
if (Frequency < gEeprom.FM_LowerLimit || gEeprom.FM_UpperLimit < Frequency) {
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gRequestDisplayScreen = DISPLAY_FM;
return;
}
gEeprom.FM_SelectedFrequency = (uint16_t)Frequency;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
gEeprom.FM_FrequencyPlaying = gEeprom.FM_SelectedFrequency; gEeprom.FM_SelectedChannel = Channel;
gEeprom.FM_FrequencyPlaying = gFM_Channels[Channel];
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying); BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
gRequestSaveFM = true; gRequestSaveFM = true;
return; return;
} }
} }
else if (gInputBoxIndex == 2) { else if (Channel < 20) {
uint8_t Channel; #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
gRequestDisplayScreen = DISPLAY_FM;
gInputBoxIndex = 0; gInputBoxIndex = 0;
Channel = ((gInputBox[0] * 10) + gInputBox[1]) - 1; gFM_ChannelPosition = Channel;
if (State == STATE_MR_MODE) {
if (FM_CheckValidChannel(Channel)) {
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
gEeprom.FM_SelectedChannel = Channel;
gEeprom.FM_FrequencyPlaying = gFM_Channels[Channel];
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
gRequestSaveFM = true;
return;
}
}
else if (Channel < 20) {
#ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key;
#endif
gRequestDisplayScreen = DISPLAY_FM;
gInputBoxIndex = 0;
gFM_ChannelPosition = Channel;
return;
}
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = (VOICE_ID_t)Key; gAnotherVoiceID = (VOICE_ID_t)Key;
#endif #endif
} }
else else
@@ -331,8 +319,7 @@ static void Key_DIGITS(KEY_Code_t Key, uint8_t state)
static void Key_FUNC(KEY_Code_t Key, uint8_t state) static void Key_FUNC(KEY_Code_t Key, uint8_t state)
{ {
if (state == BUTTON_EVENT_SHORT || state == BUTTON_EVENT_HELD) if (state == BUTTON_EVENT_SHORT || state == BUTTON_EVENT_HELD) {
{
bool autoScan = gWasFKeyPressed || (state == BUTTON_EVENT_HELD); bool autoScan = gWasFKeyPressed || (state == BUTTON_EVENT_HELD);
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
@@ -348,8 +335,7 @@ static void Key_FUNC(KEY_Code_t Key, uint8_t state)
case KEY_3: case KEY_3:
gEeprom.FM_IsMrMode = !gEeprom.FM_IsMrMode; gEeprom.FM_IsMrMode = !gEeprom.FM_IsMrMode;
if (!FM_ConfigureChannelState()) if (!FM_ConfigureChannelState()) {
{
BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying); BK1080_SetFrequency(gEeprom.FM_FrequencyPlaying);
gRequestSaveFM = true; gRequestSaveFM = true;
} }
@@ -375,12 +361,9 @@ static void Key_EXIT(uint8_t state)
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
if (gFM_ScanState == FM_SCAN_OFF) if (gFM_ScanState == FM_SCAN_OFF) {
{ if (gInputBoxIndex == 0) {
if (gInputBoxIndex == 0) if (!gAskToSave && !gAskToDelete) {
{
if (!gAskToSave && !gAskToDelete)
{
ACTION_FM(); ACTION_FM();
return; return;
} }
@@ -388,38 +371,32 @@ static void Key_EXIT(uint8_t state)
gAskToSave = false; gAskToSave = false;
gAskToDelete = false; gAskToDelete = false;
} }
else else {
{
gInputBox[--gInputBoxIndex] = 10; gInputBox[--gInputBoxIndex] = 10;
if (gInputBoxIndex) if (gInputBoxIndex) {
{ if (gInputBoxIndex != 1) {
if (gInputBoxIndex != 1)
{
gRequestDisplayScreen = DISPLAY_FM; gRequestDisplayScreen = DISPLAY_FM;
return; return;
} }
if (gInputBox[0] != 0) if (gInputBox[0] != 0) {
{
gRequestDisplayScreen = DISPLAY_FM; gRequestDisplayScreen = DISPLAY_FM;
return; return;
} }
} }
gInputBoxIndex = 0; gInputBoxIndex = 0;
} }
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_CANCEL; gAnotherVoiceID = VOICE_ID_CANCEL;
#endif #endif
} }
else else {
{
FM_PlayAndUpdate(); FM_PlayAndUpdate();
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
gAnotherVoiceID = VOICE_ID_SCANNING_STOP; gAnotherVoiceID = VOICE_ID_SCANNING_STOP;
#endif #endif
} }
gRequestDisplayScreen = DISPLAY_FM; gRequestDisplayScreen = DISPLAY_FM;
@@ -434,21 +411,16 @@ static void Key_MENU(uint8_t state)
gRequestDisplayScreen = DISPLAY_FM; gRequestDisplayScreen = DISPLAY_FM;
gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL; gBeepToPlay = BEEP_1KHZ_60MS_OPTIONAL;
if (gFM_ScanState == FM_SCAN_OFF) if (gFM_ScanState == FM_SCAN_OFF) {
{ if (!gEeprom.FM_IsMrMode) {
if (!gEeprom.FM_IsMrMode) if (gAskToSave) {
{
if (gAskToSave)
{
gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying; gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying;
gRequestSaveFM = true; gRequestSaveFM = true;
} }
gAskToSave = !gAskToSave; gAskToSave = !gAskToSave;
} }
else else {
{ if (gAskToDelete) {
if (gAskToDelete)
{
gFM_Channels[gEeprom.FM_SelectedChannel] = 0xFFFF; gFM_Channels[gEeprom.FM_SelectedChannel] = 0xFFFF;
FM_ConfigureChannelState(); FM_ConfigureChannelState();
@@ -456,21 +428,17 @@ static void Key_MENU(uint8_t state)
gRequestSaveFM = true; gRequestSaveFM = true;
} }
gAskToDelete = !gAskToDelete; gAskToDelete = !gAskToDelete;
} }
} }
else else {
{ if (gFM_AutoScan || !gFM_FoundFrequency) {
if (gFM_AutoScan || !gFM_FoundFrequency)
{
gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
gInputBoxIndex = 0; gInputBoxIndex = 0;
return; return;
} }
if (gAskToSave) if (gAskToSave) {
{
gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying; gFM_Channels[gFM_ChannelPosition] = gEeprom.FM_FrequencyPlaying;
gRequestSaveFM = true; gRequestSaveFM = true;
} }
@@ -521,8 +489,7 @@ static void Key_UP_DOWN(uint8_t state, int8_t Step)
if (Frequency < gEeprom.FM_LowerLimit) if (Frequency < gEeprom.FM_LowerLimit)
Frequency = gEeprom.FM_UpperLimit; Frequency = gEeprom.FM_UpperLimit;
else else if (Frequency > gEeprom.FM_UpperLimit)
if (Frequency > gEeprom.FM_UpperLimit)
Frequency = gEeprom.FM_LowerLimit; Frequency = gEeprom.FM_LowerLimit;
gEeprom.FM_FrequencyPlaying = Frequency; gEeprom.FM_FrequencyPlaying = Frequency;
@@ -541,18 +508,8 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
{ {
uint8_t state = bKeyPressed + 2 * bKeyHeld; uint8_t state = bKeyPressed + 2 * bKeyHeld;
switch (Key) switch (Key) {
{ case KEY_0...KEY_9:
case KEY_0:
case KEY_1:
case KEY_2:
case KEY_3:
case KEY_4:
case KEY_5:
case KEY_6:
case KEY_7:
case KEY_8:
case KEY_9:
Key_DIGITS(Key, state); Key_DIGITS(Key, state);
break; break;
case KEY_STAR: case KEY_STAR:
@@ -585,10 +542,8 @@ void FM_ProcessKeys(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld)
void FM_Play(void) void FM_Play(void)
{ {
if (!FM_CheckFrequencyLock(gEeprom.FM_FrequencyPlaying, gEeprom.FM_LowerLimit)) if (!FM_CheckFrequencyLock(gEeprom.FM_FrequencyPlaying, gEeprom.FM_LowerLimit)) {
{ if (!gFM_AutoScan) {
if (!gFM_AutoScan)
{
gFmPlayCountdown_10ms = 0; gFmPlayCountdown_10ms = 0;
gFM_FoundFrequency = true; gFM_FoundFrequency = true;
@@ -605,8 +560,7 @@ void FM_Play(void)
if (gFM_ChannelPosition < 20) if (gFM_ChannelPosition < 20)
gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying; gFM_Channels[gFM_ChannelPosition++] = gEeprom.FM_FrequencyPlaying;
if (gFM_ChannelPosition >= 20) if (gFM_ChannelPosition >= 20) {
{
FM_PlayAndUpdate(); FM_PlayAndUpdate();
GUI_SelectNextDisplay(DISPLAY_FM); GUI_SelectNextDisplay(DISPLAY_FM);
return; return;

View File

@@ -41,6 +41,7 @@ extern bool gFM_FoundFrequency;
extern uint16_t gFM_RestoreCountdown_10ms; extern uint16_t gFM_RestoreCountdown_10ms;
bool FM_CheckValidChannel(uint8_t Channel); bool FM_CheckValidChannel(uint8_t Channel);
// returns first valid channel starting at Channel
uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction); uint8_t FM_FindNextChannel(uint8_t Channel, uint8_t Direction);
int FM_ConfigureChannelState(void); int FM_ConfigureChannelState(void);
void FM_TurnOff(void); void FM_TurnOff(void);

View File

@@ -43,12 +43,10 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
{ {
unsigned int i; unsigned int i;
if (bDoScan) if (bDoScan) {
{
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080); GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
if (!gIsInitBK1080) if (!gIsInitBK1080) {
{
for (i = 0; i < ARRAY_SIZE(BK1080_RegisterTable); i++) for (i = 0; i < ARRAY_SIZE(BK1080_RegisterTable); i++)
BK1080_WriteRegister(i, BK1080_RegisterTable[i]); BK1080_WriteRegister(i, BK1080_RegisterTable[i]);
@@ -61,20 +59,14 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
gIsInitBK1080 = true; gIsInitBK1080 = true;
} }
else else {
{
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201); BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0201);
} }
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F); BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760); BK1080_SetFrequency(Frequency);
SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000);
} }
else else {
{
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0241); BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, 0x0241);
GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080); GPIO_SetBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
} }
@@ -108,11 +100,12 @@ void BK1080_Mute(bool Mute)
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, Mute ? 0x4201 : 0x0201); BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, Mute ? 0x4201 : 0x0201);
} }
void BK1080_SetFrequency(uint16_t Frequency) void BK1080_SetFrequency(uint16_t frequency)
{ {
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760); uint16_t channel = frequency - 760;
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel);
SYSTEM_DelayMs(10); SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000); BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel | 0x8000);
} }
void BK1080_GetFrequencyDeviation(uint16_t Frequency) void BK1080_GetFrequencyDeviation(uint16_t Frequency)

View File

@@ -28,7 +28,7 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan);
uint16_t BK1080_ReadRegister(BK1080_Register_t Register); uint16_t BK1080_ReadRegister(BK1080_Register_t Register);
void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value); void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value);
void BK1080_Mute(bool Mute); void BK1080_Mute(bool Mute);
void BK1080_SetFrequency(uint16_t Frequency); void BK1080_SetFrequency(uint16_t frequency);
void BK1080_GetFrequencyDeviation(uint16_t Frequency); void BK1080_GetFrequencyDeviation(uint16_t Frequency);
#endif #endif

View File

@@ -137,18 +137,13 @@ int I2C_ReadBuffer(void *pBuffer, uint8_t Size)
uint8_t *pData = (uint8_t *)pBuffer; uint8_t *pData = (uint8_t *)pBuffer;
uint8_t i; uint8_t i;
if (Size == 1) {
*pData = I2C_Read(true);
return 1;
}
for (i = 0; i < Size - 1; i++) { for (i = 0; i < Size - 1; i++) {
SYSTICK_DelayUs(1); SYSTICK_DelayUs(1);
pData[i] = I2C_Read(false); pData[i] = I2C_Read(false);
} }
SYSTICK_DelayUs(1); SYSTICK_DelayUs(1);
pData[i++] = I2C_Read(true); pData[i] = I2C_Read(true);
return Size; return Size;
} }

View File

@@ -87,22 +87,19 @@ void SETTINGS_InitEEPROM(void)
{ // 0E88..0E8F { // 0E88..0E8F
struct struct
{ {
uint16_t SelectedFrequency; uint16_t selFreq;
uint8_t SelectedChannel; uint8_t selChn;
uint8_t IsMrMode; uint8_t isMrMode;
uint8_t Padding[8]; } __attribute__((packed)) fmCfg;
} __attribute__((packed)) FM; EEPROM_ReadBuffer(0x0E88, &fmCfg, 4);
EEPROM_ReadBuffer(0x0E88, &FM, 8);
gEeprom.FM_LowerLimit = 760; gEeprom.FM_LowerLimit = 760;
gEeprom.FM_UpperLimit = 1080; gEeprom.FM_UpperLimit = 1080;
if (FM.SelectedFrequency < gEeprom.FM_LowerLimit || FM.SelectedFrequency > gEeprom.FM_UpperLimit) gEeprom.FM_SelectedFrequency =
gEeprom.FM_SelectedFrequency = 960; (fmCfg.selFreq >= gEeprom.FM_LowerLimit && fmCfg.selFreq <= gEeprom.FM_UpperLimit) ? fmCfg.selFreq : 960;
else
gEeprom.FM_SelectedFrequency = FM.SelectedFrequency; gEeprom.FM_SelectedChannel = fmCfg.selChn;
gEeprom.FM_IsMrMode = (fmCfg.isMrMode < 2) ? fmCfg.isMrMode : false;
gEeprom.FM_SelectedChannel = FM.SelectedChannel;
gEeprom.FM_IsMrMode = (FM.IsMrMode < 2) ? FM.IsMrMode : false;
} }
// 0E40..0E67 // 0E40..0E67

View File

@@ -128,9 +128,9 @@ typedef struct {
uint8_t ScreenChannel[2]; // current channels set in the radio (memory or frequency channels) uint8_t ScreenChannel[2]; // current channels set in the radio (memory or frequency channels)
uint8_t FreqChannel[2]; // last frequency channels used uint8_t FreqChannel[2]; // last frequency channels used
uint8_t MrChannel[2]; // last memory channels used uint8_t MrChannel[2]; // last memory channels used
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
uint8_t NoaaChannel[2]; uint8_t NoaaChannel[2];
#endif #endif
// The actual VFO index (0-upper/1-lower) that is now used for RX, // The actual VFO index (0-upper/1-lower) that is now used for RX,
// It is being alternated by dual watch, and flipped by crossband // It is being alternated by dual watch, and flipped by crossband
@@ -143,23 +143,23 @@ typedef struct {
uint8_t field7_0xa; uint8_t field7_0xa;
uint8_t field8_0xb; uint8_t field8_0xb;
#ifdef ENABLE_FMRADIO #ifdef ENABLE_FMRADIO
uint16_t FM_SelectedFrequency; uint16_t FM_SelectedFrequency;
uint8_t FM_SelectedChannel; uint8_t FM_SelectedChannel;
bool FM_IsMrMode; bool FM_IsMrMode;
uint16_t FM_FrequencyPlaying; uint16_t FM_FrequencyPlaying;
uint16_t FM_LowerLimit; uint16_t FM_LowerLimit;
uint16_t FM_UpperLimit; uint16_t FM_UpperLimit;
#endif #endif
uint8_t SQUELCH_LEVEL; uint8_t SQUELCH_LEVEL;
uint8_t TX_TIMEOUT_TIMER; uint8_t TX_TIMEOUT_TIMER;
bool KEY_LOCK; bool KEY_LOCK;
bool VOX_SWITCH; bool VOX_SWITCH;
uint8_t VOX_LEVEL; uint8_t VOX_LEVEL;
#ifdef ENABLE_VOICE #ifdef ENABLE_VOICE
VOICE_Prompt_t VOICE_PROMPT; VOICE_Prompt_t VOICE_PROMPT;
#endif #endif
bool BEEP_CONTROL; bool BEEP_CONTROL;
uint8_t CHANNEL_DISPLAY_MODE; uint8_t CHANNEL_DISPLAY_MODE;
bool TAIL_TONE_ELIMINATION; bool TAIL_TONE_ELIMINATION;
@@ -181,9 +181,9 @@ typedef struct {
uint8_t field38_0x33; uint8_t field38_0x33;
bool AUTO_KEYPAD_LOCK; bool AUTO_KEYPAD_LOCK;
#if defined(ENABLE_ALARM) || defined(ENABLE_TX1750) #if defined(ENABLE_ALARM) || defined(ENABLE_TX1750)
ALARM_Mode_t ALARM_MODE; ALARM_Mode_t ALARM_MODE;
#endif #endif
POWER_OnDisplayMode_t POWER_ON_DISPLAY_MODE; POWER_OnDisplayMode_t POWER_ON_DISPLAY_MODE;
ROGER_Mode_t ROGER; ROGER_Mode_t ROGER;
uint8_t REPEATER_TAIL_TONE_ELIMINATION; uint8_t REPEATER_TAIL_TONE_ELIMINATION;
@@ -225,9 +225,9 @@ typedef struct {
bool PERMIT_REMOTE_KILL; bool PERMIT_REMOTE_KILL;
#endif #endif
int16_t BK4819_XTAL_FREQ_LOW; int16_t BK4819_XTAL_FREQ_LOW;
#ifdef ENABLE_NOAA #ifdef ENABLE_NOAA
bool NOAA_AUTO_SCAN; bool NOAA_AUTO_SCAN;
#endif #endif
uint8_t VOLUME_GAIN; uint8_t VOLUME_GAIN;
uint8_t DAC_GAIN; uint8_t DAC_GAIN;