diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index a93a27c11..02239f82e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -160,10 +160,10 @@ jobs: matrix: os: ['macos', 'ubuntu', 'windows'] board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE', 'UNIVERSAL'] - cmake: ['3.10.0', 'latest'] + cmake: ['3.12.0', 'latest'] exclude: - os: 'windows' - cmake: '3.10.0' + cmake: '3.12.0' # GitHub doesn't give us many macOS runners, so don't build for every board. # We just need to know that building firmware works on macOS. Use PRALINE # since that's the most complicated one due to FPGA bitstreams. diff --git a/.github/workflows/includes-check.yml b/.github/workflows/includes-check.yml index 116400698..f16800feb 100644 --- a/.github/workflows/includes-check.yml +++ b/.github/workflows/includes-check.yml @@ -14,7 +14,7 @@ jobs: strategy: matrix: board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE', 'UNIVERSAL'] - cmake: ['3.10.0', 'latest'] + cmake: ['3.12.0', 'latest'] # Don't cancel all builds when one fails fail-fast: false diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index 611e78704..844ae7087 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -23,7 +23,7 @@ option(CHECK_INCLUDES "Check firmware sources for unused includes and transitive dependencies. (Requires iwyu)" OFF) -cmake_minimum_required(VERSION 3.10.0) +cmake_minimum_required(VERSION 3.12.0) set(CMAKE_TOOLCHAIN_FILE toolchain-arm-cortex-m.cmake) project (hackrf_firmware_all C) diff --git a/firmware/common/clock_gen.h b/firmware/common/clock_gen.h index 0bc6439b0..fa1d3da02 100644 --- a/firmware/common/clock_gen.h +++ b/firmware/common/clock_gen.h @@ -25,8 +25,6 @@ extern "C" { #endif -#include "platform_detect.h" // IWYU pragma: keep - #include #include "fixed_point.h" diff --git a/firmware/common/clock_io.c b/firmware/common/clock_io.c index b0904f894..d4d14af06 100644 --- a/firmware/common/clock_io.c +++ b/firmware/common/clock_io.c @@ -32,6 +32,7 @@ #include "gpdma.h" #include "gpio.h" +#include "platform_detect.h" #ifdef IS_NOT_PRALINE #include "sgpio.h" #endif diff --git a/firmware/common/clock_io.h b/firmware/common/clock_io.h index df540022e..4868b2d99 100644 --- a/firmware/common/clock_io.h +++ b/firmware/common/clock_io.h @@ -24,8 +24,6 @@ #include #include -#include "platform_detect.h" // IWYU pragma: keep - void clkin_detect_init(void); uint32_t clkin_frequency(void); diff --git a/firmware/common/cpld_jtag.c b/firmware/common/cpld_jtag.c index 92f89f271..441fefe80 100644 --- a/firmware/common/cpld_jtag.c +++ b/firmware/common/cpld_jtag.c @@ -22,7 +22,6 @@ #include "cpld_jtag.h" #include "platform_detect.h" - #ifdef IS_NOT_PRALINE #include #include "xapp058/micro.h" diff --git a/firmware/common/cpld_jtag.h b/firmware/common/cpld_jtag.h index 14f70437c..f49f13174 100644 --- a/firmware/common/cpld_jtag.h +++ b/firmware/common/cpld_jtag.h @@ -24,7 +24,6 @@ #include #include "gpio.h" -#include "platform_detect.h" typedef struct { gpio_t gpio_tck; diff --git a/firmware/common/cpu_clock.c b/firmware/common/cpu_clock.c index aa4ac9107..37445e516 100644 --- a/firmware/common/cpu_clock.c +++ b/firmware/common/cpu_clock.c @@ -31,9 +31,6 @@ #include "delay.h" #include "i2c_bus.h" #include "si5351c.h" -#ifdef IS_NOT_RAD1O - #include "platform_detect.h" -#endif /* Configure PLL1 (Main MCU Clock) to max speed (204MHz). diff --git a/firmware/common/cpu_clock.h b/firmware/common/cpu_clock.h index b0393081c..92ad64412 100644 --- a/firmware/common/cpu_clock.h +++ b/firmware/common/cpu_clock.h @@ -25,8 +25,6 @@ extern "C" { #endif -#include "platform_detect.h" // IWYU pragma: keep - void cpu_clock_init(void); #ifdef __cplusplus diff --git a/firmware/common/hackrf_ui.c b/firmware/common/hackrf_ui.c index 4224d40f2..ac243890e 100644 --- a/firmware/common/hackrf_ui.c +++ b/firmware/common/hackrf_ui.c @@ -23,7 +23,6 @@ #include #include "hackrf_ui.h" -#include "platform_detect.h" // IWYU pragma: keep #include "transceiver_mode.h" #ifdef IS_EXPANSION_COMPATIBLE #include "ui_portapack.h" diff --git a/firmware/common/max283x.h b/firmware/common/max283x.h index b4e446201..4db5edfe7 100644 --- a/firmware/common/max283x.h +++ b/firmware/common/max283x.h @@ -27,7 +27,6 @@ #include #include "fixed_point.h" -#include "platform_detect.h" #include "spi_ssp.h" #ifdef IS_PRALINE diff --git a/firmware/common/mixer.h b/firmware/common/mixer.h index 35c0f047a..15afe35e7 100644 --- a/firmware/common/mixer.h +++ b/firmware/common/mixer.h @@ -26,8 +26,6 @@ #include #include "fixed_point.h" -#include "platform_detect.h" - #ifdef IS_RAD1O #include "max2871.h" #endif diff --git a/firmware/common/operacake_sctimer.c b/firmware/common/operacake_sctimer.c index 1268114f9..9325f65df 100644 --- a/firmware/common/operacake_sctimer.c +++ b/firmware/common/operacake_sctimer.c @@ -30,12 +30,15 @@ #include "platform_detect.h" #include "platform_scu.h" #include "sct.h" - #ifdef IS_NOT_PRALINE #include #include #endif +#include "delay.h" +#include "platform_detect.h" +#include "sct.h" + #define U1CTRL_SET SCT_OUT14_SET #define U1CTRL_CLR SCT_OUT14_CLR #define U2CTRL0_SET SCT_OUT13_SET diff --git a/firmware/common/pins.c b/firmware/common/pins.c index 48479f951..3010cd9f5 100644 --- a/firmware/common/pins.c +++ b/firmware/common/pins.c @@ -39,7 +39,7 @@ #include "rf_path.h" #include "sgpio.h" #include "w25q80bv.h" -#if defined(IS_PRALINE) +#ifdef IS_PRALINE #include "clock_io.h" #include "ice40_spi.h" #endif diff --git a/firmware/common/pins.h b/firmware/common/pins.h index b9454d183..bc109e5b4 100644 --- a/firmware/common/pins.h +++ b/firmware/common/pins.h @@ -27,8 +27,6 @@ extern "C" { #endif -#include "platform_detect.h" // IWYU pragma: keep - void pins_shutdown(void); void pins_setup(void); diff --git a/firmware/common/platform_detect.h b/firmware/common/platform_detect.h index 0331fe9cd..4f0f0f438 100644 --- a/firmware/common/platform_detect.h +++ b/firmware/common/platform_detect.h @@ -21,7 +21,6 @@ #pragma once -#include #include #define BOARD_REV_GSG (0x80) @@ -32,67 +31,6 @@ #define PLATFORM_HACKRF1_R9 (1 << 3) #define PLATFORM_PRALINE (1 << 4) -/* clang-format off */ - -/* Helper macros for platform-specific code. */ -#if defined(UNIVERSAL) - #define IS_PRALINE (detected_platform() == BOARD_ID_PRALINE) - #define IS_NOT_PRALINE (!IS_PRALINE) - #define IS_HACKRF_ONE ( \ - detected_platform() == BOARD_ID_HACKRF1_OG || \ - detected_platform() == BOARD_ID_HACKRF1_R9 \ - ) - #define IS_NOT_HACKRF_ONE (!IS_HACKRF_ONE) - #define IS_H1_R9 (detected_platform() == BOARD_ID_HACKRF1_R9) - #define IS_NOT_H1_R9 (!IS_H1_R9) - #define IS_NOT_RAD1O true - #define IS_NOT_JAWBREAKER true - #define IS_H1_OR_PRALINE true - #define IS_H1_OR_RAD1O IS_HACKRF_ONE - #define IS_H1_OR_JAWBREAKER IS_HACKRF_ONE - #define IS_FOUR_LEDS IS_PRALINE - #define IS_EXPANSION_COMPATIBLE true -#elif defined(HACKRF_ONE) - #define IS_NOT_PRALINE true - #define IS_HACKRF_ONE true - #define IS_H1_R9 (detected_platform() == BOARD_ID_HACKRF1_R9) - #define IS_NOT_H1_R9 (!IS_H1_R9) - #define IS_NOT_RAD1O true - #define IS_NOT_JAWBREAKER true - #define IS_H1_OR_PRALINE true - #define IS_H1_OR_RAD1O true - #define IS_H1_OR_JAWBREAKER true - #define IS_EXPANSION_COMPATIBLE true -#elif defined(PRALINE) - #define IS_PRALINE true - #define IS_NOT_HACKRF_ONE true - #define IS_NOT_H1_R9 true - #define IS_NOT_RAD1O true - #define IS_NOT_JAWBREAKER true - #define IS_H1_OR_PRALINE true - #define IS_FOUR_LEDS true - #define IS_EXPANSION_COMPATIBLE true -#elif defined(RAD1O) - #define IS_NOT_PRALINE true - #define IS_NOT_HACKRF_ONE true - #define IS_NOT_H1_R9 true - #define IS_RAD1O true - #define IS_NOT_JAWBREAKER true - #define IS_H1_OR_RAD1O true - #define IS_FOUR_LEDS true -#elif defined(JAWBREAKER) - #define IS_NOT_PRALINE true - #define IS_NOT_HACKRF_ONE true - #define IS_NOT_H1_R9 true - #define IS_NOT_RAD1O true - #define IS_JAWBREAKER true - #define IS_H1_OR_JAWBREAKER true -#else - #error "No recognised platform defined" -#endif - -/* clang-format on */ - typedef enum { BOARD_ID_JELLYBEAN = 0, BOARD_ID_JAWBREAKER = 1, diff --git a/firmware/common/platform_gpio.h b/firmware/common/platform_gpio.h index a7e68bc9d..c57df96e7 100644 --- a/firmware/common/platform_gpio.h +++ b/firmware/common/platform_gpio.h @@ -27,7 +27,6 @@ extern "C" { #include "gpio.h" #include "gpio_lpc.h" -#include "platform_detect.h" typedef struct { /* LEDs */ diff --git a/firmware/common/platform_scu.h b/firmware/common/platform_scu.h index 71c0f742c..a3702bf78 100644 --- a/firmware/common/platform_scu.h +++ b/firmware/common/platform_scu.h @@ -29,8 +29,6 @@ extern "C" { #include -#include "platform_detect.h" - /* * SCU PinMux */ diff --git a/firmware/common/power.c b/firmware/common/power.c index 25424aabd..1256e5953 100644 --- a/firmware/common/power.c +++ b/firmware/common/power.c @@ -24,15 +24,13 @@ #if defined(IS_HACKRF_ONE) #include #endif -#if defined(IS_HACKRF_ONE) || defined(IS_RAD1O) || defined(IS_JAWBREAKER) - #include "platform_detect.h" -#endif -#if defined(IS_PRALINE) || defined(IS_RAD1O) - #include "delay.h" -#endif #include "gpio.h" +#include "platform_detect.h" #include "platform_gpio.h" +#if defined(IS_PRALINE) || defined(IS_RAD1O) + #include "delay.h" +#endif #ifdef IS_PRALINE void enable_1v2_power(void) diff --git a/firmware/common/power.h b/firmware/common/power.h index 22b2345eb..fc8af67a5 100644 --- a/firmware/common/power.h +++ b/firmware/common/power.h @@ -25,8 +25,6 @@ extern "C" { #endif -#include "platform_detect.h" // IWYU pragma: keep - #ifdef IS_PRALINE void enable_1v2_power(void); void disable_1v2_power(void); diff --git a/firmware/common/rf_path.h b/firmware/common/rf_path.h index 3b97ac621..a1796f13a 100644 --- a/firmware/common/rf_path.h +++ b/firmware/common/rf_path.h @@ -25,8 +25,6 @@ #include -#include "platform_detect.h" // IWYU pragma: keep - #ifdef IS_NOT_JAWBREAKER #include "gpio.h" #endif diff --git a/firmware/common/rffc5071.h b/firmware/common/rffc5071.h index c6b2c0c22..409710615 100644 --- a/firmware/common/rffc5071.h +++ b/firmware/common/rffc5071.h @@ -27,7 +27,6 @@ #include "fixed_point.h" #include "gpio.h" -#include "platform_detect.h" // IWYU pragma: keep #include "spi_bus.h" /* 31 registers, each containing 16 bits of data. */ diff --git a/firmware/common/selftest.h b/firmware/common/selftest.h index 9fca53a66..cea60da20 100644 --- a/firmware/common/selftest.h +++ b/firmware/common/selftest.h @@ -24,8 +24,6 @@ #include #include -#include "platform_detect.h" // IWYU pragma: keep - #define NUM_LOCK_ATTEMPTS 3 enum { diff --git a/firmware/common/sgpio.h b/firmware/common/sgpio.h index 58a30c276..0aebdb5f9 100644 --- a/firmware/common/sgpio.h +++ b/firmware/common/sgpio.h @@ -26,7 +26,6 @@ #include #include "gpio.h" -#include "platform_detect.h" // IWYU pragma: keep typedef enum { SGPIO_DIRECTION_RX, diff --git a/firmware/hackrf-common.cmake b/firmware/hackrf-common.cmake index eb1d57160..dfc67d9eb 100644 --- a/firmware/hackrf-common.cmake +++ b/firmware/hackrf-common.cmake @@ -74,6 +74,8 @@ if(NOT DEFINED BOARD) set(BOARD HACKRF_ONE) endif() +include(${PATH_HACKRF_FIRMWARE}/platform-detect.cmake) + if(BOARD STREQUAL "HACKRF_ONE" OR BOARD STREQUAL "PRALINE" OR BOARD STREQUAL "UNIVERSAL") set(MCU_PARTNO LPC4320) else() diff --git a/firmware/hackrf_usb/usb_api_register.c b/firmware/hackrf_usb/usb_api_register.c index 30d1d4934..1a9f02380 100644 --- a/firmware/hackrf_usb/usb_api_register.c +++ b/firmware/hackrf_usb/usb_api_register.c @@ -21,6 +21,7 @@ * the Free Software Foundation, Inc., 51 Franklin Street, * Boston, MA 02110-1301, USA. */ + #include "usb_api_register.h" #include diff --git a/firmware/hackrf_usb/usb_api_register.h b/firmware/hackrf_usb/usb_api_register.h index aef02d039..a5a36550d 100644 --- a/firmware/hackrf_usb/usb_api_register.h +++ b/firmware/hackrf_usb/usb_api_register.h @@ -23,8 +23,6 @@ #pragma once -#include "platform_detect.h" // IWYU pragma: keep - #include #include diff --git a/firmware/hackrf_usb/usb_api_selftest.c b/firmware/hackrf_usb/usb_api_selftest.c index 4c812366b..7fde6f687 100644 --- a/firmware/hackrf_usb/usb_api_selftest.c +++ b/firmware/hackrf_usb/usb_api_selftest.c @@ -23,6 +23,9 @@ #include #include +#ifdef IS_NOT_RAD1O + #include +#endif #include #include @@ -33,10 +36,6 @@ #include #include -#ifdef IS_NOT_RAD1O - #include -#endif - static char* itoa(int val, int base) { static char buf[32] = {0}; diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c index 067317b31..005babb35 100644 --- a/firmware/hackrf_usb/usb_descriptor.c +++ b/firmware/hackrf_usb/usb_descriptor.c @@ -26,8 +26,6 @@ #include -#include "platform_detect.h" - #define USB_VENDOR_ID (0x1D50) #define USB_API_VERSION (0x0112) diff --git a/firmware/hackrf_usb/usb_descriptor.h b/firmware/hackrf_usb/usb_descriptor.h index ef41d6ac9..bd43f4aa8 100644 --- a/firmware/hackrf_usb/usb_descriptor.h +++ b/firmware/hackrf_usb/usb_descriptor.h @@ -24,8 +24,6 @@ #include -#include "platform_detect.h" - #if defined(IS_HACKRF_ONE) || defined(IS_PRALINE) extern uint8_t usb_descriptor_device_hackrf[]; #endif diff --git a/firmware/hackrf_usb/usb_device.c b/firmware/hackrf_usb/usb_device.c index a2af1158a..90347e17f 100644 --- a/firmware/hackrf_usb/usb_device.c +++ b/firmware/hackrf_usb/usb_device.c @@ -25,7 +25,6 @@ #include -#include "platform_detect.h" #include "usb_descriptor.h" usb_configuration_t usb_configuration_high_speed = { diff --git a/firmware/hackrf_usb/usb_device.h b/firmware/hackrf_usb/usb_device.h index f442db379..5ef533609 100644 --- a/firmware/hackrf_usb/usb_device.h +++ b/firmware/hackrf_usb/usb_device.h @@ -25,8 +25,6 @@ #include -#include "platform_detect.h" - extern usb_device_t usb_device; #ifdef IS_HACKRF_ONE diff --git a/firmware/include-what-you-use.cmake b/firmware/include-what-you-use.cmake index b5c1bc7ec..291cfdab2 100644 --- a/firmware/include-what-you-use.cmake +++ b/firmware/include-what-you-use.cmake @@ -28,11 +28,27 @@ endif() # include-what-you-use arguments: # # --no_fwd_decls - Disable forward declaration suggestions. +# --keep - Always keep the specified include. # --mapping_file - Specify mapping files for excluding suggestions. +# -w - Disable spurious clang warnings. +# +# NOTE: We specify '--keep platform_detect.h' due to iwyu 0.23 not +# being able to detect usage of symbols within preprocessor +# macros. This results in false positives for the removal of the +# include. +# +# The alternate solution is to use "// IWYU pragma: always-keep" +# within "platform_detect.h" itself but this triggers the +# angle-quote-curse on 0.23. (e.g. https://github.com/include-what-you-use/include-what-you-use/issues/1087) +# +# iwyu versions from at least 0.26 onwards do not suffer from these +# problems which will allow us to remove it in future. # list(APPEND IWYU_COMMAND -Xiwyu --no_fwd_decls - -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/libopencm3.imp) + -Xiwyu --keep ${CMAKE_SOURCE_DIR}/common/platform_detect.h + -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/libopencm3.imp + -w) set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND}) set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU_COMMAND}) diff --git a/firmware/platform-detect.cmake b/firmware/platform-detect.cmake new file mode 100644 index 000000000..dcaeba58f --- /dev/null +++ b/firmware/platform-detect.cmake @@ -0,0 +1,87 @@ +# Copyright 2026 Great Scott Gadgets +# +# This file is part of HackRF. +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2, or (at your option) +# any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +cmake_minimum_required(VERSION 3.12.0) + +if(BOARD STREQUAL "UNIVERSAL") + add_compile_definitions( + "IS_PRALINE=(detected_platform() == BOARD_ID_PRALINE)" + "IS_NOT_PRALINE=(!IS_PRALINE)" + "IS_HACKRF_ONE=( \ + detected_platform() == BOARD_ID_HACKRF1_OG || \ + detected_platform() == BOARD_ID_HACKRF1_R9 \ + )" + "IS_NOT_HACKRF_ONE=(!IS_HACKRF_ONE)" + "IS_H1_R9=(detected_platform() == BOARD_ID_HACKRF1_R9)" + "IS_NOT_H1_R9=(!IS_H1_R9)" + "IS_NOT_RAD1O=1" + "IS_NOT_JAWBREAKER=1" + "IS_H1_OR_PRALINE=1" + "IS_H1_OR_RAD1O=IS_HACKRF_ONE" + "IS_H1_OR_JAWBREAKER=IS_HACKRF_ONE" + "IS_FOUR_LEDS=IS_PRALINE" + "IS_EXPANSION_COMPATIBLE=1" + ) +elseif(BOARD STREQUAL "HACKRF_ONE") + add_compile_definitions( + "IS_NOT_PRALINE=1" + "IS_HACKRF_ONE=1" + "IS_H1_R9=(detected_platform() == BOARD_ID_HACKRF1_R9)" + "IS_NOT_H1_R9=(!IS_H1_R9)" + "IS_NOT_RAD1O=1" + "IS_NOT_JAWBREAKER=1" + "IS_H1_OR_PRALINE=1" + "IS_H1_OR_RAD1O=1" + "IS_H1_OR_JAWBREAKER=1" + "IS_EXPANSION_COMPATIBLE=1" + ) +elseif(BOARD STREQUAL "PRALINE") + add_compile_definitions( + "IS_PRALINE=1" + "IS_NOT_HACKRF_ONE=1" + "IS_NOT_H1_R9=1" + "IS_NOT_RAD1O=1" + "IS_NOT_JAWBREAKER=1" + "IS_H1_OR_PRALINE=1" + "IS_FOUR_LEDS=1" + "IS_EXPANSION_COMPATIBLE=1" + ) +elseif(BOARD STREQUAL "RAD1O") + add_compile_definitions( + "IS_NOT_PRALINE=1" + "IS_NOT_HACKRF_ONE=1" + "IS_NOT_H1_R9=1" + "IS_RAD1O=1" + "IS_NOT_JAWBREAKER=1" + "IS_H1_OR_RAD1O=1" + "IS_FOUR_LEDS=1" + ) +elseif(BOARD STREQUAL "JAWBREAKER") + add_compile_definitions( + "IS_NOT_PRALINE=1" + "IS_NOT_HACKRF_ONE=1" + "IS_NOT_H1_R9=1" + "IS_NOT_RAD1O=1" + "IS_JAWBREAKER=1" + "IS_H1_OR_JAWBREAKER=1" + ) +else() + message(FATAL_ERROR "No recognized platform defined: ${BOARD}") +endif()