diff --git a/Makefile b/Makefile index 1652878..4b98b1a 100644 --- a/Makefile +++ b/Makefile @@ -3,6 +3,74 @@ # NOTE: Can be overridden externally. # +# +# Get firmware version by grepping for it in main.c +# +# Assumes the first occurence of #define VERSION in main.c defines the current version +# For now the 2'nd #define VERSION contains #define VERSION "unknown" +# +# Determine which OS we're running +# +UNAME_S := $(shell uname -s) +ifeq ($(UNAME_S),Linux) # We're on linux + # Note The # in #define has to be escaped , and the $ in awk has to be $$ , else make interprets them as special characters. + MAIN_C_VERSION := $(shell grep -h "\#define VERSION" main.c | head -1 | awk '{print $$3}' | sed 's/"//g') +endif + +# OSX Versioning untested , so disabled +ifeq ($(UNAME_S),Darwin) # We're on OSX + # Note The # in #define has to be escaped , and the $ in awk has to be $$ , else make interprets them as special characters. + #MAIN_C_VERSION := $(shell grep -h "\#define VERSION" main.c | head -1 | awk '{print $$3}' | sed 's/"//g') +endif + +# +#Set HW Version +# + +# Default to NanoVNA Model H with a Si5351 Clock Gen chip +ifeq ($(HW_VERSION),) + HW_VERSION = H + TARGET = F072 + UDEFS = -DBOARD_CLOCK_GEN=SI5351_CLOCK_GEN # Compile for Si5351 + UDEFS += -DHW_VERSION=$(HW_VERSION) # Pass HW_VERSION to the Compiler +else + # HW_VERSION = H ==> NanoVNA H - TARGET is a F072 - with a Si5351 Clock Gen chip + ifeq ($(HW_VERSION),H) + TARGET = F072 + UDEFS = -DBOARD_CLOCK_GEN=SI5351_CLOCK_GEN # Compile for Si5351 + UDEFS += -DHW_VERSION=$(HW_VERSION) # Pass HW_VERSION to the Compiler + else + # HW_VERSION = H_MS ==> NanoVNA H - TARGET is a F072 - with a MS5351 Clock Gen chip + ifeq ($(HW_VERSION),H_MS) + TARGET = F072 + UDEFS = -DBOARD_CLOCK_GEN=MS5351_CLOCK_GEN # Compile for MS5351 + UDEFS += -DHW_VERSION=$(HW_VERSION) # Pass HW_VERSION to the Compiler + else + # HW_VERSION = 4.3 ==> NanoVNA H4 - TARGET is a F303 - with a Si5351 Clock Gen chip + ifeq ($(HW_VERSION),4.3) + TARGET = F303 + UDEFS = -DBOARD_CLOCK_GEN=SI5351_CLOCK_GEN # Compile for Si5351 + UDEFS += -DHW_VERSION=$(HW_VERSION) # Pass HW_VERSION to the Compiler + else + # HW_VERSION = 4.3_MS ==> NanoVNA H4 - TARGET is a F303 - with a MS5351 Clock Gen chip + ifeq ($(HW_VERSION),4.3_MS) + TARGET = F303 + UDEFS = -DBOARD_CLOCK_GEN=MS5351_CLOCK_GEN # Compile for MS5351 + UDEFS += -DHW_VERSION=$(HW_VERSION) # Pass HW_VERSION to the Compiler + else + # Unnown/Illegal HW_Version specified + ERROR_TXT="Unknown HW_VERSION Specified" + ifdef ERROR_TXT + $(error Firmware build error: $(ERROR_TXT)) + endif + endif + endif + endif + endif +endif + + + #Build target ifeq ($(TARGET),) TARGET = F072 @@ -96,12 +164,19 @@ endif # # Define project name here -ifeq ($(TARGET),F303) - PROJECT = H4 + +ifeq ($(MAIN_C_VERSION),) # If we dont have a version number from main.c + PROJECT = FW-Model-$(HW_VERSION) else - PROJECT = H + PROJECT = FW-v$(MAIN_C_VERSION)-Model-$(HW_VERSION) endif +#ifeq ($(TARGET),F303) +# PROJECT = H4 +#else +# PROJECT = H +#endif + # Imported source files and paths #CHIBIOS = ../ChibiOS-RT CHIBIOS = ChibiOS @@ -240,9 +315,9 @@ CPPWARN = -Wall -Wextra -Wundef # List all user C define here, like -D_DEBUG=1 ifeq ($(TARGET),F303) - UDEFS = -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DNANOVNA_F303 + UDEFS += -DARM_MATH_CM4 -DVERSION=\"$(VERSION)\" -DNANOVNA_F303 else - UDEFS = -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\" + UDEFS += -DARM_MATH_CM0 -DVERSION=\"$(VERSION)\" endif #Enable if use RTC and need auto select source LSE or LSI UDEFS+= -DVNA_AUTO_SELECT_RTC_SOURCE diff --git a/main.c b/main.c index 2d4b40d..cebf470 100644 --- a/main.c +++ b/main.c @@ -956,7 +956,7 @@ config_t config = { ._xtal_freq = XTALFREQ, ._measure_r = MEASURE_DEFAULT_R, ._lever_mode = LM_MARKER, - ._band_mode = 0, + ._band_mode = BOARD_CLOCK_GEN, }; properties_t current_props; diff --git a/si5351.h b/si5351.h index 8758d35..207bdf4 100644 --- a/si5351.h +++ b/si5351.h @@ -19,6 +19,15 @@ * Boston, MA 02110-1301, USA. */ +// Define the two hardware clock generator models +#define SI5351_CLOCK_GEN 0 +#define MS5351_CLOCK_GEN 1 + +// Make the Si5351 generator the default +#ifndef BOARD_CLOCK_GEN +#define BOARD_CLOCK_GEN SI5351_CLOCK_GEN +#endif + #define SI5351_REG_3_OUTPUT_ENABLE_CONTROL 3 #define SI5351_CLK0_EN (1<<0) #define SI5351_CLK1_EN (1<<1) diff --git a/ui.c b/ui.c index 44b6e73..5dd1830 100644 --- a/ui.c +++ b/ui.c @@ -1542,10 +1542,10 @@ static UI_FUNCTION_ADV_CALLBACK(menu_band_sel_acb) { (void)data; if (b){ - b->p1.text = config._band_mode == 0 ? "Si5351" : "MS5351"; + b->p1.text = config._band_mode == SI5351_CLOCK_GEN ? "Si5351" : "MS5351"; return; } - config._band_mode = config._band_mode == 0 ? 1 : 0; + config._band_mode = config._band_mode == SI5351_CLOCK_GEN ? MS5351_CLOCK_GEN : SI5351_CLOCK_GEN; si5351_set_band_mode(config._band_mode); }