0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-28 22:31:25 +03:00

update mic gain code

This commit is contained in:
OneOfEleven 2023-10-30 16:28:41 +00:00
parent 1517cfc655
commit e63672521c
14 changed files with 136 additions and 101 deletions

View File

@ -95,7 +95,7 @@ static void APP_update_rssi(const int vfo)
g_current_rssi[vfo] = rssi;
if (g_squelch_open || g_monitor_enabled)
// if (g_squelch_open || g_monitor_enabled)
UI_update_rssi(rssi, vfo);
}
@ -987,6 +987,9 @@ void APP_process_radio_interrupts(void)
UART_SendText("sq close\r\n");
#endif
//APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
g_update_display = true;
}
@ -998,6 +1001,9 @@ void APP_process_radio_interrupts(void)
UART_SendText("sq open\r\n");
#endif
//APP_update_rssi(g_eeprom.rx_vfo);
g_update_rssi = true;
if (g_monitor_enabled)
BK4819_set_GPIO_pin(BK4819_GPIO6_PIN2_GREEN, true); // LED on
@ -2360,14 +2366,14 @@ void APP_time_slice_10ms(void)
APP_process_transmit();
#ifdef ENABLE_FMRADIO
if (g_schedule_fm &&
if (g_fm_schedule &&
g_fm_scan_state_dir != FM_SCAN_STATE_DIR_OFF &&
!g_monitor_enabled &&
g_current_function != FUNCTION_RECEIVE &&
g_current_function != FUNCTION_TRANSMIT)
{ // switch to FM radio mode
FM_scan();
g_schedule_fm = false;
g_fm_schedule = false;
}
#endif

View File

@ -40,8 +40,6 @@
uint16_t g_fm_channels[20];
bool g_fm_radio_mode;
uint8_t g_fm_radio_tick_500ms;
volatile uint16_t g_fm_play_tick_10ms;
fm_scan_state_dir_t g_fm_scan_state_dir;
bool g_fm_auto_scan;
uint8_t g_fm_channel_position;
@ -49,6 +47,9 @@ bool g_fm_found_frequency;
bool g_fm_auto_scan;
uint8_t g_fm_resume_tick_500ms;
uint16_t g_fm_restore_tick_10ms;
uint8_t g_fm_radio_tick_500ms;
volatile uint16_t g_fm_play_tick_10ms;
volatile bool g_fm_schedule;
bool FM_check_valid_channel(const unsigned int Channel)
{
@ -115,7 +116,7 @@ void FM_tune(uint16_t frequency, const fm_scan_state_dir_t scan_state_dir, const
g_fm_play_tick_10ms = (g_fm_scan_state_dir == FM_SCAN_STATE_DIR_OFF) ? fm_play_noscan_10ms : fm_play_scan_10ms;
g_schedule_fm = false;
g_fm_schedule = false;
g_fm_found_frequency = false;
g_ask_to_save = false;
g_ask_to_delete = false;
@ -157,7 +158,7 @@ void FM_stop_scan(void)
SETTINGS_save_fm();
g_fm_play_tick_10ms = 0;
g_schedule_fm = false;
g_fm_schedule = false;
g_ask_to_save = false;
g_speaker_enabled = true;

View File

@ -31,8 +31,6 @@ typedef enum fm_scan_state_dir_e fm_scan_state_dir_t;
extern uint16_t g_fm_channels[20];
extern bool g_fm_radio_mode;
extern uint8_t g_fm_radio_tick_500ms;
extern volatile uint16_t g_fm_play_tick_10ms;
extern fm_scan_state_dir_t g_fm_scan_state_dir;
extern bool g_fm_auto_scan;
extern uint8_t g_fm_channel_position;
@ -42,6 +40,9 @@ extern bool g_fm_found_frequency;
extern bool g_fm_auto_scan;
extern uint8_t g_fm_resume_tick_500ms;
extern uint16_t g_fm_restore_tick_10ms;
extern uint8_t g_fm_radio_tick_500ms;
extern volatile uint16_t g_fm_play_tick_10ms;
extern volatile bool g_fm_schedule;
bool FM_check_valid_channel(const unsigned int Channel);
unsigned int FM_find_next_channel(unsigned int Channel, const fm_scan_state_dir_t scan_state_dir);

View File

@ -660,7 +660,9 @@ void MENU_AcceptSetting(void)
case MENU_MIC_GAIN:
g_eeprom.mic_sensitivity = g_sub_menu_selection;
BOARD_eeprom_loadCalibration();
// BOARD_eeprom_loadCalibration();
g_eeprom.mic_sensitivity_tuning = g_mic_gain_dB_2[g_eeprom.mic_sensitivity];
BK4819_set_mic_gain(g_eeprom.mic_sensitivity_tuning);
g_flag_reconfigure_vfos = true;
break;

View File

@ -113,29 +113,35 @@ void BK1080_Init(const uint16_t frequency, const bool initialise)
// determine the lower and upper frequency limits when multiple bands are used
BK1080_freq_lower = 0xffff;
BK1080_freq_upper = 0;
for (i = 0; i < ARRAY_SIZE(FM_RADIO_FREQ_BAND_TABLE); i++)
if (!is_init)
{
const uint16_t lower = FM_RADIO_FREQ_BAND_TABLE[i].lower;
const uint16_t upper = FM_RADIO_FREQ_BAND_TABLE[i].upper;
BK1080_freq_lower = 0xffff;
BK1080_freq_upper = 0;
if (BK1080_freq_lower > lower)
BK1080_freq_lower = lower;
// if (BK1080_freq_lower > upper)
// BK1080_freq_lower = upper;
// if (BK1080_freq_upper < lower)
// BK1080_freq_upper = lower;
if (BK1080_freq_upper < upper)
BK1080_freq_upper = upper;
for (i = 0; i < ARRAY_SIZE(FM_RADIO_FREQ_BAND_TABLE); i++)
{
const uint16_t lower = FM_RADIO_FREQ_BAND_TABLE[i].lower;
const uint16_t upper = FM_RADIO_FREQ_BAND_TABLE[i].upper;
if (BK1080_freq_lower > lower)
BK1080_freq_lower = lower;
// if (BK1080_freq_lower > upper)
// BK1080_freq_lower = upper;
// if (BK1080_freq_upper < lower)
// BK1080_freq_upper = lower;
if (BK1080_freq_upper < upper)
BK1080_freq_upper = upper;
}
}
#else
// only 1 band is used
BK1080_freq_lower = FM_RADIO_FREQ_BAND_TABLE[0].lower;
BK1080_freq_upper = FM_RADIO_FREQ_BAND_TABLE[0].upper;
if (!is_init)
{
BK1080_freq_lower = FM_RADIO_FREQ_BAND_TABLE[0].lower;
BK1080_freq_upper = FM_RADIO_FREQ_BAND_TABLE[0].upper;
}
#endif
if (initialise)
@ -161,6 +167,8 @@ void BK1080_Init(const uint16_t frequency, const bool initialise)
{
BK1080_WriteRegister(BK1080_REG_02_POWER_CONFIGURATION, (1u << 9) | (1u << 0));
}
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, 0x0A5F); // 0000 1010 0101 1111
BK1080_SetFrequency(frequency);
}
@ -218,14 +226,15 @@ void BK1080_SetFrequency(uint16_t Frequency)
Frequency = BK1080_freq_lower;
// return;
}
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (SEEK_THRESHOLD << 8) | (band << 6) | (CHAN_SPACING << 4) | (VOLUME << 0));
#endif
channel = Frequency - FM_RADIO_FREQ_BAND_TABLE[band].lower; // 100kHz channel spacing
BK1080_WriteRegister(BK1080_REG_05_SYSTEM_CONFIGURATION2, (SEEK_THRESHOLD << 8) | (band << 6) | (CHAN_SPACING << 4) | (VOLUME << 0));
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel);
SYSTEM_DelayMs(1);
BK1080_WriteRegister(BK1080_REG_03_CHANNEL, channel | (1u << 15));
}

