0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 06:11:24 +03:00

Fixed FM radio key presses, now nice to use the FM radio

This commit is contained in:
OneOfEleven 2023-10-11 17:22:34 +01:00
parent 46a082ef05
commit 2f076587b4
7 changed files with 83 additions and 76 deletions

114
app/fm.c
View File

@ -230,27 +230,30 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
#define STATE_USER_MODE 1
#define STATE_SAVE 2
if (key_held)
{
if (key_pressed)
return;
return; // no sofiticatedness here - yet
}
if (key_pressed)
{
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// beeps cause bad audio clicks anf audio breaks :(
// so don't use them
g_key_input_count_down = key_input_timeout_500ms;
if (key_held && !key_pressed)
return; // key just released after long press
if (!key_held && key_pressed)
{ // key just pressed
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
return;
}
if (!g_fkey_pressed)
{
if (!g_fkey_pressed && !key_held)
{ // short key release
uint8_t State;
if (g_ask_to_delete)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
@ -262,7 +265,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
{
if (g_fm_scan_state != FM_SCAN_OFF)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
@ -295,7 +298,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
if (Frequency < g_eeprom.fm_lower_limit || g_eeprom.fm_upper_limit < Frequency)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
g_request_display_screen = DISPLAY_FM;
return;
}
@ -346,7 +349,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
return;
}
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
@ -356,8 +359,11 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
return;
}
// with f-key, or long press
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
g_fkey_pressed = false;
g_update_status = true;
g_request_display_screen = DISPLAY_FM;
@ -376,12 +382,12 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
BK1080_SetFrequency(g_eeprom.fm_frequency_playing);
g_request_save_fm = true;
}
else
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// else
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
default:
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
}
@ -390,28 +396,20 @@ static void FM_Key_STAR(bool key_pressed, bool key_held)
{
(void)key_held; // stop compiler warning
// if (key_held)
// return;
if (key_pressed)
if (key_held || key_pressed)
return;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
ACTION_Scan(false);
}
static void FM_Key_EXIT(bool key_pressed, bool key_held)
{
if (key_held)
{
return;
}
if (key_pressed)
if (key_held || key_pressed)
return;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
if (g_fm_scan_state == FM_SCAN_OFF)
{
@ -465,32 +463,41 @@ static void FM_Key_EXIT(bool key_pressed, bool key_held)
static void FM_Key_MENU(bool key_pressed, bool key_held)
{
if (key_held)
{
return;
}
unsigned int i;
int channel = -1;
if (key_pressed)
if (key_held || key_pressed)
return;
// see if the frequency is already stored in a channel
for (i = 0; i < ARRAY_SIZE(g_fm_channels) && channel < 0; i++)
if (g_fm_channels[i] == g_eeprom.fm_frequency_playing)
channel = i; // found it in the channel list
g_request_display_screen = DISPLAY_FM;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
if (g_fm_scan_state == FM_SCAN_OFF)
{
{ // not scanning
if (!g_eeprom.fm_is_channel_mode)
{
{ // frequency mode
if (g_ask_to_save)
{
g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing;
g_ask_to_save = false;
g_request_save_fm = true;
if (channel < 0)
{
g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing;
g_ask_to_save = false;
g_request_save_fm = true;
}
}
else
if (channel < 0)
g_ask_to_save = true;
}
else
{
{ // channel mode
if (g_ask_to_delete)
{
g_fm_channels[g_eeprom.fm_selected_channel] = 0xFFFF;
@ -506,10 +513,10 @@ static void FM_Key_MENU(bool key_pressed, bool key_held)
}
}
else
{
{ // scanning
if (g_fm_auto_scan || !g_fm_found_frequency)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
g_input_box_index = 0;
return;
}
@ -521,6 +528,7 @@ static void FM_Key_MENU(bool key_pressed, bool key_held)
g_request_save_fm = true;
}
else
if (channel < 0)
g_ask_to_save = true;
}
}
@ -539,17 +547,17 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step)
{
if (g_input_box_index)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
}
if (g_ask_to_save)
{
g_request_display_screen = DISPLAY_FM;
g_fm_channel_position = NUMBER_AddWithWraparound(g_fm_channel_position, Step, 0, 19);
g_fm_channel_position = NUMBER_AddWithWraparound(g_fm_channel_position, Step, 0, 19);
return;
}
@ -557,7 +565,7 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step)
{
if (g_fm_auto_scan)
{
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return;
}
@ -634,8 +642,8 @@ void FM_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held)
GENERIC_Key_PTT(key_pressed);
break;
default:
if (!key_held && key_pressed)
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
// if (!key_held && key_pressed)
// g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break;
}
}

View File

@ -34,8 +34,7 @@ static const uint16_t BK1080_RegisterTable[] =
0x0200, 0x0000,
};
static bool gIsInitBK1080;
bool is_init;
uint16_t BK1080_BaseFrequency;
uint16_t BK1080_FrequencyDeviation;
@ -47,7 +46,7 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
{
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BK1080);
if (!gIsInitBK1080)
if (!is_init)
{
for (i = 0; i < ARRAY_SIZE(BK1080_RegisterTable); i++)
BK1080_WriteRegister(i, BK1080_RegisterTable[i]);
@ -59,7 +58,7 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
SYSTEM_DelayMs(60);
gIsInitBK1080 = true;
is_init = true;
}
else
{
@ -67,11 +66,9 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
}
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760);
SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760);
// SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | (1u << 15));
}
else
{
@ -83,7 +80,6 @@ void BK1080_Init(uint16_t Frequency, bool bDoScan)
uint16_t BK1080_ReadRegister(BK1080_Register_t Register)
{
uint8_t Value[2];
I2C_Start();
I2C_Write(0x80);
I2C_Write((Register << 1) | I2C_READ);
@ -110,9 +106,9 @@ void BK1080_Mute(bool Mute)
void BK1080_SetFrequency(uint16_t Frequency)
{
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760);
SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | 0x8000);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, Frequency - 760);
// SYSTEM_DelayMs(10);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, (Frequency - 760) | (1u << 15));
}
void BK1080_GetFrequencyDeviation(uint16_t Frequency)

