0
mirror of https://github.com/OneOfEleven/uv-k5-firmware-custom.git synced 2025-04-29 14:51:26 +03:00

Tune config/eeprom serial upload/download function

This commit is contained in:
OneOfEleven 2023-10-10 17:29:46 +01:00
parent 72f3fd8d85
commit 92bf3ccf57
4 changed files with 109 additions and 108 deletions

View File

@ -1065,7 +1065,7 @@ void APP_Update(void)
GUI_DisplayScreen(); GUI_DisplayScreen();
} }
if (g_reduced_service) if (g_reduced_service || g_serial_config_count_down_500ms > 0)
return; return;
if (g_current_function != FUNCTION_TRANSMIT) if (g_current_function != FUNCTION_TRANSMIT)
@ -1487,20 +1487,29 @@ void APP_TimeSlice10ms(void)
__enable_irq(); __enable_irq();
} }
if (g_serial_config_count_down_500ms > 0)
{ // config upload/download is running
if (g_update_display)
GUI_DisplayScreen();
if (g_update_status)
UI_DisplayStatus(false);
return;
}
#ifdef ENABLE_BOOT_BEEPS #ifdef ENABLE_BOOT_BEEPS
if (g_boot_counter_10ms > 0 && (g_boot_counter_10ms % 25) == 0) if (g_boot_counter_10ms > 0 && (g_boot_counter_10ms % 25) == 0)
AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL); AUDIO_PlayBeep(BEEP_880HZ_40MS_OPTIONAL);
#endif #endif
if (g_reduced_service)
return;
#ifdef ENABLE_AM_FIX #ifdef ENABLE_AM_FIX
// if (g_eeprom.vfo_info[g_eeprom.rx_vfo].am_mode && g_setting_am_fix) // if (g_eeprom.vfo_info[g_eeprom.rx_vfo].am_mode && g_setting_am_fix)
if (g_rx_vfo->am_mode && g_setting_am_fix) if (g_rx_vfo->am_mode && g_setting_am_fix)
AM_fix_10ms(g_eeprom.rx_vfo); AM_fix_10ms(g_eeprom.rx_vfo);
#endif #endif
if (g_reduced_service)
return;
if (g_current_function != FUNCTION_POWER_SAVE || !g_rx_idle_mode) if (g_current_function != FUNCTION_POWER_SAVE || !g_rx_idle_mode)
APP_CheckRadioInterrupts(); APP_CheckRadioInterrupts();
@ -1827,6 +1836,11 @@ void APP_TimeSlice500ms(void)
// Skipped authentic device check // Skipped authentic device check
if (g_serial_config_count_down_500ms > 0)
{ // config upload/download is running
return;
}
if (g_keypad_locked > 0) if (g_keypad_locked > 0)
if (--g_keypad_locked == 0) if (--g_keypad_locked == 0)
g_update_display = true; g_update_display = true;
@ -1888,10 +1902,6 @@ void APP_TimeSlice500ms(void)
if (g_eeprom.backlight < (ARRAY_SIZE(g_sub_menu_backlight) - 1)) if (g_eeprom.backlight < (ARRAY_SIZE(g_sub_menu_backlight) - 1))
GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn backlight off GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); // turn backlight off
if (g_serial_config_count_down_500ms > 0)
{
}
if (g_reduced_service) if (g_reduced_service)
{ {
BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current); BOARD_ADC_GetBatteryInfo(&g_usb_current_voltage, &g_usb_current);

View File

@ -43,6 +43,8 @@
#define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer)) #define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer))
// ********************************************
typedef struct { typedef struct {
uint16_t ID; uint16_t ID;
uint16_t Size; uint16_t Size;
@ -53,10 +55,11 @@ typedef struct {
uint16_t ID; uint16_t ID;
} __attribute__((packed)) Footer_t; } __attribute__((packed)) Footer_t;
// version
typedef struct { typedef struct {
Header_t Header; Header_t Header;
uint32_t Timestamp; uint32_t Timestamp;
} __attribute__((packed)) CMD_0514_t; } __attribute__((packed)) version_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
@ -64,28 +67,29 @@ typedef struct {
char Version[16]; char Version[16];
bool g_has_custom_aes_key; bool g_has_custom_aes_key;
bool g_is_in_lock_screen; bool g_is_in_lock_screen;
uint8_t Padding[2]; uint8_t pad[2];
uint32_t Challenge[4]; uint32_t Challenge[4];
} __attribute__((packed)) Data; } __attribute__((packed)) Data;
} __attribute__((packed)) REPLY_0514_t; } __attribute__((packed)) reply_version_t;
// read eeprom
typedef struct { typedef struct {
Header_t Header; Header_t Header;
uint16_t Offset; uint16_t Offset;
uint8_t Size; uint8_t Size;
uint8_t Padding; uint8_t pad;
uint32_t Timestamp; uint32_t Timestamp;
} __attribute__((packed)) CMD_051B_t; } __attribute__((packed)) read_eeprom_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
struct { struct {
uint16_t Offset; uint16_t Offset;
uint8_t Size; uint8_t Size;
uint8_t Padding; uint8_t pad;
uint8_t Data[128]; uint8_t Data[128];
} __attribute__((packed)) Data; } __attribute__((packed)) Data;
} __attribute__((packed)) REPLY_051B_t; } __attribute__((packed)) reply_read_eeprom_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
@ -94,14 +98,14 @@ typedef struct {
bool bAllowPassword; bool bAllowPassword;
uint32_t Timestamp; uint32_t Timestamp;
// uint8_t Data[0]; // uint8_t Data[0];
} __attribute__((packed)) CMD_051D_t; } __attribute__((packed)) write_eeprom_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
struct { struct {
uint16_t Offset; uint16_t Offset;
} __attribute__((packed)) Data; } __attribute__((packed)) Data;
} __attribute__((packed)) REPLY_051D_t; } __attribute__((packed)) reply_write_eeprom_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
@ -110,7 +114,7 @@ typedef struct {
uint8_t ExNoiseIndicator; uint8_t ExNoiseIndicator;
uint8_t GlitchIndicator; uint8_t GlitchIndicator;
} __attribute__((packed)) Data; } __attribute__((packed)) Data;
} __attribute__((packed)) REPLY_0527_t; } __attribute__((packed)) reply_rssi_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
@ -118,7 +122,7 @@ typedef struct {
uint16_t Voltage; uint16_t Voltage;
uint16_t Current; uint16_t Current;
} __attribute__((packed)) Data; } __attribute__((packed)) Data;
} __attribute__((packed)) REPLY_0529_t; } __attribute__((packed)) reply_adc_t;
typedef struct { typedef struct {
Header_t Header; Header_t Header;
@ -157,15 +161,20 @@ static uint32_t Timestamp;
static uint16_t g_uart_write_index; static uint16_t g_uart_write_index;
static bool bIsEncrypted = true; static bool bIsEncrypted = true;
// ****************************************************
static void SendReply(void *pReply, uint16_t Size) static void SendReply(void *pReply, uint16_t Size)
{ {
Header_t Header; Header_t Header;
Footer_t Footer; Footer_t Footer;
memset((void *)&Header, 0, sizeof(Header));
memset((void *)&Footer, 0, sizeof(Footer));
if (bIsEncrypted) if (bIsEncrypted)
{ {
uint8_t *pBytes = (uint8_t *)pReply;
unsigned int i; unsigned int i;
uint8_t *pBytes = (uint8_t *)pReply;
for (i = 0; i < Size; i++) for (i = 0; i < Size; i++)
pBytes[i] ^= Obfuscation[i % 16]; pBytes[i] ^= Obfuscation[i % 16];
} }
@ -192,8 +201,8 @@ static void SendReply(void *pReply, uint16_t Size)
static void SendVersion(void) static void SendVersion(void)
{ {
REPLY_0514_t Reply; reply_version_t Reply;
memset((void *)&Reply, 0, sizeof(Reply));
Reply.Header.ID = 0x0515; Reply.Header.ID = 0x0515;
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
strcpy(Reply.Data.Version, Version); strcpy(Reply.Data.Version, Version);
@ -203,19 +212,13 @@ static void SendVersion(void)
Reply.Data.Challenge[1] = g_challenge[1]; Reply.Data.Challenge[1] = g_challenge[1];
Reply.Data.Challenge[2] = g_challenge[2]; Reply.Data.Challenge[2] = g_challenge[2];
Reply.Data.Challenge[3] = g_challenge[3]; Reply.Data.Challenge[3] = g_challenge[3];
SendReply(&Reply, sizeof(Reply)); SendReply(&Reply, sizeof(Reply));
} }
static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint32_t *pResponse) static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint32_t *pResponse)
{ {
unsigned int i; unsigned int i;
uint32_t IV[4]; uint32_t IV[4] = {0, 0, 0, 0};
IV[0] = 0;
IV[1] = 0;
IV[2] = 0;
IV[3] = 0;
AES_Encrypt(pKey, IV, pIn, IV, true); AES_Encrypt(pKey, IV, pIn, IV, true);
@ -226,21 +229,14 @@ static bool IsBadChallenge(const uint32_t *pKey, const uint32_t *pIn, const uint
return false; return false;
} }
static void CMD_0514(const uint8_t *pBuffer) static void version(const uint8_t *pBuffer)
{ {
const CMD_0514_t *pCmd = (const CMD_0514_t *)pBuffer; const version_t *pCmd = (const version_t *)pBuffer;
Timestamp = pCmd->Timestamp; Timestamp = pCmd->Timestamp;
#ifdef ENABLE_FMRADIO
g_fm_radio_count_down_500ms = fm_radio_countdown_500ms;
#endif
g_serial_config_count_down_500ms = serial_config_count_down_500ms; g_serial_config_count_down_500ms = serial_config_count_down_500ms;
// turn the LCD backlight off
// GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);
// show message // show message
g_request_display_screen = DISPLAY_MAIN; g_request_display_screen = DISPLAY_MAIN;
g_update_display = true; g_update_display = true;
@ -248,10 +244,10 @@ static void CMD_0514(const uint8_t *pBuffer)
SendVersion(); SendVersion();
} }
static void CMD_051B(const uint8_t *pBuffer) static void read_eeprom(const uint8_t *pBuffer)
{ {
const CMD_051B_t *pCmd = (const CMD_051B_t *)pBuffer; const read_eeprom_t *pCmd = (const read_eeprom_t *)pBuffer;
REPLY_051B_t Reply; reply_read_eeprom_t Reply;
bool bLocked = false; bool bLocked = false;
if (pCmd->Timestamp != Timestamp) if (pCmd->Timestamp != Timestamp)
@ -259,11 +255,7 @@ static void CMD_051B(const uint8_t *pBuffer)
g_serial_config_count_down_500ms = serial_config_count_down_500ms; g_serial_config_count_down_500ms = serial_config_count_down_500ms;
#ifdef ENABLE_FMRADIO memset((void *)&Reply, 0, sizeof(Reply));
g_fm_radio_count_down_500ms = fm_radio_countdown_500ms;
#endif
memset(&Reply, 0, sizeof(Reply));
Reply.Header.ID = 0x051C; Reply.Header.ID = 0x051C;
Reply.Header.Size = pCmd->Size + 4; Reply.Header.Size = pCmd->Size + 4;
Reply.Data.Offset = pCmd->Offset; Reply.Data.Offset = pCmd->Offset;
@ -278,10 +270,10 @@ static void CMD_051B(const uint8_t *pBuffer)
SendReply(&Reply, pCmd->Size + 8); SendReply(&Reply, pCmd->Size + 8);
} }
static void CMD_051D(const uint8_t *pBuffer) static void write_eeprom(const uint8_t *pBuffer)
{ {
const CMD_051D_t *pCmd = (const CMD_051D_t *)pBuffer; const write_eeprom_t *pCmd = (const write_eeprom_t *)pBuffer;
REPLY_051D_t Reply; reply_write_eeprom_t Reply;
bool bReloadEeprom; bool bReloadEeprom;
bool bIsLocked; bool bIsLocked;
@ -292,10 +284,7 @@ static void CMD_051D(const uint8_t *pBuffer)
bReloadEeprom = false; bReloadEeprom = false;
#ifdef ENABLE_FMRADIO memset((void *)&Reply, 0, sizeof(Reply));
g_fm_radio_count_down_500ms = fm_radio_countdown_500ms;
#endif
Reply.Header.ID = 0x051E; Reply.Header.ID = 0x051E;
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
Reply.Data.Offset = pCmd->Offset; Reply.Data.Offset = pCmd->Offset;
@ -324,24 +313,25 @@ static void CMD_051D(const uint8_t *pBuffer)
SendReply(&Reply, sizeof(Reply)); SendReply(&Reply, sizeof(Reply));
} }
static void CMD_0527(void) static void read_rssi(void)
{ {
REPLY_0527_t Reply; reply_rssi_t Reply;
memset((void *)&Reply, 0, sizeof(Reply));
Reply.Header.ID = 0x0528; Reply.Header.ID = 0x0528;
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
Reply.Data.RSSI = BK4819_ReadRegister(BK4819_REG_67) & 0x01FF; Reply.Data.RSSI = BK4819_ReadRegister(BK4819_REG_67) & 0x01FF;
Reply.Data.ExNoiseIndicator = BK4819_ReadRegister(BK4819_REG_65) & 0x007F; Reply.Data.ExNoiseIndicator = BK4819_ReadRegister(BK4819_REG_65) & 0x007F;
Reply.Data.GlitchIndicator = BK4819_ReadRegister(BK4819_REG_63); Reply.Data.GlitchIndicator = BK4819_ReadRegister(BK4819_REG_63);
SendReply(&Reply, sizeof(Reply)); SendReply(&Reply, sizeof(Reply));
} }
static void CMD_0529(void) static void read_adc(void)
{ {
uint16_t voltage; uint16_t voltage;
uint16_t current; uint16_t current;
REPLY_0529_t Reply; reply_adc_t Reply;
memset((void *)&Reply, 0, sizeof(Reply));
Reply.Header.ID = 0x52A; Reply.Header.ID = 0x52A;
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
@ -361,9 +351,10 @@ static void CMD_052D(const uint8_t *pBuffer)
uint32_t response[4]; uint32_t response[4];
bool bIsLocked; bool bIsLocked;
#ifdef ENABLE_FMRADIO g_serial_config_count_down_500ms = serial_config_count_down_500ms;
g_fm_radio_count_down_500ms = fm_radio_countdown_500ms;
#endif memset((void *)&Reply, 0, sizeof(Reply));
Reply.Header.ID = 0x052E; Reply.Header.ID = 0x052E;
Reply.Header.Size = sizeof(Reply.Data); Reply.Header.Size = sizeof(Reply.Data);
@ -426,9 +417,6 @@ static void CMD_052F(const uint8_t *pBuffer)
Timestamp = pCmd->Timestamp; Timestamp = pCmd->Timestamp;
// turn the LCD backlight off
// GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT);
// show message // show message
g_request_display_screen = DISPLAY_MAIN; g_request_display_screen = DISPLAY_MAIN;
g_update_display = true; g_update_display = true;
@ -533,46 +521,49 @@ void UART_HandleCommand(void)
{ {
switch (UART_Command.Header.ID) switch (UART_Command.Header.ID)
{ {
case 0x0514: case 0x0514: // version
CMD_0514(UART_Command.Buffer); version(UART_Command.Buffer);
break; break;
case 0x051B: case 0x051B: // read eeprom
CMD_051B(UART_Command.Buffer); read_eeprom(UART_Command.Buffer);
break; break;
case 0x051D: case 0x051D: // write eeprom
CMD_051D(UART_Command.Buffer); write_eeprom(UART_Command.Buffer);
break; break;
case 0x051F: // Not implementing non-authentic command // case 0x051F: // Not implementing non-authentic command
// break;
// case 0x0521: // Not implementing non-authentic command
// break;
case 0x0527: // read RSSI
read_rssi();
break; break;
case 0x0521: // Not implementing non-authentic command case 0x0529: // read ADC
read_adc();
break; break;
case 0x0527: case 0x052D: //
CMD_0527();
break;
case 0x0529:
CMD_0529();
break;
case 0x052D:
CMD_052D(UART_Command.Buffer); CMD_052D(UART_Command.Buffer);
break; break;
case 0x052F: case 0x052F: //
CMD_052F(UART_Command.Buffer); CMD_052F(UART_Command.Buffer);
break; break;
case 0x05DD: case 0x05DD: // reboot
#if defined(ENABLE_OVERLAY) #if defined(ENABLE_OVERLAY)
overlay_FLASH_RebootToBootloader(); overlay_FLASH_RebootToBootloader();
#else #else
NVIC_SystemReset(); NVIC_SystemReset();
#endif #endif
break; break;
default:
break;
} }
} }

Binary file not shown.

Binary file not shown.