View File

@ -280,8 +280,9 @@ void BK4819_DisableAGC(void)
// <2:0> 0b110 DC Filter Band Width for Rx (IF In).
// 000=Bypass DC filter;
//
BK4819_WriteRegister(0x7E,
(1u << 15) | // 0 AGC fix mode
BK4819_WriteRegister(0x7E, // 0x302E 0 011 000000 101 110
// (1u << 15) | // 0 AGC fix mode
(0u << 15) | // 0 AGC fix mode
(3u << 12) | // 3 AGC fix index
(5u << 3) | // 5 DC Filter band width for Tx (MIC In)
(6u << 0)); // 6 DC Filter band width for Rx (I.F In)
@ -330,63 +331,61 @@ void BK4819_DisableAGC(void)
BK4819_WriteRegister(0x10, 0x007A); // 000000 00 011 11 010
BK4819_WriteRegister(0x14, 0x0019); // 000000 00 000 11 001
// ??
// ???
BK4819_WriteRegister(0x49, 0x2A38);
BK4819_WriteRegister(0x7B, 0x8420);
}
#ifndef ENABLE_AM_FIX
void BK4819_EnableAGC(void)
{
// TODO: See if this attenuates overloading
// signals as well as boosting weak ones
//
// REG_7E
//
// <15> 0 AGC Fix Mode.
// 1=Fix; 0=Auto.
//
// <14:12> 0b011 AGC Fix Index.
// 011=Max, then 010,001,000,111,110,101,100(min).
//
// <5:3> 0b101 DC Filter Band Width for Tx (MIC In).
// 000=Bypass DC filter;
//
// <2:0> 0b110 DC Filter Band Width for Rx (IF In).
// 000=Bypass DC filter;
BK4819_WriteRegister(0x7E,
(0u << 15) | // 0 AGC fix mode
(3u << 12) | // 3 AGC fix index
(5u << 3) | // 5 DC Filter band width for Tx (MIC In)
(6u << 0)); // 6 DC Filter band width for Rx (I.F In)
// TBR: fagci has this listed as two values, agc_rssi and lna_peak_rssi
// This is why AGC appeared to do nothing as-is for Rx
//
// REG_62
//
// <15:8> 0xFF AGC RSSI
//
// <7:0> 0xFF LNA Peak RSSI
//
// TBR: Using S9+30 (173) and S9 (143) as suggested values
BK4819_WriteRegister(0x62, (173u << 8) | (143u << 0));
// AGC auto-adjusts the following LNA values, no need to set them ourselves
//BK4819_WriteRegister(0x13, (3u << 8) | (5u << 5) | (3u << 3) | (6u << 0)); // 000000 11 101 11 110
//BK4819_WriteRegister(0x12, 0x037B); // 000000 11 011 11 011
//BK4819_WriteRegister(0x11, 0x027B); // 000000 10 011 11 011
//BK4819_WriteRegister(0x10, 0x007A); // 000000 00 011 11 010
//BK4819_WriteRegister(0x14, 0x0019); // 000000 00 000 11 001
BK4819_WriteRegister(0x49, 0x2A38);
BK4819_WriteRegister(0x7B, 0x8420);
for (unsigned int i = 0; i < 8; i++)
BK4819_WriteRegister(0x06, ((i & 7u) << 13) | (0x4A << 7) | (0x36 << 0));
}
#endif
void BK4819_EnableAGC(void)
{
// TODO: See if this attenuates overloading
// signals as well as boosting weak ones
//
// REG_7E
//
// <15> 0 AGC Fix Mode.
// 1=Fix; 0=Auto.
//
// <14:12> 0b011 AGC Fix Index.
// 011=Max, then 010,001,000,111,110,101,100(min).
//
// <5:3> 0b101 DC Filter Band Width for Tx (MIC In).
// 000=Bypass DC filter;
//
// <2:0> 0b110 DC Filter Band Width for Rx (IF In).
// 000=Bypass DC filter;
BK4819_WriteRegister(0x7E,
(0u << 15) | // 0 AGC fix mode
(3u << 12) | // 3 AGC fix index
(5u << 3) | // 5 DC Filter band width for Tx (MIC In)
(6u << 0)); // 6 DC Filter band width for Rx (I.F In)
// TBR: fagci has this listed as two values, agc_rssi and lna_peak_rssi
// This is why AGC appeared to do nothing as-is for Rx
//
// REG_62
//
// <15:8> 0xFF AGC RSSI
//
// <7:0> 0xFF LNA Peak RSSI
//
// TBR: Using S9+30 (173) and S9 (143) as suggested values
BK4819_WriteRegister(0x62, (173u << 8) | (143u << 0));
// AGC auto-adjusts the following LNA values, no need to set them ourselves
//BK4819_WriteRegister(0x13, (3u << 8) | (5u << 5) | (3u << 3) | (6u << 0)); // 000000 11 101 11 110
//BK4819_WriteRegister(0x12, 0x037B); // 000000 11 011 11 011
//BK4819_WriteRegister(0x11, 0x027B); // 000000 10 011 11 011
//BK4819_WriteRegister(0x10, 0x007A); // 000000 00 011 11 010
//BK4819_WriteRegister(0x14, 0x0019); // 000000 00 000 11 001
BK4819_WriteRegister(0x49, 0x2A38);
BK4819_WriteRegister(0x7B, 0x8420);
for (unsigned int i = 0; i < 8; i++)
BK4819_WriteRegister(0x06, ((i & 7u) << 13) | (0x4A << 7) | (0x36 << 0));
}
void BK4819_set_GPIO_pin(bk4819_gpio_pin_t Pin, bool bSet)
{
@ -1074,12 +1073,12 @@ void BK4819_StartTone1(const uint16_t frequency, const unsigned int level, const
BK4819_REG_30_ENABLE_VCO_CALIB |
BK4819_REG_30_ENABLE_UNKNOWN |
// BK4819_REG_30_ENABLE_RX_LINK |
BK4819_REG_30_ENABLE_AF_DAC |
BK4819_REG_30_ENABLE_DISC_MODE |
BK4819_REG_30_ENABLE_AF_DAC | //
BK4819_REG_30_ENABLE_DISC_MODE | //
BK4819_REG_30_ENABLE_PLL_VCO |
BK4819_REG_30_ENABLE_PA_GAIN |
// BK4819_REG_30_ENABLE_MIC_ADC |
BK4819_REG_30_ENABLE_TX_DSP |
BK4819_REG_30_ENABLE_TX_DSP | //
// BK4819_REG_30_ENABLE_RX_DSP |
0);
}
@ -1124,7 +1123,7 @@ void BK4819_StopTones(const bool tx)
{
BK4819_WriteRegister(0x30,
BK4819_REG_30_ENABLE_VCO_CALIB |
BK4819_REG_30_ENABLE_UNKNOWN |
// BK4819_REG_30_ENABLE_UNKNOWN |
BK4819_REG_30_ENABLE_RX_LINK |
BK4819_REG_30_ENABLE_AF_DAC |
BK4819_REG_30_ENABLE_DISC_MODE |
@ -1192,6 +1191,16 @@ void BK4819_Sleep(void)
BK4819_WriteRegister(0x37, 0x1D00); // 0 0 0111 0 1 0000 0 0 0 0
}
void BK4819_set_mic_gain(unsigned int level)
{
if (level > 31)
level = 31;
// mic gain 0.5dB/step 0 to 31
BK4819_WriteRegister(0x7D, 0xE940 | level);
// BK4819_WriteRegister(0x19, 0x1041); // 0001 0000 0100 0001 <15> MIC AGC 1 = disable 0 = enable .. doesn't work
}
void BK4819_TurnsOffTones_TurnsOnRX(void)
{
BK4819_WriteRegister(0x70, 0);

View File

@ -108,6 +108,7 @@ void BK4819_StopTones(const bool tx);
void BK4819_PlayTone(const unsigned int tone_Hz, const unsigned int delay, const unsigned int level);
void BK4819_EnterTxMute(void);
void BK4819_ExitTxMute(void);
void BK4819_set_mic_gain(unsigned int level);
void BK4819_Sleep(void);
void BK4819_TurnsOffTones_TurnsOnRX(void);

Binary file not shown.

Binary file not shown.

2
main.c
View File

@ -115,6 +115,8 @@ void Main(void)
BOARD_eeprom_loadCalibration();
BK4819_set_mic_gain(g_eeprom.mic_sensitivity_tuning);
RADIO_configure_channel(0, VFO_CONFIGURE_RELOAD);
RADIO_configure_channel(1, VFO_CONFIGURE_RELOAD);

3
misc.c
View File

@ -261,9 +261,6 @@ volatile bool g_next_time_slice_40ms;
volatile bool g_schedule_noaa = true;
#endif
volatile bool g_flag_tail_tone_elimination_complete;
#ifdef ENABLE_FMRADIO
volatile bool g_schedule_fm;
#endif
volatile uint16_t g_boot_tick_10ms = 4000 / 10; // 4 seconds

3
misc.h
View File

@ -346,9 +346,6 @@ extern volatile bool g_next_time_slice_40ms;
extern volatile bool g_schedule_noaa;
#endif
extern volatile bool g_flag_tail_tone_elimination_complete;
#ifdef ENABLE_FMRADIO
extern volatile bool g_schedule_fm;
#endif
extern int16_t g_current_rssi[2]; // now one per VFO
extern volatile uint16_t g_boot_tick_10ms;

18
radio.c
View File

@ -665,6 +665,20 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
break;
}
BK4819_WriteRegister(0x30, 0);
BK4819_WriteRegister(0x30,
BK4819_REG_30_ENABLE_VCO_CALIB |
// BK4819_REG_30_ENABLE_UNKNOWN |
BK4819_REG_30_ENABLE_RX_LINK |
BK4819_REG_30_ENABLE_AF_DAC |
BK4819_REG_30_ENABLE_DISC_MODE |
BK4819_REG_30_ENABLE_PLL_VCO |
// BK4819_REG_30_ENABLE_PA_GAIN |
// BK4819_REG_30_ENABLE_MIC_ADC |
// BK4819_REG_30_ENABLE_TX_DSP |
BK4819_REG_30_ENABLE_RX_DSP |
0);
BK4819_set_GPIO_pin(BK4819_GPIO5_PIN1_RED, false); // LED off
BK4819_SetupPowerAmplifier(0, 0);
BK4819_set_GPIO_pin(BK4819_GPIO1_PIN29_PA_ENABLE, false); // PA off
@ -679,10 +693,6 @@ void RADIO_setup_registers(bool switch_to_function_foreground)
}
BK4819_WriteRegister(0x3F, 0); // disable interrupts
// mic gain 0.5dB/step 0 to 31
BK4819_WriteRegister(0x7D, 0xE940 | (g_eeprom.mic_sensitivity_tuning & 0x1f));
// BK4819_WriteRegister(0x19, 0x1041); // 0001 0000 0100 0001 <15> MIC AGC 1 = disable 0 = enable .. doesn't work
#ifdef ENABLE_NOAA
if (IS_NOAA_CHANNEL(g_rx_vfo->channel_save) && g_is_noaa_mode)
Frequency = NOAA_FREQUENCY_TABLE[g_noaa_channel];

View File

@ -115,7 +115,7 @@ void SystickHandler(void)
g_current_function != FUNCTION_TRANSMIT &&
g_current_function != FUNCTION_RECEIVE)
{
DECREMENT_AND_TRIGGER(g_fm_play_tick_10ms, g_schedule_fm);
DECREMENT_AND_TRIGGER(g_fm_play_tick_10ms, g_fm_schedule);
}
#endif