View File

@ -19,17 +19,18 @@
#include <stdbool.h>
#include <stdint.h>
#include "driver/bk1080-regs.h"
extern uint16_t BK1080_BaseFrequency;
extern uint16_t BK1080_FrequencyDeviation;
void BK1080_Init(uint16_t Frequency, bool bDoScan);
void BK1080_Init(uint16_t Frequency, bool bDoScan);
uint16_t BK1080_ReadRegister(BK1080_Register_t Register);
void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value);
void BK1080_Mute(bool Mute);
void BK1080_SetFrequency(uint16_t Frequency);
void BK1080_GetFrequencyDeviation(uint16_t Frequency);
void BK1080_WriteRegister(BK1080_Register_t Register, uint16_t Value);
void BK1080_Mute(bool Mute);
void BK1080_SetFrequency(uint16_t Frequency);
void BK1080_GetFrequencyDeviation(uint16_t Frequency);
#endif

View File

@ -804,7 +804,8 @@ void BK4819_SetAF(BK4819_af_type_t AF)
// AF Output Inverse Mode = Inverse
// Undocumented bits 0x2040
//
BK4819_WriteRegister(BK4819_REG_47, 0x6040 | (AF << 8));
// BK4819_WriteRegister(BK4819_REG_47, 0x6040 | (AF << 8));
BK4819_WriteRegister(BK4819_REG_47, (6u << 12) | (AF << 8) | (1u << 6));
}
void BK4819_RX_TurnOn(void)
@ -823,7 +824,7 @@ void BK4819_RX_TurnOn(void)
// Enable XTAL
// Enable Band Gap
//
BK4819_WriteRegister(BK4819_REG_37, 0x1F0F); // 0001111100001111
BK4819_WriteRegister(BK4819_REG_37, 0x1F0F); // 0001 1111 0000 1111
// Turn off everything
BK4819_WriteRegister(BK4819_REG_30, 0);
@ -1034,6 +1035,7 @@ void BK4819_PlaySingleTone(const unsigned int tone_Hz, const unsigned int delay,
{
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
BK4819_SetAF(BK4819_AF_MUTE);
// BK4819_SetAF(g_rx_vfo->am_mode ? BK4819_AF_AM : BK4819_AF_FM);
}
BK4819_WriteRegister(BK4819_REG_70, 0x0000);

View File

@ -45,9 +45,9 @@ typedef enum BK4819_af_type_e BK4819_af_type_t;
enum BK4819_filter_bandwidth_e
{
BK4819_FILTER_BW_WIDE = 0,
BK4819_FILTER_BW_NARROW,
BK4819_FILTER_BW_NARROWER
BK4819_FILTER_BW_WIDE = 0, // 25kHz
BK4819_FILTER_BW_NARROW, // 12.5kHz
BK4819_FILTER_BW_NARROWER // 6.25kHz
};
typedef enum BK4819_filter_bandwidth_e BK4819_filter_bandwidth_t;

Binary file not shown.

Binary file not shown.