diff --git a/Makefile b/Makefile index 4cfcb29a..4570fee3 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ ENABLE_SWD := 0 ENABLE_OVERLAY := 0 ENABLE_LTO := 1 ENABLE_UART := 1 -ENABLE_UART_DEBUG := 1 +ENABLE_UART_DEBUG := 0 ENABLE_AIRCOPY := 1 ENABLE_AIRCOPY_FREQ := 1 ENABLE_FMRADIO := 1 @@ -48,6 +48,14 @@ ENABLE_COPY_CHAN_TO_VFO := 1 TARGET = firmware +GIT_HASH_TMP := $(shell git rev-parse --short HEAD) +ifeq ($(GIT_HASH_TMP),) + GIT_HASH := "NOGIT" +else + GIT_HASH := $(GIT_HASH_TMP) +endif +$(info GIT_HASH = $(GIT_HASH)) + ifeq ($(ENABLE_UART), 0) ENABLE_UART_DEBUG := 0 endif @@ -195,13 +203,6 @@ endif OBJCOPY = arm-none-eabi-objcopy SIZE = arm-none-eabi-size -# the user might not have/want git installed -# can set own version string here (max 7 chars) -GIT_HASH := $(shell git rev-parse --short HEAD) -#GIT_HASH := 230930b - -$(info GIT_HASH = $(GIT_HASH)) - ASFLAGS = -c -mcpu=cortex-m0 ifeq ($(ENABLE_OVERLAY),1) ASFLAGS += -DENABLE_OVERLAY diff --git a/app/aircopy.c b/app/aircopy.c index 894956dd..ccd08d75 100644 --- a/app/aircopy.c +++ b/app/aircopy.c @@ -27,95 +27,128 @@ #include "ui/inputbox.h" #include "ui/ui.h" -static const uint16_t Obfuscation[8] = {0x6C16, 0xE614, 0x912E, 0x400D, 0x3521, 0x40D5, 0x0313, 0x80E9}; +#define AIRCOPY_MAGIC_START 0xABCD +#define AIRCOPY_MAGIC_END 0xDCBA -const uint8_t g_air_copy_block_max = 120; -uint8_t g_air_copy_block_number; -uint8_t g_errors_during_air_copy; +#define AIRCOPY_LAST_EEPROM_ADDR 0x1E00 + +static const uint16_t Obfuscation[] = { + 0x6C16, 0xE614, 0x912E, 0x400D, 0x3521, 0x40D5, 0x0313, 0x80E9 +}; + +const uint8_t g_aircopy_block_max = 120; +uint8_t g_aircopy_block_number; +uint8_t g_aircopy_rx_errors; aircopy_state_t g_aircopy_state; -uint16_t g_fsk_buffer[36]; +uint16_t g_aircopy_fsk_buffer[36]; +uint8_t g_aircopy_send_count_down_10ms; +unsigned int g_aircopy_fsk_write_index; void AIRCOPY_SendMessage(void) { - unsigned int i; + unsigned int i; + const uint16_t eeprom_addr = (uint16_t)g_aircopy_block_number * 64; + + // ********* - g_fsk_buffer[1] = (g_air_copy_block_number & 0x3FF) << 6; + // packet start + g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START; - EEPROM_ReadBuffer(g_fsk_buffer[1], &g_fsk_buffer[2], 64); + // eeprom address + g_aircopy_fsk_buffer[1] = eeprom_addr; - g_fsk_buffer[34] = CRC_Calculate(&g_fsk_buffer[1], 2 + 64); + // data + EEPROM_ReadBuffer(eeprom_addr, &g_aircopy_fsk_buffer[2], 64); - for (i = 0; i < 34; i++) - g_fsk_buffer[i + 1] ^= Obfuscation[i % 8]; + // data CRC + g_aircopy_fsk_buffer[34] = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64); - if (++g_air_copy_block_number >= g_air_copy_block_max) - { - g_aircopy_state = AIRCOPY_TX_COMPLETE; - g_update_display = true; - } + // packet end + g_aircopy_fsk_buffer[35] = AIRCOPY_MAGIC_END; + + // ********* + + // scramble the packet + for (i = 0; i < 34; i++) + g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)]; RADIO_SetTxParameters(); - BK4819_SendFSKData(g_fsk_buffer); + BK4819_SendFSKData(g_aircopy_fsk_buffer); BK4819_SetupPowerAmplifier(0, 0); BK4819_ToggleGpioOut(BK4819_GPIO5_PIN1, false); - g_air_copy_send_count_down = 30; + if (++g_aircopy_block_number >= g_aircopy_block_max) + { + g_aircopy_state = AIRCOPY_TX_COMPLETE; + g_update_display = true; + } + + // TX pause/gap time + #if 0 + g_aircopy_send_count_down_10ms = 300 / 10; // 300ms + #else + g_aircopy_send_count_down_10ms = 30 / 10; // 30ms + #endif } void AIRCOPY_StorePacket(void) { uint16_t Status; - if (g_fsk_wite_index < 36) + if (g_aircopy_fsk_write_index < ARRAY_SIZE(g_aircopy_fsk_buffer)) return; - g_fsk_wite_index = 0; - g_update_display = true; + g_aircopy_fsk_write_index = 0; + g_update_display = true; Status = BK4819_ReadRegister(BK4819_REG_0B); BK4819_PrepareFSKReceive(); - // Doc says bit 4 should be 1 = CRC OK, 0 = CRC FAIL, but original firmware checks for FAIL. + // Doc says bit 4 should be 1 = CRC OK, 0 = CRC FAIL, but original firmware checks for FAIL - if ((Status & 0x0010U) == 0 && g_fsk_buffer[0] == 0xABCD && g_fsk_buffer[35] == 0xDCBA) + if ((Status & (1u << 4)) == 0 && g_aircopy_fsk_buffer[0] == AIRCOPY_MAGIC_START && g_aircopy_fsk_buffer[35] == AIRCOPY_MAGIC_END) { uint16_t CRC; unsigned int i; for (i = 0; i < 34; i++) - g_fsk_buffer[i + 1] ^= Obfuscation[i % 8]; + g_aircopy_fsk_buffer[1 + i] ^= Obfuscation[i % ARRAY_SIZE(Obfuscation)]; - CRC = CRC_Calculate(&g_fsk_buffer[1], 2 + 64); + CRC = CRC_Calculate(&g_aircopy_fsk_buffer[1], 2 + 64); - if (g_fsk_buffer[34] == CRC) + if (g_aircopy_fsk_buffer[34] == CRC) { - const uint16_t *pData; - uint16_t Offset = g_fsk_buffer[1]; - if (Offset < 0x1E00) + uint16_t eeprom_addr = g_aircopy_fsk_buffer[1]; + + if (eeprom_addr < AIRCOPY_LAST_EEPROM_ADDR) { - pData = &g_fsk_buffer[2]; + const uint16_t *pData = &g_aircopy_fsk_buffer[2]; + for (i = 0; i < 8; i++) { - EEPROM_WriteBuffer(Offset, pData); - pData += 4; - Offset += 8; + EEPROM_WriteBuffer(eeprom_addr, pData); + pData += 4; + eeprom_addr += 8; } - if (Offset == 0x1E00) - { + //g_aircopy_block_number++; + g_aircopy_block_number = eeprom_addr / 64; + + if (eeprom_addr >= AIRCOPY_LAST_EEPROM_ADDR) + { // reached end of eeprom config area + g_aircopy_state = AIRCOPY_RX_COMPLETE; g_update_display = true; } - g_air_copy_block_number++; return; } } } - g_errors_during_air_copy++; + g_aircopy_rx_errors++; } static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) @@ -154,7 +187,7 @@ static void AIRCOPY_Key_DIGITS(key_code_t Key, bool key_pressed, bool key_held) // round the frequency to nearest step size Frequency = ((Frequency + (g_rx_vfo->step_freq / 2)) / g_rx_vfo->step_freq) * g_rx_vfo->step_freq; - g_air_copy_freq = Frequency; + g_aircopy_freq = Frequency; #ifdef ENABLE_AIRCOPY_FREQ SETTINGS_SaveSettings(); // remeber the frequency for the next time #endif @@ -188,14 +221,14 @@ static void AIRCOPY_Key_EXIT(bool key_pressed, bool key_held) else { // enter RX mode - g_aircopy_state = AIRCOPY_RX; - g_update_display = true; + g_aircopy_state = AIRCOPY_RX; + g_update_display = true; GUI_DisplayScreen(); - g_fsk_wite_index = 0; - g_air_copy_block_number = 0; - g_errors_during_air_copy = 0; - g_input_box_index = 0; + g_aircopy_fsk_write_index = 0; + g_aircopy_block_number = 0; + g_aircopy_rx_errors = 0; + g_input_box_index = 0; BK4819_PrepareFSKReceive(); } @@ -209,16 +242,17 @@ static void AIRCOPY_Key_MENU(bool key_pressed, bool key_held) if (!key_held && key_pressed) { // enter TX mode - g_aircopy_state = AIRCOPY_TX; - g_update_display = true; + g_aircopy_state = AIRCOPY_TX; + g_update_display = true; GUI_DisplayScreen(); - g_fsk_wite_index = 0; - g_air_copy_block_number = 0; - g_input_box_index = 0; - g_fsk_buffer[0] = 0xABCD; - g_fsk_buffer[1] = 0; - g_fsk_buffer[35] = 0xDCBA; + g_input_box_index = 0; + + g_aircopy_fsk_write_index = 0; + g_aircopy_block_number = 0; + g_aircopy_fsk_buffer[0] = AIRCOPY_MAGIC_START; + g_aircopy_fsk_buffer[1] = 0; // block number + g_aircopy_fsk_buffer[35] = AIRCOPY_MAGIC_END; AIRCOPY_SendMessage(); } diff --git a/app/aircopy.h b/app/aircopy.h index 57d4a0cc..5a63da51 100644 --- a/app/aircopy.h +++ b/app/aircopy.h @@ -17,8 +17,6 @@ #ifndef APP_AIRCOPY_H #define APP_AIRCOPY_H -#ifdef ENABLE_AIRCOPY - #include "driver/keyboard.h" enum aircopy_state_e @@ -31,17 +29,16 @@ enum aircopy_state_e }; typedef enum aircopy_state_e aircopy_state_t; -extern const uint8_t g_air_copy_block_max; -extern uint8_t g_air_copy_block_number; -extern uint8_t g_errors_during_air_copy; +extern const uint8_t g_aircopy_block_max; +extern uint8_t g_aircopy_block_number; +extern uint8_t g_aircopy_rx_errors; extern aircopy_state_t g_aircopy_state; -extern uint16_t g_fsk_buffer[36]; +extern uint16_t g_aircopy_fsk_buffer[36]; +extern uint8_t g_aircopy_send_count_down_10ms; +extern unsigned int g_aircopy_fsk_write_index; void AIRCOPY_SendMessage(void); void AIRCOPY_StorePacket(void); -void AIRCOPY_ProcessKeys(key_code_t Key, bool bKeyPressed, bool bKeyHeld); - -#endif +void AIRCOPY_ProcessKeys(key_code_t key, bool key_pressed, bool key_held); #endif - diff --git a/app/app.c b/app/app.c index 7713fdff..a1536b61 100644 --- a/app/app.c +++ b/app/app.c @@ -926,14 +926,15 @@ void APP_CheckRadioInterrupts(void) } #ifdef ENABLE_AIRCOPY - if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL && - g_screen_to_display == DISPLAY_AIRCOPY && - g_aircopy_state == AIRCOPY_RX) + if (interrupt_status_bits & BK4819_REG_02_FSK_FIFO_ALMOST_FULL) { - unsigned int i; - for (i = 0; i < 4; i++) - g_fsk_buffer[g_fsk_wite_index++] = BK4819_ReadRegister(BK4819_REG_5F); - AIRCOPY_StorePacket(); + if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_RX) + { + unsigned int i; + for (i = 0; i < 4; i++) + g_aircopy_fsk_buffer[g_aircopy_fsk_write_index++] = BK4819_ReadRegister(BK4819_REG_5F); + AIRCOPY_StorePacket(); + } } #endif } @@ -1324,7 +1325,8 @@ void APP_CheckKeys(void) key_code_t key; #ifdef ENABLE_AIRCOPY - if (g_setting_killed || (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state != AIRCOPY_READY)) + if (g_setting_killed || + (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state != AIRCOPY_READY)) return; #else if (g_setting_killed) @@ -1552,6 +1554,21 @@ void APP_TimeSlice10ms(void) if (g_reduced_service) return; + + #ifdef ENABLE_AIRCOPY + if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_TX) + { + if (g_aircopy_send_count_down_10ms > 0) + { + if (--g_aircopy_send_count_down_10ms == 0) + { + AIRCOPY_SendMessage(); + GUI_DisplayScreen(); + } + } + } + #endif + #ifdef ENABLE_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) @@ -1831,20 +1848,6 @@ void APP_TimeSlice10ms(void) } } - #ifdef ENABLE_AIRCOPY - if (g_screen_to_display == DISPLAY_AIRCOPY && g_aircopy_state == AIRCOPY_TX) - { - if (g_air_copy_send_count_down > 0) - { - if (--g_air_copy_send_count_down == 0) - { - AIRCOPY_SendMessage(); - GUI_DisplayScreen(); - } - } - } - #endif - APP_CheckKeys(); } diff --git a/board.c b/board.c index 6855d95d..30297ea1 100644 --- a/board.c +++ b/board.c @@ -634,7 +634,7 @@ void BOARD_EEPROM_load(void) { if (array.air_copy_freq >= FREQ_BAND_TABLE[i].lower && array.air_copy_freq < FREQ_BAND_TABLE[i].upper) { - g_air_copy_freq = array.air_copy_freq; + g_aircopy_freq = array.air_copy_freq; break; } } diff --git a/firmware.bin b/firmware.bin index eb903530..add066d5 100644 Binary files a/firmware.bin and b/firmware.bin differ diff --git a/firmware.packed.bin b/firmware.packed.bin index bb737f14..3f89cf8d 100644 Binary files a/firmware.packed.bin and b/firmware.packed.bin differ diff --git a/frequencies.c b/frequencies.c index da523f5e..67e9da87 100644 --- a/frequencies.c +++ b/frequencies.c @@ -19,7 +19,7 @@ #include "settings.h" // the initial AIRCOPY frequency to use -uint32_t g_air_copy_freq = 41002500; +uint32_t g_aircopy_freq = 41002500; // the BK4819 has 2 bands it covers, 18MHz ~ 630MHz and 760MHz ~ 1300MHz const freq_band_table_t BX4819_band1 = { 1800000, 63000000}; diff --git a/frequencies.h b/frequencies.h index abb8b2e3..93d45ce3 100644 --- a/frequencies.h +++ b/frequencies.h @@ -26,7 +26,7 @@ typedef struct { const uint32_t upper; } freq_band_table_t; -extern uint32_t g_air_copy_freq; +extern uint32_t g_aircopy_freq; extern const freq_band_table_t BX4819_band1; extern const freq_band_table_t BX4819_band2; diff --git a/helper/boot.c b/helper/boot.c index c1d42f65..1b102827 100644 --- a/helper/boot.c +++ b/helper/boot.c @@ -80,7 +80,7 @@ void BOOT_ProcessMode(boot_mode_t Mode) g_eeprom.key2_short_press_action = ACTION_OPT_NONE; g_eeprom.key2_long_press_action = ACTION_OPT_NONE; - RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_LAST - 1, g_air_copy_freq); + RADIO_InitInfo(g_rx_vfo, FREQ_CHANNEL_LAST - 1, g_aircopy_freq); g_rx_vfo->channel_bandwidth = BANDWIDTH_WIDE; g_rx_vfo->output_power = OUTPUT_POWER_LOW; diff --git a/misc.c b/misc.c index c21e7094..d70efbcc 100644 --- a/misc.c +++ b/misc.c @@ -227,10 +227,6 @@ bool g_rx_vfo_is_active; uint8_t g_menu_list_count; uint8_t g_backup_cross_vfo_rx_tx; uint8_t g_scan_delay_10ms; -#ifdef ENABLE_AIRCOPY - uint8_t g_air_copy_send_count_down; -#endif -uint8_t g_fsk_wite_index; #ifdef ENABLE_NOAA bool g_is_noaa_mode; diff --git a/misc.h b/misc.h index 72100562..2fd21c1e 100644 --- a/misc.h +++ b/misc.h @@ -302,10 +302,6 @@ extern uint16_t g_alarm_running_counter; extern uint8_t g_menu_list_count; extern uint8_t g_backup_cross_vfo_rx_tx; extern uint8_t g_scan_delay_10ms; -#ifdef ENABLE_AIRCOPY - extern uint8_t g_air_copy_send_count_down; -#endif -extern uint8_t g_fsk_wite_index; #ifdef ENABLE_NOAA extern bool g_is_noaa_mode; extern uint8_t g_noaa_channel; diff --git a/settings.c b/settings.c index f33c8cc9..ef4a6bcf 100644 --- a/settings.c +++ b/settings.c @@ -275,7 +275,7 @@ void SETTINGS_SaveSettings(void) array.tx_vfo = g_eeprom.tx_vfo; #ifdef ENABLE_AIRCOPY_FREQ // remember the AIRCOPY frequency - array.air_copy_freq = g_air_copy_freq; + array.air_copy_freq = g_aircopy_freq; #endif EEPROM_WriteBuffer(0x0EA8, &array); diff --git a/ui/aircopy.c b/ui/aircopy.c index 6e72bc25..b64e2b01 100644 --- a/ui/aircopy.c +++ b/ui/aircopy.c @@ -27,38 +27,43 @@ void UI_DisplayAircopy(void) { - char String[16]; + char str[17]; + // clear screen/display buffer memset(g_frame_buffer, 0, sizeof(g_frame_buffer)); // ********************************** + // upper text line - strcpy(String, "AIR COPY"); - + strcpy(str, "AIR COPY"); switch (g_aircopy_state) { - case AIRCOPY_READY: strcat(String, " READY"); break; - case AIRCOPY_RX: strcat(String, " RX"); break; - case AIRCOPY_TX: strcat(String, " TX"); break; - case AIRCOPY_RX_COMPLETE: strcat(String, " DONE"); break; - case AIRCOPY_TX_COMPLETE: strcat(String, " DONE"); break; - default: strcat(String, " ???"); break; + case AIRCOPY_READY: strcat(str, " READY"); break; + case AIRCOPY_RX: strcat(str, " RX"); break; + case AIRCOPY_TX: strcat(str, " TX"); break; + case AIRCOPY_RX_COMPLETE: strcat(str, " DONE"); break; + case AIRCOPY_TX_COMPLETE: strcat(str, " DONE"); break; + default: strcat(str, " ERR"); break; } - UI_PrintString(String, 0, LCD_WIDTH - 1, 0, 8); + UI_PrintString(str, 0, LCD_WIDTH - 1, 0, 8); // ********************************** + // center frequency text line if (g_input_box_index == 0) - { - NUMBER_ToDigits(g_rx_vfo->freq_config_rx.frequency, String); - UI_DisplayFrequency(String, 16, 2, 0, 0); - UI_Displaysmall_digits(2, String + 6, 97, 3, true); + { // show frequency + NUMBER_ToDigits(g_rx_vfo->freq_config_rx.frequency, str); + UI_DisplayFrequency(str, 16, 2, 0, 0); + UI_Displaysmall_digits(2, str + 6, 97, 3, true); } else + { // user is entering a new frequency UI_DisplayFrequency(g_input_box, 16, 2, 1, 0); + } // ********************************** - + // lower TX/RX status text line + #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wimplicit-fallthrough=" @@ -69,17 +74,17 @@ void UI_DisplayAircopy(void) break; case AIRCOPY_RX_COMPLETE: - if (g_errors_during_air_copy == 0) + if (g_aircopy_rx_errors == 0) { UI_PrintString("RX COMPLETE", 0, LCD_WIDTH - 1, 5, 8); break; } case AIRCOPY_RX: - sprintf(String, "RX %u.%u", g_air_copy_block_number, g_air_copy_block_max); - if (g_errors_during_air_copy > 0) - sprintf(String + strlen(String), " E %u", g_errors_during_air_copy); - UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7); + sprintf(str, "RX %u.%u", g_aircopy_block_number, g_aircopy_block_max); + if (g_aircopy_rx_errors > 0) + sprintf(str + strlen(str), " E %u", g_aircopy_rx_errors); + UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); break; case AIRCOPY_TX_COMPLETE: @@ -87,13 +92,13 @@ void UI_DisplayAircopy(void) break; case AIRCOPY_TX: - sprintf(String, "TX %u.%u", g_air_copy_block_number, g_air_copy_block_max); - UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7); + sprintf(str, "TX %u.%u", g_aircopy_block_number, g_aircopy_block_max); + UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); break; default: - strcpy(String, " ???"); - UI_PrintString(String, 0, LCD_WIDTH - 1, 5, 7); + strcpy(str, "ERROR"); + UI_PrintString(str, 0, LCD_WIDTH - 1, 5, 7); break; } diff --git a/ui/main.c b/ui/main.c index 27a7cb9d..a0d17e75 100644 --- a/ui/main.c +++ b/ui/main.c @@ -85,8 +85,12 @@ center_line_t center_line = CENTER_LINE_NONE; memset(p_line, 0, LCD_WIDTH); sprintf(s, "TX %u", secs); - UI_PrintStringSmallBold(s, 2, 0, line); // issue UI_PrintStringSmallBold //UI_PrintStringSmall(s, 2, 0, line); - + #ifdef ENABLE_SMALL_BOLD + UI_PrintStringSmallBold(s, 2, 0, line); + #else + UI_PrintStringSmall(s, 2, 0, line); + #endif + #if 1 // solid bar for (i = 0; i < bar_width; i++)