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()