0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-06-19 06:39:49 +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

102
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_USER_MODE 1
#define STATE_SAVE 2 #define STATE_SAVE 2
if (key_held)
{
if (key_pressed)
return;
return; // no sofiticatedness here - yet
}
if (key_pressed) // beeps cause bad audio clicks anf audio breaks :(
{ // so don't use them
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
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; return;
} }
if (!g_fkey_pressed) if (!g_fkey_pressed && !key_held)
{ { // short key release
uint8_t State; uint8_t State;
if (g_ask_to_delete) 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; 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) 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; 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) 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; g_request_display_screen = DISPLAY_FM;
return; return;
} }
@ -346,7 +349,7 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
return; return;
} }
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; // g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
return; return;
} }
@ -357,7 +360,10 @@ static void FM_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held)
return; return;
} }
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; // with f-key, or long press
// g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
g_fkey_pressed = false; g_fkey_pressed = false;
g_update_status = true; g_update_status = true;
g_request_display_screen = DISPLAY_FM; 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); BK1080_SetFrequency(g_eeprom.fm_frequency_playing);
g_request_save_fm = true; g_request_save_fm = true;
} }
else // else
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; // g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break; break;
default: default:
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; // g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break; break;
} }
} }
@ -390,28 +396,20 @@ static void FM_Key_STAR(bool key_pressed, bool key_held)
{ {
(void)key_held; // stop compiler warning (void)key_held; // stop compiler warning
// if (key_held) if (key_held || key_pressed)
// return;
if (key_pressed)
return; return;
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; // g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
ACTION_Scan(false); ACTION_Scan(false);
} }
static void FM_Key_EXIT(bool key_pressed, bool key_held) static void FM_Key_EXIT(bool key_pressed, bool key_held)
{ {
if (key_held) if (key_held || key_pressed)
{
return;
}
if (key_pressed)
return; 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) 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) static void FM_Key_MENU(bool key_pressed, bool key_held)
{ {
if (key_held) unsigned int i;
{ int channel = -1;
return;
}
if (key_pressed) if (key_held || key_pressed)
return; 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_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) if (g_fm_scan_state == FM_SCAN_OFF)
{ { // not scanning
if (!g_eeprom.fm_is_channel_mode) if (!g_eeprom.fm_is_channel_mode)
{ { // frequency mode
if (g_ask_to_save) if (g_ask_to_save)
{
if (channel < 0)
{ {
g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing; g_fm_channels[g_fm_channel_position] = g_eeprom.fm_frequency_playing;
g_ask_to_save = false; g_ask_to_save = false;
g_request_save_fm = true; g_request_save_fm = true;
} }
}
else else
if (channel < 0)
g_ask_to_save = true; g_ask_to_save = true;
} }
else else
{ { // channel mode
if (g_ask_to_delete) if (g_ask_to_delete)
{ {
g_fm_channels[g_eeprom.fm_selected_channel] = 0xFFFF; 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 else
{ { // scanning
if (g_fm_auto_scan || !g_fm_found_frequency) 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; g_input_box_index = 0;
return; return;
} }
@ -521,6 +528,7 @@ static void FM_Key_MENU(bool key_pressed, bool key_held)
g_request_save_fm = true; g_request_save_fm = true;
} }
else else
if (channel < 0)
g_ask_to_save = true; g_ask_to_save = true;
} }
} }
@ -539,11 +547,11 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step)
{ {
if (g_input_box_index) 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; return;
} }
g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL; // g_beep_to_play = BEEP_1KHZ_60MS_OPTIONAL;
} }
if (g_ask_to_save) if (g_ask_to_save)
@ -557,7 +565,7 @@ static void FM_Key_UP_DOWN(bool key_pressed, bool key_held, int8_t Step)
{ {
if (g_fm_auto_scan) 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; return;
} }
@ -634,8 +642,8 @@ void FM_ProcessKeys(key_code_t Key, bool key_pressed, bool key_held)
GENERIC_Key_PTT(key_pressed); GENERIC_Key_PTT(key_pressed);
break; break;
default: default:
if (!key_held && key_pressed) // if (!key_held && key_pressed)
g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; // g_beep_to_play = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL;
break; break;
} }
} }

View File

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

View File

@ -19,6 +19,7 @@
#include <stdbool.h> #include <stdbool.h>
#include <stdint.h> #include <stdint.h>
#include "driver/bk1080-regs.h" #include "driver/bk1080-regs.h"
extern uint16_t BK1080_BaseFrequency; extern uint16_t BK1080_BaseFrequency;

View File

@ -804,7 +804,8 @@ void BK4819_SetAF(BK4819_af_type_t AF)
// AF Output Inverse Mode = Inverse // AF Output Inverse Mode = Inverse
// Undocumented bits 0x2040 // 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) void BK4819_RX_TurnOn(void)
@ -1034,6 +1035,7 @@ void BK4819_PlaySingleTone(const unsigned int tone_Hz, const unsigned int delay,
{ {
GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH); GPIO_ClearBit(&GPIOC->DATA, GPIOC_PIN_AUDIO_PATH);
BK4819_SetAF(BK4819_AF_MUTE); BK4819_SetAF(BK4819_AF_MUTE);
// BK4819_SetAF(g_rx_vfo->am_mode ? BK4819_AF_AM : BK4819_AF_FM);
} }
BK4819_WriteRegister(BK4819_REG_70, 0x0000); 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 enum BK4819_filter_bandwidth_e
{ {
BK4819_FILTER_BW_WIDE = 0, BK4819_FILTER_BW_WIDE = 0, // 25kHz
BK4819_FILTER_BW_NARROW, BK4819_FILTER_BW_NARROW, // 12.5kHz
BK4819_FILTER_BW_NARROWER BK4819_FILTER_BW_NARROWER // 6.25kHz
}; };
typedef enum BK4819_filter_bandwidth_e BK4819_filter_bandwidth_t; typedef enum BK4819_filter_bandwidth_e BK4819_filter_bandwidth_t;

Binary file not shown.

Binary file not shown.