mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-11-28 19:21:03 +08:00
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.
This commit is contained in:
1 parent
9f6a714bac
commit
2ee2ecf762
1 file changed
+26
-12
@@ -39,12 +39,15 @@
|
||||
*/
|
||||
|
||||
#include "PPSCapture.hpp"
|
||||
#include <px4_arch/io_timer.h>
|
||||
#include <board_config.h>
|
||||
#include <parameters/param.h>
|
||||
#include <px4_platform_common/events.h>
|
||||
#include <systemlib/mavlink_log.h>
|
||||
|
||||
#if !defined(PPS_CAPTURE_GPIO)
|
||||
# include <px4_arch/io_timer.h>
|
||||
# include <parameters/param.h>
|
||||
#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()
|
||||
|
||||
Reference in new issue
Block a user