From 2ee2ecf762a93b894c04855432e9221b3ac66c3c Mon Sep 17 00:00:00 2001 From: Jacob Dahl Date: Sat, 30 May 2026 16:37:13 -0600 Subject: [PATCH] feat(pps_capture): support raw GPIO mode for boards without io_timer When PPS_CAPTURE_GPIO is defined, init() configures the pin directly with px4_arch_gpiosetevent and skips io_timer, so CAN nodes (no PWM outputs, no timer AF on the pin) can capture PPS over EXTI. FMU boards keep the unchanged io_timer path. --- src/drivers/pps_capture/PPSCapture.cpp | 38 ++++++++++++++++++-------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/src/drivers/pps_capture/PPSCapture.cpp b/src/drivers/pps_capture/PPSCapture.cpp index 9460fe263e1..467dd9da116 100644 --- a/src/drivers/pps_capture/PPSCapture.cpp +++ b/src/drivers/pps_capture/PPSCapture.cpp @@ -39,12 +39,15 @@ */ #include "PPSCapture.hpp" -#include #include -#include #include #include +#if !defined(PPS_CAPTURE_GPIO) +# include +# include +#endif + ModuleBase::Descriptor PPSCapture::desc{task_spawn, custom_command, print_usage}; PPSCapture::PPSCapture() : @@ -56,15 +59,29 @@ PPSCapture::PPSCapture() : PPSCapture::~PPSCapture() { - if (_channel >= 0) { - io_timer_unallocate_channel(_channel); + if (_pps_capture_gpio != 0) { px4_arch_gpiosetevent(_pps_capture_gpio, false, false, false, nullptr, nullptr); } + +#if !defined(PPS_CAPTURE_GPIO) + + if (_channel >= 0) { + io_timer_unallocate_channel(_channel); + } + +#endif } bool PPSCapture::init() { - bool success = false; +#if defined(PPS_CAPTURE_GPIO) + // Boards without an io_timer (e.g. CAN nodes) point a bare GPIO at the + // PPS edge and rely on EXTI directly. + _pps_capture_gpio = PX4_MAKE_GPIO_EXTI(PPS_CAPTURE_GPIO); + const int ret_val = px4_arch_gpiosetevent(_pps_capture_gpio, true, false, true, + &PPSCapture::gpio_interrupt_callback, this); + return ret_val == PX4_OK; +#else for (unsigned i = 0; i < PWM_OUTPUT_MAX_CHANNELS; ++i) { char param_name[17]; @@ -100,13 +117,10 @@ bool PPSCapture::init() } _pps_capture_gpio = PX4_MAKE_GPIO_EXTI(io_timer_channel_get_as_pwm_input(_channel)); - int ret_val = px4_arch_gpiosetevent(_pps_capture_gpio, true, false, true, &PPSCapture::gpio_interrupt_callback, this); - - if (ret_val == PX4_OK) { - success = true; - } - - return success; + const int ret_val = px4_arch_gpiosetevent(_pps_capture_gpio, true, false, true, + &PPSCapture::gpio_interrupt_callback, this); + return ret_val == PX4_OK; +#endif } void PPSCapture::Run()