diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index eaa1d9821..30b1e48bc 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -159,7 +159,7 @@ jobs: strategy: matrix: os: ['macos', 'ubuntu', 'windows'] - board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE'] + board: ['HACKRF_ONE', 'JAWBREAKER', 'RAD1O', 'PRALINE', 'UNIVERSAL'] cmake: ['3.10.0', 'latest'] exclude: - os: 'windows' @@ -186,7 +186,7 @@ jobs: - name: Install dependencies (macOS) run: | - brew install dfu-util + brew install dfu-util include-what-you-use python3 -m venv environment && source environment/bin/activate python3 -m pip install PyYAML if: matrix.os == 'macos' @@ -195,7 +195,7 @@ jobs: run: | python3 -m venv environment && source environment/bin/activate python3 -m pip install PyYAML - sudo apt install dfu-util + sudo apt install dfu-util iwyu if: matrix.os == 'ubuntu' - name: Build libopencm3 @@ -237,6 +237,7 @@ jobs: mingw-w64-ucrt-x86_64-cmake mingw-w64-ucrt-x86_64-dfu-util mingw-w64-ucrt-x86_64-python-yaml + mingw-w64-ucrt-x86_64-include-what-you-use - name: Build with MSYS (Windows) if: matrix.os == 'windows' diff --git a/Jenkinsfile b/Jenkinsfile index 2ee5b9e5c..d5615bb61 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -9,266 +9,290 @@ pipeline { } } stage('Test HackRF One') { - agent { - docker { - image 'hackrf' - reuseNode true - args '''--group-add=20 --group-add=46 --device-cgroup-rule="c 189:* rmw" \ - --device-cgroup-rule="c 166:* rmw" -v /dev/bus/usb:/dev/bus/usb \ - -v /tmp/req_pipe:/tmp/req_pipe -v /tmp/res_pipe:/tmp/res_pipe''' - } - } - steps { - sh './ci-scripts/install_host.sh' - sh './ci-scripts/build_h1_firmware.sh' - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs all off' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build - } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err + matrix { + axes { + axis { + name 'BOARD' + values 'HACKRF_ONE', 'UNIVERSAL' } } - retry(3) { - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs h1_eut reset' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build - } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err - } - } - sh 'sleep 1s' - sh './ci-scripts/test_host.sh' - } - retry(3) { - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs h1_tester h1_eut reset' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build - } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err - } - } - sh 'sleep 1s' - script { - try { - // Allow 5 minutes for the test to run - timeout(time: 5, unit: 'MINUTES') { - sh '''python3 ci-scripts/hackrf_test.py --ci --log log \ - --hostdir host/build/hackrf-tools/src/ \ - --fwupdate firmware/hackrf_usb/build/ \ - --tester 0000000000000000325866e629a25623 \ - --eut RunningFromRAM --unattended --rev r4''' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "HackRF One Test timeout limit reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build + stages { + stage('Build and Test') { + agent { + docker { + image 'hackrf' + reuseNode true + args '''--group-add=20 --group-add=46 --device-cgroup-rule="c 189:* rmw" \ + --device-cgroup-rule="c 166:* rmw" -v /dev/bus/usb:/dev/bus/usb \ + -v /tmp/req_pipe:/tmp/req_pipe -v /tmp/res_pipe:/tmp/res_pipe''' } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err } - } - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs all off' + steps { + sh './ci-scripts/install_host.sh' + sh "./ci-scripts/build_h1_firmware.sh ${BOARD}" + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs all off' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build + retry(3) { + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs h1_eut reset' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + sh 'sleep 1s' + sh './ci-scripts/test_host.sh' } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err - } - } - } - retry(3) { - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs h1_eut reset' + retry(3) { + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs h1_tester h1_eut reset' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + sh 'sleep 1s' + script { + try { + // Allow 5 minutes for the test to run + timeout(time: 5, unit: 'MINUTES') { + sh '''python3 ci-scripts/hackrf_test.py --ci --log log \ + --hostdir host/build/hackrf-tools/src/ \ + --fwupdate firmware/hackrf_usb/build/ \ + --tester 0000000000000000325866e629a25623 \ + --eut RunningFromRAM --unattended --rev r4''' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "HackRF One Test timeout limit reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs all off' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build + retry(3) { + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs h1_eut reset' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + sh 'sleep 1s' + sh 'python3 ci-scripts/test_sgpio_debug.py' } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err } } - sh 'sleep 1s' - sh 'python3 ci-scripts/test_sgpio_debug.py' } } } stage('Test HackRF Pro') { - agent { - docker { - image 'hackrf' - reuseNode true - args '''--group-add=20 --group-add=46 --device-cgroup-rule="c 189:* rmw" \ - --device-cgroup-rule="c 166:* rmw" -v /dev/bus/usb:/dev/bus/usb \ - -v /tmp/req_pipe:/tmp/req_pipe -v /tmp/res_pipe:/tmp/res_pipe''' - } - } - steps { - sh './ci-scripts/install_host.sh' - sh './ci-scripts/build_hpro_firmware.sh' - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs all off' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build - } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err + matrix { + axes { + axis { + name 'BOARD' + values 'PRALINE', 'UNIVERSAL' } } - retry(3) { - script { - try { - // Allow 20 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs hpro_eut reset' - } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build + stages { + stage('Build and Test') { + agent { + docker { + image 'hackrf' + reuseNode true + args '''--group-add=20 --group-add=46 --device-cgroup-rule="c 189:* rmw" \ + --device-cgroup-rule="c 166:* rmw" -v /dev/bus/usb:/dev/bus/usb \ + -v /tmp/req_pipe:/tmp/req_pipe -v /tmp/res_pipe:/tmp/res_pipe''' } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err } - } - sh 'sleep 1s' - sh './ci-scripts/test_host.sh' - } - retry(3) { - script { - try { - // Allow 10 seconds for the USB hub port power server to respond - timeout(time: 20, unit: 'SECONDS') { - sh 'hubs hpro_tester hpro_eut reset' + steps { + sh './ci-scripts/install_host.sh' + sh "./ci-scripts/build_hpro_firmware.sh ${BOARD}" + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs all off' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "USB hub port power server command timeout reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build - } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err - } - } - sh 'sleep 1s' - script { - try { - // Allow 5 minutes for the test to run - timeout(time: 5, unit: 'MINUTES') { - sh '''python3 ci-scripts/hackrf_pro_test.py --ci --log log \ - --hostdir host/build/hackrf-tools/src \ - --fwupdate firmware/hackrf_usb/build \ - --tester 0000000000000000a06063c82338145f \ - --eut RunningFromRAM -p --rev r1.2''' + retry(3) { + script { + try { + // Allow 20 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs hpro_eut reset' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + sh 'sleep 1s' + sh './ci-scripts/test_host.sh' } - } catch (FlowInterruptedException err) { - // Check if the cause was specifically an exceeded timeout - def cause = err.getCauses().get(0) - if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { - echo "HackRF Pro Test timeout limit reached." - throw err // Re-throw the exception to fail the build - } else { - echo "Build interrupted for another reason." - throw err // Re-throw the exception to fail the build + retry(3) { + script { + try { + // Allow 10 seconds for the USB hub port power server to respond + timeout(time: 20, unit: 'SECONDS') { + sh 'hubs hpro_tester hpro_eut reset' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "USB hub port power server command timeout reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } + sh 'sleep 1s' + script { + try { + // Allow 5 minutes for the test to run + timeout(time: 5, unit: 'MINUTES') { + sh '''python3 ci-scripts/hackrf_pro_test.py --ci --log log \ + --hostdir host/build/hackrf-tools/src \ + --fwupdate firmware/hackrf_usb/build \ + --tester 0000000000000000a06063c82338145f \ + --eut RunningFromRAM -p --rev r1.2''' + } + } catch (FlowInterruptedException err) { + // Check if the cause was specifically an exceeded timeout + def cause = err.getCauses().get(0) + if (cause instanceof org.jenkinsci.plugins.workflow.steps.TimeoutStepExecution.ExceededTimeout) { + echo "HackRF Pro Test timeout limit reached." + throw err // Re-throw the exception to fail the build + } else { + echo "Build interrupted for another reason." + throw err // Re-throw the exception to fail the build + } + } catch (Exception err) { + echo "An unrelated error occurred: ${err.getMessage()}" + throw err + } + } } - } catch (Exception err) { - echo "An unrelated error occurred: ${err.getMessage()}" - throw err } } } diff --git a/ci-scripts/build_h1_firmware.sh b/ci-scripts/build_h1_firmware.sh index 762d64ded..b6fc4ec43 100755 --- a/ci-scripts/build_h1_firmware.sh +++ b/ci-scripts/build_h1_firmware.sh @@ -4,6 +4,6 @@ git submodule init git submodule update cd firmware/hackrf_usb rm -rf build -cmake -DBOARD=HACKRF_ONE -B build +cmake -DBOARD=$1 -B build cmake --build build cd ../.. diff --git a/ci-scripts/build_hpro_firmware.sh b/ci-scripts/build_hpro_firmware.sh index 830d4bf7a..b6fc4ec43 100755 --- a/ci-scripts/build_hpro_firmware.sh +++ b/ci-scripts/build_hpro_firmware.sh @@ -4,6 +4,6 @@ git submodule init git submodule update cd firmware/hackrf_usb rm -rf build -cmake -DBOARD=PRALINE -B build +cmake -DBOARD=$1 -B build cmake --build build cd ../.. diff --git a/firmware/CMakeLists.txt b/firmware/CMakeLists.txt index 10c2d09d2..1e7c0b7c7 100644 --- a/firmware/CMakeLists.txt +++ b/firmware/CMakeLists.txt @@ -21,6 +21,14 @@ # Top directory CMake project for HackRF firmware cmake_minimum_required(VERSION 3.10.0) + +find_program(IWYU NAMES include-what-you-use) +if(IWYU) + list(APPEND IWYU -Xiwyu --no-fwd-decls -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/libopencm3.imp) + set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE ${IWYU}) + set(CMAKE_C_INCLUDE_WHAT_YOU_USE ${IWYU}) +endif() + set(CMAKE_TOOLCHAIN_FILE toolchain-arm-cortex-m.cmake) project (hackrf_firmware_all C) diff --git a/firmware/common/adc.h b/firmware/common/adc.h index 94481678d..b74125af4 100644 --- a/firmware/common/adc.h +++ b/firmware/common/adc.h @@ -19,12 +19,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __ADC_H__ -#define __ADC_H__ +#pragma once #include uint16_t adc_read(uint8_t pin); void adc_off(void); - -#endif // __ADC_H__ diff --git a/firmware/common/bitband.h b/firmware/common/bitband.h index dcf7aefb3..8a0afed5f 100644 --- a/firmware/common/bitband.h +++ b/firmware/common/bitband.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __BITBAND_H__ -#define __BITBAND_H__ +#pragma once #include @@ -37,5 +36,3 @@ void peripheral_bitband_clear( uint32_t peripheral_bitband_get( volatile void* const peripheral_address, const uint_fast8_t bit_number); - -#endif //__BITBAND_H__ diff --git a/firmware/common/clkin.h b/firmware/common/clkin.h index 2f2fa274c..2cef67cfc 100644 --- a/firmware/common/clkin.h +++ b/firmware/common/clkin.h @@ -19,12 +19,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __CLKIN_H__ -#define __CLKIN_H__ +#pragma once #include void clkin_detect_init(void); uint32_t clkin_frequency(void); - -#endif //__CLKIN_H__ diff --git a/firmware/common/cpld_jtag.c b/firmware/common/cpld_jtag.c index 4ef9ce5de..1be890cc4 100644 --- a/firmware/common/cpld_jtag.c +++ b/firmware/common/cpld_jtag.c @@ -24,11 +24,12 @@ #endif #include "cpld_jtag.h" +#include "platform_detect.h" #if !defined(PRALINE) #include "xapp058/micro.h" #endif -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) static refill_buffer_cb refill_buffer; static uint32_t xsvf_buffer_len, xsvf_pos; static unsigned char* xsvf_buffer; @@ -38,52 +39,86 @@ void cpld_jtag_take(jtag_t* const jtag) { const jtag_gpio_t* const gpio = jtag->gpio; + board_id_t board_id = detected_platform(); + /* Set initial GPIO state to the voltages of the internal or external pull-ups/downs, * to avoid any glitches. */ -#if (defined HACKRF_ONE || defined PRALINE) - gpio_set(gpio->gpio_pp_tms); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + gpio_set(gpio->gpio_pp_tms); #endif + break; + default: + break; + } gpio_clear(gpio->gpio_tck); -#ifndef PRALINE - gpio_set(gpio->gpio_tms); - gpio_set(gpio->gpio_tdi); + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + gpio_set(gpio->gpio_tms); + gpio_set(gpio->gpio_tdi); #endif + } -#if (defined HACKRF_ONE || defined PRALINE) - /* Do not drive PortaPack-specific TMS pin initially, just to be cautious. */ - gpio_input(gpio->gpio_pp_tms); - gpio_input(gpio->gpio_pp_tdo); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + /* Do not drive PortaPack-specific TMS pin initially, just to be cautious. */ + gpio_input(gpio->gpio_pp_tms); + gpio_input(gpio->gpio_pp_tdo); #endif + break; + default: + break; + } gpio_output(gpio->gpio_tck); -#ifndef PRALINE - gpio_output(gpio->gpio_tms); - gpio_output(gpio->gpio_tdi); - gpio_input(gpio->gpio_tdo); + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + gpio_output(gpio->gpio_tms); + gpio_output(gpio->gpio_tdi); + gpio_input(gpio->gpio_tdo); #endif + } } void cpld_jtag_release(jtag_t* const jtag) { const jtag_gpio_t* const gpio = jtag->gpio; + board_id_t board_id = detected_platform(); + /* Make all pins inputs when JTAG interface not active. * Let the pull-ups/downs do the work. */ -#if (defined HACKRF_ONE || defined PRALINE) - /* Do not drive PortaPack-specific pins, initially, just to be cautious. */ - gpio_input(gpio->gpio_pp_tms); - gpio_input(gpio->gpio_pp_tdo); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + /* Do not drive PortaPack-specific pins, initially, just to be cautious. */ + gpio_input(gpio->gpio_pp_tms); + gpio_input(gpio->gpio_pp_tdo); #endif + break; + default: + break; + } gpio_input(gpio->gpio_tck); -#ifndef PRALINE - gpio_input(gpio->gpio_tms); - gpio_input(gpio->gpio_tdi); - gpio_input(gpio->gpio_tdo); + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + gpio_input(gpio->gpio_tms); + gpio_input(gpio->gpio_tdi); + gpio_input(gpio->gpio_tdo); #endif + } } -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) /* return 0 if success else return error code see xsvfExecute() */ int cpld_jtag_program( jtag_t* const jtag, diff --git a/firmware/common/cpld_jtag.h b/firmware/common/cpld_jtag.h index 9219dbcbb..e2551e48c 100644 --- a/firmware/common/cpld_jtag.h +++ b/firmware/common/cpld_jtag.h @@ -19,21 +19,20 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __CPLD_JTAG_H__ -#define __CPLD_JTAG_H__ +#pragma once #include #include "gpio.h" -typedef struct jtag_gpio_t { +typedef struct { gpio_t gpio_tck; -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) gpio_t gpio_tms; gpio_t gpio_tdi; gpio_t gpio_tdo; #endif -#if (defined HACKRF_ONE || defined PRALINE) +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) gpio_t gpio_pp_tms; gpio_t gpio_pp_tdo; #endif @@ -59,5 +58,3 @@ int cpld_jtag_program( unsigned char* const buffer, refill_buffer_cb refill); unsigned char cpld_jtag_get_next_byte(void); - -#endif //__CPLD_JTAG_H__ diff --git a/firmware/common/cpld_xc2c.h b/firmware/common/cpld_xc2c.h index 26ac8fa4b..c48dae317 100644 --- a/firmware/common/cpld_xc2c.h +++ b/firmware/common/cpld_xc2c.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __CPLD_XC2C_H__ -#define __CPLD_XC2C_H__ +#pragma once #include #include @@ -69,5 +68,3 @@ bool cpld_xc2c64a_jtag_sram_verify( extern const cpld_xc2c64a_program_t cpld_hackrf_program_sram; extern const cpld_xc2c64a_verify_t cpld_hackrf_verify; extern const cpld_xc2c64a_row_addresses_t cpld_hackrf_row_addresses; - -#endif /*__CPLD_XC2C_H__*/ diff --git a/firmware/common/crc.h b/firmware/common/crc.h index f8acf5fc7..ee33d7dfe 100644 --- a/firmware/common/crc.h +++ b/firmware/common/crc.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __CRC_H__ -#define __CRC_H__ +#pragma once #include #include @@ -35,5 +34,3 @@ typedef struct { void crc32_init(crc32_t* const crc); void crc32_update(crc32_t* const crc, const uint8_t* const data, const size_t byte_count); uint32_t crc32_digest(const crc32_t* const crc); - -#endif //__CRC_H__ diff --git a/firmware/common/delay.h b/firmware/common/delay.h index 123141bad..870ba39e9 100644 --- a/firmware/common/delay.h +++ b/firmware/common/delay.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __DELAY_H -#define __DELAY_H +#pragma once #ifdef __cplusplus extern "C" { @@ -31,4 +30,6 @@ extern "C" { void delay(uint32_t duration); void delay_us_at_mhz(uint32_t us, uint32_t mhz); -#endif /* __DELAY_H */ +#ifdef __cplusplus +} +#endif diff --git a/firmware/common/fault_handler.h b/firmware/common/fault_handler.h index efccea24f..0b499acba 100644 --- a/firmware/common/fault_handler.h +++ b/firmware/common/fault_handler.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __FAULT_HANDLER__ -#define __FAULT_HANDLER__ +#pragma once #include @@ -30,9 +29,7 @@ // TODO: Move all this to a Cortex-M(?) include file, since these // structures are supposedly the same between processors (to an // undetermined extent). -typedef struct armv7m_scb_t armv7m_scb_t; - -struct armv7m_scb_t { +typedef struct { volatile const uint32_t CPUID; volatile uint32_t ICSR; volatile uint32_t VTOR; @@ -64,12 +61,10 @@ struct armv7m_scb_t { volatile const uint32_t ID_ISAR4; volatile const uint32_t __reserved_0x74_0x87[5]; volatile uint32_t CPACR; -} __attribute__((packed)); +} __attribute__((packed)) armv7m_scb_t; static armv7m_scb_t* const SCB = (armv7m_scb_t*) SCB_BASE; #define SCB_HFSR_DEBUGEVT (1 << 31) #define SCB_HFSR_FORCED (1 << 30) #define SCB_HFSR_VECTTBL (1 << 1) - -#endif //__FAULT_HANDLER__ diff --git a/firmware/common/firmware_info.c b/firmware/common/firmware_info.c index 1ac02074d..527dd19b6 100644 --- a/firmware/common/firmware_info.c +++ b/firmware/common/firmware_info.c @@ -30,6 +30,9 @@ #define SUPPORTED_PLATFORM PLATFORM_RAD1O #elif PRALINE #define SUPPORTED_PLATFORM PLATFORM_PRALINE +#elif UNIVERSAL + #define SUPPORTED_PLATFORM \ + (PLATFORM_PRALINE | PLATFORM_HACKRF1_OG | PLATFORM_HACKRF1_R9) #else #define SUPPORTED_PLATFORM 0 #endif diff --git a/firmware/common/firmware_info.h b/firmware/common/firmware_info.h index fb087008b..a7ae09f6e 100644 --- a/firmware/common/firmware_info.h +++ b/firmware/common/firmware_info.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef FIRMWARE_INFO_H -#define FIRMWARE_INFO_H +#pragma once #include @@ -33,5 +32,3 @@ struct firmware_info_t { } __attribute__((packed, aligned(1))); extern const struct firmware_info_t firmware_info; - -#endif \ No newline at end of file diff --git a/firmware/common/fixed_point.h b/firmware/common/fixed_point.h index 500d2e547..65656e192 100644 --- a/firmware/common/fixed_point.h +++ b/firmware/common/fixed_point.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __FIXED_POINT_H__ -#define __FIXED_POINT_H__ +#pragma once #include @@ -32,5 +31,3 @@ typedef uint64_t fp_40_24_t; /* one in 40.24 fixed-point */ #define FP_ONE_HZ (1 << 24) - -#endif /*__FIXED_POINT_H__*/ diff --git a/firmware/common/fpga.h b/firmware/common/fpga.h index bf78cf08c..4aa54239d 100644 --- a/firmware/common/fpga.h +++ b/firmware/common/fpga.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __FPGA_H -#define __FPGA_H +#pragma once #include #include @@ -37,14 +36,11 @@ typedef enum { FPGA_QUARTER_SHIFT_MODE_DOWN = 0b01, } fpga_quarter_shift_mode_t; -struct fpga_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct fpga_driver_t fpga_driver_t; - -struct fpga_driver_t { +typedef struct { ice40_spi_driver_t* bus; uint8_t regs[FPGA_NUM_REGS]; uint8_t regs_dirty; -}; +} fpga_driver_t; struct fpga_loader_t { /* Start address added as an offset to all read() calls. */ @@ -94,5 +90,3 @@ bool fpga_image_load(struct fpga_loader_t* loader, unsigned int index); bool fpga_spi_selftest(void); bool fpga_sgpio_selftest(void); bool fpga_if_xcvr_selftest(void); - -#endif // __FPGA_H diff --git a/firmware/common/fpga_regs.def b/firmware/common/fpga_regs.def index 5964657bf..0a8ce8288 100644 --- a/firmware/common/fpga_regs.def +++ b/firmware/common/fpga_regs.def @@ -1,7 +1,7 @@ /* -*- mode: c -*- * * Copyright 2012 Michael Ossmann - * Copyright 2025 Great Scott Gadgets + * Copyright 2025-2026 Great Scott Gadgets * * This file is part of HackRF. * @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __FPGA_REGS_DEF -#define __FPGA_REGS_DEF +#pragma once #define FPGA_REG_SET_CLEAN(_d, _r) (_d->regs_dirty &= ~(1UL<<_r)) #define FPGA_REG_SET_DIRTY(_d, _r) (_d->regs_dirty |= (1UL<<_r)) @@ -71,5 +70,3 @@ __MREG__(FPGA_STANDARD_TX_INTRP, 5, 0, 3) /* REG 06 (6): TX_PSTEP */ __MREG__(FPGA_STANDARD_TX_PSTEP, 6, 0, 8) - -#endif // __FPGA_REGS_DEF diff --git a/firmware/common/gpdma.h b/firmware/common/gpdma.h index 053f83a89..dc469da9f 100644 --- a/firmware/common/gpdma.h +++ b/firmware/common/gpdma.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __GPDMA_H__ -#define __GPDMA_H__ +#pragma once #include #include @@ -40,5 +39,3 @@ void gpdma_lli_enable_interrupt(gpdma_lli_t* const lli); void gpdma_lli_create_loop(gpdma_lli_t* const lli, const size_t lli_count); void gpdma_lli_create_oneshot(gpdma_lli_t* const lli, const size_t lli_count); - -#endif /*__GPDMA_H__*/ diff --git a/firmware/common/gpio.h b/firmware/common/gpio.h index 387b91a35..749fa0213 100644 --- a/firmware/common/gpio.h +++ b/firmware/common/gpio.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __GPIO_H__ -#define __GPIO_H__ +#pragma once #include @@ -35,5 +34,3 @@ void gpio_output(gpio_t gpio); void gpio_input(gpio_t gpio); void gpio_write(gpio_t gpio, const bool value); bool gpio_read(gpio_t gpio); - -#endif /*__GPIO_H__*/ diff --git a/firmware/common/gpio_lpc.h b/firmware/common/gpio_lpc.h index f018e43c8..0987537fa 100644 --- a/firmware/common/gpio_lpc.h +++ b/firmware/common/gpio_lpc.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __GPIO_LPC_H__ -#define __GPIO_LPC_H__ +#pragma once #include @@ -30,7 +29,7 @@ * register #defines and API declarations into separate header files. */ -typedef struct gpio_port { +typedef struct { volatile uint32_t dir; /* +0x000 */ uint32_t _reserved0[31]; volatile uint32_t mask; /* +0x080 */ @@ -69,5 +68,3 @@ struct gpio { .gpio_w = GPIO_LPC_W(_port_num, _pin_num), \ } // clang-format on - -#endif /*__GPIO_LPC_H__*/ diff --git a/firmware/common/hackrf_core.c b/firmware/common/hackrf_core.c index 8db0e855b..6f9bfb0c6 100644 --- a/firmware/common/hackrf_core.c +++ b/firmware/common/hackrf_core.c @@ -25,9 +25,7 @@ #include #include #include -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - #include -#endif +#include #include "delay.h" #include "gpio.h" @@ -41,10 +39,10 @@ #include "platform_scu.h" #include "spi_bus.h" #include "w25q80bv_target.h" -#if defined(HACKRF_ONE) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) #include "portapack.h" #endif -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "ice40_spi.h" #endif @@ -122,7 +120,7 @@ ssp_config_t ssp_config_w25q80bv = { .clock_prescale_rate = 2, }; -spi_bus_t spi_bus_ssp0 = { +static spi_bus_t spi_bus_ssp0 = { .obj = (void*) SSP0_BASE, .config = &ssp_config_w25q80bv, .start = spi_ssp_start, @@ -140,8 +138,8 @@ sgpio_config_t sgpio_config = { .slice_mode_multislice = true, }; -#ifdef PRALINE -ssp_config_t ssp_config_ice40_fpga = { +#if defined(PRALINE) || defined(UNIVERSAL) +static ssp_config_t ssp_config_ice40_fpga = { .data_bits = SSP_DATA_8BITS, .spi_mode = SSP_CPOL_1_CPHA_1, .serial_clock_rate = 21, @@ -161,11 +159,9 @@ radio_t radio = { .sample_rate_cb = sample_rate_set, }; -rf_path_t rf_path = { - .switchctrl = 0, -}; +rf_path_t rf_path; -jtag_gpio_t jtag_gpio_cpld = {}; +jtag_gpio_t jtag_gpio_cpld; jtag_t jtag_cpld = { .gpio = &jtag_gpio_cpld, @@ -272,62 +268,74 @@ fp_40_24_t sample_rate_set(const fp_40_24_t sample_rate, const bool program) sgpio_cpld_stream_disable(&sgpio_config); } -#ifndef PRALINE - /* Integer mode can be enabled if p1 is even and p2 is zero. */ - if (p1 & 0x1 || p2) { - si5351c_set_int_mode(&clock_gen, 0, 0); - } else { - si5351c_set_int_mode(&clock_gen, 0, 1); - } + if (detected_platform() != BOARD_ID_PRALINE) { + /* Integer mode can be enabled if p1 is even and p2 is zero. */ + if (p1 & 0x1 || p2) { + si5351c_set_int_mode(&clock_gen, 0, 0); + } else { + si5351c_set_int_mode(&clock_gen, 0, 1); + } - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - /* - * On HackRF One r9 all sample clocks are externally derived - * from MS1/CLK1 operating at twice the sample rate. - */ - si5351c_configure_multisynth(&clock_gen, 1, p1, p2, p3, 0); + if (detected_platform() == BOARD_ID_HACKRF1_R9) { + /* + * On HackRF One r9 all sample clocks are externally derived + * from MS1/CLK1 operating at twice the sample rate. + */ + si5351c_configure_multisynth(&clock_gen, 1, p1, p2, p3, 0); + } else { + /* + * On other platforms the clock generator produces three + * different sample clocks, all derived from multisynth 0. + */ + /* MS0/CLK0 is the source for the MAX5864/CPLD (CODEC_CLK). */ + si5351c_configure_multisynth(&clock_gen, 0, p1, p2, p3, 1); + + /* MS0/CLK1 is the source for the CPLD (CODEC_X2_CLK). */ + si5351c_configure_multisynth( + &clock_gen, + 1, + 0, + 0, + 0, + 0); //p1 doesn't matter + + /* MS0/CLK2 is the source for SGPIO (CODEC_X2_CLK) */ + si5351c_configure_multisynth( + &clock_gen, + 2, + 0, + 0, + 0, + 0); //p1 doesn't matter + } } else { - /* - * On other platforms the clock generator produces three - * different sample clocks, all derived from multisynth 0. - */ - /* MS0/CLK0 is the source for the MAX5864/CPLD (CODEC_CLK). */ + /* MS0/CLK0 is the source for the MAX5864/FPGA (AFE_CLK). */ si5351c_configure_multisynth(&clock_gen, 0, p1, p2, p3, 1); - /* MS0/CLK1 is the source for the CPLD (CODEC_X2_CLK). */ - si5351c_configure_multisynth(&clock_gen, 1, 0, 0, 0, 0); //p1 doesn't matter - - /* MS0/CLK2 is the source for SGPIO (CODEC_X2_CLK) */ - si5351c_configure_multisynth(&clock_gen, 2, 0, 0, 0, 0); //p1 doesn't matter - } -#else - /* MS0/CLK0 is the source for the MAX5864 (AFE_CLK). */ - si5351c_configure_multisynth(&clock_gen, 0, p1, p2, p3, 1); - - /* MS1/CLK1 is the source for the FPGA (FPGA_CLK and SCT_CLK). */ - si5351c_configure_multisynth(&clock_gen, 1, p1, p2, p3, 1); + /* MS1/CLK1 is the source for the FPGA (FPGA_CLK and SCT_CLK). */ + si5351c_configure_multisynth(&clock_gen, 1, p1, p2, p3, 1); - /* Delay FPGA_CLK relative to AFE_CLK. */ - uint8_t phase_offset = 0; - if (p1 < 2100) { - phase_offset = (p1 >> 4) - 6; - } - si5351c_set_phase(&clock_gen, 1, phase_offset); + /* Delay FPGA_CLK relative to AFE_CLK. */ + uint8_t phase_offset = 0; + if (p1 < 2100) { + phase_offset = (p1 >> 4) - 6; + } + si5351c_set_phase(&clock_gen, 1, phase_offset); + + if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { + /* + * On older boards FPGA_CLK is on CLK2 while SCT_CLK is on + * CLK1. We configure both so that behavior is consistent with + * newer boards that use CLK1 for both FPGA_CLK and SCT_CLK. + */ + si5351c_configure_multisynth(&clock_gen, 2, p1, p2, p3, 1); + si5351c_set_phase(&clock_gen, 2, phase_offset); + } - if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { - /* - * On older boards FPGA_CLK is on CLK2 while SCT_CLK is on - * CLK1. We configure both so that behavior is consistent with - * newer boards that use CLK1 for both FPGA_CLK and SCT_CLK. - */ - si5351c_configure_multisynth(&clock_gen, 2, p1, p2, p3, 1); - si5351c_set_phase(&clock_gen, 2, phase_offset); + /* Reset PLL to synchronize output clock phase. */ + si5351c_reset_pll(&clock_gen); } - /* Reset PLL to synchronize output clock phase. */ - si5351c_reset_pll(&clock_gen); -#endif - if (streaming) { sgpio_cpld_stream_enable(&sgpio_config); } @@ -478,73 +486,82 @@ void cpu_clock_init(void) CGU_BASE_SSP1_CLK = CGU_BASE_SSP1_CLK_AUTOBLOCK(1) | CGU_BASE_SSP1_CLK_CLK_SEL(CGU_SRC_PLL1); -#if (defined JAWBREAKER || defined HACKRF_ONE || defined PRALINE) - /* Disable unused clocks */ - /* Start with PLLs */ - CGU_PLL0AUDIO_CTRL = CGU_PLL0AUDIO_CTRL_PD(1); - - /* Dividers */ - CGU_IDIVA_CTRL = CGU_IDIVA_CTRL_PD(1); - CGU_IDIVB_CTRL = CGU_IDIVB_CTRL_PD(1); - CGU_IDIVC_CTRL = CGU_IDIVC_CTRL_PD(1); - CGU_IDIVD_CTRL = CGU_IDIVD_CTRL_PD(1); - CGU_IDIVE_CTRL = CGU_IDIVE_CTRL_PD(1); - - /* Base clocks */ - CGU_BASE_SPIFI_CLK = CGU_BASE_SPIFI_CLK_PD(1); /* SPIFI is only used at boot */ - CGU_BASE_USB1_CLK = CGU_BASE_USB1_CLK_PD(1); /* USB1 is not exposed on HackRF */ - CGU_BASE_PHY_RX_CLK = CGU_BASE_PHY_RX_CLK_PD(1); - CGU_BASE_PHY_TX_CLK = CGU_BASE_PHY_TX_CLK_PD(1); - CGU_BASE_LCD_CLK = CGU_BASE_LCD_CLK_PD(1); - CGU_BASE_VADC_CLK = CGU_BASE_VADC_CLK_PD(1); - CGU_BASE_SDIO_CLK = CGU_BASE_SDIO_CLK_PD(1); - CGU_BASE_UART0_CLK = CGU_BASE_UART0_CLK_PD(1); - CGU_BASE_UART1_CLK = CGU_BASE_UART1_CLK_PD(1); - CGU_BASE_UART2_CLK = CGU_BASE_UART2_CLK_PD(1); - CGU_BASE_UART3_CLK = CGU_BASE_UART3_CLK_PD(1); - CGU_BASE_OUT_CLK = CGU_BASE_OUT_CLK_PD(1); - CGU_BASE_AUDIO_CLK = CGU_BASE_AUDIO_CLK_PD(1); - CGU_BASE_CGU_OUT0_CLK = CGU_BASE_CGU_OUT0_CLK_PD(1); - CGU_BASE_CGU_OUT1_CLK = CGU_BASE_CGU_OUT1_CLK_PD(1); - - /* Disable unused peripheral clocks */ - CCU1_CLK_APB1_CAN1_CFG = 0; - CCU1_CLK_APB1_I2S_CFG = 0; - CCU1_CLK_APB1_MOTOCONPWM_CFG = 0; - //CCU1_CLK_APB3_ADC0_CFG = 0; - CCU1_CLK_APB3_ADC1_CFG = 0; - CCU1_CLK_APB3_CAN0_CFG = 0; - CCU1_CLK_APB3_DAC_CFG = 0; - //CCU1_CLK_M4_DMA_CFG = 0; - CCU1_CLK_M4_EMC_CFG = 0; - CCU1_CLK_M4_EMCDIV_CFG = 0; - CCU1_CLK_M4_ETHERNET_CFG = 0; - CCU1_CLK_M4_LCD_CFG = 0; - CCU1_CLK_M4_QEI_CFG = 0; - CCU1_CLK_M4_RITIMER_CFG = 0; - // CCU1_CLK_M4_SCT_CFG = 0; - CCU1_CLK_M4_SDIO_CFG = 0; - CCU1_CLK_M4_SPIFI_CFG = 0; - CCU1_CLK_M4_TIMER0_CFG = 0; - //CCU1_CLK_M4_TIMER1_CFG = 0; - //CCU1_CLK_M4_TIMER2_CFG = 0; - CCU1_CLK_M4_TIMER3_CFG = 0; - CCU1_CLK_M4_UART1_CFG = 0; - CCU1_CLK_M4_USART0_CFG = 0; - CCU1_CLK_M4_USART2_CFG = 0; - CCU1_CLK_M4_USART3_CFG = 0; - CCU1_CLK_M4_USB1_CFG = 0; - CCU1_CLK_M4_VADC_CFG = 0; - // CCU1_CLK_SPIFI_CFG = 0; - // CCU1_CLK_USB1_CFG = 0; - // CCU1_CLK_VADC_CFG = 0; - // CCU2_CLK_APB0_UART1_CFG = 0; - // CCU2_CLK_APB0_USART0_CFG = 0; - // CCU2_CLK_APB2_USART2_CFG = 0; - // CCU2_CLK_APB2_USART3_CFG = 0; - // CCU2_CLK_APLL_CFG = 0; - // CCU2_CLK_SDIO_CFG = 0; -#endif + switch (detected_platform()) { + case BOARD_ID_JAWBREAKER: + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: + /* Disable unused clocks */ + /* Start with PLLs */ + CGU_PLL0AUDIO_CTRL = CGU_PLL0AUDIO_CTRL_PD(1); + + /* Dividers */ + CGU_IDIVA_CTRL = CGU_IDIVA_CTRL_PD(1); + CGU_IDIVB_CTRL = CGU_IDIVB_CTRL_PD(1); + CGU_IDIVC_CTRL = CGU_IDIVC_CTRL_PD(1); + CGU_IDIVD_CTRL = CGU_IDIVD_CTRL_PD(1); + CGU_IDIVE_CTRL = CGU_IDIVE_CTRL_PD(1); + + /* Base clocks */ + CGU_BASE_SPIFI_CLK = + CGU_BASE_SPIFI_CLK_PD(1); /* SPIFI is only used at boot */ + CGU_BASE_USB1_CLK = + CGU_BASE_USB1_CLK_PD(1); /* USB1 is not exposed on HackRF */ + CGU_BASE_PHY_RX_CLK = CGU_BASE_PHY_RX_CLK_PD(1); + CGU_BASE_PHY_TX_CLK = CGU_BASE_PHY_TX_CLK_PD(1); + CGU_BASE_LCD_CLK = CGU_BASE_LCD_CLK_PD(1); + CGU_BASE_VADC_CLK = CGU_BASE_VADC_CLK_PD(1); + CGU_BASE_SDIO_CLK = CGU_BASE_SDIO_CLK_PD(1); + CGU_BASE_UART0_CLK = CGU_BASE_UART0_CLK_PD(1); + CGU_BASE_UART1_CLK = CGU_BASE_UART1_CLK_PD(1); + CGU_BASE_UART2_CLK = CGU_BASE_UART2_CLK_PD(1); + CGU_BASE_UART3_CLK = CGU_BASE_UART3_CLK_PD(1); + CGU_BASE_OUT_CLK = CGU_BASE_OUT_CLK_PD(1); + CGU_BASE_AUDIO_CLK = CGU_BASE_AUDIO_CLK_PD(1); + CGU_BASE_CGU_OUT0_CLK = CGU_BASE_CGU_OUT0_CLK_PD(1); + CGU_BASE_CGU_OUT1_CLK = CGU_BASE_CGU_OUT1_CLK_PD(1); + + /* Disable unused peripheral clocks */ + CCU1_CLK_APB1_CAN1_CFG = 0; + CCU1_CLK_APB1_I2S_CFG = 0; + CCU1_CLK_APB1_MOTOCONPWM_CFG = 0; + //CCU1_CLK_APB3_ADC0_CFG = 0; + CCU1_CLK_APB3_ADC1_CFG = 0; + CCU1_CLK_APB3_CAN0_CFG = 0; + CCU1_CLK_APB3_DAC_CFG = 0; + //CCU1_CLK_M4_DMA_CFG = 0; + CCU1_CLK_M4_EMC_CFG = 0; + CCU1_CLK_M4_EMCDIV_CFG = 0; + CCU1_CLK_M4_ETHERNET_CFG = 0; + CCU1_CLK_M4_LCD_CFG = 0; + CCU1_CLK_M4_QEI_CFG = 0; + CCU1_CLK_M4_RITIMER_CFG = 0; + // CCU1_CLK_M4_SCT_CFG = 0; + CCU1_CLK_M4_SDIO_CFG = 0; + CCU1_CLK_M4_SPIFI_CFG = 0; + CCU1_CLK_M4_TIMER0_CFG = 0; + //CCU1_CLK_M4_TIMER1_CFG = 0; + //CCU1_CLK_M4_TIMER2_CFG = 0; + CCU1_CLK_M4_TIMER3_CFG = 0; + CCU1_CLK_M4_UART1_CFG = 0; + CCU1_CLK_M4_USART0_CFG = 0; + CCU1_CLK_M4_USART2_CFG = 0; + CCU1_CLK_M4_USART3_CFG = 0; + CCU1_CLK_M4_USB1_CFG = 0; + CCU1_CLK_M4_VADC_CFG = 0; + // CCU1_CLK_SPIFI_CFG = 0; + // CCU1_CLK_USB1_CFG = 0; + // CCU1_CLK_VADC_CFG = 0; + // CCU2_CLK_APB0_UART1_CFG = 0; + // CCU2_CLK_APB0_USART0_CFG = 0; + // CCU2_CLK_APB2_USART2_CFG = 0; + // CCU2_CLK_APB2_USART3_CFG = 0; + // CCU2_CLK_APLL_CFG = 0; + // CCU2_CLK_SDIO_CFG = 0; + break; + default: + break; + } } void clock_gen_init(void) @@ -636,12 +653,20 @@ void clock_gen_shutdown(void) clock_source_t activate_best_clock_source(void) { -#if (defined HACKRF_ONE || defined PRALINE) - /* Ensure PortaPack reference oscillator is off while checking for external clock input. */ - if (portapack_reference_oscillator && portapack()) { - portapack_reference_oscillator(false); - } + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + /* Ensure PortaPack reference oscillator is off while checking for external clock input. */ + if (portapack_reference_oscillator && portapack()) { + portapack_reference_oscillator(false); + } #endif + break; + default: + break; + } clock_source_t source = CLOCK_SOURCE_HACKRF; @@ -649,18 +674,26 @@ clock_source_t activate_best_clock_source(void) if (si5351c_clkin_signal_valid(&clock_gen)) { source = CLOCK_SOURCE_EXTERNAL; } else { -#if (defined HACKRF_ONE || defined PRALINE) - /* Enable PortaPack reference oscillator (if present), and check for valid clock. */ - if (portapack_reference_oscillator && portapack()) { - portapack_reference_oscillator(true); - delay(510000); /* loop iterations @ 204MHz for >10ms for oscillator to enable. */ - if (si5351c_clkin_signal_valid(&clock_gen)) { - source = CLOCK_SOURCE_PORTAPACK; - } else { - portapack_reference_oscillator(false); + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + /* Enable PortaPack reference oscillator (if present), and check for valid clock. */ + if (portapack_reference_oscillator && portapack()) { + portapack_reference_oscillator(true); + delay(510000); /* loop iterations @ 204MHz for >10ms for oscillator to enable. */ + if (si5351c_clkin_signal_valid(&clock_gen)) { + source = CLOCK_SOURCE_PORTAPACK; + } else { + portapack_reference_oscillator(false); + } } - } #endif + break; + default: + break; + } /* No external or PortaPack clock was found. Use HackRF Si5351C crystal. */ } @@ -682,7 +715,7 @@ void ssp1_set_mode_max5864(void) spi_bus_start(max5864.bus, &ssp_config_max5864); } -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) void ssp1_set_mode_ice40(void) { spi_bus_start(&spi_bus_ssp1, &ssp_config_ice40_fpga); @@ -691,12 +724,14 @@ void ssp1_set_mode_ice40(void) void pin_shutdown(void) { - const platform_gpio_t* gpio = platform_gpio(); - const platform_scu_t* scu = platform_scu(); - /* Configure all GPIO as Input (safe state) */ gpio_init(); + /* Detect Platform */ + board_id_t board_id = detected_platform(); + const platform_gpio_t* gpio = platform_gpio(); + const platform_scu_t* scu = platform_scu(); + /* TDI and TMS pull-ups are required in all JTAG-compliant devices. * * The HackRF CPLD is always present, so let the CPLD pull up its TDI and TMS. @@ -711,119 +746,159 @@ void pin_shutdown(void) * * LPC43xx pull-up and pull-down resistors are approximately 53K. */ -#if (defined HACKRF_ONE || defined PRALINE) - scu_pinmux(scu->PINMUX_PP_TMS, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_PP_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + scu_pinmux(scu->PINMUX_PP_TMS, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_PP_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); #endif + break; + default: + break; + } scu_pinmux(scu->PINMUX_CPLD_TCK, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); -#ifndef PRALINE - scu_pinmux(scu->PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_CPLD_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION4); + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + scu_pinmux(scu->PINMUX_CPLD_TMS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_CPLD_TDI, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_CPLD_TDO, SCU_GPIO_PDN | SCU_CONF_FUNCTION4); #endif + } /* Configure SCU Pin Mux as GPIO */ scu_pinmux(scu->PINMUX_LED1, SCU_GPIO_NOPULL); scu_pinmux(scu->PINMUX_LED2, SCU_GPIO_NOPULL); scu_pinmux(scu->PINMUX_LED3, SCU_GPIO_NOPULL); -#ifdef RAD1O - scu_pinmux(scu->PINMUX_LED4, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4); + switch (board_id) { + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu_pinmux(scu->PINMUX_LED4, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION4); #endif -#ifdef PRALINE - scu_pinmux(scu->PINMUX_LED4, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu_pinmux(scu->PINMUX_LED4, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); #endif + break; + default: + break; + } /* Configure USB indicators */ -#ifdef JAWBREAKER - scu_pinmux(scu->PINMUX_USB_LED0, SCU_CONF_FUNCTION3); - scu_pinmux(scu->PINMUX_USB_LED1, SCU_CONF_FUNCTION3); + if (board_id == BOARD_ID_JAWBREAKER) { +#if defined(JAWBREAKER) + scu_pinmux(scu->PINMUX_USB_LED0, SCU_CONF_FUNCTION3); + scu_pinmux(scu->PINMUX_USB_LED1, SCU_CONF_FUNCTION3); #endif - -#ifdef PRALINE - disable_1v2_power(); - disable_3v3aux_power(); - gpio_output(gpio->gpio_1v2_enable); - gpio_output(gpio->gpio_3v3aux_enable_n); - scu_pinmux(scu->PINMUX_EN1V2, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_EN3V3_AUX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); -#else - disable_1v8_power(); - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - #ifdef HACKRF_ONE - gpio_output(gpio->h1r9_1v8_enable); - scu_pinmux(scu->H1R9_EN1V8, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - #endif - } else { - gpio_output(gpio->gpio_1v8_enable); - scu_pinmux(scu->PINMUX_EN1V8, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); } -#endif -#if (defined HACKRF_ONE || defined PRALINE) - /* Safe state: start with VAA turned off: */ - disable_rf_power(); + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + disable_1v2_power(); + disable_3v3aux_power(); + gpio_output(gpio->gpio_1v2_enable); + gpio_output(gpio->gpio_3v3aux_enable_n); + scu_pinmux(scu->PINMUX_EN1V2, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_EN3V3_AUX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); +#endif + break; + default: + disable_1v8_power(); + if (detected_platform() == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio_output(gpio->h1r9_1v8_enable); + scu_pinmux(scu->H1R9_EN1V8, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); +#endif + } else { + gpio_output(gpio->gpio_1v8_enable); + scu_pinmux(scu->PINMUX_EN1V8, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + } + break; + } - /* Configure RF power supply (VAA) switch control signal as output */ - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - #ifdef HACKRF_ONE - gpio_output(gpio->h1r9_vaa_disable); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + /* Safe state: start with VAA turned off: */ + disable_rf_power(); + + /* Configure RF power supply (VAA) switch control signal as output */ + if (board_id == BOARD_ID_HACKRF1_R9) { + #if defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio_output(gpio->h1r9_vaa_disable); #endif - } else { - gpio_output(gpio->vaa_disable); - } + } else { + gpio_output(gpio->vaa_disable); + } + break; #endif + case BOARD_ID_RAD1O: +#if defined(RAD1O) + /* Safe state: start with VAA turned off: */ + disable_rf_power(); -#ifdef RAD1O - /* Safe state: start with VAA turned off: */ - disable_rf_power(); + /* Configure RF power supply (VAA) switch control signal as output */ + gpio_output(gpio->vaa_enable); - /* Configure RF power supply (VAA) switch control signal as output */ - gpio_output(gpio->vaa_enable); + /* Disable unused clock outputs. They generate noise. */ + scu_pinmux(CLK0, SCU_CLK_IN | SCU_CONF_FUNCTION7); + scu_pinmux(CLK2, SCU_CLK_IN | SCU_CONF_FUNCTION7); - /* Disable unused clock outputs. They generate noise. */ - scu_pinmux(CLK0, SCU_CLK_IN | SCU_CONF_FUNCTION7); - scu_pinmux(CLK2, SCU_CLK_IN | SCU_CONF_FUNCTION7); - - scu_pinmux(scu->PINMUX_GPIO3_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_GPIO3_11, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_GPIO3_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_GPIO3_11, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); #endif + break; + default: + break; + } -#ifdef PRALINE - scu_pinmux(scu->P2_CTRL0, scu->P2_CTRL0_PINCFG); - scu_pinmux(scu->P2_CTRL1, scu->P2_CTRL1_PINCFG); - scu_pinmux(scu->P1_CTRL0, scu->P1_CTRL0_PINCFG); - scu_pinmux(scu->P1_CTRL1, scu->P1_CTRL1_PINCFG); - scu_pinmux(scu->P1_CTRL2, scu->P1_CTRL2_PINCFG); - scu_pinmux(scu->CLKIN_CTRL, scu->CLKIN_CTRL_PINCFG); - scu_pinmux(scu->AA_EN, scu->AA_EN_PINCFG); - scu_pinmux(scu->TRIGGER_IN, scu->TRIGGER_IN_PINCFG); - scu_pinmux(scu->TRIGGER_OUT, scu->TRIGGER_OUT_PINCFG); - scu_pinmux(scu->PPS_OUT, scu->PPS_OUT_PINCFG); - scu_pinmux(scu->PINMUX_FPGA_CRESET, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - scu_pinmux(scu->PINMUX_FPGA_CDONE, SCU_GPIO_PUP | SCU_CONF_FUNCTION4); - scu_pinmux(scu->PINMUX_FPGA_SPI_CS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); - - p2_ctrl_set(P2_SIGNAL_CLK3); - p1_ctrl_set(P1_SIGNAL_CLKIN); - narrowband_filter_set(0); - clkin_ctrl_set(CLKIN_SIGNAL_P22); - - gpio_output(gpio->p2_ctrl0); - gpio_output(gpio->p2_ctrl1); - gpio_output(gpio->p1_ctrl0); - gpio_output(gpio->p1_ctrl1); - gpio_output(gpio->p1_ctrl2); - gpio_output(gpio->clkin_ctrl); - gpio_output(gpio->pps_out); - gpio_output(gpio->aa_en); - gpio_input(gpio->trigger_in); - gpio_input(gpio->trigger_out); - gpio_clear(gpio->fpga_cfg_spi_cs); - gpio_output(gpio->fpga_cfg_spi_cs); - gpio_clear(gpio->fpga_cfg_creset); - gpio_output(gpio->fpga_cfg_creset); - gpio_input(gpio->fpga_cfg_cdone); + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu_pinmux(scu->P2_CTRL0, scu->P2_CTRL0_PINCFG); + scu_pinmux(scu->P2_CTRL1, scu->P2_CTRL1_PINCFG); + scu_pinmux(scu->P1_CTRL0, scu->P1_CTRL0_PINCFG); + scu_pinmux(scu->P1_CTRL1, scu->P1_CTRL1_PINCFG); + scu_pinmux(scu->P1_CTRL2, scu->P1_CTRL2_PINCFG); + scu_pinmux(scu->CLKIN_CTRL, scu->CLKIN_CTRL_PINCFG); + scu_pinmux(scu->AA_EN, scu->AA_EN_PINCFG); + scu_pinmux(scu->TRIGGER_IN, scu->TRIGGER_IN_PINCFG); + scu_pinmux(scu->TRIGGER_OUT, scu->TRIGGER_OUT_PINCFG); + scu_pinmux(scu->PPS_OUT, scu->PPS_OUT_PINCFG); + scu_pinmux(scu->PINMUX_FPGA_CRESET, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + scu_pinmux(scu->PINMUX_FPGA_CDONE, SCU_GPIO_PUP | SCU_CONF_FUNCTION4); + scu_pinmux(scu->PINMUX_FPGA_SPI_CS, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); + + p2_ctrl_set(P2_SIGNAL_CLK3); + p1_ctrl_set(P1_SIGNAL_CLKIN); + narrowband_filter_set(0); + clkin_ctrl_set(CLKIN_SIGNAL_P22); + + gpio_output(gpio->p2_ctrl0); + gpio_output(gpio->p2_ctrl1); + gpio_output(gpio->p1_ctrl0); + gpio_output(gpio->p1_ctrl1); + gpio_output(gpio->p1_ctrl2); + gpio_output(gpio->clkin_ctrl); + gpio_output(gpio->pps_out); + gpio_output(gpio->aa_en); + gpio_input(gpio->trigger_in); + gpio_input(gpio->trigger_out); + gpio_clear(gpio->fpga_cfg_spi_cs); + gpio_output(gpio->fpga_cfg_spi_cs); + gpio_clear(gpio->fpga_cfg_creset); + gpio_output(gpio->fpga_cfg_creset); + gpio_input(gpio->fpga_cfg_cdone); #endif + break; + default: + break; + } /* enable input on SCL and SDA pins */ SCU_SFSI2C0 = SCU_I2C0_NOMINAL; @@ -832,30 +907,43 @@ void pin_shutdown(void) /* Run after pin_shutdown() and prior to enabling power supplies. */ void pin_setup(void) { + /* Detect Platform */ + board_id_t board_id = detected_platform(); const platform_gpio_t* gpio = platform_gpio(); const platform_scu_t* scu = platform_scu(); + /* Configure LEDs */ led_off(0); led_off(1); led_off(2); -#ifdef RAD1O - led_off(3); -#endif + switch (board_id) { + case BOARD_ID_RAD1O: + led_off(3); + default: + break; + } gpio_output(gpio->led[0]); gpio_output(gpio->led[1]); gpio_output(gpio->led[2]); -#if (defined RAD1O || defined PRALINE) - gpio_output(gpio->led[3]); + switch (board_id) { + case BOARD_ID_RAD1O: + case BOARD_ID_PRALINE: +#if defined(RAD1O) || defined(PRALINE) || defined(UNIVERSAL) + gpio_output(gpio->led[3]); #endif + break; + default: + break; + } /* Configure drivers and driver pins */ ssp_config_max283x.gpio_select = gpio->max283x_select; -#if defined(PRALINE) - ssp_config_max283x.data_bits = SSP_DATA_9BITS; // send 2 words -#else - ssp_config_max283x.data_bits = SSP_DATA_16BITS; -#endif + if (board_id == BOARD_ID_PRALINE) { + ssp_config_max283x.data_bits = SSP_DATA_9BITS; // send 2 words + } else { + ssp_config_max283x.data_bits = SSP_DATA_16BITS; + } ssp_config_max5864.gpio_select = gpio->max5864_select; @@ -864,11 +952,13 @@ void pin_setup(void) spi_flash.gpio_wp = gpio->w25q80bv_wp; sgpio_config.gpio_q_invert = gpio->q_invert; -#if !defined(PRALINE) - sgpio_config.gpio_trigger_enable = gpio->trigger_enable; + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + sgpio_config.gpio_trigger_enable = gpio->trigger_enable; #endif + } -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) ssp_config_ice40_fpga.gpio_select = gpio->fpga_cfg_spi_cs; ice40.gpio_select = gpio->fpga_cfg_spi_cs; ice40.gpio_creset = gpio->fpga_cfg_creset; @@ -876,78 +966,102 @@ void pin_setup(void) #endif jtag_gpio_cpld.gpio_tck = gpio->cpld_tck; -#if defined(HACKRF_ONE) || defined(RAD1O) - jtag_gpio_cpld.gpio_tms = gpio->cpld_tms; - jtag_gpio_cpld.gpio_tdi = gpio->cpld_tdi; - jtag_gpio_cpld.gpio_tdo = gpio->cpld_tdo; + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + jtag_gpio_cpld.gpio_tms = gpio->cpld_tms; + jtag_gpio_cpld.gpio_tdi = gpio->cpld_tdi; + jtag_gpio_cpld.gpio_tdo = gpio->cpld_tdo; #endif -#if defined(HACKRF_ONE) || defined(PRALINE) - jtag_gpio_cpld.gpio_pp_tms = gpio->cpld_pp_tms; - jtag_gpio_cpld.gpio_pp_tdo = gpio->cpld_pp_tdo; + } + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + jtag_gpio_cpld.gpio_pp_tms = gpio->cpld_pp_tms; + jtag_gpio_cpld.gpio_pp_tdo = gpio->cpld_pp_tdo; #endif + break; + default: + break; + } ssp1_set_mode_max283x(); mixer_bus_setup(&mixer); -#if defined(HACKRF_ONE) if (detected_platform() == BOARD_ID_HACKRF1_R9) { - rf_path.gpio_rx = gpio->h1r9_rx; +#if defined(HACKRF_ONE) || defined(UNIVERSAL) sgpio_config.gpio_trigger_enable = gpio->h1r9_trigger_enable; - } #endif - - /* Configure RF path */ -#if defined(HACKRF_ONE) - rf_path = (rf_path_t){ - .switchctrl = 0, - .gpio_hp = gpio->hp, - .gpio_lp = gpio->lp, - .gpio_tx_mix_bp = gpio->tx_mix_bp, - .gpio_no_mix_bypass = gpio->no_mix_bypass, - .gpio_rx_mix_bp = gpio->rx_mix_bp, - .gpio_tx_amp = gpio->tx_amp, - .gpio_tx = gpio->tx, - .gpio_mix_bypass = gpio->mix_bypass, - .gpio_rx = gpio->rx, - .gpio_no_tx_amp_pwr = gpio->no_tx_amp_pwr, - .gpio_amp_bypass = gpio->amp_bypass, - .gpio_rx_amp = gpio->rx_amp, - .gpio_no_rx_amp_pwr = gpio->no_rx_amp_pwr, - }; - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - rf_path.gpio_rx = gpio->h1r9_rx; - rf_path.gpio_h1r9_no_ant_pwr = gpio->h1r9_no_ant_pwr; - } -#elif defined(RAD1O) - rf_path = (rf_path_t){ - .switchctrl = 0, - .gpio_tx_rx_n = gpio->tx_rx_n, - .gpio_tx_rx = gpio->tx_rx, - .gpio_by_mix = gpio->by_mix, - .gpio_by_mix_n = gpio->by_mix_n, - .gpio_by_amp = gpio->by_amp, - .gpio_by_amp_n = gpio->by_amp_n, - .gpio_mixer_en = gpio->mixer_en, - .gpio_low_high_filt = gpio->low_high_filt, - .gpio_low_high_filt_n = gpio->low_high_filt_n, - .gpio_tx_amp = gpio->tx_amp, - .gpio_rx_lna = gpio->rx_lna, - }; -#elif defined(PRALINE) - rf_path = (rf_path_t){ - .switchctrl = 0, - .gpio_tx_en = gpio->tx_en, - .gpio_mix_en_n = gpio->mix_en_n, - .gpio_lpf_en = gpio->lpf_en, - .gpio_rf_amp_en = gpio->rf_amp_en, - .gpio_ant_bias_en_n = gpio->ant_bias_en_n, - }; - board_rev_t rev = detected_revision(); - if ((rev == BOARD_REV_PRALINE_R1_0) || (rev == BOARD_REV_GSG_PRALINE_R1_0)) { - rf_path.gpio_mix_en_n = gpio->mix_en_n_r1_0; } + + // initialize rf_path struct and assign gpio's + switch (board_id) { + case BOARD_ID_JAWBREAKER: + break; + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + rf_path = (rf_path_t){ + .switchctrl = 0, + .gpio_hp = gpio->hp, + .gpio_lp = gpio->lp, + .gpio_tx_mix_bp = gpio->tx_mix_bp, + .gpio_no_mix_bypass = gpio->no_mix_bypass, + .gpio_rx_mix_bp = gpio->rx_mix_bp, + .gpio_tx_amp = gpio->tx_amp, + .gpio_tx = gpio->tx, + .gpio_mix_bypass = gpio->mix_bypass, + .gpio_rx = gpio->rx, + .gpio_no_tx_amp_pwr = gpio->no_tx_amp_pwr, + .gpio_amp_bypass = gpio->amp_bypass, + .gpio_rx_amp = gpio->rx_amp, + .gpio_no_rx_amp_pwr = gpio->no_rx_amp_pwr, + }; + if (board_id == BOARD_ID_HACKRF1_R9) { + rf_path.gpio_rx = gpio->h1r9_rx; + rf_path.gpio_h1r9_no_ant_pwr = gpio->h1r9_no_ant_pwr; + } +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + rf_path = (rf_path_t){ + .switchctrl = 0, + .gpio_tx_rx_n = gpio->tx_rx_n, + .gpio_tx_rx = gpio->tx_rx, + .gpio_by_mix = gpio->by_mix, + .gpio_by_mix_n = gpio->by_mix_n, + .gpio_by_amp = gpio->by_amp, + .gpio_by_amp_n = gpio->by_amp_n, + .gpio_mixer_en = gpio->mixer_en, + .gpio_low_high_filt = gpio->low_high_filt, + .gpio_low_high_filt_n = gpio->low_high_filt_n, + .gpio_tx_amp = gpio->tx_amp, + .gpio_rx_lna = gpio->rx_lna, + }; #endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + rf_path = (rf_path_t){ + .switchctrl = 0, + .gpio_tx_en = gpio->tx_en, + .gpio_mix_en_n = gpio->mix_en_n, + .gpio_lpf_en = gpio->lpf_en, + .gpio_rf_amp_en = gpio->rf_amp_en, + .gpio_ant_bias_en_n = gpio->ant_bias_en_n, + }; + if ((detected_revision() == BOARD_REV_PRALINE_R1_0) || + (detected_revision() == BOARD_REV_GSG_PRALINE_R1_0)) { + rf_path.gpio_mix_en_n = gpio->mix_en_n_r1_0; + } +#endif + break; + default: + break; + } rf_path_pin_setup(&rf_path); /* Configure external clock in */ @@ -956,52 +1070,86 @@ void pin_setup(void) sgpio_configure_pin_functions(&sgpio_config); } -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) void enable_1v2_power(void) { - gpio_set(platform_gpio()->gpio_1v2_enable); + switch (detected_platform()) { + case BOARD_ID_PRALINE: + gpio_set(platform_gpio()->gpio_1v2_enable); + break; + default: + break; + } } void disable_1v2_power(void) { - gpio_clear(platform_gpio()->gpio_1v2_enable); + switch (detected_platform()) { + case BOARD_ID_PRALINE: + gpio_clear(platform_gpio()->gpio_1v2_enable); + break; + default: + break; + } } void enable_3v3aux_power(void) { - gpio_clear(platform_gpio()->gpio_3v3aux_enable_n); + switch (detected_platform()) { + case BOARD_ID_PRALINE: + gpio_clear(platform_gpio()->gpio_3v3aux_enable_n); + break; + default: + break; + } } void disable_3v3aux_power(void) { - gpio_set(platform_gpio()->gpio_3v3aux_enable_n); + switch (detected_platform()) { + case BOARD_ID_PRALINE: + gpio_set(platform_gpio()->gpio_3v3aux_enable_n); + break; + default: + break; + } } -#else +#endif + void enable_1v8_power(void) { - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - #ifdef HACKRF_ONE + switch (detected_platform()) { + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) gpio_set(platform_gpio()->h1r9_1v8_enable); - #endif - } else { +#endif + break; + case BOARD_ID_PRALINE: + break; + default: gpio_set(platform_gpio()->gpio_1v8_enable); + break; } } void disable_1v8_power(void) { - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - #ifdef HACKRF_ONE + switch (detected_platform()) { + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) gpio_clear(platform_gpio()->h1r9_1v8_enable); - #endif - } else { +#endif + break; + case BOARD_ID_PRALINE: + break; + default: gpio_clear(platform_gpio()->gpio_1v8_enable); + break; } } -#endif -#ifdef HACKRF_ONE -void enable_rf_power(void) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +static inline void enable_rf_power_hackrf_one(void) { const platform_gpio_t* gpio = platform_gpio(); uint32_t i; @@ -1018,7 +1166,7 @@ void enable_rf_power(void) } } -void disable_rf_power(void) +static inline void disable_rf_power_hackrf_one(void) { if (detected_platform() == BOARD_ID_HACKRF1_R9) { gpio_set(platform_gpio()->h1r9_vaa_disable); @@ -1028,8 +1176,8 @@ void disable_rf_power(void) } #endif -#ifdef PRALINE -void enable_rf_power(void) +#if defined(PRALINE) || defined(UNIVERSAL) +static inline void enable_rf_power_praline(void) { gpio_clear(platform_gpio()->vaa_disable); @@ -1037,14 +1185,14 @@ void enable_rf_power(void) delay(1000000); } -void disable_rf_power(void) +static inline void disable_rf_power_praline(void) { gpio_set(platform_gpio()->vaa_disable); } #endif -#ifdef RAD1O -void enable_rf_power(void) +#if defined(RAD1O) +static inline void enable_rf_power_rad1o(void) { gpio_set(platform_gpio()->vaa_enable); @@ -1052,33 +1200,77 @@ void enable_rf_power(void) delay(1000000); } -void disable_rf_power(void) +static inline void disable_rf_power_rad1o(void) { gpio_clear(platform_gpio()->vaa_enable); } #endif -#ifdef PRALINE -void led_on(const led_t led) +void enable_rf_power(void) { - gpio_clear(platform_gpio()->led[led]); + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + enable_rf_power_hackrf_one(); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + enable_rf_power_praline(); +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + enable_rf_power_rad1o(); +#endif + break; + default: + break; + } } -void led_off(const led_t led) +void disable_rf_power(void) { - gpio_set(platform_gpio()->led[led]); + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + disable_rf_power_hackrf_one(); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + disable_rf_power_praline(); +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + disable_rf_power_rad1o(); +#endif + break; + default: + break; + } } -#else + void led_on(const led_t led) { - gpio_set(platform_gpio()->led[led]); + if (detected_platform() == BOARD_ID_PRALINE) { + gpio_clear(platform_gpio()->led[led]); + } else { + gpio_set(platform_gpio()->led[led]); + } } void led_off(const led_t led) { - gpio_clear(platform_gpio()->led[led]); + if (detected_platform() == BOARD_ID_PRALINE) { + gpio_set(platform_gpio()->led[led]); + } else { + gpio_clear(platform_gpio()->led[led]); + } } -#endif void led_toggle(const led_t led) { @@ -1087,26 +1279,33 @@ void led_toggle(const led_t led) void set_leds(const uint8_t state) { + board_id_t board_id = detected_platform(); + int num_leds = 3; -#if (defined RAD1O || defined PRALINE) - num_leds = 4; -#endif + if (board_id == BOARD_ID_RAD1O || board_id == BOARD_ID_PRALINE) { + num_leds = 4; + } + for (int i = 0; i < num_leds; i++) { -#ifdef PRALINE - gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 0); -#else - gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 1); -#endif + if (board_id == BOARD_ID_PRALINE) { + gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 0); + } else { + gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 1); + } } } void trigger_enable(const bool enable) { -#ifndef PRALINE - gpio_write(sgpio_config.gpio_trigger_enable, enable); -#else - fpga_set_trigger_enable(&fpga, enable); + if (detected_platform() != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + gpio_write(sgpio_config.gpio_trigger_enable, enable); +#endif + } else { +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_set_trigger_enable(&fpga, enable); #endif + } } void halt_and_flash(const uint32_t duration) @@ -1124,7 +1323,7 @@ void halt_and_flash(const uint32_t duration) } } -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) void p1_ctrl_set(const p1_ctrl_signal_t signal) { const platform_gpio_t* gpio = platform_gpio(); diff --git a/firmware/common/hackrf_core.h b/firmware/common/hackrf_core.h index 74a171a1f..30c4d0d0d 100644 --- a/firmware/common/hackrf_core.h +++ b/firmware/common/hackrf_core.h @@ -1,5 +1,5 @@ /* - * Copyright 2012-2022 Great Scott Gadgets + * Copyright 2012-2026 Great Scott Gadgets * Copyright 2012 Benjamin Vernoux * Copyright 2012 Jared Boone * @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __HACKRF_CORE_H -#define __HACKRF_CORE_H +#pragma once #ifdef __cplusplus extern "C" { @@ -43,7 +42,7 @@ extern "C" { #include "si5351c.h" #include "spi_ssp.h" #include "w25q80bv.h" -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "fpga.h" #include "ice40_spi.h" #endif @@ -52,7 +51,8 @@ extern "C" { extern si5351c_driver_t clock_gen; extern ssp_config_t ssp_config_w25q80bv; -#ifdef PRALINE +extern max283x_driver_t max283x; +#if defined(PRALINE) || defined(UNIVERSAL) extern ice40_spi_driver_t ice40; extern fpga_driver_t fpga; #endif @@ -71,28 +71,27 @@ void clock_gen_init(void); void clock_gen_shutdown(void); void ssp1_set_mode_max283x(void); void ssp1_set_mode_max5864(void); -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) void ssp1_set_mode_ice40(void); #endif void pin_shutdown(void); void pin_setup(void); -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) void enable_1v2_power(void); void disable_1v2_power(void); void enable_3v3aux_power(void); void disable_3v3aux_power(void); -#else +#endif void enable_1v8_power(void); void disable_1v8_power(void); -#endif fp_40_24_t sample_rate_set(const fp_40_24_t sample_rate, const bool program); clock_source_t activate_best_clock_source(void); -#if (defined HACKRF_ONE || defined RAD1O || defined PRALINE) +#if defined(RAD1O) || defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) void enable_rf_power(void); void disable_rf_power(void); #endif @@ -113,7 +112,7 @@ void trigger_enable(const bool enable); void halt_and_flash(const uint32_t duration); -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) typedef enum { P1_SIGNAL_TRIGGER_IN = 0, P1_SIGNAL_AUX_CLK1 = 1, @@ -146,5 +145,3 @@ void pps_out_set(const uint8_t value); #ifdef __cplusplus } #endif - -#endif /* __HACKRF_CORE_H */ diff --git a/firmware/common/hackrf_ui.c b/firmware/common/hackrf_ui.c index dbf1cc24e..0c96773c9 100644 --- a/firmware/common/hackrf_ui.c +++ b/firmware/common/hackrf_ui.c @@ -23,7 +23,8 @@ #include #include "hackrf_ui.h" -#if defined(PRALINE) || defined(HACKRF_ONE) +#include "platform_detect.h" +#if defined(PRALINE) || defined(HACKRF_ONE) || defined(UNIVERSAL) #include "ui_portapack.h" #endif #if defined(RAD1O) @@ -81,16 +82,26 @@ const hackrf_ui_t* hackrf_ui(void) { /* Detect on first use. If no UI hardware is detected, use a stub function table. */ if (ui == NULL && ui_enabled) { -#if (defined HACKRF_ONE || defined PRALINE) - if (portapack_hackrf_ui_init) { - ui = portapack_hackrf_ui_init(); - } + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + if (portapack_hackrf_ui_init) { + ui = portapack_hackrf_ui_init(); + } #endif -#ifdef RAD1O - if (rad1o_ui_setup) { - ui = rad1o_ui_setup(); - } + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + if (rad1o_ui_setup) { + ui = rad1o_ui_setup(); + } #endif + break; + default: + break; + } } if (ui == NULL) { diff --git a/firmware/common/hackrf_ui.h b/firmware/common/hackrf_ui.h index 24d2fa8ee..7b08a597a 100644 --- a/firmware/common/hackrf_ui.h +++ b/firmware/common/hackrf_ui.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef HACKRF_UI_H -#define HACKRF_UI_H +#pragma once #include #include @@ -71,5 +70,3 @@ typedef struct { */ const hackrf_ui_t* hackrf_ui(void); void hackrf_ui_set_enable(bool); - -#endif diff --git a/firmware/common/i2c_bus.h b/firmware/common/i2c_bus.h index 954314372..7519ba140 100644 --- a/firmware/common/i2c_bus.h +++ b/firmware/common/i2c_bus.h @@ -20,27 +20,23 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __I2C_BUS_H__ -#define __I2C_BUS_H__ +#pragma once #include #include -struct i2c_bus_t; // IWYU pragma: keep - fixed in #1704 -typedef struct i2c_bus_t i2c_bus_t; - -struct i2c_bus_t { +typedef struct _i2c_bus_t { void* const obj; - void (*start)(i2c_bus_t* const bus, const void* const config); - void (*stop)(i2c_bus_t* const bus); + void (*start)(struct _i2c_bus_t* const bus, const void* const config); + void (*stop)(struct _i2c_bus_t* const bus); void (*transfer)( - i2c_bus_t* const bus, + struct _i2c_bus_t* const bus, const uint_fast8_t peripheral_address, const uint8_t* const tx, const size_t tx_count, uint8_t* const rx, const size_t rx_count); -}; +} i2c_bus_t; void i2c_bus_start(i2c_bus_t* const bus, const void* const config); void i2c_bus_stop(i2c_bus_t* const bus); @@ -51,5 +47,3 @@ void i2c_bus_transfer( const size_t tx_count, uint8_t* const rx, const size_t rx_count); - -#endif /*__I2C_BUS_H__*/ diff --git a/firmware/common/i2c_lpc.h b/firmware/common/i2c_lpc.h index c4f3e8c3c..f5b8230e4 100644 --- a/firmware/common/i2c_lpc.h +++ b/firmware/common/i2c_lpc.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __I2C_LPC_H__ -#define __I2C_LPC_H__ +#pragma once #include #include @@ -29,7 +28,7 @@ #include "i2c_bus.h" -typedef struct i2c_lpc_config_t { +typedef struct { const uint16_t duty_cycle_count; } i2c_lpc_config_t; @@ -43,5 +42,3 @@ void i2c_lpc_transfer( uint8_t* const data_rx, const size_t count_rx); bool i2c_probe(i2c_bus_t* const bus, const uint_fast8_t device_address); - -#endif /*__I2C_LPC_H__*/ diff --git a/firmware/common/ice40_spi.h b/firmware/common/ice40_spi.h index 92ce62808..4ceddffa7 100644 --- a/firmware/common/ice40_spi.h +++ b/firmware/common/ice40_spi.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __ICE40_SPI_H -#define __ICE40_SPI_H +#pragma once #include #include @@ -29,15 +28,12 @@ #include "gpio.h" #include "spi_bus.h" -struct ice40_spi_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct ice40_spi_driver_t ice40_spi_driver_t; - -struct ice40_spi_driver_t { +typedef struct { spi_bus_t* const bus; gpio_t gpio_select; gpio_t gpio_creset; gpio_t gpio_cdone; -}; +} ice40_spi_driver_t; void ice40_spi_target_init(ice40_spi_driver_t* const drv); uint8_t ice40_spi_read(ice40_spi_driver_t* const drv, uint8_t r); @@ -47,5 +43,3 @@ bool ice40_spi_syscfg_program( uint8_t* buf, size_t (*read_block_cb)(void* ctx), void* read_ctx); - -#endif // __ICE40_SPI_H diff --git a/firmware/common/locking.h b/firmware/common/locking.h index 5620f2f95..54ba7a70f 100644 --- a/firmware/common/locking.h +++ b/firmware/common/locking.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __LOCKING_H__ -#define __LOCKING_H__ +#pragma once #include @@ -51,5 +50,3 @@ static inline uint32_t store_exclusive(uint32_t val, volatile uint32_t* addr) return 0; } #endif - -#endif /* __LOCKING_H__ */ diff --git a/firmware/common/lz4_blk.h b/firmware/common/lz4_blk.h index 19c8207e3..f4e25f7a3 100644 --- a/firmware/common/lz4_blk.h +++ b/firmware/common/lz4_blk.h @@ -19,12 +19,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __LZ4_BLK_H -#define __LZ4_BLK_H +#pragma once #include #include int lz4_blk_decompress(const uint8_t* src, uint8_t* dst, size_t length); - -#endif \ No newline at end of file diff --git a/firmware/common/lz4_buf.h b/firmware/common/lz4_buf.h index b9dec5899..ab073d43d 100644 --- a/firmware/common/lz4_buf.h +++ b/firmware/common/lz4_buf.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __LZ4_BUF_H -#define __LZ4_BUF_H +#pragma once #include @@ -31,5 +30,3 @@ extern uint8_t lz4_in_buf[LZ4_BUFFER_SIZE]; extern uint8_t lz4_out_buf[LZ4_BUFFER_SIZE]; - -#endif /*__LZ4_BUF_H */ diff --git a/firmware/common/m0_state.h b/firmware/common/m0_state.h index cd0391fc3..b7c26e8b8 100644 --- a/firmware/common/m0_state.h +++ b/firmware/common/m0_state.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __M0_STATE_H__ -#define __M0_STATE_H__ +#pragma once #include @@ -60,5 +59,3 @@ enum m0_error { extern volatile struct m0_state m0_state; void m0_set_mode(enum m0_mode mode); - -#endif /*__M0_STATE_H__*/ diff --git a/firmware/common/max2831.h b/firmware/common/max2831.h index 9298247ad..18154649a 100644 --- a/firmware/common/max2831.h +++ b/firmware/common/max2831.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2831_H -#define __MAX2831_H +#pragma once #include #include @@ -48,22 +47,21 @@ typedef enum { MAX2831_RX_HPF_600_KHZ = 3, } max2831_rx_hpf_freq_t; -struct max2831_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct max2831_driver_t max2831_driver_t; - -struct max2831_driver_t { +typedef struct _max2831_driver_t { spi_bus_t* bus; gpio_t gpio_enable; gpio_t gpio_rxtx; gpio_t gpio_rxhp; gpio_t gpio_ld; - void (*target_init)(max2831_driver_t* const drv); - void (*set_mode)(max2831_driver_t* const drv, const max2831_mode_t new_mode); + void (*target_init)(struct _max2831_driver_t* const drv); + void (*set_mode)( + struct _max2831_driver_t* const drv, + const max2831_mode_t new_mode); max2831_mode_t mode; uint16_t regs[MAX2831_NUM_REGS]; uint16_t regs_dirty; uint32_t desired_lpf_bw; -}; +} max2831_driver_t; /* Initialize chip. */ extern void max2831_setup(max2831_driver_t* const drv); @@ -108,5 +106,3 @@ extern void max2831_tx(max2831_driver_t* const drv); extern void max2831_rx(max2831_driver_t* const drv); extern void max2831_tx_calibration(max2831_driver_t* const drv); extern void max2831_rx_calibration(max2831_driver_t* const drv); - -#endif // __MAX2831_H diff --git a/firmware/common/max2831_regs.def b/firmware/common/max2831_regs.def index fb8fa8a96..fd09707d2 100644 --- a/firmware/common/max2831_regs.def +++ b/firmware/common/max2831_regs.def @@ -1,7 +1,27 @@ -/* -*- mode: c -*- */ - -#ifndef __MAX2831_REGS_DEF -#define __MAX2831_REGS_DEF +/* -*- mode: c -*- + * + * Copyright 2012 Michael Ossmann + * Copyright 2025-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. + */ + +#pragma once /* Generate static inline accessors that operate on the global * regs. Done this way to (1) allow defs to be scraped out and used @@ -128,5 +148,3 @@ __MREG__(MAX2831_RXIQ_VCM,15,10,2) // RX I/Q output common mode #define MAX2831_RXIQ_VCM_1_2 1 // 1.2V #define MAX2831_RXIQ_VCM_1_3 2 // 1.3V #define MAX2831_RXIQ_VCM_1_45 3 // 1.45V - -#endif // __MAX2831_REGS_DEF \ No newline at end of file diff --git a/firmware/common/max2831_target.h b/firmware/common/max2831_target.h index 11671b733..072faf220 100644 --- a/firmware/common/max2831_target.h +++ b/firmware/common/max2831_target.h @@ -19,12 +19,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2831_TARGET_H -#define __MAX2831_TARGET_H +#pragma once #include "max2831.h" void max2831_target_init(max2831_driver_t* const drv); void max2831_target_set_mode(max2831_driver_t* const drv, const max2831_mode_t new_mode); - -#endif // __MAX2831_TARGET_H diff --git a/firmware/common/max2837.h b/firmware/common/max2837.h index 0c7a65c88..748bafe0e 100644 --- a/firmware/common/max2837.h +++ b/firmware/common/max2837.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2837_H -#define __MAX2837_H +#pragma once #include #include @@ -41,20 +40,19 @@ typedef enum { MAX2837_MODE_RX } max2837_mode_t; -struct max2837_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct max2837_driver_t max2837_driver_t; - -struct max2837_driver_t { +typedef struct _max2837_driver_t { spi_bus_t* bus; gpio_t gpio_enable; gpio_t gpio_rx_enable; gpio_t gpio_tx_enable; - void (*target_init)(max2837_driver_t* const drv); - void (*set_mode)(max2837_driver_t* const drv, const max2837_mode_t new_mode); + void (*target_init)(struct _max2837_driver_t* const drv); + void (*set_mode)( + struct _max2837_driver_t* const drv, + const max2837_mode_t new_mode); max2837_mode_t mode; uint16_t regs[MAX2837_NUM_REGS]; uint32_t regs_dirty; -}; +} max2837_driver_t; /* Initialize chip. */ extern void max2837_setup(max2837_driver_t* const drv); @@ -91,5 +89,3 @@ bool max2837_set_txvga_gain(max2837_driver_t* const drv, const uint32_t gain_db) extern void max2837_tx(max2837_driver_t* const drv); extern void max2837_rx(max2837_driver_t* const drv); - -#endif // __MAX2837_H diff --git a/firmware/common/max2837_regs.def b/firmware/common/max2837_regs.def index 0aa2f9e57..67eb6dd7c 100644 --- a/firmware/common/max2837_regs.def +++ b/firmware/common/max2837_regs.def @@ -1,7 +1,26 @@ -/* -*- mode: c -*- */ - -#ifndef __MAX2837_REGS_DEF -#define __MAX2837_REGS_DEF +/* -*- mode: c -*- * + * Copyright 2012 Michael Ossmann + * Copyright 2025-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. + */ + +#pragma once /* Generate static inline accessors that operate on the global * regs. Done this way to (1) allow defs to be scraped out and used @@ -404,5 +423,3 @@ __MREG__(MAX2837_FUSE_RTH,30,9,1) // 0 -> 992/0uA correction, 15 -> 0/992uA correction ... if TX_DCCORR_SPI_EN __MREG__(MAX2837_TX_DCCORR_I,31,4,5) __MREG__(MAX2837_TX_DCCORR_Q,31,9,5) - -#endif // __MAX2837_REGS_DEF diff --git a/firmware/common/max2837_target.h b/firmware/common/max2837_target.h index 75d876987..2910791ed 100644 --- a/firmware/common/max2837_target.h +++ b/firmware/common/max2837_target.h @@ -21,12 +21,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2837_TARGET_H -#define __MAX2837_TARGET_H +#pragma once #include "max2837.h" void max2837_target_init(max2837_driver_t* const drv); void max2837_target_set_mode(max2837_driver_t* const drv, const max2837_mode_t new_mode); - -#endif // __MAX2837_TARGET_H diff --git a/firmware/common/max2839.h b/firmware/common/max2839.h index ac238fe25..b6c211944 100644 --- a/firmware/common/max2839.h +++ b/firmware/common/max2839.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2839_H -#define __MAX2839_H +#pragma once #include #include @@ -44,19 +43,18 @@ typedef enum { MAX2839_MODE_CLKOUT, } max2839_mode_t; -struct max2839_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct max2839_driver_t max2839_driver_t; - -struct max2839_driver_t { +typedef struct _max2839_driver_t { spi_bus_t* bus; gpio_t gpio_enable; gpio_t gpio_rxtx; - void (*target_init)(max2839_driver_t* const drv); - void (*set_mode)(max2839_driver_t* const drv, const max2839_mode_t new_mode); + void (*target_init)(struct _max2839_driver_t* const drv); + void (*set_mode)( + struct _max2839_driver_t* const drv, + const max2839_mode_t new_mode); max2839_mode_t mode; uint16_t regs[MAX2839_NUM_REGS]; uint32_t regs_dirty; -}; +} max2839_driver_t; /* Initialize chip. */ extern void max2839_setup(max2839_driver_t* const drv); @@ -93,5 +91,3 @@ bool max2839_set_txvga_gain(max2839_driver_t* const drv, const uint32_t gain_db) extern void max2839_tx(max2839_driver_t* const drv); extern void max2839_rx(max2839_driver_t* const drv); - -#endif // __MAX2839_H diff --git a/firmware/common/max2839_regs.def b/firmware/common/max2839_regs.def index bee668468..11b1d80d9 100644 --- a/firmware/common/max2839_regs.def +++ b/firmware/common/max2839_regs.def @@ -1,7 +1,26 @@ -/* -*- mode: c -*- */ - -#ifndef __MAX2839_REGS_DEF -#define __MAX2839_REGS_DEF +/* -*- mode: c -*- * + * Copyright 2012 Michael Ossmann + * Copyright 2025-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. + */ + +#pragma once /* Generate static inline accessors that operate on the global * regs. Done this way to (1) allow defs to be scraped out and used @@ -255,5 +274,3 @@ __MREG__(MAX2839_PA_DAC_Voltage_Mode_Output_Select,30,9,1) __MREG__(MAX2839_TX_DC_Offset_Correction_QChannel,31,5,6) __MREG__(MAX2839_RESERVED_31_8,31,8,3) __MREG__(MAX2839_PA_DAC_Clk_Divide_Ratio,31,9,1) - -#endif // __MAX2839_REGS_DEF diff --git a/firmware/common/max2839_target.h b/firmware/common/max2839_target.h index 894882436..0c21e98d2 100644 --- a/firmware/common/max2839_target.h +++ b/firmware/common/max2839_target.h @@ -21,12 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX2839_TARGET_H -#define __MAX2839_TARGET_H - #include "max2839.h" void max2839_target_init(max2839_driver_t* const drv); void max2839_target_set_mode(max2839_driver_t* const drv, const max2839_mode_t new_mode); - -#endif // __MAX2839_TARGET_H diff --git a/firmware/common/max283x.c b/firmware/common/max283x.c index 7c5de3806..fdbf027c1 100644 --- a/firmware/common/max283x.c +++ b/firmware/common/max283x.c @@ -27,31 +27,36 @@ #include "platform_gpio.h" #include "spi_bus.h" -#if defined(PRALINE) - #include "max2831.h" + +#if defined(PRALINE) || defined(UNIVERSAL) #include "max2831_target.h" -#else - #include "max2837.h" +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) #include "max2837_target.h" - #include "max2839.h" +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) #include "max2839_target.h" #endif extern spi_bus_t spi_bus_ssp1; -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) max2831_driver_t max2831 = { .bus = &spi_bus_ssp1, .target_init = max2831_target_init, .set_mode = max2831_target_set_mode, }; -#else +#endif + +#if !defined(PRALINE) || defined(UNIVERSAL) max2837_driver_t max2837 = { .bus = &spi_bus_ssp1, .target_init = max2837_target_init, .set_mode = max2837_target_set_mode, }; +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) max2839_driver_t max2839 = { .bus = &spi_bus_ssp1, .target_init = max2839_target_init, @@ -67,36 +72,43 @@ void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type) const platform_gpio_t* gpio = platform_gpio(); /* MAX283x GPIO PinMux */ -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) max2831.gpio_enable = gpio->max283x_enable; max2831.gpio_rxtx = gpio->max283x_rx_enable; max2831.gpio_rxhp = gpio->max2831_rxhp; max2831.gpio_ld = gpio->max2831_ld; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) max2837.gpio_enable = gpio->max283x_enable; max2837.gpio_rx_enable = gpio->max283x_rx_enable; max2837.gpio_tx_enable = gpio->max283x_tx_enable; +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) max2839.gpio_enable = gpio->max283x_enable; max2839.gpio_rxtx = gpio->max283x_rx_enable; #endif - switch (type) { -#ifdef PRALINE + switch (drv->type) { +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: memcpy(&drv->drv.max2831, &max2831, sizeof(max2831)); max2831_setup(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: memcpy(&drv->drv.max2837, &max2837, sizeof(max2837)); max2837_setup(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: memcpy(&drv->drv.max2839, &max2839, sizeof(max2839)); max2839_setup(&drv->drv.max2839); break; #endif + default: + break; } } @@ -104,44 +116,42 @@ void max283x_setup(max283x_driver_t* const drv, max283x_variant_t type) uint16_t max283x_num_regs(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return MAX2831_NUM_REGS; - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return MAX2837_NUM_REGS; - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return MAX2839_NUM_REGS; - break; #endif + default: + return 0; } - - return 0; } /* Returns the maximum data register value supported by the driver. */ uint16_t max283x_data_regs_max_value(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return MAX2831_DATA_REGS_MAX_VALUE; - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return MAX2837_DATA_REGS_MAX_VALUE; - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return MAX2839_DATA_REGS_MAX_VALUE; - break; #endif + default: + return 0; } - - return 0; } /* Read a register via SPI. Save a copy to memory and return @@ -149,22 +159,21 @@ uint16_t max283x_data_regs_max_value(max283x_driver_t* const drv) uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return max2831_reg_read(&drv->drv.max2831, r); - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return max2837_reg_read(&drv->drv.max2837, r); - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return max2839_reg_read(&drv->drv.max2839, r); - break; #endif + default: + return 0; } - - return 0; } /* Write value to register via SPI and save a copy to memory. Mark @@ -172,19 +181,23 @@ uint16_t max283x_reg_read(max283x_driver_t* const drv, uint8_t r) void max283x_reg_write(max283x_driver_t* const drv, uint8_t r, uint16_t v) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_reg_write(&drv->drv.max2831, r, v); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_reg_write(&drv->drv.max2837, r, v); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_reg_write(&drv->drv.max2839, r, v); break; #endif + default: + break; } } @@ -194,97 +207,113 @@ void max283x_reg_write(max283x_driver_t* const drv, uint8_t r, uint16_t v) void max283x_regs_commit(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_regs_commit(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_regs_commit(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_regs_commit(&drv->drv.max2839); break; #endif + default: + break; } } void max283x_set_mode(max283x_driver_t* const drv, const max283x_mode_t new_mode) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_set_mode(&drv->drv.max2831, (max2831_mode_t) new_mode); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_set_mode(&drv->drv.max2837, (max2837_mode_t) new_mode); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_set_mode(&drv->drv.max2839, (max2839_mode_t) new_mode); break; #endif + default: + break; } } max283x_mode_t max283x_mode(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return (max283x_mode_t) max2831_mode(&drv->drv.max2831); - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return (max283x_mode_t) max2837_mode(&drv->drv.max2837); - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return (max283x_mode_t) max2839_mode(&drv->drv.max2839); - break; #endif + default: + return 0; } - return 0; } /* Turn on/off all chip functions. Does not control oscillator and CLKOUT */ void max283x_start(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_start(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_start(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_start(&drv->drv.max2839); break; #endif + default: + break; } } void max283x_stop(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_stop(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_stop(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_stop(&drv->drv.max2839); break; #endif + default: + break; } } @@ -293,19 +322,23 @@ void max283x_stop(max283x_driver_t* const drv) void max283x_set_frequency(max283x_driver_t* const drv, uint32_t freq) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_set_frequency(&drv->drv.max2831, freq); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_set_frequency(&drv->drv.max2837, freq); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_set_frequency(&drv->drv.max2839, freq); break; #endif + default: + break; } } @@ -319,189 +352,209 @@ uint32_t max283x_set_lpf_bandwidth( #endif switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return max2831_set_lpf_bandwidth( &drv->drv.max2831, (max2831_mode_t) mode, bandwidth_hz); - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return max2837_set_lpf_bandwidth(&drv->drv.max2837, bandwidth_hz); - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return max2839_set_lpf_bandwidth(&drv->drv.max2839, bandwidth_hz); - break; #endif + default: + return 0; } - - return 0; } bool max283x_set_lna_gain(max283x_driver_t* const drv, const uint32_t gain_db) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return max2831_set_lna_gain(&drv->drv.max2831, gain_db); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return max2837_set_lna_gain(&drv->drv.max2837, gain_db); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return max2839_set_lna_gain(&drv->drv.max2839, gain_db); break; #endif + default: + return false; } - - return false; } bool max283x_set_vga_gain(max283x_driver_t* const drv, const uint32_t gain_db) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return max2831_set_vga_gain(&drv->drv.max2831, gain_db); - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return max2837_set_vga_gain(&drv->drv.max2837, gain_db); - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return max2839_set_vga_gain(&drv->drv.max2839, gain_db); - break; #endif + default: + return false; } - - return false; } bool max283x_set_txvga_gain(max283x_driver_t* const drv, const uint32_t gain_db) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: return max2831_set_txvga_gain(&drv->drv.max2831, gain_db); - break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: return max2837_set_txvga_gain(&drv->drv.max2837, gain_db); - break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: return max2839_set_txvga_gain(&drv->drv.max2839, gain_db); - break; #endif + default: + return false; } - - return false; } void max283x_tx(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_tx(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_tx(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_tx(&drv->drv.max2839); break; #endif + default: + break; } } void max283x_rx(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_rx(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: max2837_rx(&drv->drv.max2837); break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: max2839_rx(&drv->drv.max2839); break; #endif + default: + break; } } +/* Set MAX2831 receiver high-pass filter corner frequency in Hz */ void max283x_set_rx_hpf_frequency( max283x_driver_t* const drv, const max283x_rx_hpf_freq_t freq) { -#ifndef PRALINE +#if !defined(PRALINE) (void) freq; #endif switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_set_rx_hpf_frequency( &drv->drv.max2831, (max2831_rx_hpf_freq_t) freq); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: // unsupported break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: // unsupported break; #endif + default: + break; } } void max283x_tx_calibration(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_tx_calibration(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: // unsupported - use max283x_set_mode instead break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: // unsupported - use max283x_set_mode instead break; #endif + default: + break; } } void max283x_rx_calibration(max283x_driver_t* const drv) { switch (drv->type) { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case MAX2831_VARIANT: max2831_rx_calibration(&drv->drv.max2831); break; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) case MAX2837_VARIANT: // unsupported - use max283x_set_mode instead break; - +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) case MAX2839_VARIANT: // unsupported - use max283x_set_mode instead break; #endif + default: + break; } } diff --git a/firmware/common/max283x.h b/firmware/common/max283x.h index e67bf8dea..259d69fa2 100644 --- a/firmware/common/max283x.h +++ b/firmware/common/max283x.h @@ -21,16 +21,18 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX283x_H -#define __MAX283x_H +#pragma once #include #include -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "max2831.h" -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) #include "max2837.h" +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) #include "max2839.h" #endif @@ -52,9 +54,10 @@ typedef enum { } max283x_rx_hpf_freq_t; typedef enum { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) MAX2831_VARIANT, -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) MAX2837_VARIANT, MAX2839_VARIANT, #endif @@ -64,10 +67,13 @@ typedef struct { max283x_variant_t type; union { -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) max2831_driver_t max2831; -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) max2837_driver_t max2837; +#endif +#if defined(HACKRF_ONE) || defined(UNIVERSAL) max2839_driver_t max2839; #endif } drv; @@ -126,5 +132,3 @@ void max283x_set_rx_hpf_frequency( /* Perform MAX2831 TX and RX calibration. */ void max283x_tx_calibration(max283x_driver_t* const drv); void max283x_rx_calibration(max283x_driver_t* const drv); - -#endif // __MAX283x_H diff --git a/firmware/common/max2871.c b/firmware/common/max2871.c index 2d9b0c298..e02c67e5a 100644 --- a/firmware/common/max2871.c +++ b/firmware/common/max2871.c @@ -24,6 +24,8 @@ #include #include +#include + #include "max2871_regs.h" #include "selftest.h" #include "platform_scu.h" @@ -33,7 +35,6 @@ #define LOG printf #else #define LOG(x, ...) - #include #endif static uint32_t max2871_spi_read(max2871_driver_t* const drv); diff --git a/firmware/common/max2871.h b/firmware/common/max2871.h index 3cc9bb3a2..eb1ecbf06 100644 --- a/firmware/common/max2871.h +++ b/firmware/common/max2871.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef MAX2871_H -#define MAX2871_H +#pragma once #include @@ -39,4 +38,3 @@ extern void max2871_setup(max2871_driver_t* const drv); extern uint64_t max2871_set_frequency(max2871_driver_t* const drv, uint16_t mhz); extern void max2871_enable(max2871_driver_t* const drv); extern void max2871_disable(max2871_driver_t* const drv); -#endif diff --git a/firmware/common/max2871_regs.h b/firmware/common/max2871_regs.h index a18f62178..b0dbdacf1 100644 --- a/firmware/common/max2871_regs.h +++ b/firmware/common/max2871_regs.h @@ -19,8 +19,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef MAX2871_REGS_H -#define MAX2871_REGS_H +#pragma once + #include #define MAX2871_VASA (1 << 9) @@ -75,4 +75,3 @@ void max2871_set_F01(uint32_t v); void max2871_set_LD(uint32_t v); void max2871_set_ADCS(uint32_t v); void max2871_set_ADCM(uint32_t v); -#endif diff --git a/firmware/common/max5864.h b/firmware/common/max5864.h index 0ce2c6e11..56d730cc3 100644 --- a/firmware/common/max5864.h +++ b/firmware/common/max5864.h @@ -20,18 +20,14 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX5864_H -#define __MAX5864_H +#pragma once #include "spi_bus.h" -struct max5864_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct max5864_driver_t max5864_driver_t; - -struct max5864_driver_t { +typedef struct _max5864_driver_t { spi_bus_t* const bus; - void (*target_init)(max5864_driver_t* const drv); -}; + void (*target_init)(struct _max5864_driver_t* const drv); +} max5864_driver_t; void max5864_setup(max5864_driver_t* const drv); @@ -41,5 +37,3 @@ void max5864_idle(max5864_driver_t* const drv); void max5864_rx(max5864_driver_t* const drv); void max5864_tx(max5864_driver_t* const drv); void max5864_xcvr(max5864_driver_t* const drv); - -#endif // __MAX5864_H diff --git a/firmware/common/max5864_target.h b/firmware/common/max5864_target.h index 2ddd9ed1f..a162e0acf 100644 --- a/firmware/common/max5864_target.h +++ b/firmware/common/max5864_target.h @@ -20,11 +20,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MAX5864_TARGET_H__ -#define __MAX5864_TARGET_H__ +#pragma once #include "max5864.h" void max5864_target_init(max5864_driver_t* const drv); - -#endif /*__MAX5864_TARGET_H__*/ diff --git a/firmware/common/mixer.c b/firmware/common/mixer.c index cc5987019..8072a4e9c 100644 --- a/firmware/common/mixer.c +++ b/firmware/common/mixer.c @@ -20,103 +20,165 @@ */ #include "mixer.h" - #include "platform_gpio.h" -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) +#if defined(RAD1O) + #include "max2871.h" +#else + #include "platform_detect.h" #include "rffc5071.h" #include "rffc5071_spi.h" #include "spi_bus.h" -#elif defined(RAD1O) - #include "max2871.h" #endif -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) +#if !defined(RAD1O) static rffc5071_spi_config_t rffc5071_spi_config; -spi_bus_t spi_bus_rffc5071 = { +static spi_bus_t spi_bus_rffc5071 = { .config = &rffc5071_spi_config, .start = rffc5071_spi_start, .stop = rffc5071_spi_stop, .transfer = rffc5071_spi_transfer, .transfer_gather = rffc5071_spi_transfer_gather, }; +#endif mixer_driver_t mixer = { - .bus = &spi_bus_rffc5071, -}; -#elif defined(RAD1O) -mixer_driver_t mixer = {}; +#if !defined(RAD1O) + .rffc5071.bus = &spi_bus_rffc5071, #endif +}; void mixer_bus_setup(mixer_driver_t* const mixer) { +#if defined(RAD1O) (void) mixer; - -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) +#else const platform_gpio_t* gpio = platform_gpio(); - rffc5071_spi_config = (rffc5071_spi_config_t){ - .gpio_select = gpio->rffc5072_select, - .gpio_clock = gpio->rffc5072_clock, - .gpio_data = gpio->rffc5072_data, - }; - spi_bus_start(&spi_bus_rffc5071, &rffc5071_spi_config); #endif + + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + rffc5071_spi_config = (rffc5071_spi_config_t){ + .gpio_select = gpio->rffc5072_select, + .gpio_clock = gpio->rffc5072_clock, + .gpio_data = gpio->rffc5072_data, + }; + spi_bus_start(&spi_bus_rffc5071, &rffc5071_spi_config); +#endif + break; + case MAX2871_VARIANT: + break; + } } -void mixer_setup(mixer_driver_t* const mixer) +void mixer_setup(mixer_driver_t* const mixer, mixer_variant_t type) { + mixer->type = type; + const platform_gpio_t* gpio = platform_gpio(); -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - mixer->gpio_reset = gpio->rffc5072_reset; - #if defined(PRALINE) - mixer->gpio_ld = gpio->rffc5072_ld; + /* Mixer GPIO serial interface PinMux */ + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + mixer->rffc5071.gpio_reset = gpio->rffc5072_reset; + if (detected_platform() == BOARD_ID_PRALINE) { + #if defined(PRALINE) || defined(UNIVERSAL) + mixer->rffc5071.gpio_ld = gpio->rffc5072_ld; #endif - rffc5071_setup(mixer); -#elif defined(RAD1O) - mixer->gpio_vco_ce = gpio->vco_ce; - mixer->gpio_vco_sclk = gpio->vco_sclk; - mixer->gpio_vco_sdata = gpio->vco_sdata; - mixer->gpio_vco_le = gpio->vco_le; - mixer->gpio_synt_rfout_en = gpio->synt_rfout_en; - mixer->gpio_vco_mux = gpio->vco_mux; - max2871_setup(mixer); + } +#endif + break; + case MAX2871_VARIANT: +#if defined(RAD1O) + mixer->max2871.gpio_vco_ce = gpio->vco_ce; + mixer->max2871.gpio_vco_sclk = gpio->vco_sclk; + mixer->max2871.gpio_vco_sdata = gpio->vco_sdata; + mixer->max2871.gpio_vco_le = gpio->vco_le; + mixer->max2871.gpio_synt_rfout_en = gpio->synt_rfout_en; + mixer->max2871.gpio_vco_mux = gpio->vco_mux; #endif + break; + } + + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + rffc5071_setup(&mixer->rffc5071); +#endif + break; + case MAX2871_VARIANT: +#if defined(RAD1O) + max2871_setup(&mixer->max2871); +#endif + break; + } } uint64_t mixer_set_frequency(mixer_driver_t* const mixer, uint64_t hz) { -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - return rffc5071_set_frequency(mixer, hz); -#elif defined(RAD1O) - return max2871_set_frequency(mixer, hz / 1000000); + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + return rffc5071_set_frequency(&mixer->rffc5071, hz); #endif + break; + case MAX2871_VARIANT: +#if defined(RAD1O) + return max2871_set_frequency(&mixer->max2871, hz / 1000000); +#endif + break; + } + + return 0; } void mixer_enable(mixer_driver_t* const mixer) { -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - rffc5071_enable(mixer); -#elif defined(RAD1O) - max2871_enable(mixer); + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + rffc5071_enable(&mixer->rffc5071); #endif + break; + case MAX2871_VARIANT: +#if defined(RAD1O) + max2871_enable(&mixer->max2871); +#endif + break; + } } void mixer_disable(mixer_driver_t* const mixer) { -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - rffc5071_disable(mixer); -#elif defined(RAD1O) - max2871_disable(mixer); + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + rffc5071_disable(&mixer->rffc5071); +#endif + break; + case MAX2871_VARIANT: +#if defined(RAD1O) + max2871_disable(&mixer->max2871); #endif + break; + } } void mixer_set_gpo(mixer_driver_t* const mixer, uint8_t gpo) { -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - rffc5071_set_gpo(mixer, gpo); -#elif defined(RAD1O) - (void) mixer; +#if defined(RAD1O) (void) gpo; #endif + + switch (mixer->type) { + case RFFC5071_VARIANT: +#if !defined(RAD1O) + rffc5071_set_gpo(&mixer->rffc5071, gpo); +#endif + break; + case MAX2871_VARIANT: + break; + } } diff --git a/firmware/common/mixer.h b/firmware/common/mixer.h index bfd638bb6..d13c96572 100644 --- a/firmware/common/mixer.h +++ b/firmware/common/mixer.h @@ -20,20 +20,34 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __MIXER_H -#define __MIXER_H +#pragma once -#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(PRALINE) - #include "rffc5071.h" -typedef rffc5071_driver_t mixer_driver_t; -#elif defined(RAD1O) +#if defined(RAD1O) #include "max2871.h" -typedef max2871_driver_t mixer_driver_t; +#else + #include "rffc5071.h" #endif +typedef enum { + RFFC5071_VARIANT, + MAX2871_VARIANT, +} mixer_variant_t; + +typedef struct { + mixer_variant_t type; + + union { +#if defined(RAD1O) + max2871_driver_t max2871; +#else + rffc5071_driver_t rffc5071; +#endif + }; +} mixer_driver_t; + #include extern void mixer_bus_setup(mixer_driver_t* const mixer); -extern void mixer_setup(mixer_driver_t* const mixer); +extern void mixer_setup(mixer_driver_t* const mixer, mixer_variant_t type); /* Set frequency (Hz). */ extern uint64_t mixer_set_frequency(mixer_driver_t* const mixer, uint64_t hz); @@ -41,5 +55,3 @@ extern uint64_t mixer_set_frequency(mixer_driver_t* const mixer, uint64_t hz); extern void mixer_enable(mixer_driver_t* const mixer); extern void mixer_disable(mixer_driver_t* const mixer); extern void mixer_set_gpo(mixer_driver_t* const drv, uint8_t gpo); - -#endif // __MIXER_H diff --git a/firmware/common/operacake.h b/firmware/common/operacake.h index 39da6ef01..b604c513d 100644 --- a/firmware/common/operacake.h +++ b/firmware/common/operacake.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __OPERACAKE_H -#define __OPERACAKE_H +#pragma once #ifdef __cplusplus extern "C" { @@ -57,5 +56,3 @@ uint16_t gpio_test(uint8_t address); #ifdef __cplusplus } #endif - -#endif /* __OPERACAKE_H */ diff --git a/firmware/common/operacake_sctimer.c b/firmware/common/operacake_sctimer.c index 9ae37567e..d56a1fa4d 100644 --- a/firmware/common/operacake_sctimer.c +++ b/firmware/common/operacake_sctimer.c @@ -23,6 +23,7 @@ #include "operacake_sctimer.h" #include + #include #include #if !defined(PRALINE) @@ -30,6 +31,8 @@ #include #endif +#include + #include "delay.h" #include "sct.h" @@ -95,25 +98,31 @@ void operacake_sctimer_init(void) P7_0, SCU_CONF_EPUN_DIS_PULLUP | SCU_CONF_EHS_FAST | SCU_CONF_FUNCTION1); -#ifndef PRALINE - // Configure the SGPIO to output the clock (f=2 * sample clock) on pin 12 - SGPIO_OUT_MUX_CFG12 = SGPIO_OUT_MUX_CFG_P_OUT_CFG(0x08) | // clkout output mode - SGPIO_OUT_MUX_CFG_P_OE_CFG(0); // gpio_oe - SGPIO_GPIO_OENREG |= BIT12; + uint8_t sct_clock_input; + if (detected_platform() != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + // Configure the SGPIO to output the clock (f=2 * sample clock) on pin 12 + SGPIO_OUT_MUX_CFG12 = + SGPIO_OUT_MUX_CFG_P_OUT_CFG(0x08) | // clkout output mode + SGPIO_OUT_MUX_CFG_P_OE_CFG(0); // gpio_oe + SGPIO_GPIO_OENREG |= BIT12; - // Use the GIMA to connect the SGPIO clock to the SCTimer - GIMA_CTIN_1_IN = 0x2 << 4; // Route SGPIO12 to SCTIN1 + // Use the GIMA to connect the SGPIO clock to the SCTimer + GIMA_CTIN_1_IN = 0x2 << 4; // Route SGPIO12 to SCTIN1 - uint8_t sct_clock_input = SCT_CONFIG_CKSEL_RISING_EDGES_ON_INPUT_1; -#else - // Configure pin P6_4 as SCT_IN_6 - scu_pinmux(P6_4, SCU_CLK_IN | SCU_CONF_FUNCTION1); + sct_clock_input = SCT_CONFIG_CKSEL_RISING_EDGES_ON_INPUT_1; +#endif + } else { +#if defined(PRALINE) || defined(UNIVERSAL) + // Configure pin P6_4 as SCT_IN_6 + scu_pinmux(P6_4, SCU_CLK_IN | SCU_CONF_FUNCTION1); - // Use the GIMA to connect MS0/CLK1 (SCT_CLK) on pin P6_4 to the SCTimer - GIMA_CTIN_6_IN = 0x0 << 4; + // Use the GIMA to connect MS0/CLK1 (SCT_CLK) on pin P6_4 to the SCTimer + GIMA_CTIN_6_IN = 0x0 << 4; - uint8_t sct_clock_input = SCT_CONFIG_CKSEL_RISING_EDGES_ON_INPUT_6; + sct_clock_input = SCT_CONFIG_CKSEL_RISING_EDGES_ON_INPUT_6; #endif + } // We configure this register first, because the user manual says to SCT_CONFIG |= SCT_CONFIG_UNIFY_32_BIT | SCT_CONFIG_CLKMODE_PRESCALED_BUS_CLOCK | diff --git a/firmware/common/operacake_sctimer.h b/firmware/common/operacake_sctimer.h index 805b3cf93..04c86e924 100644 --- a/firmware/common/operacake_sctimer.h +++ b/firmware/common/operacake_sctimer.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __OPERACAKE_SCTIMER_H -#define __OPERACAKE_SCTIMER_H +#pragma once #include #include @@ -37,5 +36,3 @@ void operacake_sctimer_enable(bool enable); void operacake_sctimer_set_dwell_times(struct operacake_dwell_times* times, int n); void operacake_sctimer_stop(void); void operacake_sctimer_reset_state(void); - -#endif /* __OPERACAKE_SCTIMER_H */ diff --git a/firmware/common/platform_detect.h b/firmware/common/platform_detect.h index f02e733bc..4f0f0f438 100644 --- a/firmware/common/platform_detect.h +++ b/firmware/common/platform_detect.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PLATFORM_DETECT_H__ -#define __PLATFORM_DETECT_H__ +#pragma once #include @@ -76,5 +75,3 @@ void detect_hardware_platform(void); board_id_t detected_platform(void); board_rev_t detected_revision(void); uint32_t supported_platform(void); - -#endif //__PLATFORM_DETECT_H__ diff --git a/firmware/common/platform_gpio.c b/firmware/common/platform_gpio.c index df07fc2aa..f44ff4f8d 100644 --- a/firmware/common/platform_gpio.c +++ b/firmware/common/platform_gpio.c @@ -23,9 +23,7 @@ #include -#if defined(HACKRF_ONE) - #include "platform_detect.h" -#endif +#include "platform_detect.h" // clang-format off @@ -36,190 +34,285 @@ const platform_gpio_t* platform_gpio(void) return _platform_gpio; } + board_id_t board_id = detected_platform(); static platform_gpio_t gpio; /* LEDs */ gpio.led[0] = &GPIO2_1; gpio.led[1] = &GPIO2_2; gpio.led[2] = &GPIO2_8; + switch (board_id) { + case BOARD_ID_RAD1O: #if defined(RAD1O) - gpio.led[3] = &GPIO5_26; -#elif defined(PRALINE) - gpio.led[3] = &GPIO4_6; + gpio.led[3] = &GPIO5_26; +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.led[3] = &GPIO4_6; #endif + break; + default: + break; + } /* Power Supply Control */ -#if defined(PRALINE) - gpio.gpio_1v2_enable = &GPIO4_7; - gpio.gpio_3v3aux_enable_n = &GPIO5_15; -#else - gpio.gpio_1v8_enable = &GPIO3_6; + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.gpio_1v2_enable = &GPIO4_7; + gpio.gpio_3v3aux_enable_n = &GPIO5_15; #endif + break; + default: + gpio.gpio_1v8_enable = &GPIO3_6; + break; + } /* MAX283x GPIO (XCVR_CTL / CS_XCVR) PinMux */ -#if defined(PRALINE) - gpio.max283x_select = &GPIO6_28; - gpio.max283x_enable = &GPIO7_1; - gpio.max283x_rx_enable = &GPIO7_2; - gpio.max2831_rxhp = &GPIO6_29; - gpio.max2831_ld = &GPIO4_11; -#else - gpio.max283x_select = &GPIO0_15; - gpio.max283x_enable = &GPIO2_6; - gpio.max283x_rx_enable = &GPIO2_5; - gpio.max283x_tx_enable = &GPIO2_4; + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.max283x_select = &GPIO6_28; + gpio.max283x_enable = &GPIO7_1; + gpio.max283x_rx_enable = &GPIO7_2; + gpio.max2831_rxhp = &GPIO6_29; + gpio.max2831_ld = &GPIO4_11; #endif + break; + default: + gpio.max283x_select = &GPIO0_15; + gpio.max283x_enable = &GPIO2_6; + gpio.max283x_rx_enable = &GPIO2_5; + gpio.max283x_tx_enable = &GPIO2_4; + break; + } /* MAX5864 SPI chip select (AD_CS / CS_AD) GPIO PinMux */ -#if defined(PRALINE) - gpio.max5864_select = &GPIO6_30; -#else - gpio.max5864_select = &GPIO2_7; + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.max5864_select = &GPIO6_30; #endif + break; + default: + gpio.max5864_select = &GPIO2_7; + break; + } /* RF supply (VAA) control */ -#if defined(HACKRF_ONE) - gpio.vaa_disable = &GPIO2_9; -#elif defined(PRALINE) - gpio.vaa_disable = &GPIO4_1; -#elif defined(RAD1O) - gpio.vaa_enable = &GPIO2_9; + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio.vaa_disable = &GPIO2_9; +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.vaa_disable = &GPIO4_1; #endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + gpio.vaa_enable = &GPIO2_9; +#endif + break; + default: + break; + } /* W25Q80BV Flash */ - gpio.w25q80bv_hold = &GPIO1_14; - gpio.w25q80bv_wp = &GPIO1_15; - gpio.w25q80bv_select = &GPIO5_11; + gpio.w25q80bv_hold = &GPIO1_14; + gpio.w25q80bv_wp = &GPIO1_15; + gpio.w25q80bv_select = &GPIO5_11; /* RF switch control */ -#if defined(HACKRF_ONE) - gpio.hp = &GPIO2_0; - gpio.lp = &GPIO2_10; - gpio.tx_mix_bp = &GPIO2_11; - gpio.no_mix_bypass = &GPIO1_0; - gpio.rx_mix_bp = &GPIO2_12; - gpio.tx_amp = &GPIO2_15; - gpio.tx = &GPIO5_15; - gpio.mix_bypass = &GPIO5_16; - gpio.rx = &GPIO5_5; - gpio.no_tx_amp_pwr = &GPIO3_5; - gpio.amp_bypass = &GPIO0_14; - gpio.rx_amp = &GPIO1_11; - gpio.no_rx_amp_pwr = &GPIO1_12; - // HackRF One rev 9 - gpio.h1r9_rx = &GPIO0_7; - gpio.h1r9_no_ant_pwr = &GPIO2_4; -#elif defined(RAD1O) - gpio.tx_rx_n = &GPIO1_11; - gpio.tx_rx = &GPIO0_14; - gpio.by_mix = &GPIO1_12; - gpio.by_mix_n = &GPIO2_10; - gpio.by_amp = &GPIO1_0; - gpio.by_amp_n = &GPIO5_5; - gpio.mixer_en = &GPIO5_16; - gpio.low_high_filt = &GPIO2_11; - gpio.low_high_filt_n = &GPIO2_12; - gpio.tx_amp = &GPIO2_15; - gpio.rx_lna = &GPIO5_15; -#elif defined(PRALINE) - gpio.tx_en = &GPIO3_4; - gpio.mix_en_n = &GPIO3_2; - gpio.mix_en_n_r1_0 = &GPIO5_6; - gpio.lpf_en = &GPIO4_8; - gpio.rf_amp_en = &GPIO4_9; - gpio.ant_bias_en_n = &GPIO1_12; + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio.hp = &GPIO2_0; + gpio.lp = &GPIO2_10; + gpio.tx_mix_bp = &GPIO2_11; + gpio.no_mix_bypass = &GPIO1_0; + gpio.rx_mix_bp = &GPIO2_12; + gpio.tx_amp = &GPIO2_15; + gpio.tx = &GPIO5_15; + gpio.mix_bypass = &GPIO5_16; + gpio.rx = &GPIO5_5; + gpio.no_tx_amp_pwr = &GPIO3_5; + gpio.amp_bypass = &GPIO0_14; + gpio.rx_amp = &GPIO1_11; + gpio.no_rx_amp_pwr = &GPIO1_12; + // HackRF One rev 9 + gpio.h1r9_rx = &GPIO0_7; + gpio.h1r9_no_ant_pwr = &GPIO2_4; #endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + gpio.tx_rx_n = &GPIO1_11; + gpio.tx_rx = &GPIO0_14; + gpio.by_mix = &GPIO1_12; + gpio.by_mix_n = &GPIO2_10; + gpio.by_amp = &GPIO1_0; + gpio.by_amp_n = &GPIO5_5; + gpio.mixer_en = &GPIO5_16; + gpio.low_high_filt = &GPIO2_11; + gpio.low_high_filt_n = &GPIO2_12; + gpio.tx_amp = &GPIO2_15; + gpio.rx_lna = &GPIO5_15; +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.tx_en = &GPIO3_4; + gpio.mix_en_n = &GPIO3_2; + gpio.mix_en_n_r1_0 = &GPIO5_6; + gpio.lpf_en = &GPIO4_8; + gpio.rf_amp_en = &GPIO4_9; + gpio.ant_bias_en_n = &GPIO1_12; +#endif + break; + case BOARD_ID_JELLYBEAN: + case BOARD_ID_JAWBREAKER: + break; + default: + break; + } /* CPLD JTAG interface GPIO pins_FPGA config pins in Praline */ - gpio.cpld_tck = &GPIO3_0; -#if defined(PRALINE) - gpio.fpga_cfg_creset = &GPIO2_11; - gpio.fpga_cfg_cdone = &GPIO5_14; - gpio.fpga_cfg_spi_cs = &GPIO2_10; + gpio.cpld_tck = &GPIO3_0; + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.fpga_cfg_creset = &GPIO2_11; + gpio.fpga_cfg_cdone = &GPIO5_14; + gpio.fpga_cfg_spi_cs = &GPIO2_10; #endif -#if defined(HACKRF_ONE) || defined(RAD1O) - gpio.cpld_tdo = &GPIO5_18; - gpio.cpld_tms = &GPIO3_4; - gpio.cpld_tdi = &GPIO3_1; + break; + default: + gpio.cpld_tdo = &GPIO5_18; + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_RAD1O: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) || defined(RAD1O) + gpio.cpld_tms = &GPIO3_4; + gpio.cpld_tdi = &GPIO3_1; #endif -#if defined(HACKRF_ONE) || defined(PRALINE) - gpio.cpld_pp_tms = &GPIO1_1; - gpio.cpld_pp_tdo = &GPIO1_8; + break; + case BOARD_ID_JAWBREAKER: +#if defined(JAWBREAKER) + gpio.cpld_tms = &GPIO3_1; + gpio.cpld_tdi = &GPIO3_4; #endif + break; + default: + break; + } + } + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + gpio.cpld_pp_tms = &GPIO1_1; + gpio.cpld_pp_tdo = &GPIO1_8; +#endif + break; + default: + break; + } /* Other CPLD interface GPIO pins */ -#if !defined(PRALINE) - gpio.trigger_enable = &GPIO5_12; + switch (board_id) { + case BOARD_ID_PRALINE: + break; + default: +#if !defined(PRALINE) || defined(UNIVERSAL) + gpio.trigger_enable = &GPIO5_12; #endif - gpio.q_invert = &GPIO0_13; + break; + } + gpio.q_invert = &GPIO0_13; /* RFFC5071 GPIO serial interface PinMux */ -#if defined(JAWBREAKER) || defined(HACKRF_ONE) - gpio.rffc5072_select = &GPIO2_13; - gpio.rffc5072_clock = &GPIO5_6; - gpio.rffc5072_data = &GPIO3_3; - gpio.rffc5072_reset = &GPIO2_14; -#elif defined(RAD1O) - gpio.vco_ce = &GPIO2_13; - gpio.vco_sclk = &GPIO5_6; - gpio.vco_sdata = &GPIO3_3; - gpio.vco_le = &GPIO2_14; - gpio.vco_mux = &GPIO5_25; - gpio.synt_rfout_en = &GPIO3_5; -#elif defined(PRALINE) - gpio.rffc5072_select = &GPIO2_13; - gpio.rffc5072_clock = &GPIO5_18; - gpio.rffc5072_data = &GPIO4_14; - gpio.rffc5072_reset = &GPIO2_14; - gpio.rffc5072_ld = &GPIO6_25; -#endif - - /* Praline */ -#if defined(PRALINE) - gpio.p2_ctrl0 = &GPIO7_3; - gpio.p2_ctrl1 = &GPIO7_4; - gpio.p1_ctrl0 = &GPIO0_14; - gpio.p1_ctrl1 = &GPIO5_16; - gpio.p1_ctrl2 = &GPIO3_5; - gpio.clkin_ctrl = &GPIO0_15; - gpio.aa_en = &GPIO1_7; - gpio.trigger_in = &GPIO6_26; - gpio.trigger_out = &GPIO5_6; - gpio.pps_out = &GPIO5_5; -#endif - - /* HackRF One r9 */ -#if defined(HACKRF_ONE) - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - /* HackRF One r9 clock control */ + switch (board_id) { + case BOARD_ID_JAWBREAKER: + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio.rffc5072_select = &GPIO2_13; + gpio.rffc5072_clock = &GPIO5_6; + gpio.rffc5072_data = &GPIO3_3; + gpio.rffc5072_reset = &GPIO2_14; +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + gpio.vco_ce = &GPIO2_13; + gpio.vco_sclk = &GPIO5_6; + gpio.vco_sdata = &GPIO3_3; + gpio.vco_le = &GPIO2_14; + gpio.vco_mux = &GPIO5_25; + gpio.synt_rfout_en = &GPIO3_5; +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + gpio.rffc5072_select = &GPIO2_13; + gpio.rffc5072_clock = &GPIO5_18; + gpio.rffc5072_data = &GPIO4_14; + gpio.rffc5072_reset = &GPIO2_14; + gpio.rffc5072_ld = &GPIO6_25; +#endif + break; + default: + break; + } + +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + /* HackRF One r9 clock control */ + switch (board_id) { + case BOARD_ID_HACKRF1_R9: gpio.h1r9_clkin_en = &GPIO5_15; gpio.h1r9_clkout_en = &GPIO0_9; gpio.h1r9_mcu_clk_en = &GPIO0_8; + break; + default: + break; + } - /* HackRF One r9 power control */ - gpio.h1r9_1v8_enable = &GPIO2_9; - gpio.h1r9_vaa_disable = &GPIO3_6; - + switch (board_id) { + case BOARD_ID_HACKRF1_R9: + gpio.h1r9_1v8_enable = &GPIO2_9; + gpio.h1r9_vaa_disable = &GPIO3_6; gpio.h1r9_trigger_enable = &GPIO5_5; + break; + default: + break; } #endif - /* RAD1O */ -#if defined(RAD1O) - gpio.lcd_cs = &GPIO4_12; /* P9_0 */ - gpio.lcd_bl_en = &GPIO0_8; /* P1_1 */ - gpio.lcd_reset = &GPIO5_17; /* P9_4 */ -#endif - - /* Portapack */ -#if defined(HACKRF_ONE) || defined(PRALINE) - gpio.io_stbx = &GPIO5_0; /* P2_0 */ - gpio.addr = &GPIO5_1; /* P2_1 */ - gpio.lcd_te = &GPIO5_3; /* P2_3 */ - gpio.unused = &GPIO5_7; /* P2_8 */ - gpio.lcd_rdx = &GPIO5_4; /* P2_4 */ - gpio.lcd_wrx = &GPIO1_10; /* P2_9 */ - gpio.dir = &GPIO1_13; /* P2_13 */ +#if defined(PRALINE) || defined(UNIVERSAL) + switch (board_id) { + case BOARD_ID_PRALINE: + gpio.p2_ctrl0 = &GPIO7_3; + gpio.p2_ctrl1 = &GPIO7_4; + gpio.p1_ctrl0 = &GPIO0_14; + gpio.p1_ctrl1 = &GPIO5_16; + gpio.p1_ctrl2 = &GPIO3_5; + gpio.clkin_ctrl = &GPIO0_15; + gpio.aa_en = &GPIO1_7; + gpio.trigger_in = &GPIO6_26; + gpio.trigger_out = &GPIO5_6; + gpio.pps_out = &GPIO5_5; + break; + default: + break; + } #endif _platform_gpio = &gpio; diff --git a/firmware/common/platform_gpio.h b/firmware/common/platform_gpio.h index e327e4ba8..27ae57a95 100644 --- a/firmware/common/platform_gpio.h +++ b/firmware/common/platform_gpio.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PLATFORM_GPIO_H -#define __PLATFORM_GPIO_H +#pragma once #ifdef __cplusplus extern "C" { @@ -31,7 +30,7 @@ extern "C" { typedef struct { /* LEDs */ -#if defined(PRALINE) || defined(RAD1O) +#if defined(PRALINE) || defined(UNIVERSAL) || defined(RAD1O) gpio_t led[4]; #else gpio_t led[3]; @@ -39,7 +38,7 @@ typedef struct { /* Power Supply Control */ gpio_t gpio_1v8_enable; -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t gpio_1v2_enable; gpio_t gpio_3v3aux_enable_n; #endif @@ -49,7 +48,7 @@ typedef struct { gpio_t max283x_enable; gpio_t max283x_rx_enable; gpio_t max283x_tx_enable; -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t max2831_rxhp; gpio_t max2831_ld; #endif @@ -69,7 +68,7 @@ typedef struct { gpio_t w25q80bv_select; /* RF switch control */ -#if defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) gpio_t hp; gpio_t lp; gpio_t tx_mix_bp; @@ -99,7 +98,7 @@ typedef struct { gpio_t tx_amp; gpio_t rx_lna; #endif -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t tx_en; gpio_t mix_en_n; gpio_t mix_en_n_r1_0; @@ -110,23 +109,23 @@ typedef struct { /* CPLD JTAG interface GPIO pins, FPGA config pins in Praline */ gpio_t cpld_tck; -#if defined(HACKRF_ONE) || defined(RAD1O) gpio_t cpld_tdo; +#if !defined(PRALINE) || defined(UNIVERSAL) gpio_t cpld_tms; gpio_t cpld_tdi; #endif -#if defined(HACKRF_ONE) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) gpio_t cpld_pp_tms; gpio_t cpld_pp_tdo; #endif -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t fpga_cfg_creset; gpio_t fpga_cfg_cdone; gpio_t fpga_cfg_spi_cs; #endif /* Other CPLD interface GPIO pins */ -#if !defined(PRALINE) +#if !defined(PRALINE) || defined(UNIVERSAL) gpio_t trigger_enable; #endif gpio_t q_invert; @@ -145,7 +144,7 @@ typedef struct { gpio_t synt_rfout_en; // RAD1O /* Praline */ -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t p2_ctrl0; gpio_t p2_ctrl1; gpio_t p1_ctrl0; @@ -158,8 +157,7 @@ typedef struct { gpio_t pps_out; #endif - /* HackRF One r9 */ -#if defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) /* HackRF One r9 clock control */ gpio_t h1r9_clkin_en; gpio_t h1r9_clkout_en; @@ -178,7 +176,7 @@ typedef struct { #endif /* Portapack */ -#if defined(HACKRF_ONE) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) gpio_t io_stbx; gpio_t addr; __attribute__((unused)) gpio_t lcd_te; @@ -369,5 +367,3 @@ static const struct gpio GPIO7_25 = GPIO(7, 25); #ifdef __cplusplus } #endif - -#endif /* __PLATFORM_GPIO_H */ diff --git a/firmware/common/platform_scu.c b/firmware/common/platform_scu.c index df611bd20..2687cd6c8 100644 --- a/firmware/common/platform_scu.c +++ b/firmware/common/platform_scu.c @@ -25,6 +25,8 @@ #include +#include "platform_detect.h" + // clang-format off const platform_scu_t* platform_scu(void) @@ -34,317 +36,423 @@ const platform_scu_t* platform_scu(void) return _platform_scu; } + board_id_t board_id = detected_platform(); static platform_scu_t scu; - /* LED PinMux */ - scu.PINMUX_LED1 = SCU_PINMUX_LED1; /* GPIO2[1] on P4_1 */ - scu.PINMUX_LED2 = SCU_PINMUX_LED2; /* GPIO2[2] on P4_2 */ - scu.PINMUX_LED3 = SCU_PINMUX_LED3; /* GPIO2[8] on P6_12 */ -#if defined(PRALINE) - scu.PINMUX_LED4 = (P8_6); /* GPIO4[6] on P8_6 */ -#elif defined(RAD1O) - scu.PINMUX_LED4 = (PB_6); /* GPIO5[26] on PB_6 */ + /* GPIO Output PinMux */ + scu.PINMUX_LED1 = SCU_PINMUX_LED1; /* GPIO2[1] on P4_1 */ + scu.PINMUX_LED2 = SCU_PINMUX_LED2; /* GPIO2[2] on P4_2 */ + scu.PINMUX_LED3 = SCU_PINMUX_LED3; /* GPIO2[8] on P6_12 */ + switch (board_id) { + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu.PINMUX_LED4 = (PB_6); /* GPIO5[26] on PB_6 */ +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.PINMUX_LED4 = (P8_6); /* GPIO4[6] on P8_6 */ #endif + break; + default: + break; + } - /* Power Supply PinMux */ - scu.PINMUX_EN1V8 = (P6_10); /* GPIO3[6] on P6_10 */ - scu.PINMUX_EN1V2 = (P8_7); /* GPIO4[7] on P8_7 */ -#if defined(PRALINE) - scu.PINMUX_EN3V3_AUX_N = (P6_7); /* GPIO5[15] on P6_7 */ - scu.PINMUX_EN3V3_OC_N = (P6_11); /* GPIO3[7] on P6_11 */ + scu.PINMUX_EN1V8 = (P6_10); /* GPIO3[6] on P6_10 */ + scu.PINMUX_EN1V2 = (P8_7); /* GPIO4[7] on P8_7 */ + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.PINMUX_EN3V3_AUX_N = (P6_7); /* GPIO5[15] on P6_7 */ + scu.PINMUX_EN3V3_OC_N = (P6_11); /* GPIO3[7] on P6_11 */ #endif + break; + default: + break; + } /* GPIO Input PinMux */ - scu.PINMUX_BOOT0 = (P1_1); /* GPIO0[8] on P1_1 */ - scu.PINMUX_BOOT1 = (P1_2); /* GPIO0[9] on P1_2 */ -#if !defined(HACKRF_ONE) - scu.PINMUX_BOOT2 = (P2_8); /* GPIO5[7] on P2_8 */ - scu.PINMUX_BOOT3 = (P2_9); /* GPIO1[10] on P2_9 */ + scu.PINMUX_BOOT0 = (P1_1); /* GPIO0[8] on P1_1 */ + scu.PINMUX_BOOT1 = (P1_2); /* GPIO0[9] on P1_2 */ + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + break; + default: +#if !defined(HACKRF_ONE) || defined(UNIVERSAL) + scu.PINMUX_BOOT2 = (P2_8); /* GPIO5[7] on P2_8 */ + scu.PINMUX_BOOT3 = (P2_9); /* GPIO1[10] on P2_9 */ #endif - scu.PINMUX_PP_LCD_TE = (P2_3); /* GPIO5[3] on P2_3 */ - scu.PINMUX_PP_LCD_RDX = (P2_4); /* GPIO5[4] on P2_4 */ - scu.PINMUX_PP_UNUSED = (P2_8); /* GPIO5[7] on P2_8 */ - scu.PINMUX_PP_LCD_WRX = (P2_9); /* GPIO1[10] on P2_9 */ - scu.PINMUX_PP_DIR = (P2_13); /* GPIO1[13] on P2_13 */ + break; + } + scu.PINMUX_PP_LCD_TE = (P2_3); /* GPIO5[3] on P2_3 */ + scu.PINMUX_PP_LCD_RDX = (P2_4); /* GPIO5[4] on P2_4 */ + scu.PINMUX_PP_UNUSED = (P2_8); /* GPIO5[7] on P2_8 */ + scu.PINMUX_PP_LCD_WRX = (P2_9); /* GPIO1[10] on P2_9 */ + scu.PINMUX_PP_DIR = (P2_13); /* GPIO1[13] on P2_13 */ /* USB peripheral */ + switch (board_id) { + case BOARD_ID_JAWBREAKER: #if defined(JAWBREAKER) - scu.PINMUX_USB_LED0 = (P6_8); - scu.PINMUX_USB_LED1 = (P6_7); + scu.PINMUX_USB_LED0 = (P6_8); + scu.PINMUX_USB_LED1 = (P6_7); #endif + break; + default: + break; + } /* SSP1 Peripheral PinMux */ - scu.SSP1_CIPO = (P1_3); /* P1_3 */ - scu.SSP1_COPI = (P1_4); /* P1_4 */ - scu.SSP1_SCK = (P1_19); /* P1_19 */ - scu.SSP1_CS = (P1_20); /* P1_20 */ + scu.SSP1_CIPO = (P1_3); /* P1_3 */ + scu.SSP1_COPI = (P1_4); /* P1_4 */ + scu.SSP1_SCK = (P1_19); /* P1_19 */ + scu.SSP1_CS = (P1_20); /* P1_20 */ /* CPLD JTAG interface */ - scu.PINMUX_CPLD_TCK = (P6_1); /* GPIO3[ 0] */ -#if defined(PRALINE) - scu.PINMUX_FPGA_CRESET = (P5_2); /* GPIO2[11] on P5_2 */ - scu.PINMUX_FPGA_CDONE = (P4_10); /* GPIO5[14] */ - scu.PINMUX_FPGA_SPI_CS = (P5_1); /* GPIO2[10] */ -#elif defined(RAD1O) || defined(HACKRF_ONE) - scu.PINMUX_CPLD_TMS = (P6_5); /* GPIO3[ 4] */ - scu.PINMUX_CPLD_TDI = (P6_2); /* GPIO3[ 1] */ - scu.PINMUX_CPLD_TDO = (P9_5); /* GPIO5[18] */ -#else - scu.PINMUX_CPLD_TMS = (P6_2); /* GPIO3[ 1] */ - scu.PINMUX_CPLD_TDI = (P6_5); /* GPIO3[ 4] */ + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.PINMUX_FPGA_CRESET = (P5_2); /* GPIO2[11] on P5_2 */ + scu.PINMUX_FPGA_CDONE = (P4_10); /* GPIO5[14] */ + scu.PINMUX_FPGA_SPI_CS = (P5_1); /* GPIO2[10] */ #endif + break; + default: + break; + } + scu.PINMUX_CPLD_TDO = (P9_5); /* GPIO5[18] */ + scu.PINMUX_CPLD_TCK = (P6_1); /* GPIO3[ 0] */ + switch (board_id) { + case BOARD_ID_RAD1O: + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: + scu.PINMUX_CPLD_TMS = (P6_5); /* GPIO3[ 4] */ + scu.PINMUX_CPLD_TDI = (P6_2); /* GPIO3[ 1] */ + break; + default: + scu.PINMUX_CPLD_TMS = (P6_2); /* GPIO3[ 1] */ + scu.PINMUX_CPLD_TDI = (P6_5); /* GPIO3[ 4] */ + break; + } /* CPLD SGPIO interface */ -#if defined(PRALINE) - scu.PINMUX_SGPIO0 = (P0_0); - scu.PINMUX_SGPIO1 = (P0_1); - scu.PINMUX_SGPIO2 = (P1_15); - scu.PINMUX_SGPIO3 = (P1_16); - scu.PINMUX_SGPIO4 = (P9_4); - scu.PINMUX_SGPIO5 = (P6_6); - scu.PINMUX_SGPIO6 = (P2_2); - scu.PINMUX_SGPIO7 = (P1_0); - scu.PINMUX_SGPIO8 = (P8_0); - scu.PINMUX_SGPIO9 = (P9_3); - scu.PINMUX_SGPIO10 = (P8_2); - scu.PINMUX_SGPIO11 = (P1_17); - scu.PINMUX_SGPIO12 = (P1_18); - scu.PINMUX_SGPIO14 = (P1_18); - scu.PINMUX_SGPIO15 = (P1_18); - - scu.PINMUX_SGPIO0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); - scu.PINMUX_SGPIO1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); - scu.PINMUX_SGPIO2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO3_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO4_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO5_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO6_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.PINMUX_SGPIO7_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO8_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.PINMUX_SGPIO9_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO10_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.PINMUX_SGPIO11_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO12_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.PINMUX_SGPIO14_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.PINMUX_SGPIO15_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); -#else - scu.PINMUX_SGPIO0 = (P0_0); - scu.PINMUX_SGPIO1 = (P0_1); - scu.PINMUX_SGPIO2 = (P1_15); - scu.PINMUX_SGPIO3 = (P1_16); - scu.PINMUX_SGPIO4 = (P6_3); - scu.PINMUX_SGPIO5 = (P6_6); - scu.PINMUX_SGPIO6 = (P2_2); - scu.PINMUX_SGPIO7 = (P1_0); - scu.PINMUX_SGPIO8 = (P9_6); - scu.PINMUX_SGPIO9 = (P4_3); - scu.PINMUX_SGPIO10 = (P1_14); - scu.PINMUX_SGPIO11 = (P1_17); - scu.PINMUX_SGPIO12 = (P1_18); - scu.PINMUX_SGPIO14 = (P4_9); - scu.PINMUX_SGPIO15 = (P4_10); - - scu.PINMUX_SGPIO0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); - scu.PINMUX_SGPIO1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); - scu.PINMUX_SGPIO2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO3_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO4_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO5_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); - scu.PINMUX_SGPIO6_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.PINMUX_SGPIO7_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO8_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO9_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION7); - scu.PINMUX_SGPIO10_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO11_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); - scu.PINMUX_SGPIO12_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.PINMUX_SGPIO14_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.PINMUX_SGPIO15_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.PINMUX_SGPIO0 = (P0_0); + scu.PINMUX_SGPIO1 = (P0_1); + scu.PINMUX_SGPIO2 = (P1_15); + scu.PINMUX_SGPIO3 = (P1_16); + scu.PINMUX_SGPIO4 = (P9_4); + scu.PINMUX_SGPIO5 = (P6_6); + scu.PINMUX_SGPIO6 = (P2_2); + scu.PINMUX_SGPIO7 = (P1_0); + scu.PINMUX_SGPIO8 = (P8_0); + scu.PINMUX_SGPIO9 = (P9_3); + scu.PINMUX_SGPIO10 = (P8_2); + scu.PINMUX_SGPIO11 = (P1_17); + scu.PINMUX_SGPIO12 = (P1_18); + scu.PINMUX_SGPIO14 = (P1_18); + scu.PINMUX_SGPIO15 = (P1_18); + + scu.PINMUX_SGPIO0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); + scu.PINMUX_SGPIO1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); + scu.PINMUX_SGPIO2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO3_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO4_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO5_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO6_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.PINMUX_SGPIO7_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO8_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.PINMUX_SGPIO9_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO10_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.PINMUX_SGPIO11_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO12_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.PINMUX_SGPIO14_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.PINMUX_SGPIO15_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); +#endif + break; + default: +#if !defined(PRALINE) || defined(UNIVERSAL) + scu.PINMUX_SGPIO0 = (P0_0); + scu.PINMUX_SGPIO1 = (P0_1); + scu.PINMUX_SGPIO2 = (P1_15); + scu.PINMUX_SGPIO3 = (P1_16); + scu.PINMUX_SGPIO4 = (P6_3); + scu.PINMUX_SGPIO5 = (P6_6); + scu.PINMUX_SGPIO6 = (P2_2); + scu.PINMUX_SGPIO7 = (P1_0); + scu.PINMUX_SGPIO8 = (P9_6); + scu.PINMUX_SGPIO9 = (P4_3); + scu.PINMUX_SGPIO10 = (P1_14); + scu.PINMUX_SGPIO11 = (P1_17); + scu.PINMUX_SGPIO12 = (P1_18); + scu.PINMUX_SGPIO14 = (P4_9); + scu.PINMUX_SGPIO15 = (P4_10); + + scu.PINMUX_SGPIO0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); + scu.PINMUX_SGPIO1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION3); + scu.PINMUX_SGPIO2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO3_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO4_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO5_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION2); + scu.PINMUX_SGPIO6_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.PINMUX_SGPIO7_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO8_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO9_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION7); + scu.PINMUX_SGPIO10_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO11_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION6); + scu.PINMUX_SGPIO12_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.PINMUX_SGPIO14_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.PINMUX_SGPIO15_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); #endif + break; + } scu.TRIGGER_EN = (P4_8); /* GPIO5[12] on P4_8 */ /* MAX283x GPIO (XCVR_CTL) PinMux */ -#if defined(PRALINE) - scu.XCVR_ENABLE = PE_1; /* GPIO7[1] on PE_1 */ - scu.XCVR_RXENABLE = PE_2; /* GPIO7[2] on PE_2 */ - scu.XCVR_CS = PD_14; /* GPIO6[28] on PD_14 */ - scu.XCVR_RXHP = PD_15; /* GPIO6[29] on PD_15 */ - scu.XCVR_LD = P9_6; /* GPIO4[11] on P9_6 */ - - scu.XCVR_ENABLE_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.XCVR_RXENABLE_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.XCVR_CS_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.XCVR_RXHP_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.XCVR_LD_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0 | - SCU_CONF_EPD_EN_PULLDOWN | SCU_CONF_EPUN_DIS_PULLUP); -#elif defined(JAWBREAKER) || defined(HACKRF_ONE) - scu.XCVR_ENABLE = P4_6; /* GPIO2[6] on P4_6 */ - scu.XCVR_RXENABLE = P4_5; /* GPIO2[5] on P4_5 */ - scu.XCVR_TXENABLE = P4_4; /* GPIO2[4] on P4_4 */ - scu.XCVR_CS = P1_20; /* GPIO0[15] on P1_20 */ - - scu.XCVR_ENABLE_PINCFG = (SCU_GPIO_FAST); - scu.XCVR_RXENABLE_PINCFG = (SCU_GPIO_FAST); - scu.XCVR_TXENABLE_PINCFG = (SCU_GPIO_FAST); - scu.XCVR_CS_PINCFG = (SCU_GPIO_FAST); -#elif defined(RAD1O) - scu.XCVR_RXHP = P8_1; /* GPIO[] on P8_1 */ - scu.XCVR_B6 = P8_2; /* GPIO[] on P8_2 */ - scu.XCVR_B7 = P9_3; /* GPIO[] on P9_3 */ + switch (board_id) { + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu.XCVR_RXHP = P8_1; /* GPIO[] on P8_1 */ + scu.XCVR_B6 = P8_2; /* GPIO[] on P8_2 */ + scu.XCVR_B7 = P9_3; /* GPIO[] on P9_3 */ +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.XCVR_ENABLE = PE_1; /* GPIO7[1] on PE_1 */ + scu.XCVR_RXENABLE = PE_2; /* GPIO7[2] on PE_2 */ + scu.XCVR_CS = PD_14; /* GPIO6[28] on PD_14 */ + scu.XCVR_RXHP = PD_15; /* GPIO6[29] on PD_15 */ + scu.XCVR_LD = P9_6; /* GPIO4[11] on P9_6 */ + + scu.XCVR_ENABLE_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.XCVR_RXENABLE_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.XCVR_CS_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.XCVR_RXHP_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.XCVR_LD_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0 | + SCU_CONF_EPD_EN_PULLDOWN | SCU_CONF_EPUN_DIS_PULLUP); #endif + break; + case BOARD_ID_JELLYBEAN: + case BOARD_ID_JAWBREAKER: + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(JELLYBEAN) || defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(UNIVERSAL) + scu.XCVR_ENABLE = P4_6; /* GPIO2[6] on P4_6 */ + scu.XCVR_RXENABLE = P4_5; /* GPIO2[5] on P4_5 */ + scu.XCVR_TXENABLE = P4_4; /* GPIO2[4] on P4_4 */ + scu.XCVR_CS = P1_20; /* GPIO0[15] on P1_20 */ + + scu.XCVR_ENABLE_PINCFG = (SCU_GPIO_FAST); + scu.XCVR_RXENABLE_PINCFG = (SCU_GPIO_FAST); + scu.XCVR_TXENABLE_PINCFG = (SCU_GPIO_FAST); + scu.XCVR_CS_PINCFG = (SCU_GPIO_FAST); +#endif + break; + default: + break; + } /* MAX5864 SPI chip select (AD_CS) GPIO PinMux */ -#if defined(PRALINE) - scu.AD_CS = (PD_16); /* GPIO6[30] on PD_16 */ - scu.AD_CS_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); -#else - scu.AD_CS = (P5_7); /* GPIO2[7] on P5_7 */ - scu.AD_CS_PINCFG = (SCU_GPIO_FAST); + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.AD_CS = (PD_16); /* GPIO6[30] on PD_16 */ + scu.AD_CS_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); #endif + break; + default: + scu.AD_CS = (P5_7); /* GPIO2[7] on P5_7 */ + scu.AD_CS_PINCFG = (SCU_GPIO_FAST); + break; + } /* RFFC5071 GPIO serial interface PinMux */ -#if defined(PRALINE) - scu.MIXER_ENX = (P5_4); /* GPIO2[13] on P5_4 */ - scu.MIXER_SCLK = (P9_5); /* GPIO5[18] on P9_5 */ - scu.MIXER_SDATA = (P9_2); /* GPIO4[14] on P9_2 */ - scu.MIXER_RESETX = (P5_5); /* GPIO2[14] on P5_5 */ - scu.MIXER_LD = (PD_11); /* GPIO6[25] on PD_11 */ - - scu.MIXER_SCLK_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.MIXER_SDATA_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.MIXER_LD_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); -#elif defined(JAWBREAKER) || defined(HACKRF_ONE) - scu.MIXER_ENX = (P5_4); /* GPIO2[13] on P5_4 */ - scu.MIXER_SCLK = (P2_6); /* GPIO5[6] on P2_6 */ - scu.MIXER_SDATA = (P6_4); /* GPIO3[3] on P6_4 */ - scu.MIXER_RESETX = (P5_5); /* GPIO2[14] on P5_5 */ - - scu.MIXER_SCLK_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.MIXER_SDATA_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); -#elif defined(RAD1O) - scu.VCO_CE = (P5_4); /* GPIO2[13] on P5_4 */ - scu.VCO_SCLK = (P2_6); /* GPIO5[6] on P2_6 */ - scu.VCO_SDATA = (P6_4); /* GPIO3[3] on P6_4 */ - scu.VCO_LE = (P5_5); /* GPIO2[14] on P5_5 */ - scu.VCO_MUX = (PB_5); /* GPIO5[25] on PB_5 */ - scu.MIXER_EN = (P6_8); /* GPIO5[16] on P6_8 */ - scu.SYNT_RFOUT_EN = (P6_9); /* GPIO3[5] on P6_9 */ + switch (board_id) { + case BOARD_ID_JAWBREAKER: + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(JAWBREAKER) || defined(HACKRF_ONE) || defined(UNIVERSAL) + scu.MIXER_ENX = (P5_4); /* GPIO2[13] on P5_4 */ + scu.MIXER_SCLK = (P2_6); /* GPIO5[6] on P2_6 */ + scu.MIXER_SDATA = (P6_4); /* GPIO3[3] on P6_4 */ + scu.MIXER_RESETX = (P5_5); /* GPIO2[14] on P5_5 */ + + scu.MIXER_SCLK_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.MIXER_SDATA_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.MIXER_ENX = (P5_4); /* GPIO2[13] on P5_4 */ + scu.MIXER_SCLK = (P9_5); /* GPIO5[18] on P9_5 */ + scu.MIXER_SDATA = (P9_2); /* GPIO4[14] on P9_2 */ + scu.MIXER_RESETX = (P5_5); /* GPIO2[14] on P5_5 */ + scu.MIXER_LD = (PD_11); /* GPIO6[25] on PD_11 */ + + scu.MIXER_SCLK_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.MIXER_SDATA_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.MIXER_LD_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); #endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu.VCO_CE = (P5_4); /* GPIO2[13] on P5_4 */ + scu.VCO_SCLK = (P2_6); /* GPIO5[6] on P2_6 */ + scu.VCO_SDATA = (P6_4); /* GPIO3[3] on P6_4 */ + scu.VCO_LE = (P5_5); /* GPIO2[14] on P5_5 */ + scu.VCO_MUX = (PB_5); /* GPIO5[25] on PB_5 */ + scu.MIXER_EN = (P6_8); /* GPIO5[16] on P6_8 */ + scu.SYNT_RFOUT_EN = (P6_9); /* GPIO3[5] on P6_9 */ +#endif + break; + default: + break; + } /* RF LDO control */ + switch (board_id) { + case BOARD_ID_JAWBREAKER: #if defined(JAWBREAKER) - scu.RF_LDO_ENABLE = (P5_0); /* GPIO2[9] on P5_0 */ + scu.RF_LDO_ENABLE = (P5_0); /* GPIO2[9] on P5_0 */ #endif + break; + default: + break; + } /* RF supply (VAA) control */ -#if defined(PRALINE) - scu.NO_VAA_ENABLE = P8_1; /* GPIO4[1] on P8_1 */ -#elif defined(HACKRF_ONE) - scu.NO_VAA_ENABLE = P5_0; /* GPIO2[9] on P5_0 */ -#elif defined(RAD1O) - scu.VAA_ENABLE = P5_0; /* GPIO2[9] on P5_0 */ + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + scu.NO_VAA_ENABLE = P5_0; /* GPIO2[9] on P5_0 */ +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.NO_VAA_ENABLE = P8_1; /* GPIO4[1] on P8_1 */ +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu.VAA_ENABLE = P5_0; /* GPIO2[9] on P5_0 */ #endif + break; + default: + break; + } /* SPI flash */ scu.SSP0_CIPO = (P3_6); scu.SSP0_COPI = (P3_7); scu.SSP0_SCK = (P3_3); - scu.SSP0_CS = (P3_8); /* GPIO5[11] on P3_8 */ - scu.FLASH_HOLD = (P3_4); /* GPIO1[14] on P3_4 */ - scu.FLASH_WP = (P3_5); /* GPIO1[15] on P3_5 */ + scu.SSP0_CS = (P3_8); /* GPIO5[11] on P3_8 */ + scu.FLASH_HOLD = (P3_4); /* GPIO1[14] on P3_4 */ + scu.FLASH_WP = (P3_5); /* GPIO1[15] on P3_5 */ /* RF switch control */ -#if defined(PRALINE) - scu.TX_EN = P6_5; /* GPIO3[4] on P6_5 */ - scu.MIX_EN_N = P6_3; /* GPIO3[2] on P6_3 */ - scu.MIX_EN_N_R1_0 = P2_6; /* GPIO5[6] on P2_6 */ - scu.LPF_EN = PA_1; /* GPIO4[8] on PA_1 */ - scu.RF_AMP_EN = PA_2; /* GPIO4[9] on PA_2 */ - scu.ANT_BIAS_EN_N = P2_12; /* GPIO1[12] on P2_12 */ - scu.ANT_BIAS_OC_N = P2_11; /* GPIO1[11] on P2_11 */ -#elif defined(HACKRF_ONE) - scu.HP = P4_0; /* GPIO2[0] on P4_0 */ - scu.LP = P5_1; /* GPIO2[10] on P5_1 */ - scu.TX_MIX_BP = P5_2; /* GPIO2[11] on P5_2 */ - scu.NO_MIX_BYPASS = P1_7; /* GPIO1[0] on P1_7 */ - scu.RX_MIX_BP = P5_3; /* GPIO2[12] on P5_3 */ - scu.TX_AMP = P5_6; /* GPIO2[15] on P5_6 */ - scu.TX = P6_7; /* GPIO5[15] on P6_7 */ - scu.MIX_BYPASS = P6_8; /* GPIO5[16] on P6_8 */ - scu.RX = P2_5; /* GPIO5[5] on P2_5 */ - scu.NO_TX_AMP_PWR = P6_9; /* GPIO3[5] on P6_9 */ - scu.AMP_BYPASS = P2_10; /* GPIO0[14] on P2_10 */ - scu.RX_AMP = P2_11; /* GPIO1[11] on P2_11 */ - scu.NO_RX_AMP_PWR = P2_12; /* GPIO1[12] on P2_12 */ -#elif defined(RAD1O) - scu.BY_AMP = P1_7; /* GPIO1[0] on P1_7 */ - scu.BY_AMP_N = P2_5; /* GPIO5[5] on P2_5 */ - scu.TX_RX = P2_10; /* GPIO0[14] on P2_10 */ - scu.TX_RX_N = P2_11; /* GPIO1[11] on P2_11 */ - scu.BY_MIX = P2_12; /* GPIO1[12] on P2_12 */ - scu.BY_MIX_N = P5_1; /* GPIO2[10] on P5_1 */ - scu.LOW_HIGH_FILT = P5_2; /* GPIO2[11] on P5_2 */ - scu.LOW_HIGH_FILT_N = P5_3; /* GPIO2[12] on P5_3 */ - scu.TX_AMP = P5_6; /* GPIO2[15] on P5_6 */ - scu.RX_LNA = P6_7; /* GPIO5[15] on P6_7 */ + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + scu.HP = P4_0; /* GPIO2[0] on P4_0 */ + scu.LP = P5_1; /* GPIO2[10] on P5_1 */ + scu.TX_MIX_BP = P5_2; /* GPIO2[11] on P5_2 */ + scu.NO_MIX_BYPASS = P1_7; /* GPIO1[0] on P1_7 */ + scu.RX_MIX_BP = P5_3; /* GPIO2[12] on P5_3 */ + scu.TX_AMP = P5_6; /* GPIO2[15] on P5_6 */ + scu.TX = P6_7; /* GPIO5[15] on P6_7 */ + scu.MIX_BYPASS = P6_8; /* GPIO5[16] on P6_8 */ + scu.RX = P2_5; /* GPIO5[5] on P2_5 */ + scu.NO_TX_AMP_PWR = P6_9; /* GPIO3[5] on P6_9 */ + scu.AMP_BYPASS = P2_10; /* GPIO0[14] on P2_10 */ + scu.RX_AMP = P2_11; /* GPIO1[11] on P2_11 */ + scu.NO_RX_AMP_PWR = P2_12; /* GPIO1[12] on P2_12 */ #endif - - /* Praline */ -#if defined(PRALINE) - scu.P2_CTRL0 = (PE_3); /* GPIO7[3] on PE_3 */ - scu.P2_CTRL1 = (PE_4); /* GPIO7[4] on PE_4 */ - scu.P1_CTRL0 = (P2_10); /* GPIO0[14] on P2_10 */ - scu.P1_CTRL1 = (P6_8); /* GPIO5[16] on P6_8 */ - scu.P1_CTRL2 = (P6_9); /* GPIO3[5] on P6_9 */ - scu.CLKIN_CTRL = (P1_20); /* GPIO0[15] on P1_20 */ - scu.AA_EN = (P1_14); /* GPIO1[7] on P1_14 */ - scu.TRIGGER_IN = (PD_12); /* GPIO6[26] on PD_12 */ - scu.TRIGGER_OUT = (P2_6); /* GPIO5[6] on P2_6 */ - scu.PPS_OUT = (P2_5); /* GPIO5[5] on P2_5 */ - - scu.P2_CTRL0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.P2_CTRL1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.P1_CTRL0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.P1_CTRL1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.P1_CTRL2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.CLKIN_CTRL_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.AA_EN_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu.TRIGGER_IN_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.TRIGGER_OUT_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu.PPS_OUT_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + scu.BY_AMP = P1_7; /* GPIO1[0] on P1_7 */ + scu.BY_AMP_N = P2_5; /* GPIO5[5] on P2_5 */ + scu.TX_RX = P2_10; /* GPIO0[14] on P2_10 */ + scu.TX_RX_N = P2_11; /* GPIO1[11] on P2_11 */ + scu.BY_MIX = P2_12; /* GPIO1[12] on P2_12 */ + scu.BY_MIX_N = P5_1; /* GPIO2[10] on P5_1 */ + scu.LOW_HIGH_FILT = P5_2; /* GPIO2[11] on P5_2 */ + scu.LOW_HIGH_FILT_N = P5_3; /* GPIO2[12] on P5_3 */ + scu.TX_AMP = P5_6; /* GPIO2[15] on P5_6 */ + scu.RX_LNA = P6_7; /* GPIO5[15] on P6_7 */ +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + scu.TX_EN = P6_5; /* GPIO3[4] on P6_5 */ + scu.MIX_EN_N = P6_3; /* GPIO3[2] on P6_3 */ + scu.MIX_EN_N_R1_0 = P2_6; /* GPIO5[6] on P2_6 */ + scu.LPF_EN = PA_1; /* GPIO4[8] on PA_1 */ + scu.RF_AMP_EN = PA_2; /* GPIO4[9] on PA_2 */ + scu.ANT_BIAS_EN_N = P2_12; /* GPIO1[12] on P2_12 */ + scu.ANT_BIAS_OC_N = P2_11; /* GPIO1[11] on P2_11 */ #endif + break; + default: + break; + } - /* HackRF One r9 */ -#if defined(HACKRF_ONE) - scu.H1R9_CLKIN_EN = P6_7; /* GPIO5[15] on P6_7 */ - scu.H1R9_CLKOUT_EN = P1_2; /* GPIO0[9] on P1_2 = has boot pull-down; */ - scu.H1R9_MCU_CLK_EN = P1_1; /* GPIO0[8] on P1_1 = has boot pull-up; */ - scu.H1R9_RX = P2_7; /* GPIO0[7] on P4_4 = has boot pull-up; */ - scu.H1R9_NO_ANT_PWR = P4_4; /* GPIO2[4] on P4_4 */ - scu.H1R9_EN1V8 = P5_0; /* GPIO2[9] on P5_0 */ - scu.H1R9_NO_VAA_EN = P6_10; /* GPIO3[6] on P6_10 */ - scu.H1R9_TRIGGER_EN = P2_5; /* GPIO5[5] on P2_5 */ + /* Praline */ +#if defined(PRALINE) || defined(UNIVERSAL) + switch (board_id) { + case BOARD_ID_PRALINE: + scu.P2_CTRL0 = (PE_3); /* GPIO7[3] on PE_3 */ + scu.P2_CTRL1 = (PE_4); /* GPIO7[4] on PE_4 */ + scu.P1_CTRL0 = (P2_10); /* GPIO0[14] on P2_10 */ + scu.P1_CTRL1 = (P6_8); /* GPIO5[16] on P6_8 */ + scu.P1_CTRL2 = (P6_9); /* GPIO3[5] on P6_9 */ + scu.CLKIN_CTRL = (P1_20); /* GPIO0[15] on P1_20 */ + scu.AA_EN = (P1_14); /* GPIO1[7] on P1_14 */ + scu.TRIGGER_IN = (PD_12); /* GPIO6[26] on PD_12 */ + scu.TRIGGER_OUT = (P2_6); /* GPIO5[6] on P2_6 */ + scu.PPS_OUT = (P2_5); /* GPIO5[5] on P2_5 */ + + scu.P2_CTRL0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.P2_CTRL1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.P1_CTRL0_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.P1_CTRL1_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.P1_CTRL2_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.CLKIN_CTRL_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.AA_EN_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu.TRIGGER_IN_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.TRIGGER_OUT_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu.PPS_OUT_PINCFG = (SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + break; + default: + break; + } #endif /* Miscellaneous */ - scu.PINMUX_PP_D0 = (P7_0); /* GPIO3[8] */ - scu.PINMUX_PP_D1 = (P7_1); /* GPIO3[9] */ - scu.PINMUX_PP_D2 = (P7_2); /* GPIO3[10] */ - scu.PINMUX_PP_D3 = (P7_3); /* GPIO3[11] */ - scu.PINMUX_PP_D4 = (P7_4); /* GPIO3[12] */ - scu.PINMUX_PP_D5 = (P7_5); /* GPIO3[13] */ - scu.PINMUX_PP_D6 = (P7_6); /* GPIO3[14] */ - scu.PINMUX_PP_D7 = (P7_7); /* GPIO3[15] */ - + scu.PINMUX_PP_D0 = (P7_0); /* GPIO3[8] */ + scu.PINMUX_PP_D1 = (P7_1); /* GPIO3[9] */ + scu.PINMUX_PP_D2 = (P7_2); /* GPIO3[10] */ + scu.PINMUX_PP_D3 = (P7_3); /* GPIO3[11] */ + scu.PINMUX_PP_D4 = (P7_4); /* GPIO3[12] */ + scu.PINMUX_PP_D5 = (P7_5); /* GPIO3[13] */ + scu.PINMUX_PP_D6 = (P7_6); /* GPIO3[14] */ + scu.PINMUX_PP_D7 = (P7_7); /* GPIO3[15] */ /* TODO add other Pins */ - - scu.PINMUX_GPIO3_8 = (P7_0); /* GPIO3[8] */ - scu.PINMUX_GPIO3_9 = (P7_1); /* GPIO3[9] */ - scu.PINMUX_GPIO3_10 = (P7_2); /* GPIO3[10] */ - scu.PINMUX_GPIO3_11 = (P7_3); /* GPIO3[11] */ - scu.PINMUX_GPIO3_12 = (P7_4); /* GPIO3[12] */ - scu.PINMUX_GPIO3_13 = (P7_5); /* GPIO3[13] */ - scu.PINMUX_GPIO3_14 = (P7_6); /* GPIO3[14] */ - scu.PINMUX_GPIO3_15 = (P7_7); /* GPIO3[15] */ + scu.PINMUX_GPIO3_8 = (P7_0); /* GPIO3[8] */ + scu.PINMUX_GPIO3_9 = (P7_1); /* GPIO3[9] */ + scu.PINMUX_GPIO3_10 = (P7_2); /* GPIO3[10] */ + scu.PINMUX_GPIO3_11 = (P7_3); /* GPIO3[11] */ + scu.PINMUX_GPIO3_12 = (P7_4); /* GPIO3[12] */ + scu.PINMUX_GPIO3_13 = (P7_5); /* GPIO3[13] */ + scu.PINMUX_GPIO3_14 = (P7_6); /* GPIO3[14] */ + scu.PINMUX_GPIO3_15 = (P7_7); /* GPIO3[15] */ scu.PINMUX_PP_TDO = (P1_5); /* GPIO1[8] */ scu.PINMUX_SD_POW = (P1_5); /* GPIO1[8] */ @@ -357,15 +465,33 @@ const platform_scu_t* platform_scu(void) scu.PINMUX_SD_DAT3 = (P1_12); /* GPIO1[5] */ scu.PINMUX_SD_CD = (P1_13); /* GPIO1[6] */ - scu.PINMUX_PP_IO_STBX = (P2_0); /* GPIO5[0] */ - scu.PINMUX_PP_ADDR = (P2_1); /* GPIO5[1] */ - scu.PINMUX_U0_TXD = (P2_0); /* GPIO5[0] */ - scu.PINMUX_U0_RXD = (P2_1); /* GPIO5[1] */ + scu.PINMUX_PP_IO_STBX = (P2_0); /* GPIO5[0] */ + scu.PINMUX_PP_ADDR = (P2_1); /* GPIO5[1] */ + scu.PINMUX_U0_TXD = (P2_0); /* GPIO5[0] */ + scu.PINMUX_U0_RXD = (P2_1); /* GPIO5[1] */ - scu.PINMUX_ISP = (P2_7); /* GPIO0[7] */ + scu.PINMUX_ISP = (P2_7); /* GPIO0[7] */ scu.PINMUX_GP_CLKIN = (P4_7); + /* HackRF One r9 */ +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + switch (board_id) { + case BOARD_ID_HACKRF1_R9: + scu.H1R9_CLKIN_EN = P6_7; /* GPIO5[15] on P6_7 */ + scu.H1R9_CLKOUT_EN = P1_2; /* GPIO0[9] on P1_2 = has boot pull-down; */ + scu.H1R9_MCU_CLK_EN = P1_1; /* GPIO0[8] on P1_1 = has boot pull-up; */ + scu.H1R9_RX = P2_7; /* GPIO0[7] on P4_4 = has boot pull-up; */ + scu.H1R9_NO_ANT_PWR = P4_4; /* GPIO2[4] on P4_4 */ + scu.H1R9_EN1V8 = P5_0; /* GPIO2[9] on P5_0 */ + scu.H1R9_NO_VAA_EN = P6_10; /* GPIO3[6] on P6_10 */ + scu.H1R9_TRIGGER_EN = P2_5; /* GPIO5[5] on P2_5 */ + break; + default: + break; + } +#endif + _platform_scu = &scu; return _platform_scu; diff --git a/firmware/common/platform_scu.h b/firmware/common/platform_scu.h index 793eefa5f..e1126daeb 100644 --- a/firmware/common/platform_scu.h +++ b/firmware/common/platform_scu.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PLATFORM_SCU_H -#define __PLATFORM_SCU_H +#pragma once #ifdef __cplusplus extern "C" { @@ -35,18 +34,17 @@ extern "C" { */ typedef struct { - /* LED PinMux */ + /* GPIO Output PinMux */ scu_grp_pin_t PINMUX_LED1; scu_grp_pin_t PINMUX_LED2; scu_grp_pin_t PINMUX_LED3; -#if defined(RAD1O) || defined(PRALINE) +#if defined(RAD1O) || defined(PRALINE) || defined(UNIVERSAL) scu_grp_pin_t PINMUX_LED4; #endif - /* Power Supply PinMux */ scu_grp_pin_t PINMUX_EN1V8; scu_grp_pin_t PINMUX_EN1V2; -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) scu_grp_pin_t PINMUX_EN3V3_AUX_N; scu_grp_pin_t PINMUX_EN3V3_OC_N; #endif @@ -54,7 +52,7 @@ typedef struct { /* GPIO Input PinMux */ scu_grp_pin_t PINMUX_BOOT0; scu_grp_pin_t PINMUX_BOOT1; -#if !defined(HACKRF_ONE) +#if !defined(HACKRF_ONE) || defined(UNIVERSAL) scu_grp_pin_t PINMUX_BOOT2; scu_grp_pin_t PINMUX_BOOT3; #endif @@ -77,16 +75,15 @@ typedef struct { scu_grp_pin_t SSP1_CS; /* CPLD JTAG interface */ -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) scu_grp_pin_t PINMUX_FPGA_CRESET; scu_grp_pin_t PINMUX_FPGA_CDONE; scu_grp_pin_t PINMUX_FPGA_SPI_CS; -#else +#endif scu_grp_pin_t PINMUX_CPLD_TDO; + scu_grp_pin_t PINMUX_CPLD_TCK; scu_grp_pin_t PINMUX_CPLD_TMS; scu_grp_pin_t PINMUX_CPLD_TDI; -#endif - scu_grp_pin_t PINMUX_CPLD_TCK; /* CPLD SGPIO interface */ scu_grp_pin_t PINMUX_SGPIO0; @@ -142,36 +139,32 @@ typedef struct { scu_grp_pin_t AD_CS_PINCFG; /* RFFC5071 GPIO serial interface PinMux */ - scu_grp_pin_t MIXER_ENX; - scu_grp_pin_t MIXER_SCLK; - scu_grp_pin_t MIXER_SDATA; - scu_grp_pin_t MIXER_RESETX; - uint32_t MIXER_SCLK_PINCFG; - uint32_t MIXER_SDATA_PINCFG; -#if defined(PRALINE) - scu_grp_pin_t MIXER_LD; - uint32_t MIXER_LD_PINCFG; -#elif defined(RAD1O) - scu_grp_pin_t VCO_CE; - scu_grp_pin_t VCO_SCLK; - scu_grp_pin_t VCO_SDATA; - scu_grp_pin_t VCO_LE; - scu_grp_pin_t VCO_MUX; - scu_grp_pin_t MIXER_EN; - scu_grp_pin_t SYNT_RFOUT_EN; + scu_grp_pin_t MIXER_ENX; // JAWBREAKER, HACKRF_ONE, PRALINE + scu_grp_pin_t MIXER_SCLK; // JAWBREAKER, HACKRF_ONE, PRALINE + scu_grp_pin_t MIXER_SDATA; // JAWBREAKER, HACKRF_ONE, PRALINE + scu_grp_pin_t MIXER_RESETX; // JAWBREAKER, HACKRF_ONE, PRALINE + uint32_t MIXER_SCLK_PINCFG; // JAWBREAKER, HACKRF_ONE, PRALINE + uint32_t MIXER_SDATA_PINCFG; // JAWBREAKER, HACKRF_ONE, PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) + scu_grp_pin_t MIXER_LD; // PRALINE + uint32_t MIXER_LD_PINCFG; // PRALINE +#endif +#if defined(RAD1O) + scu_grp_pin_t VCO_CE; // RAD1O + scu_grp_pin_t VCO_SCLK; // RAD1O + scu_grp_pin_t VCO_SDATA; // RAD1O + scu_grp_pin_t VCO_LE; // RAD1O + scu_grp_pin_t VCO_MUX; // RAD1O + scu_grp_pin_t MIXER_EN; // RAD1O + scu_grp_pin_t SYNT_RFOUT_EN; // RAD1O #endif /* RF LDO control */ -#if defined(JAWBREAKER) - scu_grp_pin_t RF_LDO_ENABLE; -#endif + scu_grp_pin_t RF_LDO_ENABLE; // JAWBREAKER /* RF supply (VAA) control */ -#if defined(PRALINE) || defined(HACKRF_ONE) - scu_grp_pin_t NO_VAA_ENABLE; -#elif defined(RAD1O) - scu_grp_pin_t VAA_ENABLE; -#endif + scu_grp_pin_t NO_VAA_ENABLE; // HACKRF_ONE, PRALINE + scu_grp_pin_t VAA_ENABLE; // RAD1O /* SPI flash */ scu_grp_pin_t SSP0_CIPO; @@ -182,15 +175,7 @@ typedef struct { scu_grp_pin_t FLASH_WP; /* RF switch control */ -#if defined(PRALINE) - scu_grp_pin_t TX_EN; - scu_grp_pin_t MIX_EN_N; - scu_grp_pin_t MIX_EN_N_R1_0; - scu_grp_pin_t LPF_EN; - scu_grp_pin_t RF_AMP_EN; - scu_grp_pin_t ANT_BIAS_EN_N; - scu_grp_pin_t ANT_BIAS_OC_N; -#elif defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) scu_grp_pin_t HP; scu_grp_pin_t LP; scu_grp_pin_t TX_MIX_BP; @@ -204,7 +189,8 @@ typedef struct { scu_grp_pin_t AMP_BYPASS; scu_grp_pin_t RX_AMP; scu_grp_pin_t NO_RX_AMP_PWR; -#elif defined(RAD1O) +#endif +#if defined(RAD1O) scu_grp_pin_t BY_AMP; scu_grp_pin_t BY_AMP_N; scu_grp_pin_t TX_RX; @@ -216,9 +202,18 @@ typedef struct { scu_grp_pin_t TX_AMP; scu_grp_pin_t RX_LNA; #endif +#if defined(PRALINE) || defined(UNIVERSAL) + scu_grp_pin_t TX_EN; // PRALINE + scu_grp_pin_t MIX_EN_N; // PRALINE + scu_grp_pin_t MIX_EN_N_R1_0; // PRALINE + scu_grp_pin_t LPF_EN; // PRALINE + scu_grp_pin_t RF_AMP_EN; // PRALINE + scu_grp_pin_t ANT_BIAS_EN_N; // PRALINE + scu_grp_pin_t ANT_BIAS_OC_N; // PRALINE +#endif /* Praline */ -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) scu_grp_pin_t P2_CTRL0; scu_grp_pin_t P2_CTRL1; scu_grp_pin_t P1_CTRL0; @@ -242,18 +237,6 @@ typedef struct { scu_grp_pin_t PPS_OUT_PINCFG; #endif - /* HackRF One r9 */ -#if defined(HACKRF_ONE) - scu_grp_pin_t H1R9_CLKIN_EN; - scu_grp_pin_t H1R9_CLKOUT_EN; - scu_grp_pin_t H1R9_MCU_CLK_EN; - scu_grp_pin_t H1R9_RX; - scu_grp_pin_t H1R9_NO_ANT_PWR; - scu_grp_pin_t H1R9_EN1V8; - scu_grp_pin_t H1R9_NO_VAA_EN; - scu_grp_pin_t H1R9_TRIGGER_EN; -#endif - /* Miscellaneous */ scu_grp_pin_t PINMUX_PP_D0; scu_grp_pin_t PINMUX_PP_D1; @@ -263,9 +246,7 @@ typedef struct { scu_grp_pin_t PINMUX_PP_D5; scu_grp_pin_t PINMUX_PP_D6; scu_grp_pin_t PINMUX_PP_D7; - /* TODO add other Pins */ - scu_grp_pin_t PINMUX_GPIO3_8; scu_grp_pin_t PINMUX_GPIO3_9; scu_grp_pin_t PINMUX_GPIO3_10; @@ -294,12 +275,24 @@ typedef struct { scu_grp_pin_t PINMUX_ISP; scu_grp_pin_t PINMUX_GP_CLKIN; + + /* HackRF One r9 */ +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + scu_grp_pin_t H1R9_CLKIN_EN; + scu_grp_pin_t H1R9_CLKOUT_EN; + scu_grp_pin_t H1R9_MCU_CLK_EN; + scu_grp_pin_t H1R9_RX; + scu_grp_pin_t H1R9_NO_ANT_PWR; + scu_grp_pin_t H1R9_EN1V8; + scu_grp_pin_t H1R9_NO_VAA_EN; + scu_grp_pin_t H1R9_TRIGGER_EN; +#endif } platform_scu_t; // Detects and returns the global platform scu instance of the active board id and revision. const platform_scu_t* platform_scu(void); -// Platform detection needs these for error indication. +// Platform_detect needs these for error indication #define SCU_PINMUX_LED1 (P4_1) /* GPIO2[1] on P4_1 */ #define SCU_PINMUX_LED2 (P4_2) /* GPIO2[2] on P4_2 */ #define SCU_PINMUX_LED3 (P6_12) /* GPIO2[8] on P6_12 */ @@ -307,5 +300,3 @@ const platform_scu_t* platform_scu(void); #ifdef __cplusplus } #endif - -#endif /* __PLATFORM_SCU_H */ diff --git a/firmware/common/portapack.c b/firmware/common/portapack.c index fefa2f11f..455df8712 100644 --- a/firmware/common/portapack.c +++ b/firmware/common/portapack.c @@ -38,7 +38,7 @@ static void portapack_sleep_milliseconds(const uint32_t milliseconds) delay(milliseconds * 40800); } -typedef struct portapack_if_t { +typedef struct { gpio_t gpio_dir; gpio_t gpio_lcd_rdx; gpio_t gpio_lcd_wrx; diff --git a/firmware/common/portapack.h b/firmware/common/portapack.h index d4dda66e2..fdc369b8e 100644 --- a/firmware/common/portapack.h +++ b/firmware/common/portapack.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __PORTAPACK_H__ -#define __PORTAPACK_H__ +#pragma once #include #include @@ -29,31 +28,31 @@ #define ARRAY_SIZEOF(x) (sizeof(x) / sizeof(x[0])) -typedef struct ui_color_t { +typedef struct { uint16_t v; } ui_color_t; -typedef struct ui_point_t { +typedef struct { int16_t x; int16_t y; } ui_point_t; -typedef struct ui_size_t { +typedef struct { int16_t width; int16_t height; } ui_size_t; -typedef struct ui_rect_t { +typedef struct { ui_point_t point; ui_size_t size; } ui_rect_t; -typedef struct ui_bitmap_t { +typedef struct { ui_size_t size; const uint8_t* const data; } ui_bitmap_t; -typedef struct ui_font_t { +typedef struct { const ui_size_t glyph_size; const uint8_t* const data; char c_start; @@ -61,7 +60,7 @@ typedef struct ui_font_t { size_t data_stride; } ui_font_t; -typedef struct portapack_t { +typedef struct { } portapack_t; void portapack_init(void); @@ -85,5 +84,3 @@ void portapack_draw_bitmap( const ui_color_t background); ui_bitmap_t portapack_font_glyph(const ui_font_t* const font, const char c); - -#endif /*__PORTAPACK_H__*/ diff --git a/firmware/common/rad1o/decoder.h b/firmware/common/rad1o/decoder.h index 5f1bcda40..5575ef939 100644 --- a/firmware/common/rad1o/decoder.h +++ b/firmware/common/rad1o/decoder.h @@ -1,8 +1,5 @@ -#ifndef __RAD1O_DECODER_H__ -#define __RAD1O_DECODER_H__ +#pragma once #include uint8_t* rad1o_pk_decode(const uint8_t* data, int* len); - -#endif diff --git a/firmware/common/rad1o/display.h b/firmware/common/rad1o/display.h index 63711dfc5..af5da5e13 100644 --- a/firmware/common/rad1o/display.h +++ b/firmware/common/rad1o/display.h @@ -1,5 +1,4 @@ -#ifndef __RAD1O_DISPLAY_H__ -#define __RAD1O_DISPLAY_H__ +#pragma once #include @@ -27,5 +26,3 @@ void rad1o_lcdFill(uint8_t f); void rad1o_lcdDisplay(void); void rad1o_lcdSetPixel(uint8_t x, uint8_t y, uint8_t f); uint8_t* rad1o_lcdGetBuffer(void); - -#endif diff --git a/firmware/common/rad1o/draw.h b/firmware/common/rad1o/draw.h index c8f6708b7..dfdaaf689 100644 --- a/firmware/common/rad1o/draw.h +++ b/firmware/common/rad1o/draw.h @@ -1,9 +1,6 @@ -#ifndef __RAD1O_DRAW_H__ -#define __RAD1O_DRAW_H__ +#pragma once #include void rad1o_drawHLine(uint8_t y, uint8_t x1, uint8_t x2, uint8_t color); void rad1o_drawVLine(uint8_t x, uint8_t y1, uint8_t y2, uint8_t color); - -#endif diff --git a/firmware/common/rad1o/fonts.h b/firmware/common/rad1o/fonts.h index 98e0a7ace..bd1ce0b5f 100644 --- a/firmware/common/rad1o/fonts.h +++ b/firmware/common/rad1o/fonts.h @@ -1,5 +1,4 @@ -#ifndef __RAD1O_FONTS_H__ -#define __RAD1O_FONTS_H__ +#pragma once #include @@ -31,5 +30,3 @@ typedef const struct FONT_DEF* FONT; #define FONT_DEFAULT 0 #define FONT_INTERNAL 1 #define FONT_EXTERNAL 2 - -#endif diff --git a/firmware/common/rad1o/print.h b/firmware/common/rad1o/print.h index 19ef16312..8981da250 100644 --- a/firmware/common/rad1o/print.h +++ b/firmware/common/rad1o/print.h @@ -1,5 +1,4 @@ -#ifndef __RAD1O_PRINT_H__ -#define __RAD1O_PRINT_H__ +#pragma once #include @@ -9,5 +8,3 @@ void rad1o_lcdClear(void); void rad1o_lcdMoveCrsr(int32_t dx, int32_t dy); void rad1o_lcdSetCrsr(int32_t dx, int32_t dy); void rad1o_setSystemFont(void); - -#endif diff --git a/firmware/common/rad1o/render.h b/firmware/common/rad1o/render.h index 1c6233814..535ee471e 100644 --- a/firmware/common/rad1o/render.h +++ b/firmware/common/rad1o/render.h @@ -1,5 +1,4 @@ -#ifndef __RENDER_H_ -#define __RENDER_H_ +#pragma once #include @@ -10,4 +9,3 @@ void rad1o_setIntFont(const struct FONT_DEF* font); int rad1o_getFontHeight(void); int rad1o_DoString(int sx, int sy, const char* s); int rad1o_DoChar(int sx, int sy, int c); -#endif diff --git a/firmware/common/rad1o/smallfonts.h b/firmware/common/rad1o/smallfonts.h index af69bf27b..3204e62a1 100644 --- a/firmware/common/rad1o/smallfonts.h +++ b/firmware/common/rad1o/smallfonts.h @@ -35,12 +35,10 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ /**************************************************************************/ -#ifndef __RAD1O_SMALLFONTS_H__ -#define __RAD1O_SMALLFONTS_H__ + +#pragma once /* Partially based on original code for the KS0108 by Stephane Rey */ /* Current version by Kevin Townsend */ extern const struct FONT_DEF Font_7x8; - -#endif diff --git a/firmware/common/rad1o/ubuntu18.h b/firmware/common/rad1o/ubuntu18.h index 38b58e761..b8d28b071 100644 --- a/firmware/common/rad1o/ubuntu18.h +++ b/firmware/common/rad1o/ubuntu18.h @@ -1,6 +1,3 @@ -#ifndef __RAD1O_UBUNTU18_H__ -#define __RAD1O_UBUNTU18_H__ +#pragma once extern const struct FONT_DEF Font_Ubuntu18pt; - -#endif diff --git a/firmware/common/radio.c b/firmware/common/radio.c index c714d5e7f..f45028c8d 100644 --- a/firmware/common/radio.c +++ b/firmware/common/radio.c @@ -22,7 +22,6 @@ #include #include -#include #include "fixed_point.h" #include "hackrf_core.h" @@ -32,7 +31,7 @@ #include "radio.h" #include "rf_path.h" #include "tuning.h" -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "fpga.h" #include "tune_config.h" #endif @@ -197,18 +196,22 @@ static bool radio_update_sample_rate(radio_t* const radio, uint64_t* bank) case TRANSCEIVER_MODE_SS: n = compute_resample_log(rate / FP_ONE_HZ, requested_n); if (n != radio->config[RADIO_BANK_APPLIED][RADIO_RESAMPLE_TX]) { -#ifdef PRALINE - fpga_set_tx_interpolation_ratio(&fpga, n); + if (detected_platform() == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_set_tx_interpolation_ratio(&fpga, n); #endif + } radio->config[RADIO_BANK_APPLIED][RADIO_RESAMPLE_TX] = n; } break; default: n = compute_resample_log(rate / FP_ONE_HZ, requested_n); if (n != radio->config[RADIO_BANK_APPLIED][RADIO_RESAMPLE_RX]) { -#ifdef PRALINE - fpga_set_rx_decimation_ratio(&fpga, n); + if (detected_platform() == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_set_rx_decimation_ratio(&fpga, n); #endif + } radio->config[RADIO_BANK_APPLIED][RADIO_RESAMPLE_RX] = n; } } @@ -243,7 +246,7 @@ static bool radio_update_sample_rate(radio_t* const radio, uint64_t* bank) static fp_40_24_t applied_offset = RADIO_UNSET; -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) static const tune_config_t* select_tune_config(uint64_t opmode) { switch (opmode) { @@ -294,15 +297,20 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank) radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_RF] = RADIO_UNSET; } -#ifdef PRALINE - const uint64_t requested_rotation = bank[RADIO_ROTATION]; - if (requested_rotation != RADIO_UNSET) { - rotation = requested_rotation; - } else if (radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] != RADIO_UNSET) { - return true; - } - fpga_set_rx_quarter_shift_mode(&fpga, rotation >> 6); + if (detected_platform() == BOARD_ID_PRALINE) { + const uint64_t requested_rotation = bank[RADIO_ROTATION]; + if (requested_rotation != RADIO_UNSET) { + rotation = requested_rotation; + } else if ( + radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] != + RADIO_UNSET) { + return true; + } +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_set_rx_quarter_shift_mode(&fpga, rotation >> 6); #endif + } + radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] = rotation; return true; } @@ -319,44 +327,50 @@ static bool radio_update_frequency(radio_t* const radio, uint64_t* bank) bool new_rf = (radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_RF] != requested_rf); uint64_t requested_rf_hz = requested_rf / FP_ONE_HZ; -#ifdef PRALINE - if (applied_afe_rate == RADIO_UNSET) { - return false; - } - uint64_t opmode = bank[RADIO_OPMODE]; - if (opmode == RADIO_UNSET) { - opmode = radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE]; - } - const tune_config_t* tune_config = select_tune_config(opmode); - const tune_config_t* applied_tune_config = - select_tune_config(radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE]); - bool new_config = (applied_tune_config != tune_config); - while ((tune_config->rf_range_end_mhz != 0) || (tune_config->if_mhz != 0)) { - if ((requested_rf_hz == 0) || - (tune_config->rf_range_end_mhz > (requested_rf_hz / FREQ_ONE_MHZ))) { - break; - } - tune_config++; - } - bool new_rotation = - (radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] != - ((uint64_t) tune_config->shift << 6)); - if (new_rotation) { - fpga_set_rx_quarter_shift_mode(&fpga, tune_config->shift); - radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] = - tune_config->shift << 6; - } - fp_40_24_t offset = applied_afe_rate / 4; - bool new_offset = (applied_offset != offset); - if (new_rotation || new_offset || new_config || new_rf) { - tuning_set_frequency(tune_config, requested_rf_hz, offset / FP_ONE_HZ); - applied_offset = offset; - } -#else - if (new_rf) { - set_freq(requested_rf_hz); - } + if (detected_platform() == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + if (applied_afe_rate == RADIO_UNSET) { + return false; + } + uint64_t opmode = bank[RADIO_OPMODE]; + if (opmode == RADIO_UNSET) { + opmode = radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE]; + } + const tune_config_t* tune_config = select_tune_config(opmode); + const tune_config_t* applied_tune_config = select_tune_config( + radio->config[RADIO_BANK_APPLIED][RADIO_OPMODE]); + bool new_config = (applied_tune_config != tune_config); + while ((tune_config->rf_range_end_mhz != 0) || + (tune_config->if_mhz != 0)) { + if ((requested_rf_hz == 0) || + (tune_config->rf_range_end_mhz > + (requested_rf_hz / FREQ_ONE_MHZ))) { + break; + } + tune_config++; + } + bool new_rotation = + (radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] != + ((uint64_t) tune_config->shift << 6)); + if (new_rotation) { + fpga_set_rx_quarter_shift_mode(&fpga, tune_config->shift); + radio->config[RADIO_BANK_APPLIED][RADIO_ROTATION] = + tune_config->shift << 6; + } + uint64_t offset = applied_afe_rate / 4; + bool new_offset = (applied_offset != offset); + if (new_rotation || new_offset || new_config || new_rf) { + tuning_set_frequency(tune_config, requested_rf_hz, offset >> 24); + applied_offset = offset; + } #endif + } else { + if (new_rf) { +#if !defined(PRALINE) || defined(UNIVERSAL) + set_freq(requested_rf_hz); +#endif + } + } radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_RF] = requested_rf; radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_IF] = RADIO_UNSET; radio->config[RADIO_BANK_APPLIED][RADIO_FREQUENCY_LO] = RADIO_UNSET; @@ -393,68 +407,93 @@ static bool radio_update_bandwidth(radio_t* const radio, uint64_t* bank) { bool new_bw = false; -#ifdef PRALINE - /* Praline legacy mode always sets baseband bandwidth automatically. */ - (void) bank; - uint32_t lpf_bandwidth = auto_bandwidth(radio); - - if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) { - max283x_set_lpf_bandwidth(&max283x, MAX283x_MODE_TX, lpf_bandwidth); - radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = lpf_bandwidth; - new_bw = true; - } - if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] != lpf_bandwidth) { - max283x_set_lpf_bandwidth(&max283x, MAX283x_MODE_RX, lpf_bandwidth); - radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = lpf_bandwidth; - new_bw = true; - } - bool narrow_lpf_enable = false; - bool applied_narrow_lpf_enable = - radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF]; - if (lpf_bandwidth <= 1750000) { - narrow_lpf_enable = true; - } - if (applied_narrow_lpf_enable != narrow_lpf_enable) { - narrowband_filter_set(narrow_lpf_enable); - radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF] = - narrow_lpf_enable; - new_bw = true; - } - /* Always set HPF bandwidth to 30 kHz for now. */ - const max283x_rx_hpf_freq_t hpf_bandwidth = MAX283x_RX_HPF_30_KHZ; - if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] != hpf_bandwidth) { - max283x_set_rx_hpf_frequency(&max283x, hpf_bandwidth); - radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] = hpf_bandwidth; - new_bw = true; - } -#else - uint64_t lpf_bandwidth; - lpf_bandwidth = bank[RADIO_XCVR_TX_LPF]; - if (lpf_bandwidth == RADIO_UNSET) { - lpf_bandwidth = bank[RADIO_XCVR_RX_LPF]; - } - if (lpf_bandwidth == RADIO_UNSET) { - lpf_bandwidth = bank[RADIO_BB_BANDWIDTH_TX]; - } - if (lpf_bandwidth == RADIO_UNSET) { - lpf_bandwidth = bank[RADIO_BB_BANDWIDTH_RX]; - } - if (lpf_bandwidth == RADIO_UNSET) { - lpf_bandwidth = radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF]; - } - if (lpf_bandwidth == RADIO_UNSET) { - lpf_bandwidth = auto_bandwidth(radio); - } - - if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != lpf_bandwidth) { - max283x_set_lpf_bandwidth(&max283x, MAX283x_MODE_TX, lpf_bandwidth); - radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_RX] = lpf_bandwidth; - radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_TX] = lpf_bandwidth; - radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = lpf_bandwidth; - radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = lpf_bandwidth; - new_bw = true; - } + if (detected_platform() == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + /* Praline legacy mode always sets baseband bandwidth automatically. */ + (void) bank; + uint32_t lpf_bandwidth = auto_bandwidth(radio); + + if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != + lpf_bandwidth) { + max283x_set_lpf_bandwidth( + &max283x, + MAX283x_MODE_TX, + lpf_bandwidth); + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = + lpf_bandwidth; + new_bw = true; + } + if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] != + lpf_bandwidth) { + max283x_set_lpf_bandwidth( + &max283x, + MAX283x_MODE_RX, + lpf_bandwidth); + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = + lpf_bandwidth; + new_bw = true; + } + bool narrow_lpf_enable = false; + bool applied_narrow_lpf_enable = + radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF]; + if (lpf_bandwidth <= 1750000) { + narrow_lpf_enable = true; + } + if (applied_narrow_lpf_enable != narrow_lpf_enable) { + narrowband_filter_set(narrow_lpf_enable); + radio->config[RADIO_BANK_APPLIED][RADIO_RX_NARROW_LPF] = + narrow_lpf_enable; + new_bw = true; + } + /* Always set HPF bandwidth to 30 kHz for now. */ + const max283x_rx_hpf_freq_t hpf_bandwidth = MAX283x_RX_HPF_30_KHZ; + if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] != + hpf_bandwidth) { + max283x_set_rx_hpf_frequency(&max283x, hpf_bandwidth); + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_HPF] = + hpf_bandwidth; + new_bw = true; + } #endif + } else { +#if !defined(PRALINE) || defined(UNIVERSAL) + uint64_t lpf_bandwidth; + lpf_bandwidth = bank[RADIO_XCVR_TX_LPF]; + if (lpf_bandwidth == RADIO_UNSET) { + lpf_bandwidth = bank[RADIO_XCVR_RX_LPF]; + } + if (lpf_bandwidth == RADIO_UNSET) { + lpf_bandwidth = bank[RADIO_BB_BANDWIDTH_TX]; + } + if (lpf_bandwidth == RADIO_UNSET) { + lpf_bandwidth = bank[RADIO_BB_BANDWIDTH_RX]; + } + if (lpf_bandwidth == RADIO_UNSET) { + lpf_bandwidth = + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF]; + } + if (lpf_bandwidth == RADIO_UNSET) { + lpf_bandwidth = auto_bandwidth(radio); + } + + if (radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] != + lpf_bandwidth) { + max283x_set_lpf_bandwidth( + &max283x, + MAX283x_MODE_TX, + lpf_bandwidth); + radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_RX] = + lpf_bandwidth; + radio->config[RADIO_BANK_APPLIED][RADIO_BB_BANDWIDTH_TX] = + lpf_bandwidth; + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_TX_LPF] = + lpf_bandwidth; + radio->config[RADIO_BANK_APPLIED][RADIO_XCVR_RX_LPF] = + lpf_bandwidth; + new_bw = true; + } +#endif + } return new_bw; } @@ -590,26 +629,33 @@ static bool radio_update_trigger(radio_t* const radio, uint64_t* bank) static bool radio_update_dc_block(radio_t* const radio, uint64_t* bank) { -#ifndef PRALINE +#if !defined(PRALINE) && !defined(UNIVERSAL) (void) radio; (void) bank; return false; -#else - const uint64_t requested = bank[RADIO_DC_BLOCK]; - bool enable = requested; +#endif - if (requested == RADIO_UNSET) { - enable = true; - } + if (detected_platform() == BOARD_ID_PRALINE) { + const uint64_t requested = bank[RADIO_DC_BLOCK]; + bool enable = requested; - if (radio->config[RADIO_BANK_APPLIED][RADIO_DC_BLOCK] == (uint64_t) enable) { - return false; - } + if (requested == RADIO_UNSET) { + enable = true; + } - fpga_set_rx_dc_block_enable(&fpga, enable); - radio->config[RADIO_BANK_APPLIED][RADIO_DC_BLOCK] = enable; - return true; + if (radio->config[RADIO_BANK_APPLIED][RADIO_DC_BLOCK] == + (uint64_t) enable) { + return false; + } + +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_set_rx_dc_block_enable(&fpga, enable); #endif + radio->config[RADIO_BANK_APPLIED][RADIO_DC_BLOCK] = enable; + return true; + } else { + return false; + } } bool radio_update(radio_t* const radio) diff --git a/firmware/common/radio.h b/firmware/common/radio.h index 7b526a9d5..0c171d470 100644 --- a/firmware/common/radio.h +++ b/firmware/common/radio.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __RF_CONFIG_H__ -#define __RF_CONFIG_H__ +#pragma once #include #include @@ -216,7 +215,7 @@ typedef enum { */ typedef fp_40_24_t (*sample_rate_fn)(const fp_40_24_t sample_rate, const bool program); -typedef struct radio_t { +typedef struct { radio_config_mode_t config_mode; uint64_t config[RADIO_NUM_BANKS][RADIO_NUM_REGS]; volatile uint32_t regs_dirty; @@ -254,5 +253,3 @@ bool radio_update(radio_t* const radio); * the request bank for the new mode. */ void radio_switch_opmode(radio_t* const radio, const transceiver_mode_t mode); - -#endif /*__RF_CONFIG_H__*/ diff --git a/firmware/common/rf_path.c b/firmware/common/rf_path.c index 30c8c7183..d9efb8b2f 100644 --- a/firmware/common/rf_path.c +++ b/firmware/common/rf_path.c @@ -23,7 +23,7 @@ #include "rf_path.h" -#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) || defined(UNIVERSAL) #include #endif @@ -34,7 +34,8 @@ #include "mixer.h" #include "platform_detect.h" #include "sgpio.h" -#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) || defined(UNIVERSAL) + #include "gpio.h" #include "platform_scu.h" #endif @@ -94,17 +95,18 @@ #define SWITCHCTRL_ANT_PWR (1 << 6) /* turn on antenna port power */ -#ifdef HACKRF_ONE - +#if defined(HACKRF_ONE) || defined(UNIVERSAL) static void switchctrl_set_hackrf_one(rf_path_t* const rf_path, uint8_t ctrl) { + board_id_t board_id = detected_platform(); + if (ctrl & SWITCHCTRL_TX) { - if (detected_platform() != BOARD_ID_HACKRF1_R9) { + if (board_id != BOARD_ID_HACKRF1_R9) { gpio_set(rf_path->gpio_tx); } gpio_clear(rf_path->gpio_rx); } else { - if (detected_platform() != BOARD_ID_HACKRF1_R9) { + if (board_id != BOARD_ID_HACKRF1_R9) { gpio_clear(rf_path->gpio_tx); } gpio_set(rf_path->gpio_rx); @@ -167,7 +169,7 @@ static void switchctrl_set_hackrf_one(rf_path_t* const rf_path, uint8_t ctrl) gpio_set(rf_path->gpio_no_rx_amp_pwr); } - if (detected_platform() == BOARD_ID_HACKRF1_R9) { + if (board_id == BOARD_ID_HACKRF1_R9) { if (ctrl & SWITCHCTRL_ANT_PWR) { gpio_clear(rf_path->gpio_h1r9_no_ant_pwr); } else { @@ -187,7 +189,7 @@ static void switchctrl_set_hackrf_one(rf_path_t* const rf_path, uint8_t ctrl) } #endif -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) static void switchctrl_set_praline(rf_path_t* const rf_path, uint8_t ctrl) { if (ctrl & SWITCHCTRL_TX) { @@ -228,7 +230,7 @@ static void switchctrl_set_praline(rf_path_t* const rf_path, uint8_t ctrl) } #endif -#ifdef RAD1O +#if defined(RAD1O) static void switchctrl_set_rad1o(rf_path_t* const rf_path, uint8_t ctrl) { if (ctrl & SWITCHCTRL_TX) { @@ -295,167 +297,224 @@ static void switchctrl_set_rad1o(rf_path_t* const rf_path, uint8_t ctrl) static void switchctrl_set(rf_path_t* const rf_path, const uint8_t gpo) { -#ifdef JAWBREAKER - (void) rf_path; /* silence unused param warning */ - mixer_set_gpo(&mixer, gpo); -#elif HACKRF_ONE - switchctrl_set_hackrf_one(rf_path, gpo); -#elif PRALINE - switchctrl_set_praline(rf_path, gpo); -#elif RAD1O - switchctrl_set_rad1o(rf_path, gpo); -#else - (void) gpo; +#if defined(JAWBREAKER) + (void) rf_path; +#endif + + switch (detected_platform()) { + case BOARD_ID_JAWBREAKER: +#if defined(JAWBREAKER) + mixer_set_gpo(&mixer, gpo); +#endif + break; + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + switchctrl_set_hackrf_one(rf_path, gpo); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + switchctrl_set_praline(rf_path, gpo); #endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + switchctrl_set_rad1o(rf_path, gpo); +#endif + break; + default: + break; + } } void rf_path_pin_setup(rf_path_t* const rf_path) { +#if defined(JAWBREAKER) + (void) rf_path; +#endif + + board_id_t board_id = detected_platform(); #if !defined(JAWBREAKER) const platform_scu_t* scu = platform_scu(); #endif -#ifdef HACKRF_ONE - /* Configure RF switch control signals */ - // clang-format off - scu_pinmux(scu->HP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->LP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->TX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->NO_MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->RX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu_pinmux(scu->NO_TX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->AMP_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->RX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->NO_RX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - // clang-format on - if (detected_platform() == BOARD_ID_HACKRF1_R9) { - scu_pinmux(scu->H1R9_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->H1R9_NO_ANT_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - gpio_clear(rf_path->gpio_h1r9_no_ant_pwr); - gpio_output(rf_path->gpio_h1r9_no_ant_pwr); - scu_pinmux(scu->H1R9_NO_VAA_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - } else { - scu_pinmux(scu->TX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu_pinmux(scu->RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - gpio_output(rf_path->gpio_tx); - scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - } - - /* - * Safe (initial) switch settings turn off both amplifiers and antenna port - * power and enable both amp bypass and mixer bypass. - */ - switchctrl_set(rf_path, SWITCHCTRL_SAFE); - - /* Configure RF switch control signals as outputs */ - gpio_output(rf_path->gpio_amp_bypass); - gpio_output(rf_path->gpio_no_mix_bypass); - gpio_output(rf_path->gpio_rx_amp); - gpio_output(rf_path->gpio_no_rx_amp_pwr); - gpio_output(rf_path->gpio_hp); - gpio_output(rf_path->gpio_lp); - gpio_output(rf_path->gpio_tx_mix_bp); - gpio_output(rf_path->gpio_rx_mix_bp); - gpio_output(rf_path->gpio_tx_amp); - gpio_output(rf_path->gpio_no_tx_amp_pwr); - gpio_output(rf_path->gpio_mix_bypass); - gpio_output(rf_path->gpio_rx); -#elif RAD1O - /* Configure RF switch control signals */ - // clang-format off - scu_pinmux(scu->BY_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->BY_AMP_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu_pinmux(scu->TX_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->TX_RX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->BY_MIX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->BY_MIX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->LOW_HIGH_FILT, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->LOW_HIGH_FILT_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->RX_LNA, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - scu_pinmux(scu->MIXER_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - // clang-format on - - /* Configure RF power supply (VAA) switch */ - scu_pinmux(scu->VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + /* Configure RF switch control signals */ + // clang-format off + scu_pinmux(scu->HP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->LP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->TX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->NO_MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->RX_MIX_BP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->MIX_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu_pinmux(scu->NO_TX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->AMP_BYPASS, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->RX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->NO_RX_AMP_PWR, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + // clang-format on + if (board_id == BOARD_ID_HACKRF1_R9) { + scu_pinmux(scu->H1R9_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux( + scu->H1R9_NO_ANT_PWR, + SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + gpio_clear(rf_path->gpio_h1r9_no_ant_pwr); + gpio_output(rf_path->gpio_h1r9_no_ant_pwr); + scu_pinmux( + scu->H1R9_NO_VAA_EN, + SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + } else { + scu_pinmux(scu->TX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu_pinmux(scu->RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + gpio_output(rf_path->gpio_tx); + scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + } - /* - * Safe (initial) switch settings turn off both amplifiers and antenna port - * power and enable both amp bypass and mixer bypass. - */ - switchctrl_set(rf_path, SWITCHCTRL_SAFE); - - /* Configure RF switch control signals as outputs */ - gpio_output(rf_path->gpio_tx_rx_n); - gpio_output(rf_path->gpio_tx_rx); - gpio_output(rf_path->gpio_by_mix); - gpio_output(rf_path->gpio_by_mix_n); - gpio_output(rf_path->gpio_by_amp); - gpio_output(rf_path->gpio_by_amp_n); - gpio_output(rf_path->gpio_mixer_en); - gpio_output(rf_path->gpio_low_high_filt); - gpio_output(rf_path->gpio_low_high_filt_n); - gpio_output(rf_path->gpio_tx_amp); - gpio_output(rf_path->gpio_rx_lna); -#elif PRALINE - /* Configure RF switch control signals */ - scu_pinmux(scu->TX_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - board_rev_t rev = detected_revision(); - if ((rev == BOARD_REV_PRALINE_R1_0) || (rev == BOARD_REV_GSG_PRALINE_R1_0)) { - scu_pinmux(scu->MIX_EN_N_R1_0, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); - } else { - scu_pinmux(scu->MIX_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - } - scu_pinmux(scu->LPF_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - scu_pinmux(scu->RF_AMP_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + /* + * Safe (initial) switch settings turn off both amplifiers and antenna port + * power and enable both amp bypass and mixer bypass. + */ + switchctrl_set(rf_path, SWITCHCTRL_SAFE); + + /* Configure RF switch control signals as outputs */ + gpio_output(rf_path->gpio_amp_bypass); + gpio_output(rf_path->gpio_no_mix_bypass); + gpio_output(rf_path->gpio_rx_amp); + gpio_output(rf_path->gpio_no_rx_amp_pwr); + gpio_output(rf_path->gpio_hp); + gpio_output(rf_path->gpio_lp); + gpio_output(rf_path->gpio_tx_mix_bp); + gpio_output(rf_path->gpio_rx_mix_bp); + gpio_output(rf_path->gpio_tx_amp); + gpio_output(rf_path->gpio_no_tx_amp_pwr); + gpio_output(rf_path->gpio_mix_bypass); + gpio_output(rf_path->gpio_rx); +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + /* Configure RF switch control signals */ + // clang-format off + scu_pinmux(scu->BY_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->BY_AMP_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu_pinmux(scu->TX_RX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->TX_RX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->BY_MIX, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->BY_MIX_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->LOW_HIGH_FILT, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->LOW_HIGH_FILT_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->TX_AMP, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->RX_LNA, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + scu_pinmux(scu->MIXER_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + // clang-format on + + /* Configure RF power supply (VAA) switch */ + scu_pinmux(scu->VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + + /* + * Safe (initial) switch settings turn off both amplifiers and antenna port + * power and enable both amp bypass and mixer bypass. + */ + switchctrl_set(rf_path, SWITCHCTRL_SAFE); + + /* Configure RF switch control signals as outputs */ + gpio_output(rf_path->gpio_tx_rx_n); + gpio_output(rf_path->gpio_tx_rx); + gpio_output(rf_path->gpio_by_mix); + gpio_output(rf_path->gpio_by_mix_n); + gpio_output(rf_path->gpio_by_amp); + gpio_output(rf_path->gpio_by_amp_n); + gpio_output(rf_path->gpio_mixer_en); + gpio_output(rf_path->gpio_low_high_filt); + gpio_output(rf_path->gpio_low_high_filt_n); + gpio_output(rf_path->gpio_tx_amp); + gpio_output(rf_path->gpio_rx_lna); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + /* Configure RF switch control signals */ + scu_pinmux(scu->TX_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + board_rev_t rev = detected_revision(); + if ((rev == BOARD_REV_PRALINE_R1_0) || + (rev == BOARD_REV_GSG_PRALINE_R1_0)) { + scu_pinmux(scu->MIX_EN_N_R1_0, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); + } else { + scu_pinmux(scu->MIX_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + } + scu_pinmux(scu->LPF_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + scu_pinmux(scu->RF_AMP_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - /* Configure antenna port power control signal */ - scu_pinmux(scu->ANT_BIAS_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + /* Configure antenna port power control signal */ + scu_pinmux(scu->ANT_BIAS_EN_N, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - /* Configure RF power supply (VAA) switch */ - scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); + /* Configure RF power supply (VAA) switch */ + scu_pinmux(scu->NO_VAA_ENABLE, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); - /* - * Safe (initial) switch settings turn off both amplifiers and antenna port - * power and enable both amp bypass and mixer bypass. - */ - switchctrl_set(rf_path, SWITCHCTRL_SAFE); - - /* Configure RF switch control signals as outputs */ - gpio_output(rf_path->gpio_ant_bias_en_n); - gpio_output(rf_path->gpio_tx_en); - gpio_output(rf_path->gpio_mix_en_n); - gpio_output(rf_path->gpio_lpf_en); - gpio_output(rf_path->gpio_rf_amp_en); -#else - (void) rf_path; /* silence unused param warning */ + /* + * Safe (initial) switch settings turn off both amplifiers and antenna port + * power and enable both amp bypass and mixer bypass. + */ + switchctrl_set(rf_path, SWITCHCTRL_SAFE); + + /* Configure RF switch control signals as outputs */ + gpio_output(rf_path->gpio_ant_bias_en_n); + gpio_output(rf_path->gpio_tx_en); + gpio_output(rf_path->gpio_mix_en_n); + gpio_output(rf_path->gpio_lpf_en); + gpio_output(rf_path->gpio_rf_amp_en); #endif + break; + default: + break; + } } void rf_path_init(rf_path_t* const rf_path) { + board_id_t board_id = detected_platform(); + ssp1_set_mode_max5864(); max5864_setup(&max5864); max5864_shutdown(&max5864); ssp1_set_mode_max283x(); -#ifdef PRALINE - max283x_setup(&max283x, MAX2831_VARIANT); -#else - if (detected_platform() == BOARD_ID_HACKRF1_R9) { + switch (board_id) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + max283x_setup(&max283x, MAX2831_VARIANT); +#endif + break; + case BOARD_ID_HACKRF1_R9: +#if !defined(PRALINE) || defined(UNIVERSAL) max283x_setup(&max283x, MAX2839_VARIANT); - } else { +#endif + break; + default: +#if !defined(PRALINE) || defined(UNIVERSAL) max283x_setup(&max283x, MAX2837_VARIANT); - } #endif + break; + } max283x_start(&max283x); - // On HackRF One, the mixer is now set up earlier in boot. -#ifndef HACKRF_ONE - mixer_setup(&mixer); -#endif + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + // On HackRF One, the mixer is now set up earlier in boot. + break; + default: + if (board_id == BOARD_ID_RAD1O) { + mixer_setup(&mixer, MAX2871_VARIANT); + } else { + mixer_setup(&mixer, RFFC5071_VARIANT); + } + break; + } rf_path->switchctrl = SWITCHCTRL_SAFE; } @@ -501,7 +560,7 @@ void rf_path_set_direction(rf_path_t* const rf_path, const rf_path_direction_t d sgpio_configure(&sgpio_config, SGPIO_DIRECTION_RX); break; -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) case RF_PATH_DIRECTION_TX_CALIBRATION: case RF_PATH_DIRECTION_RX_CALIBRATION: rf_path->switchctrl &= ~SWITCHCTRL_TX; diff --git a/firmware/common/rf_path.h b/firmware/common/rf_path.h index 2d098d862..17092a70b 100644 --- a/firmware/common/rf_path.h +++ b/firmware/common/rf_path.h @@ -21,12 +21,11 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __RFPATH_H__ -#define __RFPATH_H__ +#pragma once #include -#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) +#if defined(HACKRF_ONE) || defined(RAD1O) || defined(PRALINE) || defined(UNIVERSAL) #include "gpio.h" #endif @@ -34,7 +33,7 @@ typedef enum { RF_PATH_DIRECTION_OFF, RF_PATH_DIRECTION_RX, RF_PATH_DIRECTION_TX, -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) RF_PATH_DIRECTION_TX_CALIBRATION, RF_PATH_DIRECTION_RX_CALIBRATION, #endif @@ -46,45 +45,50 @@ typedef enum { RF_PATH_FILTER_HIGH_PASS = 2, } rf_path_filter_t; -typedef struct rf_path_t { +typedef struct { uint8_t switchctrl; -#ifdef HACKRF_ONE - gpio_t gpio_hp; - gpio_t gpio_lp; - gpio_t gpio_tx_mix_bp; - gpio_t gpio_no_mix_bypass; - gpio_t gpio_rx_mix_bp; - gpio_t gpio_tx_amp; - gpio_t gpio_tx; - gpio_t gpio_mix_bypass; - gpio_t gpio_rx; - gpio_t gpio_no_tx_amp_pwr; - gpio_t gpio_amp_bypass; - gpio_t gpio_rx_amp; - gpio_t gpio_no_rx_amp_pwr; - // In HackRF One r9 this control signal has been moved to the microcontroller. - gpio_t gpio_h1r9_no_ant_pwr; + + struct { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + gpio_t gpio_hp; + gpio_t gpio_lp; + gpio_t gpio_tx_mix_bp; + gpio_t gpio_no_mix_bypass; + gpio_t gpio_rx_mix_bp; + gpio_t gpio_tx_amp; + gpio_t gpio_tx; + gpio_t gpio_mix_bypass; + gpio_t gpio_rx; + gpio_t gpio_no_tx_amp_pwr; + gpio_t gpio_amp_bypass; + gpio_t gpio_rx_amp; + gpio_t gpio_no_rx_amp_pwr; + // In HackRF One r9 this control signal has been moved to the microcontroller. + gpio_t gpio_h1r9_no_ant_pwr; #endif -#ifdef RAD1O - gpio_t gpio_tx_rx_n; - gpio_t gpio_tx_rx; - gpio_t gpio_by_mix; - gpio_t gpio_by_mix_n; - gpio_t gpio_by_amp; - gpio_t gpio_by_amp_n; - gpio_t gpio_mixer_en; - gpio_t gpio_low_high_filt; - gpio_t gpio_low_high_filt_n; - gpio_t gpio_tx_amp; - gpio_t gpio_rx_lna; + +#if defined(RAD1O) + gpio_t gpio_tx_rx_n; + gpio_t gpio_tx_rx; + gpio_t gpio_by_mix; + gpio_t gpio_by_mix_n; + gpio_t gpio_by_amp; + gpio_t gpio_by_amp_n; + gpio_t gpio_mixer_en; + gpio_t gpio_low_high_filt; + gpio_t gpio_low_high_filt_n; + gpio_t gpio_tx_amp; + gpio_t gpio_rx_lna; #endif -#ifdef PRALINE - gpio_t gpio_tx_en; - gpio_t gpio_mix_en_n; - gpio_t gpio_lpf_en; - gpio_t gpio_rf_amp_en; - gpio_t gpio_ant_bias_en_n; + +#if defined(PRALINE) || defined(UNIVERSAL) + gpio_t gpio_tx_en; + gpio_t gpio_mix_en_n; + gpio_t gpio_lpf_en; + gpio_t gpio_rf_amp_en; + gpio_t gpio_ant_bias_en_n; #endif + }; } rf_path_t; void rf_path_pin_setup(rf_path_t* const rf_path); @@ -96,5 +100,3 @@ void rf_path_set_filter(rf_path_t* const rf_path, const rf_path_filter_t filter) void rf_path_set_lna(rf_path_t* const rf_path, const uint_fast8_t enable); void rf_path_set_antenna(rf_path_t* const rf_path, const uint_fast8_t enable); - -#endif /*__RFPATH_H__*/ diff --git a/firmware/common/rffc5071.c b/firmware/common/rffc5071.c index 177537f59..7700fdb4c 100644 --- a/firmware/common/rffc5071.c +++ b/firmware/common/rffc5071.c @@ -34,15 +34,16 @@ #include #include -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include #endif #include "delay.h" +#include "platform_detect.h" #include "rffc5071.h" #include "rffc5071_regs.def" // private register def macros #include "selftest.h" -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "platform_scu.h" #endif @@ -104,15 +105,19 @@ void rffc5071_init(rffc5071_driver_t* const drv) */ void rffc5071_setup(rffc5071_driver_t* const drv) { + board_id_t board_id = detected_platform(); + gpio_set(drv->gpio_reset); gpio_output(drv->gpio_reset); -#ifdef PRALINE - /* Configure mixer PLL lock detect pin */ - const platform_scu_t* scu = platform_scu(); - scu_pinmux(scu->MIXER_LD, scu->MIXER_LD_PINCFG); - gpio_input(drv->gpio_ld); + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + /* Configure mixer PLL lock detect pin */ + const platform_scu_t* scu = platform_scu(); + scu_pinmux(scu->MIXER_LD, scu->MIXER_LD_PINCFG); + gpio_input(drv->gpio_ld); #endif + } rffc5071_init(drv); @@ -130,10 +135,16 @@ void rffc5071_setup(rffc5071_driver_t* const drv) set_RFFC5071_FULLD(drv, 0); set_RFFC5071_MODE(drv, 1); -#if defined(PRALINE) || defined(HACKRF_ONE) - /* Enable GPO Lock output signal */ - set_RFFC5071_LOCK(drv, 1); -#endif + switch (board_id) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: + /* Enable GPO Lock output signal */ + set_RFFC5071_LOCK(drv, 1); + break; + default: + break; + } /* Enable reference oscillator standby */ set_RFFC5071_REFST(drv, 1); @@ -176,13 +187,17 @@ void rffc5071_lock_test(rffc5071_driver_t* const drv) bool rffc5071_check_lock(rffc5071_driver_t* const drv) { -#ifdef PRALINE - return gpio_read(drv->gpio_ld); + if (detected_platform() == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + return gpio_read(drv->gpio_ld); #else - set_RFFC5071_READSEL(drv, 0b0001); - rffc5071_regs_commit(drv); - return !!(rffc5071_reg_read(drv, RFFC5071_READBACK_REG) & 0x8000); + return false; #endif + } else { + set_RFFC5071_READSEL(drv, 0b0001); + rffc5071_regs_commit(drv); + return !!(rffc5071_reg_read(drv, RFFC5071_READBACK_REG) & 0x8000); + } } static uint16_t rffc5071_spi_read(rffc5071_driver_t* const drv, uint8_t r) @@ -344,9 +359,17 @@ void rffc5071_set_gpo(rffc5071_driver_t* const drv, uint8_t gpo) rffc5071_regs_commit(drv); } -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) bool rffc5071_poll_ld(rffc5071_driver_t* const drv, uint8_t* prelock_state) { + // This is only supported on Praline hardware. + // + // For all other boards we'll just return true to avoid a situation where a + // a caller is waiting for a lock signal that will never be detected. + if (detected_platform() != BOARD_ID_PRALINE) { + return true; + } + // The RFFC5072 can be configured to output PLL lock status on // GPO4. The lock detect signal is produced by a window detector // on the VCO tuning voltage. It goes high to show PLL lock when @@ -412,7 +435,9 @@ bool rffc5071_poll_ld(rffc5071_driver_t* const drv, uint8_t* prelock_state) uint8_t rsm_state = (rb >> 11) & 0b11111; // get gpo4 lock detect signal + #if defined(PRALINE) || defined(UNIVERSAL) bool gpo4_ld = gpio_read(drv->gpio_ld); + #endif // parse state switch (rsm_state) { diff --git a/firmware/common/rffc5071.h b/firmware/common/rffc5071.h index 506f1a095..b5ac946ce 100644 --- a/firmware/common/rffc5071.h +++ b/firmware/common/rffc5071.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __RFFC5071_H -#define __RFFC5071_H +#pragma once #include #include @@ -35,7 +34,7 @@ typedef struct { spi_bus_t* const bus; gpio_t gpio_reset; -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) gpio_t gpio_ld; #endif uint16_t regs[RFFC5071_NUM_REGS]; @@ -67,9 +66,7 @@ extern void rffc5071_enable(rffc5071_driver_t* const drv); extern void rffc5071_disable(rffc5071_driver_t* const drv); extern void rffc5071_set_gpo(rffc5071_driver_t* const drv, uint8_t); -#ifdef PRALINE +extern bool rffc5071_check_lock(rffc5071_driver_t* const drv); +#if defined(PRALINE) || defined(UNIVERSAL) extern bool rffc5071_poll_ld(rffc5071_driver_t* const drv, uint8_t* prelock_state); #endif -extern bool rffc5071_check_lock(rffc5071_driver_t* const drv); - -#endif // __RFFC5071_H diff --git a/firmware/common/rffc5071_regs.def b/firmware/common/rffc5071_regs.def index 022010c03..dd352a036 100644 --- a/firmware/common/rffc5071_regs.def +++ b/firmware/common/rffc5071_regs.def @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __RFFC5071_REGS_DEF -#define __RFFC5071_REGS_DEF +#pragma once #define RFFC5071_REG_SET_CLEAN(_d, _r) (_d->regs_dirty &= ~(1UL<<_r)) #define RFFC5071_REG_SET_DIRTY(_d, _r) (_d->regs_dirty |= (1UL<<_r)) @@ -257,5 +256,3 @@ __MREG__(RFFC5071_LFSR,30,9,1) __MREG__(RFFC5071_TSEL,30,10,2) __MREG__(RFFC5071_TMUX,30,12,3) __MREG__(RFFC5071_TEN,30,15,1) - -#endif // __RFFC5071_REGS_DEF diff --git a/firmware/common/rffc5071_spi.h b/firmware/common/rffc5071_spi.h index 7df2d8bf4..552d07696 100644 --- a/firmware/common/rffc5071_spi.h +++ b/firmware/common/rffc5071_spi.h @@ -20,15 +20,14 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __RFFC5071_SPI_H -#define __RFFC5071_SPI_H +#pragma once #include #include "gpio.h" #include "spi_bus.h" -typedef struct rffc5071_spi_config_t { +typedef struct { gpio_t gpio_select; gpio_t gpio_clock; gpio_t gpio_data; @@ -41,5 +40,3 @@ void rffc5071_spi_transfer_gather( spi_bus_t* const bus, const spi_transfer_t* const transfer, const size_t count); - -#endif // __RFFC5071_SPI_H diff --git a/firmware/common/rom_iap.h b/firmware/common/rom_iap.h index 50cfcf933..8b0273429 100644 --- a/firmware/common/rom_iap.h +++ b/firmware/common/rom_iap.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __ROM_IAP__ -#define __ROM_IAP__ +#pragma once #include #include @@ -93,7 +92,7 @@ typedef enum INVALID_FLASH_UNIT = 0x00000014, /* Invalid flash unit. */ USER_CODE_CHECKSUM = 0x00000015, ERROR_SETTING_ACTIVE_PARTITION = 0x00000016, - + /* Special Error */ ERROR_IAP_NOT_IMPLEMENTED = 0x00000100 /* IAP is not implemented in this part */ } isp_iap_ret_code_t; @@ -118,5 +117,3 @@ typedef struct { bool iap_is_implemented(void); isp_iap_ret_code_t iap_cmd_call(iap_cmd_res_t* iap_cmd_res); - -#endif //__ROM_IAP__ diff --git a/firmware/common/sct.h b/firmware/common/sct.h index 61c43199b..5bedfa752 100644 --- a/firmware/common/sct.h +++ b/firmware/common/sct.h @@ -19,6 +19,8 @@ * Boston, MA 02110-1301, USA. */ +#pragma once + #include #include diff --git a/firmware/common/selftest.h b/firmware/common/selftest.h index 86ee22132..8223a582f 100644 --- a/firmware/common/selftest.h +++ b/firmware/common/selftest.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SELFTEST_H -#define __SELFTEST_H +#pragma once #include #include @@ -38,23 +37,22 @@ typedef uint8_t test_result_t; typedef struct { uint16_t mixer_id; -#ifndef RAD1O +#if !defined(RAD1O) bool mixer_locks[NUM_LOCK_ATTEMPTS]; #endif -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) uint16_t max2831_mux_rssi_1; uint16_t max2831_mux_temp; uint16_t max2831_mux_rssi_2; bool max2831_mux_test_ok; -#else +#endif uint16_t max283x_readback_bad_value; uint16_t max283x_readback_expected_value; uint8_t max283x_readback_register_count; uint8_t max283x_readback_total_registers; -#endif uint8_t si5351_rev_id; bool si5351_readback_ok; -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) test_result_t fpga_image_load; test_result_t fpga_spi; test_result_t sgpio_rx; @@ -76,5 +74,3 @@ typedef struct { } selftest_t; extern selftest_t selftest; - -#endif // __SELFTEST_H diff --git a/firmware/common/sgpio.c b/firmware/common/sgpio.c index f364d7b08..ac755d516 100644 --- a/firmware/common/sgpio.c +++ b/firmware/common/sgpio.c @@ -58,7 +58,7 @@ void sgpio_configure_pin_functions(sgpio_config_t* const config) scu_pinmux(scu->PINMUX_SGPIO15, scu->PINMUX_SGPIO15_PINCFG); /* GPIO5[14] */ if (detected_platform() == BOARD_ID_HACKRF1_R9) { -#if defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) scu_pinmux( scu->H1R9_TRIGGER_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION4); /* GPIO5[5] */ @@ -72,10 +72,12 @@ void sgpio_configure_pin_functions(sgpio_config_t* const config) sgpio_cpld_set_mixer_invert(config, 0); gpio_output(config->gpio_q_invert); -#ifndef PRALINE - trigger_enable(false); - gpio_output(config->gpio_trigger_enable); + if (detected_platform() != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + trigger_enable(false); + gpio_output(config->gpio_trigger_enable); #endif + } } void sgpio_set_slice_mode(sgpio_config_t* const config, const bool multi_slice) @@ -157,11 +159,11 @@ void sgpio_configure(sgpio_config_t* const config, const sgpio_direction_t direc SGPIO_OUT_MUX_CFG_P_OE_CFG(0) // gpio_oe (state set by GPIO_OEREG) | SGPIO_OUT_MUX_CFG_P_OUT_CFG(0) // dout_doutm1 (1-bit mode) ; - SGPIO_OUT_MUX_CFG(10) = // GPIO10: Output: disable + SGPIO_OUT_MUX_CFG(10) = // GPIO10: Output: disable SGPIO_OUT_MUX_CFG_P_OE_CFG(0) // gpio_oe (state set by GPIO_OEREG) | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) // gpio_out (level set by GPIO_OUTREG) ; - SGPIO_OUT_MUX_CFG(11) = // GPIO11: Output: direction + SGPIO_OUT_MUX_CFG(11) = // GPIO11: Output: direction SGPIO_OUT_MUX_CFG_P_OE_CFG(0) // gpio_oe (state set by GPIO_OEREG) | SGPIO_OUT_MUX_CFG_P_OUT_CFG(4) // gpio_out (level set by GPIO_OUTREG) ; diff --git a/firmware/common/sgpio.h b/firmware/common/sgpio.h index 08d7d222e..f6fdf2134 100644 --- a/firmware/common/sgpio.h +++ b/firmware/common/sgpio.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SGPIO_H__ -#define __SGPIO_H__ +#pragma once #include #include @@ -33,9 +32,9 @@ typedef enum { SGPIO_DIRECTION_TX, } sgpio_direction_t; -typedef struct sgpio_config_t { +typedef struct { gpio_t gpio_q_invert; -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) gpio_t gpio_trigger_enable; #endif bool slice_mode_multislice; @@ -50,5 +49,3 @@ void sgpio_cpld_stream_disable(sgpio_config_t* const config); bool sgpio_cpld_stream_is_enabled(sgpio_config_t* const config); void sgpio_cpld_set_mixer_invert(sgpio_config_t* const config, uint_fast8_t invert); - -#endif //__SGPIO_H__ diff --git a/firmware/common/si5351c.c b/firmware/common/si5351c.c index 8b6e52fda..64402d89e 100644 --- a/firmware/common/si5351c.c +++ b/firmware/common/si5351c.c @@ -23,7 +23,7 @@ #include #include -#if defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) #include #endif @@ -32,7 +32,7 @@ #include "platform_detect.h" #include "selftest.h" #include "si5351c.h" -#if defined(HACKRF_ONE) +#if defined(HACKRF_ONE) || defined(UNIVERSAL) #include "gpio.h" #include "platform_gpio.h" #include "platform_scu.h" @@ -202,8 +202,9 @@ void si5351c_configure_multisynth( void si5351c_configure_clock_control(si5351c_driver_t* const drv) { - const uint8_t pll = SI5351C_CLK_PLL_SRC_A; + uint8_t pll = SI5351C_CLK_PLL_SRC_A; uint8_t clkout_ctrl; + board_id_t board_id = detected_platform(); if (clkout_enabled) { clkout_ctrl = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC(pll) | @@ -238,7 +239,8 @@ void si5351c_configure_clock_control(si5351c_driver_t* const drv) SI5351C_CLK_POWERDOWN | SI5351C_CLK_INT_MODE /* not connected, but: PLL B int mode */ }; - if (detected_platform() == BOARD_ID_HACKRF1_R9) { + if (board_id == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) data[1] = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC_A | SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_6MA); @@ -249,30 +251,33 @@ void si5351c_configure_clock_control(si5351c_driver_t* const drv) data[4] = SI5351C_CLK_POWERDOWN; data[5] = SI5351C_CLK_POWERDOWN; data[6] = SI5351C_CLK_POWERDOWN; +#endif } -#ifdef PRALINE - /* CLK0: AFE_CLK */ - data[1] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | - SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | - SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_4MA); - /* CLK1: SCT_CLK and FPGA_CLK */ - data[2] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | - SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | - SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_2MA); - /* CLK4: XCVR_CLK */ - data[5] = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC(pll) | - SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | - SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_4MA) | SI5351C_CLK_INV; - if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { - /* CLK2: FPGA_CLK (not shared with SCT_CLK on older boards) */ - data[3] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + /* CLK0: AFE_CLK */ + data[1] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | + SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | + SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_4MA); + /* CLK1: SCT_CLK and FPGA_CLK */ + data[2] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_2MA); - } else { - /* CLK2: MCU_CLK */ - data[3] = SI5351C_CLK_POWERDOWN; - } + /* CLK4: XCVR_CLK */ + data[5] = SI5351C_CLK_INT_MODE | SI5351C_CLK_PLL_SRC(pll) | + SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | + SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_4MA) | SI5351C_CLK_INV; + if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { + /* CLK2: FPGA_CLK (not shared with SCT_CLK on older boards) */ + data[3] = SI5351C_CLK_FRAC_MODE | SI5351C_CLK_PLL_SRC(pll) | + SI5351C_CLK_SRC(SI5351C_CLK_SRC_MULTISYNTH_SELF) | + SI5351C_CLK_IDRV(SI5351C_CLK_IDRV_2MA); + } else { + /* CLK2: MCU_CLK */ + data[3] = SI5351C_CLK_POWERDOWN; + } #endif + } si5351c_write(drv, data, sizeof(data)); } @@ -287,30 +292,38 @@ void si5351c_enable_clock_outputs(si5351c_driver_t* const drv) /* 7: Clock to CPU is deactivated as it is not used and creates noise */ /* 3: External clock output is deactivated by default */ -#ifndef PRALINE - uint8_t value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | - SI5351C_CLK_ENABLE(2) | SI5351C_CLK_ENABLE(4) | SI5351C_CLK_ENABLE(5) | - SI5351C_CLK_DISABLE(6) | SI5351C_CLK_DISABLE(7); -#else - uint8_t value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | - SI5351C_CLK_ENABLE(4) | SI5351C_CLK_ENABLE(5) | SI5351C_CLK_DISABLE(6) | - SI5351C_CLK_DISABLE(7); - if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { - /* CLK2: FPGA_CLK (not shared with SCT_CLK on older boards) */ - value |= SI5351C_CLK_ENABLE(2); + board_id_t board_id = detected_platform(); + + uint8_t value = 0; + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | + SI5351C_CLK_ENABLE(4) | SI5351C_CLK_ENABLE(5) | + SI5351C_CLK_DISABLE(6) | SI5351C_CLK_DISABLE(7); + if ((detected_revision() & ~BOARD_REV_GSG) < BOARD_REV_PRALINE_R1_1) { + /* CLK2: FPGA_CLK (not shared with SCT_CLK on older boards) */ + value |= SI5351C_CLK_ENABLE(2); + } else { + value |= SI5351C_CLK_DISABLE(2); + } +#endif } else { - value |= SI5351C_CLK_DISABLE(2); + value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | + SI5351C_CLK_DISABLE(2) | SI5351C_CLK_ENABLE(4) | + SI5351C_CLK_ENABLE(5) | SI5351C_CLK_DISABLE(6) | + SI5351C_CLK_DISABLE(7); } -#endif uint8_t clkout = 3; /* HackRF One r9 has only three clock generator outputs. */ - if (detected_platform() == BOARD_ID_HACKRF1_R9) { + if (board_id == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) clkout = 2; value = SI5351C_CLK_ENABLE(0) | SI5351C_CLK_ENABLE(1) | SI5351C_CLK_DISABLE(3) | SI5351C_CLK_DISABLE(4) | SI5351C_CLK_DISABLE(5) | SI5351C_CLK_DISABLE(6) | SI5351C_CLK_DISABLE(7); +#endif } value |= (clkout_enabled) ? SI5351C_CLK_ENABLE(clkout) : @@ -318,16 +331,16 @@ void si5351c_enable_clock_outputs(si5351c_driver_t* const drv) uint8_t data[] = {SI5351C_REG_OUTPUT_EN, value}; si5351c_write(drv, data, sizeof(data)); -#if defined(HACKRF_ONE) if (detected_platform() == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) const platform_gpio_t* gpio = platform_gpio(); if (clkout_enabled) { gpio_set(gpio->h1r9_clkout_en); } else { gpio_clear(gpio->h1r9_clkout_en); } - } #endif + } } void si5351c_set_int_mode( @@ -427,8 +440,8 @@ void si5351c_init(si5351c_driver_t* const drv) selftest.report.pass = false; } -#if defined(HACKRF_ONE) if (detected_platform() == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) const platform_gpio_t* gpio = platform_gpio(); const platform_scu_t* scu = platform_scu(); @@ -446,9 +459,8 @@ void si5351c_init(si5351c_driver_t* const drv) scu_pinmux(scu->H1R9_MCU_CLK_EN, SCU_GPIO_FAST | SCU_CONF_FUNCTION0); gpio_clear(gpio->h1r9_mcu_clk_en); gpio_output(gpio->h1r9_mcu_clk_en); - } #endif - (void) drv; + } } /* diff --git a/firmware/common/si5351c.h b/firmware/common/si5351c.h index d151a74d6..8168477e5 100644 --- a/firmware/common/si5351c.h +++ b/firmware/common/si5351c.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SI5351C_H -#define __SI5351C_H +#pragma once #ifdef __cplusplus extern "C" { @@ -115,5 +114,3 @@ void si5351c_set_phase( #ifdef __cplusplus } #endif - -#endif /* __SI5351C_H */ diff --git a/firmware/common/spi_bus.h b/firmware/common/spi_bus.h index cd8856447..07d5787d8 100644 --- a/firmware/common/spi_bus.h +++ b/firmware/common/spi_bus.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SPI_BUS_H__ -#define __SPI_BUS_H__ +#pragma once #include @@ -30,20 +29,20 @@ typedef struct { const size_t count; } spi_transfer_t; -struct spi_bus_t; // IWYU pragma: keep - fixed in #1704 -typedef struct spi_bus_t spi_bus_t; - -struct spi_bus_t { +typedef struct _spi_bus_t { void* const obj; const void* config; - void (*start)(spi_bus_t* const bus, const void* const config); - void (*stop)(spi_bus_t* const bus); - void (*transfer)(spi_bus_t* const bus, void* const data, const size_t count); + void (*start)(struct _spi_bus_t* const bus, const void* const config); + void (*stop)(struct _spi_bus_t* const bus); + void (*transfer)( + struct _spi_bus_t* const bus, + void* const data, + const size_t count); void (*transfer_gather)( - spi_bus_t* const bus, + struct _spi_bus_t* const bus, const spi_transfer_t* const transfers, const size_t count); -}; +} spi_bus_t; void spi_bus_start(spi_bus_t* const bus, const void* const config); void spi_bus_stop(spi_bus_t* const bus); @@ -52,5 +51,3 @@ void spi_bus_transfer_gather( spi_bus_t* const bus, const spi_transfer_t* const transfers, const size_t count); - -#endif /*__SPI_BUS_H__*/ diff --git a/firmware/common/spi_ssp.h b/firmware/common/spi_ssp.h index 2325f49f1..822772b51 100644 --- a/firmware/common/spi_ssp.h +++ b/firmware/common/spi_ssp.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __SPI_SSP_H__ -#define __SPI_SSP_H__ +#pragma once #include #include @@ -31,7 +30,7 @@ #include "gpio.h" #include "spi_bus.h" -typedef struct ssp_config_t { +typedef struct { ssp_datasize_t data_bits; ssp_cpol_cpha_t spi_mode; uint8_t serial_clock_rate; @@ -46,5 +45,3 @@ void spi_ssp_transfer_gather( spi_bus_t* const bus, const spi_transfer_t* const transfers, const size_t count); - -#endif /*__SPI_SSP_H__*/ diff --git a/firmware/common/streaming.h b/firmware/common/streaming.h index 47f466c14..47af5120b 100644 --- a/firmware/common/streaming.h +++ b/firmware/common/streaming.h @@ -21,12 +21,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __STREAMING_H__ -#define __STREAMING_H__ +#pragma once #include void baseband_streaming_enable(sgpio_config_t* const sgpio_config); void baseband_streaming_disable(sgpio_config_t* const sgpio_config); - -#endif /*__STREAMING_H__*/ diff --git a/firmware/common/tune_config.h b/firmware/common/tune_config.h index dd21d0283..34c692e6e 100644 --- a/firmware/common/tune_config.h +++ b/firmware/common/tune_config.h @@ -19,10 +19,9 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __TUNE_CONFIG_H__ -#define __TUNE_CONFIG_H__ +#pragma once -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) #include "fpga.h" typedef struct { @@ -391,5 +390,3 @@ static const tune_config_t praline_tune_config_rx[] = { }; // clang-format on #endif - -#endif /*__TUNE_CONFIG_H__*/ diff --git a/firmware/common/tuning.c b/firmware/common/tuning.c index 47724e369..637ed6ce9 100644 --- a/firmware/common/tuning.c +++ b/firmware/common/tuning.c @@ -27,51 +27,76 @@ #include "hackrf_ui.h" #include "max283x.h" #include "mixer.h" +#include "platform_detect.h" #include "sgpio.h" -#if defined(PRALINE) || defined(HACKRF_ONE) +#if defined(PRALINE) || defined(HACKRF_ONE) || defined(UNIVERSAL) #include "operacake.h" #endif -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) #include "fpga.h" #endif -#ifndef PRALINE +static uint64_t MIN_LP_FREQ_MHZ; +static uint64_t MAX_LP_FREQ_MHZ; - #define MIN_LP_FREQ_MHZ (0) - #define MAX_LP_FREQ_MHZ (2170ULL) +static uint64_t ABS_MIN_BYPASS_FREQ_MHZ; +static uint64_t MIN_BYPASS_FREQ_MHZ; +static uint64_t MAX_BYPASS_FREQ_MHZ; +static uint64_t ABS_MAX_BYPASS_FREQ_MHZ; - #define ABS_MIN_BYPASS_FREQ_MHZ (2000ULL) - #define MIN_BYPASS_FREQ_MHZ (MAX_LP_FREQ_MHZ) - #define MAX_BYPASS_FREQ_MHZ (2740ULL) - #define ABS_MAX_BYPASS_FREQ_MHZ (3000ULL) +static uint64_t MIN_HP_FREQ_MHZ; +#if !defined(PRALINE) || defined(UNIVERSAL) +static uint64_t MID1_HP_FREQ_MHZ; +static uint64_t MID2_HP_FREQ_MHZ; +#endif +static uint64_t MAX_HP_FREQ_MHZ; - #define MIN_HP_FREQ_MHZ (MAX_BYPASS_FREQ_MHZ) - #define MID1_HP_FREQ_MHZ (3600ULL) - #define MID2_HP_FREQ_MHZ (5100ULL) - #define MAX_HP_FREQ_MHZ (7250ULL) +static uint64_t MIN_LO_FREQ_HZ; +static uint64_t MAX_LO_FREQ_HZ; - #define MIN_LO_FREQ_HZ (84375000ULL) - #define MAX_LO_FREQ_HZ (5400000000ULL) +void tuning_setup(void) +{ + switch (detected_platform()) { + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + MIN_LP_FREQ_MHZ = 0; + MAX_LP_FREQ_MHZ = 2320ULL; -#else + ABS_MIN_BYPASS_FREQ_MHZ = 2000ULL; + MIN_BYPASS_FREQ_MHZ = MAX_LP_FREQ_MHZ; + MAX_BYPASS_FREQ_MHZ = 2580ULL; + ABS_MAX_BYPASS_FREQ_MHZ = 3000ULL; - #define MIN_LP_FREQ_MHZ (0) - #define MAX_LP_FREQ_MHZ (2320ULL) + MIN_HP_FREQ_MHZ = MAX_BYPASS_FREQ_MHZ; + MAX_HP_FREQ_MHZ = 7250ULL; - #define ABS_MIN_BYPASS_FREQ_MHZ (2000ULL) - #define MIN_BYPASS_FREQ_MHZ (MAX_LP_FREQ_MHZ) - #define MAX_BYPASS_FREQ_MHZ (2580ULL) - #define ABS_MAX_BYPASS_FREQ_MHZ (3000ULL) + MIN_LO_FREQ_HZ = 84375000ULL; + MAX_LO_FREQ_HZ = 5400000000ULL; +#endif + break; + default: +#if !defined(PRALINE) || defined(UNIVERSAL) + MIN_LP_FREQ_MHZ = 0; + MAX_LP_FREQ_MHZ = 2170ULL; - #define MIN_HP_FREQ_MHZ (MAX_BYPASS_FREQ_MHZ) - #define MAX_HP_FREQ_MHZ (7250ULL) + ABS_MIN_BYPASS_FREQ_MHZ = 2000ULL; + MIN_BYPASS_FREQ_MHZ = MAX_LP_FREQ_MHZ; + MAX_BYPASS_FREQ_MHZ = 2740ULL; + ABS_MAX_BYPASS_FREQ_MHZ = 3000ULL; - #define MIN_LO_FREQ_HZ (84375000ULL) - #define MAX_LO_FREQ_HZ (5400000000ULL) + MIN_HP_FREQ_MHZ = MAX_BYPASS_FREQ_MHZ; + MID1_HP_FREQ_MHZ = 3600ULL; + MID2_HP_FREQ_MHZ = 5100ULL; + MAX_HP_FREQ_MHZ = 7250ULL; + MIN_LO_FREQ_HZ = 84375000ULL; + MAX_LO_FREQ_HZ = 5400000000ULL; #endif + break; + } +} -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) static uint32_t max2837_freq_nominal_hz = 2560000000; /* @@ -93,7 +118,7 @@ bool set_freq(const uint64_t freq) max283x_set_mode(&max283x, MAX283x_MODE_STANDBY); if (freq_mhz < MAX_LP_FREQ_MHZ) { rf_path_set_filter(&rf_path, RF_PATH_FILTER_LOW_PASS); - #ifdef RAD1O + #if defined(RAD1O) max2837_freq_nominal_hz = 2300 * FREQ_ONE_MHZ; #else /* IF is graduated from 2650 MHz to 2340 MHz */ @@ -137,15 +162,15 @@ bool set_freq(const uint64_t freq) max283x_set_mode(&max283x, prior_max283x_mode); if (success) { hackrf_ui()->set_frequency(freq); - #ifdef HACKRF_ONE + #if defined(HACKRF_ONE) || defined(UNIVERSAL) operacake_set_range(freq_mhz); #endif } return success; } +#endif -#else - +#if defined(PRALINE) || defined(UNIVERSAL) bool tuning_set_frequency( const tune_config_t* cfg, const uint64_t freq, diff --git a/firmware/common/tuning.h b/firmware/common/tuning.h index b76dbcc33..cc5a124cd 100644 --- a/firmware/common/tuning.h +++ b/firmware/common/tuning.h @@ -21,30 +21,29 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __TUNING_H__ -#define __TUNING_H__ +#pragma once #include #include #include "rf_path.h" -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "tune_config.h" #endif #define FREQ_ONE_MHZ (1000ULL * 1000) +void tuning_setup(void); + bool set_freq(const uint64_t freq); bool set_freq_explicit( const uint64_t if_freq_hz, const uint64_t lo_freq_hz, const rf_path_filter_t path); -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) bool tuning_set_frequency( const tune_config_t* cfg, const uint64_t freq, const uint32_t offset); #endif - -#endif /*__TUNING_H__*/ diff --git a/firmware/common/ui_portapack.c b/firmware/common/ui_portapack.c index 8a44db046..aaa96cb0d 100644 --- a/firmware/common/ui_portapack.c +++ b/firmware/common/ui_portapack.c @@ -393,7 +393,7 @@ static ui_point_t portapack_lcd_draw_string(ui_point_t point, const char* s) return point; } -typedef struct draw_list_t { +typedef struct { const ui_bitmap_t* bitmap; const ui_point_t point; } draw_list_t; diff --git a/firmware/common/ui_portapack.h b/firmware/common/ui_portapack.h index 0565cf6ab..e0695839f 100644 --- a/firmware/common/ui_portapack.h +++ b/firmware/common/ui_portapack.h @@ -20,11 +20,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __UI_PORTAPACK_H__ -#define __UI_PORTAPACK_H__ +#pragma once #include "hackrf_ui.h" const hackrf_ui_t* portapack_hackrf_ui_init(void) __attribute__((weak)); - -#endif /*__UI_PORTAPACK_H__*/ diff --git a/firmware/common/ui_rad1o.h b/firmware/common/ui_rad1o.h index 5b3e74217..73350d11d 100644 --- a/firmware/common/ui_rad1o.h +++ b/firmware/common/ui_rad1o.h @@ -20,11 +20,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __UI_RAD1O_H__ -#define __UI_RAD1O_H__ +#pragma once #include "hackrf_ui.h" const hackrf_ui_t* rad1o_ui_setup(void) __attribute__((weak)); - -#endif /*__UI_RAD1O_H__*/ diff --git a/firmware/common/usb.c b/firmware/common/usb.c index 64cd6c08f..026b7ec96 100644 --- a/firmware/common/usb.c +++ b/firmware/common/usb.c @@ -25,7 +25,6 @@ #include #include -#include #include #include diff --git a/firmware/common/usb.h b/firmware/common/usb.h index ee2ff9b69..9445728a3 100644 --- a/firmware/common/usb.h +++ b/firmware/common/usb.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_H__ -#define __USB_H__ +#pragma once #include #include @@ -77,5 +76,3 @@ void usb_endpoint_schedule_append( const usb_endpoint_t* const endpoint, usb_transfer_descriptor_t* const tail_td, usb_transfer_descriptor_t* const new_td); - -#endif //__USB_H__ diff --git a/firmware/common/usb_queue.h b/firmware/common/usb_queue.h index 8793558f0..b6134946d 100644 --- a/firmware/common/usb_queue.h +++ b/firmware/common/usb_queue.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_QUEUE_H__ -#define __USB_QUEUE_H__ +#pragma once #include @@ -30,27 +29,25 @@ #include "usb_type.h" -typedef struct _usb_transfer_t usb_transfer_t; -typedef struct _usb_queue_t usb_queue_t; typedef void (*transfer_completion_cb)(void*, unsigned int); // This is an opaque datatype. Thou shall not touch these members. -struct _usb_transfer_t { +typedef struct _usb_transfer_t { struct _usb_transfer_t* next; usb_transfer_descriptor_t td ATTR_ALIGNED(64); unsigned int maximum_length; struct _usb_queue_t* queue; transfer_completion_cb completion_cb; void* user_data; -}; +} usb_transfer_t; // This is an opaque datatype. Thou shall not touch these members. -struct _usb_queue_t { - struct usb_endpoint_t* endpoint; +typedef struct _usb_queue_t { + usb_endpoint_t* endpoint; const unsigned int pool_size; usb_transfer_t* volatile free_transfers; usb_transfer_t* volatile active; -}; +} usb_queue_t; #define USB_DECLARE_QUEUE(endpoint_name) struct _usb_queue_t endpoint_name##_queue; #define USB_DEFINE_QUEUE(endpoint_name, _pool_size) \ @@ -81,5 +78,3 @@ int usb_transfer_schedule_ack(const usb_endpoint_t* const endpoint); void usb_queue_init(usb_queue_t* const queue); void usb_queue_transfer_complete(usb_endpoint_t* const endpoint); - -#endif //__USB_QUEUE_H__ diff --git a/firmware/common/usb_request.h b/firmware/common/usb_request.h index 40d5013d1..c61d77d64 100644 --- a/firmware/common/usb_request.h +++ b/firmware/common/usb_request.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_REQUEST_H__ -#define __USB_REQUEST_H__ +#pragma once #include "usb_type.h" @@ -61,5 +60,3 @@ void usb_setup_complete(usb_endpoint_t* const endpoint); void usb_control_in_complete(usb_endpoint_t* const endpoint); void usb_control_out_complete(usb_endpoint_t* const endpoint); - -#endif //__USB_REQUEST_H__ diff --git a/firmware/common/usb_standard_request.h b/firmware/common/usb_standard_request.h index e9ea9f691..84a8c4587 100644 --- a/firmware/common/usb_standard_request.h +++ b/firmware/common/usb_standard_request.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_STANDARD_REQUEST_H__ -#define __USB_STANDARD_REQUEST_H__ +#pragma once #include #include @@ -50,5 +49,3 @@ usb_transfer_type_t usb_endpoint_descriptor_transfer_type( bool usb_set_configuration( usb_device_t* const device, const uint_fast8_t configuration_number); - -#endif //__USB_STANDARD_REQUEST_H__ diff --git a/firmware/common/usb_type.h b/firmware/common/usb_type.h index b268c6bbf..44810de54 100644 --- a/firmware/common/usb_type.h +++ b/firmware/common/usb_type.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_TYPE_H__ -#define __USB_TYPE_H__ +#pragma once #include @@ -145,17 +144,13 @@ typedef struct { uint8_t* wcid_extended_properties_descriptor; } usb_device_t; -typedef struct usb_endpoint_t usb_endpoint_t; - -struct usb_endpoint_t { +typedef struct _usb_endpoint_t { usb_setup_t setup; uint8_t buffer[32]; // Buffer for use during IN stage. const uint_fast8_t address; usb_device_t* const device; - usb_endpoint_t* const in; - usb_endpoint_t* const out; - void (*setup_complete)(usb_endpoint_t* const endpoint); - void (*transfer_complete)(usb_endpoint_t* const endpoint); -}; - -#endif //__USB_TYPE_H__ + struct _usb_endpoint_t* const in; + struct _usb_endpoint_t* const out; + void (*setup_complete)(struct _usb_endpoint_t* const endpoint); + void (*transfer_complete)(struct _usb_endpoint_t* const endpoint); +} usb_endpoint_t; diff --git a/firmware/common/w25q80bv.c b/firmware/common/w25q80bv.c index 9e7e1acd9..f569bedf0 100644 --- a/firmware/common/w25q80bv.c +++ b/firmware/common/w25q80bv.c @@ -27,10 +27,11 @@ * programming the flash. */ -#include "w25q80bv.h" - -#include #include +#include + +#include "platform_detect.h" +#include "w25q80bv.h" #define ARRAY_SIZE(arr) (sizeof(arr) / sizeof((arr)[0])) @@ -59,13 +60,13 @@ void w25q80bv_setup(w25q80bv_driver_t* const drv) uint8_t device_id; drv->page_len = 256U; -#ifdef PRALINE - drv->num_pages = 16384U; - drv->num_bytes = 4194304U; -#else - drv->num_pages = 4096U; - drv->num_bytes = 1048576U; -#endif + if (detected_platform() == BOARD_ID_PRALINE) { + drv->num_pages = 16384U; + drv->num_bytes = 4194304U; + } else { + drv->num_pages = 4096U; + drv->num_bytes = 1048576U; + } drv->target_init(drv); diff --git a/firmware/common/w25q80bv.h b/firmware/common/w25q80bv.h index f737afe66..a43d64450 100644 --- a/firmware/common/w25q80bv.h +++ b/firmware/common/w25q80bv.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __W25Q80BV_H__ -#define __W25Q80BV_H__ +#pragma once #include #include @@ -40,18 +39,15 @@ typedef union { uint8_t id_8b[8]; /* 8*8bits 64bits Unique ID */ } w25q80bv_unique_id_t; -struct w25q80bv_driver_t; // IWYU pragma: keep - fixed in #1704 -typedef struct w25q80bv_driver_t w25q80bv_driver_t; - -struct w25q80bv_driver_t { +typedef struct _w25q80bv_driver_t { spi_bus_t* bus; gpio_t gpio_hold; gpio_t gpio_wp; - void (*target_init)(w25q80bv_driver_t* const drv); + void (*target_init)(struct _w25q80bv_driver_t* const drv); size_t page_len; size_t num_pages; size_t num_bytes; -}; +} w25q80bv_driver_t; void w25q80bv_setup(w25q80bv_driver_t* const drv); void w25q80bv_get_full_status(w25q80bv_driver_t* const drv, uint8_t* data); @@ -69,5 +65,3 @@ void w25q80bv_read( uint32_t len, uint8_t* const data); void w25q80bv_clear_status(w25q80bv_driver_t* const drv); - -#endif //__W25Q80BV_H__ diff --git a/firmware/common/w25q80bv_target.h b/firmware/common/w25q80bv_target.h index 2fad7aa3f..8da28d25d 100644 --- a/firmware/common/w25q80bv_target.h +++ b/firmware/common/w25q80bv_target.h @@ -20,11 +20,8 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __W25Q80BV_TARGET_H__ -#define __W25Q80BV_TARGET_H__ +#pragma once #include "w25q80bv.h" void w25q80bv_target_init(w25q80bv_driver_t* const drv); - -#endif /*__W25Q80BV_TARGET_H__*/ diff --git a/firmware/hackrf-common.cmake b/firmware/hackrf-common.cmake index 26a24d6e5..9a349b1ef 100644 --- a/firmware/hackrf-common.cmake +++ b/firmware/hackrf-common.cmake @@ -74,7 +74,7 @@ if(NOT DEFINED BOARD) set(BOARD HACKRF_ONE) endif() -if(BOARD STREQUAL "HACKRF_ONE" OR BOARD STREQUAL "PRALINE") +if(BOARD STREQUAL "HACKRF_ONE" OR BOARD STREQUAL "PRALINE" OR BOARD STREQUAL "UNIVERSAL") set(MCU_PARTNO LPC4320) else() set(MCU_PARTNO LPC4330) @@ -195,7 +195,8 @@ macro(DeclareTargets) ${PATH_HACKRF_FIRMWARE_COMMON}/m0_state.c ${PATH_HACKRF_FIRMWARE_COMMON}/adc.c ${PATH_HACKRF_FIRMWARE_COMMON}/da7219.c - ) + ${PATH_HACKRF_FIRMWARE_COMMON}/max283x.c + ) if(BOARD STREQUAL "RAD1O") SET(SRC_M4 @@ -216,14 +217,26 @@ macro(DeclareTargets) ${SRC_M4} ${PATH_HACKRF_FIRMWARE_COMMON}/fpga.c ${PATH_HACKRF_FIRMWARE_COMMON}/ice40_spi.c - ${PATH_HACKRF_FIRMWARE_COMMON}/max283x.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2831.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2831_target.c ) else() SET(SRC_M4 ${SRC_M4} - ${PATH_HACKRF_FIRMWARE_COMMON}/max283x.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2837_target.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2839.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2839_target.c + ) + endif() + + if(BOARD STREQUAL "UNIVERSAL") + SET(SRC_M4 + ${SRC_M4} + ${PATH_HACKRF_FIRMWARE_COMMON}/fpga.c + ${PATH_HACKRF_FIRMWARE_COMMON}/ice40_spi.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2831.c + ${PATH_HACKRF_FIRMWARE_COMMON}/max2831_target.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2837.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2837_target.c ${PATH_HACKRF_FIRMWARE_COMMON}/max2839.c diff --git a/firmware/hackrf_usb/CMakeLists.txt b/firmware/hackrf_usb/CMakeLists.txt index 3ab1beed0..3fd3ea871 100644 --- a/firmware/hackrf_usb/CMakeLists.txt +++ b/firmware/hackrf_usb/CMakeLists.txt @@ -35,7 +35,7 @@ add_custom_command( OUTPUT ${PATH_PRALINE_FPGA_OBJ} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} COMMAND ${CMAKE_COMMAND} -E copy ${PATH_PRALINE_FPGA_BIN} "fpga.bin" - COMMAND ${CMAKE_OBJCOPY} + COMMAND ${CMAKE_OBJCOPY} -I binary -O elf32-littlearm -B arm @@ -75,6 +75,26 @@ set(SRC_M4 set(SRC_M0 sgpio_m0.s) +if(BOARD STREQUAL "UNIVERSAL") + SET(SRC_M4 + ${SRC_M4} + usb_api_cpld.c + "${PATH_HACKRF_FIRMWARE_COMMON}/cpld_xc2c.c" + "${PATH_HACKRF_CPLD_DATA_C}" + "${PATH_HACKRF_FIRMWARE_COMMON}/xapp058/lenval.c" + "${PATH_HACKRF_FIRMWARE_COMMON}/xapp058/micro.c" + "${PATH_HACKRF_FIRMWARE_COMMON}/xapp058/ports.c" + + "${PATH_HACKRF_FIRMWARE_COMMON}/lz4_blk.c" + "${PATH_HACKRF_FIRMWARE_COMMON}/fpga_image.c" + "${PATH_HACKRF_FIRMWARE_COMMON}/fpga_selftest.c" + usb_api_praline.c + ) + SET(OBJ_M4 + ${PATH_PRALINE_FPGA_OBJ} + ) +endif() + if(BOARD STREQUAL "PRALINE") SET(SRC_M4 ${SRC_M4} @@ -98,7 +118,7 @@ else() ) endif() -if(BOARD STREQUAL "HACKRF_ONE" OR BOARD STREQUAL "PRALINE") +if(BOARD STREQUAL "PRALINE" OR BOARD STREQUAL "HACKRF_ONE" OR BOARD STREQUAL "UNIVERSAL") SET(SRC_M4 ${SRC_M4} "${PATH_HACKRF_FIRMWARE_COMMON}/portapack.c" diff --git a/firmware/hackrf_usb/hackrf_usb.c b/firmware/hackrf_usb/hackrf_usb.c index 6170ce6d3..fbe93f7c6 100644 --- a/firmware/hackrf_usb/hackrf_usb.c +++ b/firmware/hackrf_usb/hackrf_usb.c @@ -25,9 +25,8 @@ #include #include -#include -#include #include +#include #include #include @@ -40,30 +39,30 @@ #include #include #include +#include #include #include #include #include #include -#if defined(HACKRF_ONE) +#if !defined(PRALINE) || defined(UNIVERSAL) + #include + #include +#endif +#if !defined(RAD1O) #include + #include #endif -#if defined(PRALINE) || defined(HACKRF_ONE) +#if defined(PRALINE) || defined(HACKRF_ONE) || defined(UNIVERSAL) #include #endif -#if defined(PRALINE) || defined(HACKRF_ONE) || defined(JAWBREAKER) - #include -#endif -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include #if !(defined(DFU_MODE) || defined(RAM_MODE)) #include #include #include #endif -#else - #include - #include #endif #include "usb_api_adc.h" @@ -79,9 +78,10 @@ #include "usb_descriptor.h" #include "usb_device.h" #include "usb_endpoint.h" -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include "usb_api_praline.h" -#else +#endif +#if !defined(PRALINE) || defined(UNIVERSAL) #include "usb_api_cpld.h" #endif @@ -99,12 +99,12 @@ static usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_read_si5351c, usb_vendor_request_set_sample_rate_frac, usb_vendor_request_set_baseband_filter_bandwidth, -#ifdef RAD1O - NULL, // write_rffc5071 not used - NULL, // read_rffc5071 not used -#else +#if !defined(RAD1O) usb_vendor_request_write_rffc5071, usb_vendor_request_read_rffc5071, +#else + NULL, // write_rffc5071 not used + NULL, // read_rffc5071 not used #endif usb_vendor_request_erase_spiflash, usb_vendor_request_write_spiflash, @@ -119,7 +119,7 @@ static usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_set_vga_gain, usb_vendor_request_set_txvga_gain, NULL, // was set_if_freq -#if (defined HACKRF_ONE || defined PRALINE) +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) usb_vendor_request_set_antenna_enable, #else NULL, @@ -136,7 +136,7 @@ static usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_spiflash_status, usb_vendor_request_spiflash_clear_status, usb_vendor_request_operacake_gpio_test, -#ifdef HACKRF_ONE +#if defined(HACKRF_ONE) || defined(UNIVERSAL) usb_vendor_request_cpld_checksum, #else NULL, @@ -153,7 +153,7 @@ static usb_request_handler_fn vendor_request_handler[] = { usb_vendor_request_read_supported_platform, usb_vendor_request_set_leds, usb_vendor_request_user_config_set_bias_t_opts, -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) usb_vendor_request_write_fpga_reg, usb_vendor_request_read_fpga_reg, usb_vendor_request_p2_ctrl, @@ -249,7 +249,7 @@ void usb_set_descriptor_by_serial_number(void) } } -#ifndef PRALINE +#if !defined(PRALINE) || defined(UNIVERSAL) static bool cpld_jtag_sram_load(jtag_t* const jtag) { cpld_jtag_take(jtag); @@ -277,7 +277,7 @@ static void m0_rom_to_ram(void) memcpy(dest, (uint32_t*) (base + src), len); } -#if defined(PRALINE) && !(defined(DFU_MODE) || defined(RAM_MODE)) +#if (defined(PRALINE) || defined(UNIVERSAL)) && !(defined(DFU_MODE) || defined(RAM_MODE)) extern uint32_t _binary_fpga_bin_start; void fpga_loader_setup(void) @@ -308,72 +308,90 @@ int main(void) // This will be cleared if any self-test check fails. selftest.report.pass = true; + // Detect hardware platform before we do anything else. detect_hardware_platform(); + board_id_t board_id = detected_platform(); + pin_shutdown(); -#ifndef RAD1O - clock_gen_shutdown(); -#endif + if (board_id != BOARD_ID_RAD1O) { + clock_gen_shutdown(); + } delay_us_at_mhz(10000, 96); pin_setup(); -#ifndef PRALINE - enable_1v8_power(); - #ifndef RAD1O - /* - * On rad1o, the clock generator power supply comes from the RF supply - * which is enabled later. On H1 and Jawbreaker, the clock generator is - * on the main 3V3 supply. - */ - clock_gen_init(); - #endif -#else - enable_3v3aux_power(); + if (board_id != BOARD_ID_PRALINE) { + enable_1v8_power(); + if (board_id != BOARD_ID_RAD1O) { + /* + * On rad1o, the clock generator power supply comes from the RF supply + * which is enabled later. On H1 and Jawbreaker, the clock generator is + * on the main 3V3 supply. + */ + clock_gen_init(); + } + } else { +#if defined(PRALINE) || defined(UNIVERSAL) + enable_3v3aux_power(); #if !defined(DFU_MODE) && !defined(RAM_MODE) - enable_1v2_power(); - enable_rf_power(); - /* - * On Praline, the clock generator power supply comes from 3V3FPGA - * which is enabled when 1V2FPGA is turned on. - */ - clock_gen_init(); + enable_1v2_power(); + enable_rf_power(); + /* + * On Praline, the clock generator power supply comes from 3V3FPGA + * which is enabled when 1V2FPGA is turned on. + */ + clock_gen_init(); #endif #endif -#ifdef HACKRF_ONE - // Set up mixer before enabling RF power, because its - // GPO is used to control the antenna bias tee. - mixer_setup(&mixer); -#endif -#if (defined HACKRF_ONE || defined RAD1O) - enable_rf_power(); + } + tuning_setup(); + if (board_id == BOARD_ID_HACKRF1_OG || board_id == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + // Set up mixer before enabling RF power, because its + // GPO is used to control the antenna bias tee. + mixer_setup(&mixer, RFFC5071_VARIANT); #endif -#ifdef RAD1O - clock_gen_init(); + } + if (board_id == BOARD_ID_HACKRF1_OG || board_id == BOARD_ID_HACKRF1_R9 || + board_id == BOARD_ID_RAD1O) { +#if defined(RAD1O) || defined(HACKRF_ONE) || defined(UNIVERSAL) + enable_rf_power(); #endif + } + if (board_id == BOARD_ID_RAD1O) { + clock_gen_init(); + } cpu_clock_init(); /* Wake the M0 */ ipc_halt_m0(); ipc_start_m0((uint32_t) &__ram_m0_start__); -#ifndef PRALINE - if (!cpld_jtag_sram_load(&jtag_cpld)) { - halt_and_flash(6000000); - } -#else + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + if (!cpld_jtag_sram_load(&jtag_cpld)) { + halt_and_flash(6000000); + } +#endif + } else { +#if defined(PRALINE) || defined(UNIVERSAL) #if defined(DFU_MODE) || defined(RAM_MODE) - selftest.fpga_image_load = SKIPPED; - selftest.report.pass = false; + selftest.fpga_image_load = SKIPPED; + selftest.report.pass = false; #else - fpga_image_load(&fpga_loader, 0); + fpga_image_load(&fpga_loader, 0); #endif - delay_us_at_mhz(100, 204); - fpga_spi_selftest(); - fpga_sgpio_selftest(); + delay_us_at_mhz(100, 204); + fpga_spi_selftest(); + fpga_sgpio_selftest(); #endif + } radio_init(&radio); -#if (defined HACKRF_ONE || defined PRALINE) - portapack_init(); + if (board_id == BOARD_ID_HACKRF1_OG || board_id == BOARD_ID_HACKRF1_R9 || + board_id == BOARD_ID_PRALINE) { +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) + portapack_init(); #endif + } #ifndef DFU_MODE usb_set_descriptor_by_serial_number(); @@ -382,6 +400,35 @@ int main(void) usb_set_configuration_changed_cb(usb_configuration_changed); usb_peripheral_reset(); + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + memcpy(&usb_device, + &usb_device_hackrf_one, + sizeof(usb_device_hackrf_one)); +#endif + break; + case BOARD_ID_JAWBREAKER: +#if defined(JAWBREAKER) + memcpy(&usb_device, + &usb_device_jawbreaker, + sizeof(usb_device_jawbreaker)); +#endif + break; + case BOARD_ID_RAD1O: +#if defined(RAD1O) + memcpy(&usb_device, &usb_device_rad1o, sizeof(usb_device_rad1o)); +#endif + break; + case BOARD_ID_PRALINE: +#if defined(PRALINE) || defined(UNIVERSAL) + memcpy(&usb_device, &usb_device_praline, sizeof(usb_device_praline)); +#endif + break; + default: + break; + }; usb_device_init(0, &usb_device); usb_queue_init(&usb_endpoint_control_out_queue); @@ -400,13 +447,17 @@ int main(void) rf_path_init(&rf_path); -#ifndef RAD1O - rffc5071_lock_test(&mixer); + if (board_id != BOARD_ID_RAD1O) { +#if !defined(RAD1O) + rffc5071_lock_test(&mixer.rffc5071); #endif + } -#ifdef PRALINE - fpga_if_xcvr_selftest(); + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + fpga_if_xcvr_selftest(); #endif + } if (da7219_detect()) { operacake_skip_i2c_address(DA7219_ADDRESS); @@ -452,11 +503,13 @@ int main(void) case TRANSCEIVER_MODE_RX_SWEEP: sweep_mode(request.seq); break; -#ifndef PRALINE case TRANSCEIVER_MODE_CPLD_UPDATE: - cpld_update(); - break; + if (board_id != BOARD_ID_PRALINE) { +#if !defined(PRALINE) || defined(UNIVERSAL) + cpld_update(); #endif + } + break; default: break; } diff --git a/firmware/hackrf_usb/usb_api_adc.h b/firmware/hackrf_usb/usb_api_adc.h index e321267e2..ed4e7f934 100644 --- a/firmware/hackrf_usb/usb_api_adc.h +++ b/firmware/hackrf_usb/usb_api_adc.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_ADC_H__ -#define __USB_API_ADC_H__ +#pragma once #include #include @@ -28,5 +27,3 @@ usb_request_status_t usb_vendor_request_adc_read( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif // __USB_API_ADC_H__ diff --git a/firmware/hackrf_usb/usb_api_board_info.c b/firmware/hackrf_usb/usb_api_board_info.c index a1ad3bce5..8e64ad7f4 100644 --- a/firmware/hackrf_usb/usb_api_board_info.c +++ b/firmware/hackrf_usb/usb_api_board_info.c @@ -34,7 +34,7 @@ #include #include #include -#ifdef HACKRF_ONE +#if defined(HACKRF_ONE) || defined(UNIVERSAL) #include #include #endif @@ -131,18 +131,19 @@ usb_request_status_t usb_vendor_request_reset( if (stage == USB_TRANSFER_STAGE_SETUP) { pin_shutdown(); clock_gen_shutdown(); -#ifdef HACKRF_ONE - /* - * Set boot pins as inputs so that the bootloader reads them - * correctly after the reset. - */ if (detected_platform() == BOARD_ID_HACKRF1_R9) { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) + /* + * Set boot pins as inputs so that the bootloader reads them + * correctly after the reset. + */ const platform_gpio_t* gpio = platform_gpio(); gpio_input(gpio->h1r9_mcu_clk_en); gpio_input(gpio->h1r9_clkout_en); gpio_input(gpio->h1r9_rx); - } #endif + } + wwdt_reset(100000); usb_transfer_schedule_ack(endpoint->in); diff --git a/firmware/hackrf_usb/usb_api_board_info.h b/firmware/hackrf_usb/usb_api_board_info.h index 77e4066d2..ec50d7cef 100644 --- a/firmware/hackrf_usb/usb_api_board_info.h +++ b/firmware/hackrf_usb/usb_api_board_info.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_BOARD_INFO_H__ -#define __USB_API_BOARD_INFO_H__ +#pragma once #include @@ -52,5 +51,3 @@ usb_request_status_t usb_vendor_request_read_board_rev( usb_request_status_t usb_vendor_request_read_supported_platform( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_BOARD_INFO_H__ */ diff --git a/firmware/hackrf_usb/usb_api_cpld.c b/firmware/hackrf_usb/usb_api_cpld.c index 7d8200c33..05636a0be 100644 --- a/firmware/hackrf_usb/usb_api_cpld.c +++ b/firmware/hackrf_usb/usb_api_cpld.c @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -90,6 +91,15 @@ usb_request_status_t usb_vendor_request_cpld_checksum( static uint32_t cpld_crc; uint8_t length; + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + // supported + break; + default: + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { cpld_jtag_take(&jtag_cpld); const bool checksum_success = cpld_xc2c64a_jtag_checksum( diff --git a/firmware/hackrf_usb/usb_api_cpld.h b/firmware/hackrf_usb/usb_api_cpld.h index f508ea5fc..786a9160f 100644 --- a/firmware/hackrf_usb/usb_api_cpld.h +++ b/firmware/hackrf_usb/usb_api_cpld.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_CPLD_H__ -#define __USB_API_CPLD_H__ +#pragma once #include #include @@ -32,5 +31,3 @@ void cpld_update(void); usb_request_status_t usb_vendor_request_cpld_checksum( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_CPLD_H__ */ diff --git a/firmware/hackrf_usb/usb_api_m0_state.h b/firmware/hackrf_usb/usb_api_m0_state.h index 4e7ba2a4e..a08188d77 100644 --- a/firmware/hackrf_usb/usb_api_m0_state.h +++ b/firmware/hackrf_usb/usb_api_m0_state.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __M0_STATE_USB_H__ -#define __M0_STATE_USB_H__ +#pragma once #include #include @@ -28,5 +27,3 @@ usb_request_status_t usb_vendor_request_get_m0_state( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /*__M0_STATE_USB_H__*/ diff --git a/firmware/hackrf_usb/usb_api_operacake.h b/firmware/hackrf_usb/usb_api_operacake.h index 6e772ec1b..824311aa4 100644 --- a/firmware/hackrf_usb/usb_api_operacake.h +++ b/firmware/hackrf_usb/usb_api_operacake.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_OPERACAKE_H__ -#define __USB_API_OPERACAKE_H__ +#pragma once #include #include @@ -53,5 +52,3 @@ usb_request_status_t usb_vendor_request_operacake_get_mode( usb_request_status_t usb_vendor_request_operacake_set_dwell_times( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_OPERACAKE_H__ */ diff --git a/firmware/hackrf_usb/usb_api_praline.c b/firmware/hackrf_usb/usb_api_praline.c index 6a44da602..2a41b839c 100644 --- a/firmware/hackrf_usb/usb_api_praline.c +++ b/firmware/hackrf_usb/usb_api_praline.c @@ -24,6 +24,7 @@ #include "usb_api_praline.h" #include +#include #include #include #include @@ -35,6 +36,10 @@ usb_request_status_t usb_vendor_request_p1_ctrl( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { p1_ctrl_set(endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); @@ -46,6 +51,10 @@ usb_request_status_t usb_vendor_request_p2_ctrl( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { p2_ctrl_set(endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); @@ -57,6 +66,10 @@ usb_request_status_t usb_vendor_request_clkin_ctrl( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { clkin_ctrl_set(endpoint->setup.value & 1); usb_transfer_schedule_ack(endpoint->in); @@ -68,6 +81,10 @@ usb_request_status_t usb_vendor_request_set_narrowband_filter( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { narrowband_filter_set(endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); @@ -86,6 +103,10 @@ usb_request_status_t usb_vendor_request_set_fpga_bitstream( #else extern struct fpga_loader_t fpga_loader; + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { if (!fpga_image_load(&fpga_loader, endpoint->setup.value)) { return USB_REQUEST_STATUS_STALL; diff --git a/firmware/hackrf_usb/usb_api_praline.h b/firmware/hackrf_usb/usb_api_praline.h index df96c9217..97816373d 100644 --- a/firmware/hackrf_usb/usb_api_praline.h +++ b/firmware/hackrf_usb/usb_api_praline.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_PRALINE_H__ -#define __USB_API_PRALINE_H__ +#pragma once #include #include @@ -44,5 +43,3 @@ usb_request_status_t usb_vendor_request_set_narrowband_filter( usb_request_status_t usb_vendor_request_set_fpga_bitstream( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_PRALINE_H__ */ diff --git a/firmware/hackrf_usb/usb_api_register.c b/firmware/hackrf_usb/usb_api_register.c index 01d9fa8fb..b74589ec0 100644 --- a/firmware/hackrf_usb/usb_api_register.c +++ b/firmware/hackrf_usb/usb_api_register.c @@ -30,17 +30,19 @@ #include #include +#include #include #include #include #include #include -#if defined(PRALINE) || defined(HACKRF_ONE) || defined(JAWBREAKER) - #include -#endif -#if defined(PRALINE) +#if defined(PRALINE) || defined(UNIVERSAL) #include #endif +#if !defined(RAD1O) + #include + #include +#endif usb_request_status_t usb_vendor_request_write_max283x( usb_endpoint_t* const endpoint, @@ -136,20 +138,29 @@ usb_request_status_t usb_vendor_request_read_si5351c( } } -#ifndef RAD1O usb_request_status_t usb_vendor_request_write_rffc5071( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { +#if defined(RAD1O) + (void) endpoint; + (void) stage; + if (detected_platform() == BOARD_ID_RAD1O) { + return USB_REQUEST_STATUS_STALL; + } +#endif + if (stage == USB_TRANSFER_STAGE_SETUP) { +#if !defined(RAD1O) if (endpoint->setup.index < RFFC5071_NUM_REGS) { rffc5071_reg_write( - &mixer, + &mixer.rffc5071, endpoint->setup.index, endpoint->setup.value); usb_transfer_schedule_ack(endpoint->in); return USB_REQUEST_STATUS_OK; } +#endif return USB_REQUEST_STATUS_STALL; } else { return USB_REQUEST_STATUS_OK; @@ -160,10 +171,19 @@ usb_request_status_t usb_vendor_request_read_rffc5071( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { - uint16_t value; +#if defined(RAD1O) + (void) endpoint; + (void) stage; + if (detected_platform() == BOARD_ID_RAD1O) { + return USB_REQUEST_STATUS_STALL; + } +#endif + if (stage == USB_TRANSFER_STAGE_SETUP) { +#if !defined(RAD1O) + uint16_t value; if (endpoint->setup.index < RFFC5071_NUM_REGS) { - value = rffc5071_reg_read(&mixer, endpoint->setup.index); + value = rffc5071_reg_read(&mixer.rffc5071, endpoint->setup.index); endpoint->buffer[0] = value & 0xff; endpoint->buffer[1] = value >> 8; usb_transfer_schedule_block( @@ -175,12 +195,12 @@ usb_request_status_t usb_vendor_request_read_rffc5071( usb_transfer_schedule_ack(endpoint->out); return USB_REQUEST_STATUS_OK; } +#endif return USB_REQUEST_STATUS_STALL; } else { return USB_REQUEST_STATUS_OK; } } -#endif usb_request_status_t usb_vendor_request_set_clkout_enable( usb_endpoint_t* const endpoint, @@ -266,13 +286,18 @@ usb_request_status_t usb_vendor_request_user_config_set_bias_t_opts( return USB_REQUEST_STATUS_OK; } -#ifdef PRALINE usb_request_status_t usb_vendor_request_write_fpga_reg( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { +#if defined(PRALINE) || defined(UNIVERSAL) fpga_reg_write(&fpga, endpoint->setup.index, endpoint->setup.value); +#endif usb_transfer_schedule_ack(endpoint->in); return USB_REQUEST_STATUS_OK; } @@ -283,7 +308,12 @@ usb_request_status_t usb_vendor_request_read_fpga_reg( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() != BOARD_ID_PRALINE) { + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { +#if defined(PRALINE) || defined(UNIVERSAL) const uint8_t value = fpga_reg_read(&fpga, endpoint->setup.index); endpoint->buffer[0] = value; usb_transfer_schedule_block( @@ -292,11 +322,11 @@ usb_request_status_t usb_vendor_request_read_fpga_reg( 1, NULL, NULL); +#endif usb_transfer_schedule_ack(endpoint->out); } return USB_REQUEST_STATUS_OK; } -#endif /* * Each register is transferred as a uint8_t register number followed by a diff --git a/firmware/hackrf_usb/usb_api_register.h b/firmware/hackrf_usb/usb_api_register.h index c94710cb7..58a84aff1 100644 --- a/firmware/hackrf_usb/usb_api_register.h +++ b/firmware/hackrf_usb/usb_api_register.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_REGISTER_H__ -#define __USB_API_REGISTER_H__ +#pragma once #include #include @@ -57,7 +56,7 @@ usb_request_status_t usb_vendor_request_set_leds( usb_request_status_t usb_vendor_request_user_config_set_bias_t_opts( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) usb_request_status_t usb_vendor_request_write_fpga_reg( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); @@ -71,5 +70,3 @@ usb_request_status_t usb_vendor_request_write_radio_reg( usb_request_status_t usb_vendor_request_read_radio_reg( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_REGISTER_H__ */ diff --git a/firmware/hackrf_usb/usb_api_selftest.c b/firmware/hackrf_usb/usb_api_selftest.c index 4fe2e6288..fa5267b50 100644 --- a/firmware/hackrf_usb/usb_api_selftest.c +++ b/firmware/hackrf_usb/usb_api_selftest.c @@ -21,20 +21,18 @@ #include #include -#if defined(PRALINE) || defined(HACKRF_ONE) || defined(JAWBREAKER) +#if !defined(RAD1O) #include #endif #include #include +#include #include #include #include #include -#if !defined(PRALINE) - #include -#endif #include "usb_api_selftest.h" @@ -63,7 +61,7 @@ void append(char** dest, size_t* capacity, const char* str) } } -#ifdef PRALINE +#if defined(PRALINE) || defined(UNIVERSAL) static const char* test_result_to_str(test_result_t result) { switch (result) { @@ -82,91 +80,105 @@ static const char* test_result_to_str(test_result_t result) void generate_selftest_report(void) { + board_id_t board_id = detected_platform(); + char* s = &selftest.report.msg[0]; size_t c = sizeof(selftest.report.msg); -#ifdef RAD1O - append(&s, &c, "Mixer: MAX2871, ID: "); - append(&s, &c, itoa(selftest.mixer_id, 10)); - append(&s, &c, "\n"); -#else - append(&s, &c, "Mixer: RFFC5072, ID: "); - append(&s, &c, itoa(selftest.mixer_id >> 3, 10)); - append(&s, &c, ", Rev: "); - append(&s, &c, itoa(selftest.mixer_id & 0x7, 10)); - append(&s, &c, ", Locks: "); - bool lock; - for (int i = 0; i < NUM_LOCK_ATTEMPTS; i++) { - lock = selftest.mixer_locks[i]; - append(&s, &c, itoa(lock, 2)); - } - if (lock) { - append(&s, &c, " (PASS)"); + if (board_id == BOARD_ID_RAD1O) { +#if defined(RAD1O) + append(&s, &c, "Mixer: MAX2871, ID: "); + append(&s, &c, itoa(selftest.mixer_id, 10)); + append(&s, &c, "\n"); +#endif } else { - append(&s, &c, " (FAIL)"); - } - append(&s, &c, "\n"); +#if !defined(RAD1O) + append(&s, &c, "Mixer: RFFC5072, ID: "); + append(&s, &c, itoa(selftest.mixer_id >> 3, 10)); + append(&s, &c, ", Rev: "); + append(&s, &c, itoa(selftest.mixer_id & 0x7, 10)); + append(&s, &c, ", Locks: "); + bool lock; + for (int i = 0; i < NUM_LOCK_ATTEMPTS; i++) { + lock = selftest.mixer_locks[i]; + append(&s, &c, itoa(lock, 2)); + } + if (lock) { + append(&s, &c, " (PASS)"); + } else { + append(&s, &c, " (FAIL)"); + } + append(&s, &c, "\n"); #endif + } + append(&s, &c, "Clock: Si5351"); append(&s, &c, ", Rev: "); append(&s, &c, itoa(selftest.si5351_rev_id, 10)); append(&s, &c, ", readback: "); append(&s, &c, selftest.si5351_readback_ok ? "OK" : "FAIL"); append(&s, &c, "\n"); -#ifdef PRALINE - append(&s, &c, "Transceiver: MAX2831, RSSI mux test: "); - append(&s, &c, selftest.max2831_mux_test_ok ? "PASS" : "FAIL"); - append(&s, &c, "\n"); -#else - append(&s, &c, "Transceiver: "); - append(&s, - &c, - (detected_platform() == BOARD_ID_HACKRF1_R9 ? "MAX2839" : "MAX2837")); - append(&s, &c, ", readback success: "); - append(&s, &c, itoa(selftest.max283x_readback_register_count, 10)); - append(&s, &c, "/"); - append(&s, &c, itoa(selftest.max283x_readback_total_registers, 10)); - if (selftest.max283x_readback_register_count < - selftest.max283x_readback_total_registers) { - append(&s, &c, ", bad value: 0x"); - append(&s, &c, itoa(selftest.max283x_readback_bad_value, 10)); - append(&s, &c, ", expected: 0x"); - append(&s, &c, itoa(selftest.max283x_readback_expected_value, 10)); - } - append(&s, &c, "\n"); + + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + append(&s, &c, "Transceiver: MAX2831, RSSI mux test: "); + append(&s, &c, selftest.max2831_mux_test_ok ? "PASS" : "FAIL"); + append(&s, &c, "\n"); #endif -#ifdef PRALINE - append(&s, &c, "FPGA configuration: "); - append(&s, &c, test_result_to_str(selftest.fpga_image_load)); - append(&s, &c, "\n"); - append(&s, &c, "FPGA SPI: "); - append(&s, &c, test_result_to_str(selftest.fpga_spi)); - append(&s, &c, "\n"); - append(&s, &c, "SGPIO RX test: "); - append(&s, &c, test_result_to_str(selftest.sgpio_rx)); - append(&s, &c, "\n"); - append(&s, &c, "Loopback test: "); - append(&s, &c, test_result_to_str(selftest.xcvr_loopback)); - append(&s, &c, "\n"); - // Dump transceiver loopback measurements. - for (int i = 0; i < 4; ++i) { - struct xcvr_measurements* m = &selftest.xcvr_measurements[i]; - append(&s, &c, " "); - append(&s, &c, itoa(i, 10)); - append(&s, &c, ":"); - append(&s, &c, itoa(m->zcs_i, 10)); - append(&s, &c, ","); - append(&s, &c, itoa(m->zcs_q, 10)); - append(&s, &c, ","); - append(&s, &c, itoa(m->max_mag_i, 10)); - append(&s, &c, ","); - append(&s, &c, itoa(m->max_mag_q, 10)); - append(&s, &c, ","); - append(&s, &c, itoa(m->avg_mag_sq_i, 10)); - append(&s, &c, ","); - append(&s, &c, itoa(m->avg_mag_sq_q, 10)); + } else { +#if !defined(PRALINE) || defined(UNIVERSAL) + append(&s, &c, "Transceiver: "); + append(&s, &c, (board_id == BOARD_ID_HACKRF1_R9 ? "MAX2839" : "MAX2837")); + append(&s, &c, ", readback success: "); + append(&s, &c, itoa(selftest.max283x_readback_register_count, 10)); + append(&s, &c, "/"); + append(&s, &c, itoa(selftest.max283x_readback_total_registers, 10)); + if (selftest.max283x_readback_register_count < + selftest.max283x_readback_total_registers) { + append(&s, &c, ", bad value: 0x"); + append(&s, &c, itoa(selftest.max283x_readback_bad_value, 10)); + append(&s, &c, ", expected: 0x"); + append(&s, + &c, + itoa(selftest.max283x_readback_expected_value, 10)); + } append(&s, &c, "\n"); +#endif } + if (board_id == BOARD_ID_PRALINE) { +#if defined(PRALINE) || defined(UNIVERSAL) + append(&s, &c, "FPGA configuration: "); + append(&s, &c, test_result_to_str(selftest.fpga_image_load)); + append(&s, &c, "\n"); + append(&s, &c, "FPGA SPI: "); + append(&s, &c, test_result_to_str(selftest.fpga_spi)); + append(&s, &c, "\n"); + append(&s, &c, "SGPIO RX test: "); + append(&s, &c, test_result_to_str(selftest.sgpio_rx)); + append(&s, &c, "\n"); + append(&s, &c, "Loopback test: "); + append(&s, &c, test_result_to_str(selftest.xcvr_loopback)); + append(&s, &c, "\n"); + // Dump transceiver loopback measurements. + for (int i = 0; i < 4; ++i) { + struct xcvr_measurements* m = &selftest.xcvr_measurements[i]; + append(&s, &c, " "); + append(&s, &c, itoa(i, 10)); + append(&s, &c, ":"); + append(&s, &c, itoa(m->zcs_i, 10)); + append(&s, &c, ","); + append(&s, &c, itoa(m->zcs_q, 10)); + append(&s, &c, ","); + append(&s, &c, itoa(m->max_mag_i, 10)); + append(&s, &c, ","); + append(&s, &c, itoa(m->max_mag_q, 10)); + append(&s, &c, ","); + append(&s, &c, itoa(m->avg_mag_sq_i, 10)); + append(&s, &c, ","); + append(&s, &c, itoa(m->avg_mag_sq_q, 10)); + append(&s, &c, "\n"); + } #endif + } } usb_request_status_t usb_vendor_request_read_selftest( diff --git a/firmware/hackrf_usb/usb_api_selftest.h b/firmware/hackrf_usb/usb_api_selftest.h index 694786534..7f5af7dab 100644 --- a/firmware/hackrf_usb/usb_api_selftest.h +++ b/firmware/hackrf_usb/usb_api_selftest.h @@ -19,8 +19,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_SELFTEST_H -#define __USB_API_SELFTEST_H +#pragma once #include #include @@ -32,5 +31,3 @@ usb_request_status_t usb_vendor_request_read_selftest( usb_request_status_t usb_vendor_request_test_rtc_osc( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif // __USB_API_SELFTEST_H diff --git a/firmware/hackrf_usb/usb_api_spiflash.h b/firmware/hackrf_usb/usb_api_spiflash.h index 726734a2d..f8e3209f2 100644 --- a/firmware/hackrf_usb/usb_api_spiflash.h +++ b/firmware/hackrf_usb/usb_api_spiflash.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_SPIFLASH_H__ -#define __USB_API_SPIFLASH_H__ +#pragma once #include #include @@ -42,5 +41,3 @@ usb_request_status_t usb_vendor_request_spiflash_status( usb_request_status_t usb_vendor_request_spiflash_clear_status( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_SPIFLASH_H__ */ diff --git a/firmware/hackrf_usb/usb_api_sweep.c b/firmware/hackrf_usb/usb_api_sweep.c index 0c5dbfff8..62e8d05f8 100644 --- a/firmware/hackrf_usb/usb_api_sweep.c +++ b/firmware/hackrf_usb/usb_api_sweep.c @@ -24,11 +24,11 @@ #include #include -#include #include #include #include +#include #include #include #include @@ -44,11 +44,6 @@ #define MAX(x, y) ((x) > (y) ? (x) : (y)) #define FREQ_GRANULARITY 1000000 #define MAX_RANGES 10 -#ifndef PRALINE - #define THROWAWAY_BUFFERS 2 -#else - #define THROWAWAY_BUFFERS 1 -#endif static uint64_t sweep_freq; static uint16_t frequencies[MAX_RANGES * 2]; @@ -57,6 +52,7 @@ static uint16_t num_ranges = 0; static uint32_t dwell_blocks = 0; static uint32_t step_width = 0; static uint32_t offset = 0; +static uint32_t throwaway_buffers = 0; static enum sweep_style style = LINEAR; /* Do this before starting sweep mode with request_transceiver_mode(). */ @@ -64,6 +60,12 @@ usb_request_status_t usb_vendor_request_init_sweep( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + if (detected_platform() == BOARD_ID_PRALINE) { + throwaway_buffers = 1; + } else { + throwaway_buffers = 2; + } + uint32_t num_bytes; int i; if (stage == USB_TRANSFER_STAGE_SETUP) { @@ -120,7 +122,7 @@ void sweep_bulk_transfer_complete(void* user_data, unsigned int bytes_transferre // For each buffer transferred, we need to bump the count to allow // for the buffer(s) that are to be discarded. - m0_state.m4_count += (THROWAWAY_BUFFERS + 1) * 0x4000; + m0_state.m4_count += (throwaway_buffers + 1) * 0x4000; } void sweep_mode(uint32_t seq) @@ -173,7 +175,7 @@ void sweep_mode(uint32_t seq) // Set M0 to switch back to RX after we have received our // discard buffers. - m0_state.threshold += (0x4000 * THROWAWAY_BUFFERS); + m0_state.threshold += (0x4000 * throwaway_buffers); m0_state.next_mode = M0_MODE_RX; // Write metadata to buffer. @@ -198,7 +200,7 @@ void sweep_mode(uint32_t seq) NULL); // Use other buffer next time. - phase = (phase + 1) % THROWAWAY_BUFFERS; + phase = (phase + 1) % throwaway_buffers; if (++blocks_queued == dwell_blocks) { // Calculate next sweep frequency. diff --git a/firmware/hackrf_usb/usb_api_sweep.h b/firmware/hackrf_usb/usb_api_sweep.h index 95cfe848c..cf4c84add 100644 --- a/firmware/hackrf_usb/usb_api_sweep.h +++ b/firmware/hackrf_usb/usb_api_sweep.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_SWEEP_H__ -#define __USB_API_SWEEP_H__ +#pragma once #include @@ -38,5 +37,3 @@ usb_request_status_t usb_vendor_request_init_sweep( const usb_transfer_stage_t stage); void sweep_mode(uint32_t seq); - -#endif /* __USB_API_SWEEP_H__ */ diff --git a/firmware/hackrf_usb/usb_api_transceiver.c b/firmware/hackrf_usb/usb_api_transceiver.c index ab3d6af4c..96d3dd547 100644 --- a/firmware/hackrf_usb/usb_api_transceiver.c +++ b/firmware/hackrf_usb/usb_api_transceiver.c @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include @@ -276,6 +277,16 @@ usb_request_status_t usb_vendor_request_set_antenna_enable( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage) { + switch (detected_platform()) { + case BOARD_ID_HACKRF1_OG: + case BOARD_ID_HACKRF1_R9: + case BOARD_ID_PRALINE: + // supported + break; + default: + return USB_REQUEST_STATUS_STALL; + } + if (stage == USB_TRANSFER_STAGE_SETUP) { radio_reg_write( &radio, diff --git a/firmware/hackrf_usb/usb_api_transceiver.h b/firmware/hackrf_usb/usb_api_transceiver.h index e28e6bbb5..02385acf7 100644 --- a/firmware/hackrf_usb/usb_api_transceiver.h +++ b/firmware/hackrf_usb/usb_api_transceiver.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_TRANSCEIVER_H__ -#define __USB_API_TRANSCEIVER_H__ +#pragma once #include @@ -83,5 +82,3 @@ void transceiver_shutdown(void); void rx_mode(uint32_t seq); void tx_mode(uint32_t seq); void off_mode(uint32_t seq); - -#endif /*__USB_API_TRANSCEIVER_H__*/ diff --git a/firmware/hackrf_usb/usb_api_ui.h b/firmware/hackrf_usb/usb_api_ui.h index 62eecfa79..56688ca19 100644 --- a/firmware/hackrf_usb/usb_api_ui.h +++ b/firmware/hackrf_usb/usb_api_ui.h @@ -20,8 +20,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_API_UI_H__ -#define __USB_API_UI_H__ +#pragma once #include #include @@ -29,5 +28,3 @@ usb_request_status_t usb_vendor_request_set_ui_enable( usb_endpoint_t* const endpoint, const usb_transfer_stage_t stage); - -#endif /* end of include guard: __USB_API_UI_H__ */ diff --git a/firmware/hackrf_usb/usb_bulk_buffer.h b/firmware/hackrf_usb/usb_bulk_buffer.h index f3021bf55..e21a84ffb 100644 --- a/firmware/hackrf_usb/usb_bulk_buffer.h +++ b/firmware/hackrf_usb/usb_bulk_buffer.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_BULK_BUFFER_H__ -#define __USB_BULK_BUFFER_H__ +#pragma once #include @@ -34,5 +33,3 @@ * unless you also adjust the ldscripts. */ extern uint8_t usb_bulk_buffer[USB_BULK_BUFFER_SIZE]; - -#endif /*__USB_BULK_BUFFER_H__*/ diff --git a/firmware/hackrf_usb/usb_descriptor.c b/firmware/hackrf_usb/usb_descriptor.c index 7c98f0caa..f213f484c 100644 --- a/firmware/hackrf_usb/usb_descriptor.c +++ b/firmware/hackrf_usb/usb_descriptor.c @@ -51,7 +51,8 @@ #define USB_STRING_LANGID (0x0409) -uint8_t usb_descriptor_device[] = { +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) +uint8_t usb_descriptor_device_hackrf[] = { 18, // bLength USB_DESCRIPTOR_TYPE_DEVICE, // bDescriptorType USB_WORD(0x0200), // bcdUSB @@ -60,13 +61,50 @@ uint8_t usb_descriptor_device[] = { 0x00, // bDeviceProtocol USB_MAX_PACKET0, // bMaxPacketSize0 USB_WORD(USB_VENDOR_ID), // idVendor - USB_WORD(USB_PRODUCT_ID), // idProduct + USB_WORD(0x6089), // idProduct USB_WORD(USB_API_VERSION), // bcdDevice 0x01, // iManufacturer 0x02, // iProduct 0x04, // iSerialNumber 0x01 // bNumConfigurations }; +#endif +#if defined(JAWBREAKER) +uint8_t usb_descriptor_device_jawbreaker[] = { + 18, // bLength + USB_DESCRIPTOR_TYPE_DEVICE, // bDescriptorType + USB_WORD(0x0200), // bcdUSB + 0x00, // bDeviceClass + 0x00, // bDeviceSubClass + 0x00, // bDeviceProtocol + USB_MAX_PACKET0, // bMaxPacketSize0 + USB_WORD(USB_VENDOR_ID), // idVendor + USB_WORD(0x604B), // idProduct + USB_WORD(USB_API_VERSION), // bcdDevice + 0x01, // iManufacturer + 0x02, // iProduct + 0x04, // iSerialNumber + 0x01 // bNumConfigurations +}; +#endif +#if defined(RAD1O) +uint8_t usb_descriptor_device_rad1o[] = { + 18, // bLength + USB_DESCRIPTOR_TYPE_DEVICE, // bDescriptorType + USB_WORD(0x0200), // bcdUSB + 0x00, // bDeviceClass + 0x00, // bDeviceSubClass + 0x00, // bDeviceProtocol + USB_MAX_PACKET0, // bMaxPacketSize0 + USB_WORD(USB_VENDOR_ID), // idVendor + USB_WORD(0xCC15), // idProduct + USB_WORD(USB_API_VERSION), // bcdDevice + 0x01, // iManufacturer + 0x02, // iProduct + 0x04, // iSerialNumber + 0x01 // bNumConfigurations +}; +#endif uint8_t usb_descriptor_device_qualifier[] = { 10, // bLength @@ -185,8 +223,8 @@ uint8_t usb_descriptor_string_manufacturer[] = { 's', 0x00, }; -uint8_t usb_descriptor_string_product[] = { -#ifdef HACKRF_ONE +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +uint8_t usb_descriptor_string_product_hackrf_one[] = { 22, // bLength USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType 'H', 0x00, @@ -199,7 +237,26 @@ uint8_t usb_descriptor_string_product[] = { 'O', 0x00, 'n', 0x00, 'e', 0x00, -#elif JAWBREAKER +}; +#endif +#if defined(PRALINE) || defined(UNIVERSAL) +uint8_t usb_descriptor_string_product_praline[] = { + 22, // bLength + USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType + 'H', 0x00, + 'a', 0x00, + 'c', 0x00, + 'k', 0x00, + 'R', 0x00, + 'F', 0x00, + ' ', 0x00, + 'P', 0x00, + 'r', 0x00, + 'o', 0x00, +}; +#endif +#if defined(JAWBREAKER) +uint8_t usb_descriptor_string_product_jawbreaker[] = { 36, // bLength USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType 'H', 0x00, @@ -219,7 +276,10 @@ uint8_t usb_descriptor_string_product[] = { 'k', 0x00, 'e', 0x00, 'r', 0x00, -#elif RAD1O +}; +#endif +#if defined(RAD1O) +uint8_t usb_descriptor_string_product_rad1o[] = { 12, // bLength USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType 'r', 0x00, @@ -227,30 +287,8 @@ uint8_t usb_descriptor_string_product[] = { 'd', 0x00, '1', 0x00, 'o', 0x00, -#elif PRALINE - 22, // bLength - USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType - 'H', 0x00, - 'a', 0x00, - 'c', 0x00, - 'k', 0x00, - 'R', 0x00, - 'F', 0x00, - ' ', 0x00, - 'P', 0x00, - 'r', 0x00, - 'o', 0x00, -#else - 14, // bLength - USB_DESCRIPTOR_TYPE_STRING, // bDescriptorType - 'H', 0x00, - 'a', 0x00, - 'c', 0x00, - 'k', 0x00, - 'R', 0x00, - 'F', 0x00, -#endif }; +#endif uint8_t usb_descriptor_string_config_description[] = { 24, // bLength @@ -291,14 +329,46 @@ uint8_t usb_descriptor_string_serial_number[] = { uint8_t usb_descriptor_string_serial_number[USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN]; #endif -uint8_t* usb_descriptor_strings[] = { +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +uint8_t* usb_descriptor_strings_hackrf_one[] = { + usb_descriptor_string_languages, + usb_descriptor_string_manufacturer, + usb_descriptor_string_product_hackrf_one, + usb_descriptor_string_config_description, + usb_descriptor_string_serial_number, + 0, // TERMINATOR +}; +#endif +#if defined(PRALINE) || defined(UNIVERSAL) +uint8_t* usb_descriptor_strings_praline[] = { usb_descriptor_string_languages, usb_descriptor_string_manufacturer, - usb_descriptor_string_product, + usb_descriptor_string_product_praline, usb_descriptor_string_config_description, usb_descriptor_string_serial_number, 0, // TERMINATOR }; +#endif +#if defined(JAWBREAKER) +uint8_t* usb_descriptor_strings_jawbreaker[] = { + usb_descriptor_string_languages, + usb_descriptor_string_manufacturer, + usb_descriptor_string_product_jawbreaker, + usb_descriptor_string_config_description, + usb_descriptor_string_serial_number, + 0, // TERMINATOR +}; +#endif +#if defined(RAD1O) +uint8_t* usb_descriptor_strings_rad1o[] = { + usb_descriptor_string_languages, + usb_descriptor_string_manufacturer, + usb_descriptor_string_product_rad1o, + usb_descriptor_string_config_description, + usb_descriptor_string_serial_number, + 0, // TERMINATOR +}; +#endif uint8_t wcid_string_descriptor[] = { 18, // bLength diff --git a/firmware/hackrf_usb/usb_descriptor.h b/firmware/hackrf_usb/usb_descriptor.h index 2c2990e01..93f3eb781 100644 --- a/firmware/hackrf_usb/usb_descriptor.h +++ b/firmware/hackrf_usb/usb_descriptor.h @@ -20,22 +20,46 @@ * Boston, MA 02110-1301, USA. */ +#pragma once + #include -extern uint8_t usb_descriptor_device[]; +#if defined(HACKRF_ONE) || defined(PRALINE) || defined(UNIVERSAL) +extern uint8_t usb_descriptor_device_hackrf[]; +#endif +#if defined(JAWBREAKER) +extern uint8_t usb_descriptor_device_jawbreaker[]; +#endif +#if defined(RAD1O) +extern uint8_t usb_descriptor_device_rad1o[]; +#endif extern uint8_t usb_descriptor_device_qualifier[]; extern uint8_t usb_descriptor_configuration_full_speed[]; extern uint8_t usb_descriptor_configuration_high_speed[]; extern uint8_t usb_descriptor_string_languages[]; extern uint8_t usb_descriptor_string_manufacturer[]; -extern uint8_t usb_descriptor_string_product[]; +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +extern uint8_t usb_descriptor_string_product_hackrf_one[]; +#endif +#if defined(PRALINE) || defined(UNIVERSAL) +extern uint8_t usb_descriptor_string_product_praline[]; +#endif +#if defined(JAWBREAKER) +extern uint8_t usb_descriptor_string_product_jawbreaker[]; +#endif +#if defined(RAD1O) +extern uint8_t usb_descriptor_string_product_rad1o[]; +#endif #define USB_DESCRIPTOR_STRING_SERIAL_LEN 32 #define USB_DESCRIPTOR_STRING_SERIAL_BUF_LEN \ (USB_DESCRIPTOR_STRING_SERIAL_LEN * 2 + 2) /* UTF-16LE */ extern uint8_t usb_descriptor_string_serial_number[]; -extern uint8_t* usb_descriptor_strings[]; +extern uint8_t* usb_descriptor_strings_hackrf_one[]; +extern uint8_t* usb_descriptor_strings_jawbreaker[]; +extern uint8_t* usb_descriptor_strings_rad1o[]; +extern uint8_t* usb_descriptor_strings_praline[]; #define USB_WCID_VENDOR_REQ 0x19 extern uint8_t wcid_string_descriptor[]; diff --git a/firmware/hackrf_usb/usb_device.c b/firmware/hackrf_usb/usb_device.c index b689ce9fe..4ad464246 100644 --- a/firmware/hackrf_usb/usb_device.c +++ b/firmware/hackrf_usb/usb_device.c @@ -45,12 +45,49 @@ usb_configuration_t* usb_configurations[] = { 0, }; -usb_device_t usb_device = { - .descriptor = usb_descriptor_device, - .descriptor_strings = usb_descriptor_strings, +usb_device_t usb_device; + +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +const usb_device_t usb_device_hackrf_one = { + .descriptor = usb_descriptor_device_hackrf, + .descriptor_strings = usb_descriptor_strings_hackrf_one, + .qualifier_descriptor = usb_descriptor_device_qualifier, + .configurations = &usb_configurations, + .configuration = 0, + .wcid_string_descriptor = wcid_string_descriptor, + .wcid_feature_descriptor = wcid_feature_descriptor, +}; +#endif +#if defined(PRALINE) || defined(UNIVERSAL) +const usb_device_t usb_device_praline = { + .descriptor = usb_descriptor_device_hackrf, + .descriptor_strings = usb_descriptor_strings_praline, + .qualifier_descriptor = usb_descriptor_device_qualifier, + .configurations = &usb_configurations, + .configuration = 0, + .wcid_string_descriptor = wcid_string_descriptor, + .wcid_feature_descriptor = wcid_feature_descriptor, +}; +#endif +#if defined(JAWBREAKER) +const usb_device_t usb_device_jawbreaker = { + .descriptor = usb_descriptor_device_jawbreaker, + .descriptor_strings = usb_descriptor_strings_jawbreaker, + .qualifier_descriptor = usb_descriptor_device_qualifier, + .configurations = &usb_configurations, + .configuration = 0, + .wcid_string_descriptor = wcid_string_descriptor, + .wcid_feature_descriptor = wcid_feature_descriptor, +}; +#endif +#if defined(RAD1O) +const usb_device_t usb_device_rad1o = { + .descriptor = usb_descriptor_device_rad1o, + .descriptor_strings = usb_descriptor_strings_rad1o, .qualifier_descriptor = usb_descriptor_device_qualifier, .configurations = &usb_configurations, .configuration = 0, .wcid_string_descriptor = wcid_string_descriptor, .wcid_feature_descriptor = wcid_feature_descriptor, }; +#endif diff --git a/firmware/hackrf_usb/usb_device.h b/firmware/hackrf_usb/usb_device.h index 05008dca1..528d084dc 100644 --- a/firmware/hackrf_usb/usb_device.h +++ b/firmware/hackrf_usb/usb_device.h @@ -21,11 +21,21 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_DEVICE_H__ -#define __USB_DEVICE_H__ +#pragma once #include extern usb_device_t usb_device; -#endif /* end of include guard: __USB_DEVICE_H__ */ +#if defined(HACKRF_ONE) || defined(UNIVERSAL) +extern const usb_device_t usb_device_hackrf_one; +#endif +#if defined(PRALINE) || defined(UNIVERSAL) +extern const usb_device_t usb_device_praline; +#endif +#if defined(JAWBREAKER) +extern const usb_device_t usb_device_jawbreaker; +#endif +#if defined(RAD1O) +extern const usb_device_t usb_device_rad1o; +#endif diff --git a/firmware/hackrf_usb/usb_endpoint.h b/firmware/hackrf_usb/usb_endpoint.h index acb86ab5f..e96094f6c 100644 --- a/firmware/hackrf_usb/usb_endpoint.h +++ b/firmware/hackrf_usb/usb_endpoint.h @@ -21,8 +21,7 @@ * Boston, MA 02110-1301, USA. */ -#ifndef __USB_ENDPOINT_H__ -#define __USB_ENDPOINT_H__ +#pragma once #include #include @@ -38,5 +37,3 @@ extern USB_DECLARE_QUEUE(usb_endpoint_bulk_in); extern usb_endpoint_t usb_endpoint_bulk_out; extern USB_DECLARE_QUEUE(usb_endpoint_bulk_out); - -#endif /* end of include guard: __USB_ENDPOINT_H__ */ diff --git a/firmware/libopencm3.imp b/firmware/libopencm3.imp new file mode 100644 index 000000000..1cf19631d --- /dev/null +++ b/firmware/libopencm3.imp @@ -0,0 +1,11 @@ +# include-what-you-use mapping file for libopencm3/ +# +# Usage: include-what-you-use -Xiwyu;--mapping_file=libopencm3.imp + +[ + # allow libopencm3 to take responsibility for architecture-specific dispatch of nvic.h includes + { "include": ["", "private", "", "public"] }, + { "include": ["\"libopencm3/lpc43xx/m0/nvic.h\"", "private", "", "public"] }, + { "include": ["", "private", "", "public"] }, + { "include": ["\"libopencm3/lpc43xx/m4/nvic.h\"", "private", "", "public"] }, +] diff --git a/host/libhackrf/src/hackrf.h b/host/libhackrf/src/hackrf.h index e00ba3ff2..eeca65e03 100644 --- a/host/libhackrf/src/hackrf.h +++ b/host/libhackrf/src/hackrf.h @@ -21,8 +21,7 @@ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABI ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef __HACKRF_H__ -#define __HACKRF_H__ +#pragma once #include #include @@ -2389,5 +2388,3 @@ extern ADDAPI int ADDCALL hackrf_radio_write_register( #ifdef __cplusplus } // __cplusplus defined. #endif - -#endif /*__HACKRF_H__*/