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

fixed VFO freq/band bug

This commit is contained in:
OneOfEleven 2023-11-05 05:09:01 +00:00
parent 29a77d111b
commit 359fa3bf47
11 changed files with 94 additions and 111 deletions

View File

@ -29,7 +29,7 @@ ENABLE_NOAA := 0
ENABLE_VOICE := 0 ENABLE_VOICE := 0
ENABLE_MUTE_RADIO_FOR_VOICE := 0 ENABLE_MUTE_RADIO_FOR_VOICE := 0
# Tx on Voice 1.0 kB # Tx on Voice 1.0 kB
ENABLE_VOX := 0 ENABLE_VOX := 1
ENABLE_VOX_MORE_SENSITIVE := 1 ENABLE_VOX_MORE_SENSITIVE := 1
ENABLE_REDUCE_LOW_MID_TX_POWER := 1 ENABLE_REDUCE_LOW_MID_TX_POWER := 1
# Tx Alarm 600 B # Tx Alarm 600 B

View File

@ -194,7 +194,6 @@ void toggle_chan_scanlist(void)
void processFKeyFunction(const key_code_t Key) void processFKeyFunction(const key_code_t Key)
{ {
uint8_t Band;
uint8_t vfo = g_eeprom.config.setting.tx_vfo_num; uint8_t vfo = g_eeprom.config.setting.tx_vfo_num;
if (g_current_function == FUNCTION_TRANSMIT || g_current_display_screen == DISPLAY_MENU) if (g_current_function == FUNCTION_TRANSMIT || g_current_display_screen == DISPLAY_MENU)
@ -245,23 +244,28 @@ void processFKeyFunction(const key_code_t Key)
APP_stop_scan(); APP_stop_scan();
Band = g_tx_vfo->channel_attributes.band + 1;
if (g_eeprom.config.setting.enable_350 || Band != BAND5_350MHz)
{ {
if (Band > BAND7_470MHz) unsigned int band = g_tx_vfo->channel_attributes.band;
Band = BAND1_50MHz; // wrap-a-round
}
else
Band = BAND6_400MHz; // jump to next band
g_tx_vfo->channel_attributes.band = Band;
g_eeprom.config.setting.indices.vfo[vfo].screen = FREQ_CHANNEL_FIRST + Band; #if defined(ENABLE_UART) && defined(ENABLE_UART_DEBUG)
g_eeprom.config.setting.indices.vfo[vfo].frequency = FREQ_CHANNEL_FIRST + Band; UART_printf("band %u\r\n", band);
#endif
if (++band > BAND7_470MHz)
band = BAND1_50MHz;
if (!g_eeprom.config.setting.enable_350 && band == BAND5_350MHz)
band = BAND6_400MHz; // jump to next band
g_tx_vfo->channel_attributes.band = band;
g_eeprom.config.setting.indices.vfo[vfo].screen = FREQ_CHANNEL_FIRST + band;
g_eeprom.config.setting.indices.vfo[vfo].frequency = FREQ_CHANNEL_FIRST + band;
}
g_request_save_vfo = true; g_request_save_vfo = true;
g_vfo_configure_mode = VFO_CONFIGURE_RELOAD; g_vfo_configure_mode = VFO_CONFIGURE_RELOAD;
g_request_display_screen = DISPLAY_MAIN; g_request_display_screen = DISPLAY_MAIN;
break; break;
case KEY_2: // A/B case KEY_2: // A/B

View File

@ -56,31 +56,31 @@ uint8_t I2C_Read_fast(bool bFinal)
for (i = 0; i < 8; i++) for (i = 0; i < 8; i++)
{ {
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
Data <<= 1; Data <<= 1;
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA)) if (GPIO_CheckBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA))
Data |= 1U; Data |= 1U;
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
} }
PORTCON_PORTA_IE &= ~PORTCON_PORTA_IE_A11_MASK; PORTCON_PORTA_IE &= ~PORTCON_PORTA_IE_A11_MASK;
PORTCON_PORTA_OD |= PORTCON_PORTA_OD_A11_BITS_ENABLE; PORTCON_PORTA_OD |= PORTCON_PORTA_OD_A11_BITS_ENABLE;
GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT; GPIOA->DIR |= GPIO_DIR_11_BITS_OUTPUT;
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
if (bFinal) if (bFinal)
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
else else
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SDA);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_SetBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL); GPIO_ClearBit(&GPIOA->DATA, GPIOA_PIN_I2C_SCL);
SYSTICK_Delay250ns(1); SYSTICK_Delay250ns(2);
return Data; return Data;
} }

