diff --git a/Makefile b/Makefile index 8ffd81b..ff7ae92 100755 --- a/Makefile +++ b/Makefile @@ -1,5 +1,9 @@ TARGET = firmware +ENABLE_AIRCOPY := 1 +ENABLE_OVERLAY := 1 +ENABLE_UART := 1 + BSP_DEFINITIONS := $(wildcard hardware/*/*.def) BSP_HEADERS := $(patsubst hardware/%,bsp/%,$(BSP_DEFINITIONS)) BSP_HEADERS := $(patsubst %.def,%.h,$(BSP_HEADERS)) @@ -8,18 +12,26 @@ OBJS = # Startup files OBJS += start.o OBJS += init.o +ifeq ($(ENABLE_OVERLAY),1) OBJS += sram-overlay.o +endif OBJS += external/printf/printf.o # Drivers OBJS += driver/adc.o +ifeq ($(ENABLE_UART),1) OBJS += driver/aes.o +endif OBJS += driver/backlight.o OBJS += driver/bk1080.o OBJS += driver/bk4819.o +ifeq ($(filter $(ENABLE_AIRCOPY) $(ENABLE_UART),1),1) OBJS += driver/crc.o +endif OBJS += driver/eeprom.o +ifeq ($(ENABLE_OVERLAY),1) OBJS += driver/flash.o +endif OBJS += driver/gpio.o OBJS += driver/i2c.o OBJS += driver/keyboard.o @@ -27,11 +39,15 @@ OBJS += driver/spi.o OBJS += driver/st7565.o OBJS += driver/system.o OBJS += driver/systick.o +ifeq ($(ENABLE_UART),1) OBJS += driver/uart.o +endif # Main OBJS += app/action.o +ifeq ($(ENABLE_AIRCOPY),1) OBJS += app/aircopy.o +endif OBJS += app/app.o OBJS += app/dtmf.o OBJS += app/fm.o @@ -39,7 +55,9 @@ OBJS += app/generic.o OBJS += app/main.o OBJS += app/menu.o OBJS += app/scanner.o +ifeq ($(ENABLE_UART),1) OBJS += app/uart.o +endif OBJS += audio.o OBJS += bitmaps.o OBJS += board.o @@ -53,7 +71,9 @@ OBJS += misc.o OBJS += radio.o OBJS += scheduler.o OBJS += settings.o +ifeq ($(ENABLE_AIRCOPY),1) OBJS += ui/aircopy.o +endif OBJS += ui/battery.o OBJS += ui/fmradio.o OBJS += ui/helper.o @@ -76,7 +96,7 @@ else TOP := $(shell pwd) endif -AS = arm-none-eabi-as +AS = arm-none-eabi-gcc CC = arm-none-eabi-gcc LD = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy @@ -84,10 +104,22 @@ SIZE = arm-none-eabi-size GIT_HASH := $(shell git rev-parse --short HEAD) -ASFLAGS = -mcpu=cortex-m0 +ASFLAGS = -c -mcpu=cortex-m0 +ifeq ($(ENABLE_OVERLAY),1) +ASFLAGS += -DENABLE_OVERLAY +endif CFLAGS = -Os -Wall -Werror -mcpu=cortex-m0 -fno-builtin -fshort-enums -fno-delete-null-pointer-checks -std=c11 -MMD CFLAGS += -DPRINTF_INCLUDE_CONFIG_H CFLAGS += -DGIT_HASH=\"$(GIT_HASH)\" +ifeq ($(ENABLE_AIRCOPY),1) +CFLAGS += -DENABLE_AIRCOPY +endif +ifeq ($(ENABLE_OVERLAY),1) +CFLAGS += -DENABLE_OVERLAY +endif +ifeq ($(ENABLE_UART),1) +CFLAGS += -DENABLE_UART +endif LDFLAGS = -mcpu=cortex-m0 -nostartfiles -Wl,-T,firmware.ld ifeq ($(DEBUG),1) diff --git a/app/app.c b/app/app.c index addb695..1bb2b51 100644 --- a/app/app.c +++ b/app/app.c @@ -16,7 +16,9 @@ #include #include "app/action.h" +#if defined(ENABLE_AIRCOPY) #include "app/aircopy.h" +#endif #include "app/app.h" #include "app/dtmf.h" #include "app/fm.h" @@ -24,7 +26,9 @@ #include "app/main.h" #include "app/menu.h" #include "app/scanner.h" +#if defined(ENABLE_UART) #include "app/uart.h" +#endif #include "ARMCM0.h" #include "audio.h" #include "board.h" @@ -44,7 +48,9 @@ #include "misc.h" #include "radio.h" #include "settings.h" +#if defined(ENABLE_OVERLAY) #include "sram-overlay.h" +#endif #include "ui/battery.h" #include "ui/inputbox.h" #include "ui/menu.h" @@ -535,6 +541,7 @@ void APP_CheckRadioInterrupts(void) g_SquelchLost = false; BK4819_ToggleGpioOut(BK4819_GPIO0_PIN28_GREEN, false); } +#if defined(ENABLE_AIRCOPY) if (Mask & BK4819_REG_02_FSK_FIFO_ALMOST_FULL && gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState == AIRCOPY_TRANSFER && gAirCopyIsSendMode == 0) { uint8_t i; @@ -543,6 +550,7 @@ void APP_CheckRadioInterrupts(void) } AIRCOPY_StorePacket(); } +#endif } } @@ -732,7 +740,11 @@ void APP_CheckKeys(void) { KEY_Code_t Key; - if (gSetting_KILLED || (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState != AIRCOPY_READY)) { + if (gSetting_KILLED +#if defined(ENABLE_AIRCOPY) + || (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState != AIRCOPY_READY) +#endif + ) { return; } @@ -802,11 +814,13 @@ void APP_TimeSlice10ms(void) { gFlashLightBlinkCounter++; +#if defined(ENABLE_UART) if (UART_IsCommandAvailable()) { __disable_irq(); UART_HandleCommand(); __enable_irq(); } +#endif if (gReducedService) { return; @@ -987,6 +1001,7 @@ void APP_TimeSlice10ms(void) } } +#if defined(ENABLE_AIRCOPY) if (gScreenToDisplay == DISPLAY_AIRCOPY && gAircopyState == AIRCOPY_TRANSFER && gAirCopyIsSendMode == 1) { if (gAircopySendCountdown) { gAircopySendCountdown--; @@ -996,6 +1011,7 @@ void APP_TimeSlice10ms(void) } } } +#endif APP_CheckKeys(); } @@ -1020,7 +1036,11 @@ void APP_TimeSlice500ms(void) if (gReducedService) { BOARD_ADC_GetBatteryInfo(&gBatteryCurrentVoltage, &gBatteryCurrent); if (gBatteryCurrent > 500 || gBatteryCalibration[3] < gBatteryCurrentVoltage) { +#if defined(ENABLE_OVERLAY) overlay_FLASH_RebootToBootloader(); +#else + NVIC_SystemReset(); +#endif } return; } @@ -1048,7 +1068,11 @@ void APP_TimeSlice500ms(void) GPIO_ClearBit(&GPIOB->DATA, GPIOB_PIN_BACKLIGHT); } } - if (gScreenToDisplay != DISPLAY_AIRCOPY && (gScreenToDisplay != DISPLAY_SCANNER || (gScanCssState >= SCAN_CSS_STATE_FOUND))) { + if ( +#if defined(ENABLE_AIRCOPY) + gScreenToDisplay != DISPLAY_AIRCOPY && +#endif + (gScreenToDisplay != DISPLAY_SCANNER || (gScanCssState >= SCAN_CSS_STATE_FOUND))) { if (gEeprom.AUTO_KEYPAD_LOCK && gKeyLockCountdown && !gDTMF_InputMode) { gKeyLockCountdown--; if (gKeyLockCountdown == 0) { @@ -1406,13 +1430,19 @@ static void APP_ProcessKey(KEY_Code_t Key, bool bKeyPressed, bool bKeyHeld) case DISPLAY_SCANNER: SCANNER_ProcessKeys(Key, bKeyPressed, bKeyHeld); break; +#if defined(ENABLE_AIRCOPY) case DISPLAY_AIRCOPY: AIRCOPY_ProcessKeys(Key, bKeyPressed, bKeyHeld); break; +#endif default: break; } - } else if (gScreenToDisplay != DISPLAY_SCANNER && gScreenToDisplay != DISPLAY_AIRCOPY) { + } else if (gScreenToDisplay != DISPLAY_SCANNER +#if defined(ENABLE_AIRCOPY) + && gScreenToDisplay != DISPLAY_AIRCOPY +#endif + ) { ACTION_Handle(Key, bKeyPressed, bKeyHeld); } else if (!bKeyHeld && bKeyPressed) { gBeepToPlay = BEEP_500HZ_60MS_DOUBLE_BEEP_OPTIONAL; diff --git a/app/menu.c b/app/menu.c index 20a4bd8..b092fdb 100644 --- a/app/menu.c +++ b/app/menu.c @@ -15,6 +15,9 @@ */ #include +#if !defined(ENABLE_OVERLAY) +#include "ARMCM0.h" +#endif #include "app/dtmf.h" #include "app/generic.h" #include "app/menu.h" @@ -28,7 +31,9 @@ #include "frequencies.h" #include "misc.h" #include "settings.h" +#if defined(ENABLE_OVERLAY) #include "sram-overlay.h" +#endif #include "ui/inputbox.h" #include "ui/menu.h" #include "ui/ui.h" @@ -980,7 +985,11 @@ static void MENU_Key_MENU(bool bKeyPressed, bool bKeyHeld) AUDIO_SetVoiceID(0, VOICE_ID_CONFIRM); AUDIO_PlaySingleVoice(true); MENU_AcceptSetting(); +#if defined(ENABLE_OVERLAY) overlay_FLASH_RebootToBootloader(); +#else + NVIC_SystemReset(); +#endif } gFlagAcceptSetting = true; gIsInSubMenu = false; diff --git a/app/uart.c b/app/uart.c index 4af7319..c2d68b4 100644 --- a/app/uart.c +++ b/app/uart.c @@ -15,6 +15,9 @@ */ #include +#if !defined(ENABLE_OVERLAY) +#include "ARMCM0.h" +#endif #include "app/fm.h" #include "app/uart.h" #include "board.h" @@ -29,7 +32,9 @@ #include "functions.h" #include "misc.h" #include "settings.h" +#if defined(ENABLE_OVERLAY) #include "sram-overlay.h" +#endif #include "version.h" #define DMA_INDEX(x, y) (((x) + (y)) % sizeof(UART_DMA_Buffer)) @@ -510,7 +515,11 @@ void UART_HandleCommand(void) break; case 0x05DD: +#if defined(ENABLE_OVERLAY) overlay_FLASH_RebootToBootloader(); +#else + NVIC_SystemReset(); +#endif break; } } diff --git a/audio.c b/audio.c index 347717a..8d5a300 100644 --- a/audio.c +++ b/audio.c @@ -69,9 +69,11 @@ void AUDIO_PlayBeep(BEEP_Type_t Beep) return; } +#if defined(ENABLE_AIRCOPY) if (gScreenToDisplay == DISPLAY_AIRCOPY) { return; } +#endif if (gCurrentFunction == FUNCTION_RECEIVE) { return; } diff --git a/board.c b/board.c index 3a9ef2c..78c955f 100644 --- a/board.c +++ b/board.c @@ -36,8 +36,11 @@ #include "helper/battery.h" #include "misc.h" #include "settings.h" +#if defined(ENABLE_OVERLAY) #include "sram-overlay.h" +#endif +#if defined(ENABLE_OVERLAY) void BOARD_FLASH_Init(void) { FLASH_Init(FLASH_READ_MODE_1_CYCLE); @@ -47,6 +50,7 @@ void BOARD_FLASH_Init(void) overlay_FLASH_ClockMultiplier = 48; FLASH_Init(FLASH_READ_MODE_2_CYCLE); } +#endif void BOARD_GPIO_Init(void) { @@ -336,7 +340,9 @@ void BOARD_Init(void) BOARD_ADC_Init(); ST7565_Init(); BK1080_Init(0, false); +#if defined(ENABLE_AIRCOPY) || defined(ENABLE_UART) CRC_Init(); +#endif } void BOARD_EEPROM_Init(void) diff --git a/driver/bk4819.c b/driver/bk4819.c index 438c1e9..70f8a9b 100644 --- a/driver/bk4819.c +++ b/driver/bk4819.c @@ -491,6 +491,7 @@ void BK4819_TurnsOffTones_TurnsOnRX(void) ); } +#if defined(ENABLE_AIRCOPY) void BK4819_SetupAircopy(void) { BK4819_WriteRegister(BK4819_REG_70, 0x00E0); // Enable Tone2, tuning gain 48 @@ -508,6 +509,7 @@ void BK4819_ResetFSK(void) SYSTEM_DelayMs(30); BK4819_Idle(); } +#endif void BK4819_Idle(void) { @@ -828,6 +830,7 @@ uint8_t BK4819_GetCTCType(void) return (BK4819_ReadRegister(BK4819_REG_0C) >> 10) & 3; } +#if defined(ENABLE_AIRCOPY) void BK4819_SendFSKData(uint16_t *pData) { uint8_t i; @@ -882,6 +885,7 @@ void BK4819_PrepareFSKReceive(void) // FSK SyncLength Selection BK4819_WriteRegister(BK4819_REG_59, 0x3068); } +#endif void BK4819_PlayRoger(void) { diff --git a/helper/boot.c b/helper/boot.c index a4c5548..d6c6ccd 100644 --- a/helper/boot.c +++ b/helper/boot.c @@ -46,9 +46,11 @@ BOOT_Mode_t BOOT_GetMode(void) if (Keys[0] == KEY_SIDE1) { return BOOT_MODE_F_LOCK; } +#if defined(ENABLE_AIRCOPY) if (Keys[0] == KEY_SIDE2) { return BOOT_MODE_AIRCOPY; } +#endif } return BOOT_MODE_NORMAL; @@ -62,6 +64,7 @@ void BOOT_ProcessMode(BOOT_Mode_t Mode) GUI_SelectNextDisplay(DISPLAY_MENU); gMenuListCount = 57; gF_LOCK = true; +#if defined(ENABLE_AIRCOPY) } else if (Mode == BOOT_MODE_AIRCOPY) { gEeprom.DUAL_WATCH = DUAL_WATCH_OFF; gEeprom.BATTERY_SAVE = 0; @@ -83,6 +86,7 @@ void BOOT_ProcessMode(BOOT_Mode_t Mode) BK4819_ResetFSK(); gAircopyState = AIRCOPY_READY; GUI_SelectNextDisplay(DISPLAY_AIRCOPY); +#endif } else { GUI_SelectNextDisplay(DISPLAY_MAIN); } diff --git a/main.c b/main.c index f509419..16386a7 100644 --- a/main.c +++ b/main.c @@ -26,7 +26,9 @@ #include "driver/gpio.h" #include "driver/system.h" #include "driver/systick.h" +#if defined(ENABLE_UART) #include "driver/uart.h" +#endif #include "helper/battery.h" #include "helper/boot.h" #include "misc.h" @@ -35,11 +37,15 @@ #include "ui/lock.h" #include "ui/welcome.h" +#if defined(ENABLE_UART) static const char Version[] = "UV-K5 Firmware, Open Edition, OEFW-"GIT_HASH"\r\n"; +#endif void _putchar(char c) { +#if defined(ENABLE_UART) UART_Send((uint8_t *)&c, 1); +#endif } void Main(void) @@ -61,8 +67,10 @@ void Main(void) SYSTICK_Init(); BOARD_Init(); +#if defined(ENABLE_UART) UART_Init(); UART_Send(Version, sizeof(Version)); +#endif // Not implementing authentic device checks diff --git a/misc.c b/misc.c index cdf9424..1058ebd 100644 --- a/misc.c +++ b/misc.c @@ -119,7 +119,9 @@ uint8_t gPttDebounceCounter; uint8_t gMenuListCount; uint8_t gBackupCROSS_BAND_RX_TX; uint8_t gScanDelay; +#if defined(ENABLE_AIRCOPY) uint8_t gAircopySendCountdown; +#endif uint8_t gFSKWriteIndex; uint8_t gNeverUsed; diff --git a/misc.h b/misc.h index fb20117..b6e0ffd 100644 --- a/misc.h +++ b/misc.h @@ -170,7 +170,9 @@ extern uint8_t gPttDebounceCounter; extern uint8_t gMenuListCount; extern uint8_t gBackupCROSS_BAND_RX_TX; extern uint8_t gScanDelay; +#if defined(ENABLE_AIRCOPY) extern uint8_t gAircopySendCountdown; +#endif extern uint8_t gFSKWriteIndex; extern uint8_t gNeverUsed; diff --git a/settings.c b/settings.c index af67444..8cf0525 100644 --- a/settings.c +++ b/settings.c @@ -17,7 +17,9 @@ #include #include "app/fm.h" #include "driver/eeprom.h" +#if defined(ENABLE_UART) #include "driver/uart.h" +#endif #include "misc.h" #include "settings.h" @@ -33,7 +35,9 @@ void SETTINGS_SaveFM(void) uint8_t Padding[4]; } State; +#if defined(ENABLE_UART) UART_LogSend("sFm\r\n", 5); +#endif memset(&State, 0xFF, sizeof(State)); State.Channel = gEeprom.FM_SelectedChannel; @@ -50,7 +54,9 @@ void SETTINGS_SaveVfoIndices(void) { uint8_t State[8]; +#if defined(ENABLE_UART) UART_LogSend("sidx\r\n", 6); +#endif State[0] = gEeprom.ScreenChannel[0]; State[1] = gEeprom.MrChannel[0]; @@ -69,7 +75,9 @@ void SETTINGS_SaveSettings(void) uint8_t State[8]; uint32_t Password[2]; +#if defined(ENABLE_UART) UART_LogSend("spub\r\n", 6); +#endif State[0] = gEeprom.CHAN_1_CALL; State[1] = gEeprom.SQUELCH_LEVEL; @@ -168,7 +176,9 @@ void SETTINGS_SaveSettings(void) void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, uint8_t Mode) { +#if defined(ENABLE_UART) UART_LogSend("schn\r\n", 6); +#endif if (IS_NOT_NOAA_CHANNEL(Channel)) { uint16_t OffsetMR; @@ -222,7 +232,9 @@ void SETTINGS_SaveChannel(uint8_t Channel, uint8_t VFO, const VFO_Info_t *pVFO, void SETTINGS_UpdateChannel(uint8_t Channel, const VFO_Info_t *pVFO, bool bUpdate) { +#if defined(ENABLE_UART) UART_LogSend("svalid\r\n", 8); +#endif if (IS_NOT_NOAA_CHANNEL(Channel)) { uint8_t State[8]; diff --git a/start.S b/start.S index 7399bb9..eb29dd7 100644 --- a/start.S +++ b/start.S @@ -245,7 +245,9 @@ HandlerReset: mov sp, r0 bl DATA_Init bl BSS_Init +#if defined(ENABLE_OVERLAY) bl BOARD_FLASH_Init +#endif bl Main b . diff --git a/ui/lock.c b/ui/lock.c index 3fb2d5f..1b67910 100644 --- a/ui/lock.c +++ b/ui/lock.c @@ -16,7 +16,9 @@ #include #include "ARMCM0.h" +#if defined(ENABLE_UART) #include "app/uart.h" +#endif #include "audio.h" #include "driver/keyboard.h" #include "driver/st7565.h" @@ -109,11 +111,13 @@ void UI_DisplayLock(void) gKeyReading0 = Key; } +#if defined(ENABLE_UART) if (UART_IsCommandAvailable()) { __disable_irq(); UART_HandleCommand(); __enable_irq(); } +#endif if (gUpdateDisplay) { Render(); diff --git a/ui/ui.c b/ui/ui.c index a174826..b8ca84b 100644 --- a/ui/ui.c +++ b/ui/ui.c @@ -20,7 +20,9 @@ #include "app/scanner.h" #include "driver/keyboard.h" #include "misc.h" +#if defined(ENABLE_AIRCOPY) #include "ui/aircopy.h" +#endif #include "ui/fmradio.h" #include "ui/inputbox.h" #include "ui/main.h" @@ -50,9 +52,11 @@ void GUI_DisplayScreen(void) case DISPLAY_SCANNER: UI_DisplayScanner(); break; +#if defined(ENABLE_AIRCOPY) case DISPLAY_AIRCOPY: UI_DisplayAircopy(); break; +#endif default: break; } diff --git a/ui/ui.h b/ui/ui.h index f2809a1..d8a0b61 100644 --- a/ui/ui.h +++ b/ui/ui.h @@ -25,7 +25,9 @@ enum GUI_DisplayType_t { DISPLAY_FM = 0x01U, DISPLAY_MENU = 0x02U, DISPLAY_SCANNER = 0x03U, +#if defined(ENABLE_AIRCOPY) DISPLAY_AIRCOPY = 0x04U, +#endif DISPLAY_INVALID = 0xFFU, };