From ac47cebe864d43f667eab34b172fd462ac0fa0a2 Mon Sep 17 00:00:00 2001 From: Allen Hill Date: Thu, 3 Sep 2026 16:06:57 -0700 Subject: [PATCH] Add ~empty implementation of HAL for pico2 --- .clang-tidy | 6 +- CMakeLists.txt | 25 +-- CMakePresets.json | 6 +- .../target/avr-attiny3216/CMakeLists.txt | 1 - src/avclan/target/pico2/CMakeLists.txt | 32 ++++ src/avclan/target/pico2/board.cc | 5 + src/avclan/target/pico2/cd_timer.cc | 12 ++ src/avclan/target/pico2/media.cc | 10 ++ src/avclan/target/pico2/phy.cc | 53 ++++++ .../pico2/pimoroni_pico_plus2w_rp2350.h | 162 ++++++++++++++++++ src/avclan/target/pico2/stdio.cc | 9 + 11 files changed, 304 insertions(+), 17 deletions(-) create mode 100644 src/avclan/target/pico2/board.cc create mode 100644 src/avclan/target/pico2/cd_timer.cc create mode 100644 src/avclan/target/pico2/media.cc create mode 100644 src/avclan/target/pico2/phy.cc create mode 100644 src/avclan/target/pico2/pimoroni_pico_plus2w_rp2350.h create mode 100644 src/avclan/target/pico2/stdio.cc diff --git a/.clang-tidy b/.clang-tidy index be9b558..417eea8 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,12 +19,14 @@ Checks: | -readability-function-cognitive-complexity, -misc-non-private-member-variables-in-classes WarningsAsErrors: "" -ExcludeHeaderFilterRegex: 'out/build' -HeaderFilterRegex: '^src/.*' +ExcludeHeaderFilterRegex: "out/build" +HeaderFilterRegex: "^src/.*" SystemHeaders: false # AnalyzeTemporaryDtors: false FormatStyle: none CheckOptions: + - key: modernize-deprecated-headers.CheckHeaderFile + value: "false" - key: readability-magic-numbers.IgnorePowersOf2IntegerValues value: "true" - key: readability-magic-numbers.IgnoredIntegerValues diff --git a/CMakeLists.txt b/CMakeLists.txt index 3c1e8dd..eea396d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,16 +28,6 @@ set(CMAKE_CXX_STANDARD 23) set(CMAKE_C_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON) -add_compile_options( - -Wall -Wswitch-enum -Werror - - # Debug must not be -O0: both the vendored usart.h and avr-libc's - # #warning when __OPTIMIZE__ is undefined, and -Werror makes - # that fatal. - $<$:-Og> - $<$:-fanalyzer> - $<$:-Wno-analyzer-use-of-uninitialized-value>) - if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU") if(CMAKE_CXX_COMPILER_VERSION VERSION_LESS "13") message(FATAL_ERROR "This project requires at least GCC v13") @@ -78,6 +68,21 @@ add_library(avclan STATIC src/avclan/bus.cc ) +target_compile_definitions(avclan PUBLIC + AVCLAN_FRAME_POOL_N=${AVCLAN_FRAME_POOL_N} + AVCLAN_MSG_QUEUE_SIZE=${AVCLAN_MSG_QUEUE_SIZE} +) + +target_compile_options(avclan PUBLIC + -Wall -Wswitch-enum -Werror + + # Debug must not be -O0: both the vendored usart.h and avr-libc's + # #warning when __OPTIMIZE__ is undefined, and -Werror makes + # that fatal. + $<$:-Og> + $<$:-fanalyzer> + $<$:-Wno-analyzer-use-of-uninitialized-value>) + # avclan exports its public generic headers (src/avclan) to consumers and # reaches into src/ for sibling headers (stdio.h, board.h) during its own # build. The selected target adds its own per-target include path. diff --git a/CMakePresets.json b/CMakePresets.json index 98e206c..8054bb6 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -61,7 +61,7 @@ }, "environment": { "PICO_PLATFORM": "rp2350-arm-s", - "PICO_BOARD": "pico2" + "PICO_BOARD": "pimoroni_pico_plus2w_rp2350" } }, { @@ -71,9 +71,7 @@ "description": "", "generator": "Ninja", "environment": { - "PICO_COMPILER": "pico_arm_gcc", - "CC": "/usr/bin/gcc-15", - "CXX": "/usr/bin/g++-15" + "PICO_COMPILER": "pico_arm_gcc" } }, { diff --git a/src/avclan/target/avr-attiny3216/CMakeLists.txt b/src/avclan/target/avr-attiny3216/CMakeLists.txt index 6ec7870..c048aae 100644 --- a/src/avclan/target/avr-attiny3216/CMakeLists.txt +++ b/src/avclan/target/avr-attiny3216/CMakeLists.txt @@ -150,7 +150,6 @@ target_compile_definitions(avclan PUBLIC __CLK_PRESCALE_DIV=__${CLK_PRESCALE_DIV} TCB_CLKSEL=${TCB_CLKSEL} RTC_STATUS_PERIOD_MS=${RTC_STATUS_PERIOD_MS} - AVCLAN_FRAME_POOL_N=${AVCLAN_FRAME_POOL_N} ) target_compile_options(avclan PUBLIC --param=min-pagesize=0 diff --git a/src/avclan/target/pico2/CMakeLists.txt b/src/avclan/target/pico2/CMakeLists.txt index e69de29..0bcf0e1 100644 --- a/src/avclan/target/pico2/CMakeLists.txt +++ b/src/avclan/target/pico2/CMakeLists.txt @@ -0,0 +1,32 @@ +list(APPEND PICO_CONFIG_HEADER_FILES ${CMAKE_CURRENT_LIST_DIR}/pimoroni_pico_plus2w_rp2350.h) +pico_sdk_init() + +target_sources(avclan PRIVATE + phy.cc + media.cc + cd_timer.cc + board.cc + stdio.cc + ) + +target_link_libraries(avclan PUBLIC + pico_stdlib pico_stdio_usb +) + +add_executable(mockingboard_pico + ${avclan-mockingboard_SOURCE_DIR}/src/sniffer.cc +) +target_link_libraries(mockingboard_pico PUBLIC + avclan +) + +# Silence warnings in TinyUSB, and only there. +file(GLOB_RECURSE _tinyusb_sources ${PICO_TINYUSB_PATH}/src/*.c) +set_source_files_properties(${_tinyusb_sources} + TARGET_DIRECTORY avclan mockingboard_pico + PROPERTIES COMPILE_OPTIONS "-w") +unset(_tinyusb_sources) + +pico_add_extra_outputs(mockingboard_pico) +pico_set_float_implementation(mockingboard_pico none) +pico_set_double_implementation(mockingboard_pico none) diff --git a/src/avclan/target/pico2/board.cc b/src/avclan/target/pico2/board.cc new file mode 100644 index 0000000..3b2218b --- /dev/null +++ b/src/avclan/target/pico2/board.cc @@ -0,0 +1,5 @@ +#include "hal/board.h" + +extern "C" void board_init() {} + +extern "C" void board_enable_interrupts() {} diff --git a/src/avclan/target/pico2/cd_timer.cc b/src/avclan/target/pico2/cd_timer.cc new file mode 100644 index 0000000..d00d29a --- /dev/null +++ b/src/avclan/target/pico2/cd_timer.cc @@ -0,0 +1,12 @@ +#include "hal/cd_timer.h" + +extern "C" void cdtimer_init(void *ptr, void(clbk)(void *), + bool(isplay)(void *)) {} + +extern "C" void cdtimer_reset() {} + +extern "C" void cdtimer_restore() {} + +extern "C" void cdtimer_disable() {} + +volatile bool cdtimer_pending_flag; diff --git a/src/avclan/target/pico2/media.cc b/src/avclan/target/pico2/media.cc new file mode 100644 index 0000000..281f107 --- /dev/null +++ b/src/avclan/target/pico2/media.cc @@ -0,0 +1,10 @@ +#include "hal/media.h" + +extern "C" void media_init(void) {} + +extern "C" void media_action(MediaAction fn) {} + +#ifndef NDEBUG +extern "C" bool media_mic_toggle(void) { return false; } +extern "C" bool media_busy(void) { return true; } +#endif diff --git a/src/avclan/target/pico2/phy.cc b/src/avclan/target/pico2/phy.cc new file mode 100644 index 0000000..ecd0713 --- /dev/null +++ b/src/avclan/target/pico2/phy.cc @@ -0,0 +1,53 @@ +#include "hal/phy.h" +#include "avclan.h" + +using namespace avclan; +using enum detail::Error::Read; +using enum detail::Error::Send; + +extern "C" void phy_init() {} + +extern "C" void phy_mute(bool mute) {} + +extern "C" bool phy_is_muted() { return true; } + +extern "C" bool phy_active() { return false; } + +extern "C" void phy_guard_enter() {} + +extern "C" void phy_guard_leave() {} + +extern "C" Read phy_read_startbit() { return BAD_STARTBIT; } + +extern "C" Send phy_send_startbit() { return MUTED; } + +extern "C" Send phy_read_ack() { return MUTED; } + +extern "C" void phy_send_ack() {} + +extern "C" void phy_send_bit(Bit bit) {} + +extern "C" Bit phy_send_bits_u8(const uint8_t *bits, int8_t len) { + return Bit::bit_zero; +}; + +extern "C" Bit phy_send_bits_u16(const uint16_t *bits, int8_t len) { + return Bit::bit_zero; +}; + +extern "C" Bit phy_send_byte(const uint8_t *byte) { return Bit::bit_zero; }; + +extern "C" Bit phy_read_bits_u8(uint8_t *bits, uint8_t len) { + return Bit::bit_zero; +}; + +extern "C" Bit phy_read_bits_u16(uint16_t *bits, int8_t len) { + return Bit::bit_zero; +}; + +extern "C" Bit phy_read_byte(uint8_t *byte) { return Bit::bit_zero; }; + +#if !defined(NDEBUG) && defined(MEASURE_BUS) +// Sample and dump bus bit timing over the serial link (REPL `M`). +void phy_measure(void); +#endif diff --git a/src/avclan/target/pico2/pimoroni_pico_plus2w_rp2350.h b/src/avclan/target/pico2/pimoroni_pico_plus2w_rp2350.h new file mode 100644 index 0000000..aa2c987 --- /dev/null +++ b/src/avclan/target/pico2/pimoroni_pico_plus2w_rp2350.h @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2020 Raspberry Pi (Trading) Ltd. + * + * SPDX-License-Identifier: BSD-3-Clause + */ + +// ----------------------------------------------------- +// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLER SO +// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES +// ----------------------------------------------------- + +// This header may be included by other board headers as "boards/pimoroni_pico_plus2w_rp2350.h" + +// pico_cmake_set PICO_PLATFORM=rp2350 + +#ifndef _BOARDS_PIMORONI_PICO_PLUS2W_RP2350_H +#define _BOARDS_PIMORONI_PICO_PLUS2W_RP2350_H + +// For board detection +#define PIMORONI_PICO_PLUS2_RP2350 +#define PIMORONI_PICO_PLUS2W_RP2350 + +// --- BOARD SPECIFIC --- +#define SPICE_SPI 0 +#define SPICE_TX_MISO_PIN 32 +#define SPICE_RX_CS_PIN 33 +#define SPICE_NETLIGHT_SCK_PIN 34 +#define SPICE_RESET_MOSI_PIN 35 +#define SPICE_PWRKEY_BL_PIN 36 + +#define PIMORONI_PICO_PLUS2_USER_SW_PIN 45 +#define PIMORONI_PICO_PLUS2_PSRAM_CS_PIN 47 + +// --- UART --- +#ifndef PICO_DEFAULT_UART +#define PICO_DEFAULT_UART 0 +#endif +#ifndef PICO_DEFAULT_UART_TX_PIN +#define PICO_DEFAULT_UART_TX_PIN 0 +#endif +#ifndef PICO_DEFAULT_UART_RX_PIN +#define PICO_DEFAULT_UART_RX_PIN 1 +#endif + +// --- LED --- +#ifndef PICO_DEFAULT_LED_PIN +#define PICO_DEFAULT_LED_PIN 25 +#endif +// no PICO_DEFAULT_WS2812_PIN + +// --- I2C --- +#ifndef PICO_DEFAULT_I2C +#define PICO_DEFAULT_I2C 0 +#endif +#ifndef PICO_DEFAULT_I2C_SDA_PIN +#define PICO_DEFAULT_I2C_SDA_PIN 4 +#endif +#ifndef PICO_DEFAULT_I2C_SCL_PIN +#define PICO_DEFAULT_I2C_SCL_PIN 5 +#endif + +// --- SPI --- +#ifndef PICO_DEFAULT_SPI +#define PICO_DEFAULT_SPI 0 +#endif +#ifndef PICO_DEFAULT_SPI_SCK_PIN +#define PICO_DEFAULT_SPI_SCK_PIN SPICE_NETLIGHT_SCK_PIN +#endif +#ifndef PICO_DEFAULT_SPI_TX_PIN +#define PICO_DEFAULT_SPI_TX_PIN SPICE_RESET_MOSI_PIN +#endif +#ifndef PICO_DEFAULT_SPI_RX_PIN +#define PICO_DEFAULT_SPI_RX_PIN SPICE_TX_MISO_PIN +#endif +#ifndef PICO_DEFAULT_SPI_CSN_PIN +#define PICO_DEFAULT_SPI_CSN_PIN SPICE_RX_CS_PIN +#endif + +// --- FLASH --- + +#define PICO_BOOT_STAGE2_CHOOSE_W25Q080 1 + +#ifndef PICO_FLASH_SPI_CLKDIV +#define PICO_FLASH_SPI_CLKDIV 2 +#endif + +// pico_cmake_set_default PICO_FLASH_SIZE_BYTES = (16 * 1024 * 1024) +#ifndef PICO_FLASH_SIZE_BYTES +#define PICO_FLASH_SIZE_BYTES (16 * 1024 * 1024) +#endif + +#ifndef CYW43_WL_GPIO_COUNT +#define CYW43_WL_GPIO_COUNT 3 +#endif + +#ifndef CYW43_WL_GPIO_LED_PIN +#define CYW43_WL_GPIO_LED_PIN 0 +#endif + +// If CYW43_WL_GPIO_VBUS_PIN is defined then a CYW43 GPIO has to be used to read VBUS. +// This can be passed to cyw43_arch_gpio_get to determine if the device is battery powered. +// PICO_VBUS_PIN and CYW43_WL_GPIO_VBUS_PIN should not both be defined. + +// no CYW43_WL_GPIO_VBUS_PIN + +// If CYW43_USES_VSYS_PIN is defined then CYW43 uses the VSYS GPIO (defined by PICO_VSYS_PIN) for other purposes. +// If this is the case, to use the VSYS GPIO it's necessary to ensure CYW43 is not using it. +// This can be achieved by wrapping the use of the VSYS GPIO in cyw43_thread_enter / cyw43_thread_exit. + +// no CYW43_USES_VSYS_PIN + +// The GPIO Pin used to read VBUS to determine if the device is battery powered. +#ifndef PICO_VBUS_PIN +#define PICO_VBUS_PIN 24 +#endif + +// The GPIO Pin used to monitor VSYS. Typically you would use this with ADC. +// There is an example in adc/read_vsys in pico-examples. +#ifndef PICO_VSYS_PIN +#define PICO_VSYS_PIN 43 +#endif + +#ifndef PICO_RP2350_A2_SUPPORTED +#define PICO_RP2350_A2_SUPPORTED 1 +#endif + +// PICO_CONFIG: CYW43_PIN_WL_DYNAMIC, flag to indicate if cyw43 SPI pins can be changed at runtime, type=bool, default=false, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_PIN_WL_DYNAMIC +#define CYW43_PIN_WL_DYNAMIC 1 +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_REG_ON, gpio pin to power up the cyw43 chip, type=int, default=23, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_REG_ON +#define CYW43_DEFAULT_PIN_WL_REG_ON 23u +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_DATA_OUT, gpio pin for spi data out to the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_DATA_OUT +#define CYW43_DEFAULT_PIN_WL_DATA_OUT 24u +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_DATA_IN, gpio pin for spi data in from the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_DATA_IN +#define CYW43_DEFAULT_PIN_WL_DATA_IN 24u +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_HOST_WAKE, gpio (irq) pin for the irq line from the cyw43 chip, type=int, default=24, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_HOST_WAKE +#define CYW43_DEFAULT_PIN_WL_HOST_WAKE 24u +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_CLOCK, gpio pin for the spi clock line to the cyw43 chip, type=int, default=29, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_CLOCK +#define CYW43_DEFAULT_PIN_WL_CLOCK 29u +#endif + +// PICO_CONFIG: CYW43_DEFAULT_PIN_WL_CS, gpio pin for the spi chip select to the cyw43 chip, type=int, default=25, advanced=true, group=pico_cyw43_driver +#ifndef CYW43_DEFAULT_PIN_WL_CS +#define CYW43_DEFAULT_PIN_WL_CS 25u +#endif + +#endif \ No newline at end of file diff --git a/src/avclan/target/pico2/stdio.cc b/src/avclan/target/pico2/stdio.cc new file mode 100644 index 0000000..7de9405 --- /dev/null +++ b/src/avclan/target/pico2/stdio.cc @@ -0,0 +1,9 @@ + +#include "hal/stdio.h" +#include "pico/stdio_usb.h" + +extern "C" void stdio_init() { stdio_usb_init(); } + +extern "C" bool stdio_write_nonblock(const void *buf, uint8_t len) { + return false; +}