Binary file not shown.

Binary file not shown.

2
misc.c
View File

@ -90,8 +90,6 @@ bool g_monitor_enabled;
bool g_has_aes_key; bool g_has_aes_key;
uint32_t g_challenge[4]; uint32_t g_challenge[4];
uint16_t g_eeprom_rssi_calib[7][4];
volatile uint16_t g_schedule_power_save_tick_10ms = battery_save_count_10ms; volatile uint16_t g_schedule_power_save_tick_10ms = battery_save_count_10ms;
volatile bool g_schedule_power_save; volatile bool g_schedule_power_save;

2
misc.h
View File

@ -183,8 +183,6 @@ extern const uint32_t g_default_aes_key[4];
extern bool g_has_aes_key; extern bool g_has_aes_key;
extern uint32_t g_challenge[4]; extern uint32_t g_challenge[4];
extern uint16_t g_eeprom_rssi_calib[7][4];
extern volatile uint16_t g_schedule_power_save_tick_10ms; extern volatile uint16_t g_schedule_power_save_tick_10ms;
extern volatile bool g_schedule_power_save; extern volatile bool g_schedule_power_save;

View File

@ -350,9 +350,9 @@ void RADIO_configure_channel(const unsigned int VFO, const unsigned int configur
RADIO_ConfigureSquelchAndOutputPower(p_vfo); RADIO_ConfigureSquelchAndOutputPower(p_vfo);
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
AM_fix_reset(VFO);
if (p_vfo->channel.am_mode > 0 && g_eeprom.config.setting.am_fix) if (p_vfo->channel.am_mode > 0 && g_eeprom.config.setting.am_fix)
{ {
AM_fix_reset(VFO);
AM_fix_10ms(VFO); AM_fix_10ms(VFO);
} }
else else

View File

@ -329,7 +329,6 @@ void SETTINGS_read_eeprom(void)
// EEPROM cleaning // EEPROM cleaning
#if 1 #if 1
memset(&g_eeprom.config.unused13, 0xff, sizeof(g_eeprom.config.unused13)); memset(&g_eeprom.config.unused13, 0xff, sizeof(g_eeprom.config.unused13));
memset(&g_eeprom.unused, 0xff, sizeof(g_eeprom.unused)); memset(&g_eeprom.unused, 0xff, sizeof(g_eeprom.unused));
@ -347,38 +346,25 @@ void SETTINGS_read_eeprom(void)
{ // used channel { // used channel
g_eeprom.config.channel_attributes[index].unused = 0x00; g_eeprom.config.channel_attributes[index].unused = 0x00;
memset(g_eeprom.config.channel_name[index].unused, 0x00, sizeof(g_eeprom.config.channel_name[index].unused)); memset(g_eeprom.config.channel_name[index].unused, 0x00, sizeof(g_eeprom.config.channel_name[index].unused));
// ensure the channel band attribute is correct
if (g_eeprom.config.channel[index].frequency > 0 && g_eeprom.config.channel[index].frequency < 0xffffffff)
g_eeprom.config.channel_attributes[index].band = FREQUENCY_GetBand(g_eeprom.config.channel[index].frequency);
} }
} }
#endif // force default VFO attributes
for (index = 200; index < 207; index++)
#if 1 g_eeprom.config.channel_attributes[index].attributes = 0xC0 | (index - 200);
// ensure the channel band attribute is correct g_eeprom.config.channel_attributes[207].attributes = 0x00;
for (index = 0; index < 200; index++)
if (g_eeprom.config.channel_attributes[index].band <= BAND7_470MHz &&
g_eeprom.config.channel[index].frequency > 0 &&
g_eeprom.config.channel[index].frequency < 0xffffffff)
g_eeprom.config.channel_attributes[index].band = FREQUENCY_GetBand(g_eeprom.config.channel[index].frequency);
// 0D60 .. force default VFO attributes
for (index = 0; index < 7; index++)
g_eeprom.config.channel_attributes[200 + index].attributes = 0xC0 | index;
g_eeprom.config.channel_attributes[200 + 7].attributes = 0x00;
#endif
SETTINGS_save_attributes(); SETTINGS_save_attributes();
#endif
// **************************************** // ****************************************
// eeprom calibration data
memset(&g_eeprom.calib.unused3, 0xff, sizeof(g_eeprom.calib.unused3)); // memset(&g_eeprom.calib.unused3, 0xff, sizeof(g_eeprom.calib.unused3));
memcpy(&g_eeprom_rssi_calib[0], &g_eeprom.calib.rssi_band_123, 8);
memcpy(&g_eeprom_rssi_calib[1], &g_eeprom_rssi_calib[0], 8);
memcpy(&g_eeprom_rssi_calib[2], &g_eeprom_rssi_calib[0], 8);
memcpy(&g_eeprom_rssi_calib[3], &g_eeprom.calib.rssi_band_4567, 8);
memcpy(&g_eeprom_rssi_calib[4], &g_eeprom_rssi_calib[3], 8);
memcpy(&g_eeprom_rssi_calib[5], &g_eeprom_rssi_calib[3], 8);
memcpy(&g_eeprom_rssi_calib[6], &g_eeprom_rssi_calib[3], 8);
if (g_eeprom.calib.battery[0] >= 5000) if (g_eeprom.calib.battery[0] >= 5000)
{ {

View File

@ -455,9 +455,11 @@ typedef struct {
uint8_t unused6[6]; // 0xff's uint8_t unused6[6]; // 0xff's
} __attribute__((packed)) squelch_band[2]; // 0 = bands 4567, 1 = bands 123 } __attribute__((packed)) squelch_band[2]; // 0 = bands 4567, 1 = bands 123
// 0x1EC0 // 0x1EC0 .. mine = 006E 0078 0082 008C 0086 00AA 00CE 00F2
uint16_t rssi_band_4567[4]; // RSSI bargraph thresholds .. (dBm + 160) * 2 struct { // RSSI bargraph thresholds .. (dBm + 160) * 2
uint16_t rssi_band_123[4]; // RSSI bargraph thresholds .. (dBm + 160) * 2 uint16_t band_4567[4]; //
uint16_t band_123[4]; //
} __attribute__((packed)) rssi_cal;
// 0x1ED0 // 0x1ED0
struct struct

105
ui/main.c
View File

@ -285,56 +285,62 @@ void UI_update_rssi(const int16_t rssi, const uint16_t glitch, const uint16_t no
{ // original little RS bars { // original little RS bars
// const int16_t dBm = (rssi / 2) - 160; // const int16_t dBm = (rssi / 2) - 160;
const uint8_t Line = (vfo == 0) ? 3 : 7; const uint8_t line = (vfo == 0) ? 3 : 7;
uint8_t *p_line = g_frame_buffer[Line - 1]; uint8_t *pline = g_frame_buffer[line - 1];
uint8_t rssi_level = 0; unsigned int rssi_level = 0;
int16_t rssi_cal[7];
// TODO: sort out all 8 values from the eeprom
#if 1 #if 1
const unsigned int band = g_rx_vfo->channel_attributes.band; if (g_tx_vfo->channel_attributes.band < 3)
const int16_t level0 = g_eeprom_rssi_calib[band][0]; {
const int16_t level1 = g_eeprom_rssi_calib[band][1]; rssi_cal[0] = g_eeprom.calib.rssi_cal.band_123[0];
const int16_t level2 = g_eeprom_rssi_calib[band][2]; rssi_cal[2] = g_eeprom.calib.rssi_cal.band_123[1];
const int16_t level3 = g_eeprom_rssi_calib[band][3]; rssi_cal[4] = g_eeprom.calib.rssi_cal.band_123[2];
rssi_cal[6] = g_eeprom.calib.rssi_cal.band_123[3];
}
else
{
rssi_cal[0] = g_eeprom.calib.rssi_cal.band_4567[0];
rssi_cal[2] = g_eeprom.calib.rssi_cal.band_4567[1];
rssi_cal[4] = g_eeprom.calib.rssi_cal.band_4567[2];
rssi_cal[6] = g_eeprom.calib.rssi_cal.band_4567[3];
}
#else #else
const int16_t level0 = (-115 + 160) * 2; // -115dBm rssi_cal[0] = (-110 + 160) * 2; // -110 dBm
const int16_t level1 = ( -89 + 160) * 2; // -89dBm rssi_cal[2] = ( -90 + 160) * 2; // -90 dBm
const int16_t level2 = ( -64 + 160) * 2; // -64dBm rssi_cal[4] = ( -70 + 160) * 2; // -70 dBm
const int16_t level3 = ( -39 + 160) * 2; // -39dBm rssi_cal[6] = ( -50 + 160) * 2; // -50 dBm
#endif #endif
// create intermediate threshold values (linear interpolation) to make full use of the available RSSI bars/graphics // linear interpolate the 4 values into 7
const int16_t level01 = (level0 + level1) / 2; rssi_cal[1] = (rssi_cal[0] + rssi_cal[2]) / 2;
const int16_t level12 = (level1 + level2) / 2; rssi_cal[3] = (rssi_cal[2] + rssi_cal[4]) / 2;
const int16_t level23 = (level2 + level3) / 2; rssi_cal[5] = (rssi_cal[4] + rssi_cal[6]) / 2;
g_vfo_rssi[vfo] = rssi; g_vfo_rssi[vfo] = rssi;
if (rssi >= level3) if (rssi >= rssi_cal[6])
rssi_level = 7; rssi_level = 7;
else else
if (rssi >= level23) if (rssi >= rssi_cal[5])
rssi_level = 6; rssi_level = 6;
else else
if (rssi >= level2) if (rssi >= rssi_cal[4])
rssi_level = 5; rssi_level = 5;
else else
if (rssi >= level12) if (rssi >= rssi_cal[3])
rssi_level = 4; rssi_level = 4;
else else
if (rssi >= level1) if (rssi >= rssi_cal[2])
rssi_level = 3; rssi_level = 3;
else else
if (rssi >= level01) if (rssi >= rssi_cal[1])
rssi_level = 2; rssi_level = 2;
else else
if (rssi >= level0 || g_current_function == FUNCTION_NEW_RECEIVE) if (rssi >= rssi_cal[0] || g_current_function == FUNCTION_NEW_RECEIVE)
{
rssi_level = 1; rssi_level = 1;
}
if (g_vfo_rssi_bar_level[vfo] == rssi_level) // if (g_vfo_rssi_bar_level[vfo] == rssi_level)
return; // return;
g_vfo_rssi_bar_level[vfo] = rssi_level; g_vfo_rssi_bar_level[vfo] = rssi_level;
@ -348,18 +354,18 @@ void UI_update_rssi(const int16_t rssi, const uint16_t glitch, const uint16_t no
if (g_current_function == FUNCTION_TRANSMIT || g_current_display_screen != DISPLAY_MAIN) if (g_current_function == FUNCTION_TRANSMIT || g_current_display_screen != DISPLAY_MAIN)
return; // display is in use return; // display is in use
p_line = g_frame_buffer[Line - 1]; pline = g_frame_buffer[line - 1];
memset(p_line, 0, 23); memset(pline, 0, 23);
// untested !!! // untested !!!
if (rssi_level == 0) if (rssi_level == 0)
p_line = NULL; pline = NULL;
else else
UI_drawBars(p_line, rssi_level); UI_drawBars(pline, rssi_level);
ST7565_DrawLine(0, Line, 23, p_line); ST7565_DrawLine(0, line, 23, pline);
} }
} }
@ -768,31 +774,20 @@ void UI_DisplayMain(void)
const uint8_t freq_in_channel = g_vfo_info[vfo_num].freq_in_channel; const uint8_t freq_in_channel = g_vfo_info[vfo_num].freq_in_channel;
// const uint8_t freq_in_channel = SETTINGS_find_channel(frequency); // currently way to slow // const uint8_t freq_in_channel = SETTINGS_find_channel(frequency); // currently way to slow
// if (g_vfo_info[vfo_num].channel.compand) strcpy(str, " ");
{
strcpy(str, " ");
#ifdef ENABLE_SCAN_IGNORE_LIST #ifdef ENABLE_SCAN_IGNORE_LIST
if (FI_freq_ignored(frequency) >= 0) if (FI_freq_ignored(frequency) >= 0)
str[0] = 'I'; // frequency is in the ignore list str[0] = 'I'; // frequency is in the ignore list
#endif #endif
if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST) if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST)
str[1] = 'F'; // channel number that contains this VFO frequency str[1] = 'F'; // this VFO frequency is also found in a channel
if (g_vfo_info[vfo_num].channel.compand) if (g_vfo_info[vfo_num].channel.compand)
str[2] = 'C'; // compander is enabled str[2] = 'C'; // compander is enabled
UI_PrintStringSmall(str, LCD_WIDTH - (7 * 3), 0, line + 1); UI_PrintStringSmall(str, LCD_WIDTH - (7 * 3), 0, line + 1);
}
// else
// {
// if (is_freq_chan && freq_in_channel <= USER_CHANNEL_LAST)
// { // channel number that contains this VFO frequency
// sprintf(str, "%03u", freq_in_channel);
// UI_PrintStringSmall(str, LCD_WIDTH - (7 * 3), 0, line + 1);
// }
// }
} }
#endif #endif
} }