Skip to content

Commit

Permalink
pps_capture: make it configurable via output functions
Browse files Browse the repository at this point in the history
  • Loading branch information
bkueng authored and Igor-Misic committed Dec 14, 2021
1 parent 292a86d commit 25207a9
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 12 deletions.
61 changes: 49 additions & 12 deletions src/drivers/pps_capture/PPSCapture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,15 @@
*/

#include "PPSCapture.hpp"
#include "board_config.h"
#include <px4_arch/io_timer.h>
#include <board_config.h>
#include <parameters/param.h>

#ifdef BOARD_WITH_IO
# define PARAM_PREFIX "PWM_AUX"
#else
# define PARAM_PREFIX "PWM_MAIN"
#endif

PPSCapture::PPSCapture() :
ScheduledWorkItem(MODULE_NAME, px4::wq_configurations::hp_default)
Expand All @@ -49,36 +56,66 @@ PPSCapture::PPSCapture() :

PPSCapture::~PPSCapture()
{
#if defined(PPS_CAPTURE_CHANNEL)
io_timer_unallocate_channel(PPS_CAPTURE_CHANNEL);
px4_arch_gpiosetevent(_pps_capture_gpio, false, false, false, nullptr, nullptr);
#endif
if (_channel >= 0) {
io_timer_unallocate_channel(_channel);
px4_arch_gpiosetevent(_pps_capture_gpio, false, false, false, nullptr, nullptr);
}
}

bool PPSCapture::init()
{
bool success = false;

param_t p_ctrl_alloc = param_find("SYS_CTRL_ALLOC");
int32_t ctrl_alloc = 0;

if (p_ctrl_alloc != PARAM_INVALID) {
param_get(p_ctrl_alloc, &ctrl_alloc);
}

if (ctrl_alloc == 1) {

for (unsigned i = 0; i < 16; ++i) {
char param_name[17];
snprintf(param_name, sizeof(param_name), "%s_%s%d", PARAM_PREFIX, "FUNC", i + 1);
param_t function_handle = param_find(param_name);
int32_t function;

if (function_handle != PARAM_INVALID && param_get(function_handle, &function) == 0) {
if (function == 2064) { // PPS_Input
_channel = i;
}
}
}
}

#if defined(PPS_CAPTURE_CHANNEL)

int ret = io_timer_allocate_channel(PPS_CAPTURE_CHANNEL, IOTimerChanMode_PPS);
if (_channel == -1) {
_channel = PPS_CAPTURE_CHANNEL;
}

#endif

if (_channel == -1) {
PX4_WARN("No pps channel configured");
return false;
}

int ret = io_timer_allocate_channel(_channel, IOTimerChanMode_PPS);

if (ret != PX4_OK) {
PX4_ERR("gpio alloc failed (%i) for PPS at channel (%d)", ret, PPS_CAPTURE_CHANNEL);
PX4_ERR("gpio alloc failed (%i) for PPS at channel (%d)", ret, _channel);
return false;
}

_pps_capture_gpio = PX4_MAKE_GPIO_EXTI(io_timer_channel_get_as_pwm_input(PPS_CAPTURE_CHANNEL));
_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;
}

#else
#error Driver requires PPS_CAPTURE_CHANNEL to be enabled
#endif

return success;
}

Expand Down
1 change: 1 addition & 0 deletions src/drivers/pps_capture/PPSCapture.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ class PPSCapture : public ModuleBase<PPSCapture>, public px4::ScheduledWorkItem
private:
void Run() override;

int _channel{-1};
uint32_t _pps_capture_gpio{0};
uORB::Publication<pps_capture_s> _pps_capture_pub{ORB_ID(pps_capture)};
uORB::Subscription _sensor_gps_sub{ORB_ID(sensor_gps)};
Expand Down
6 changes: 6 additions & 0 deletions src/lib/mixer_module/output_functions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,9 @@ functions:
condition: "CAM_CAP_FBACK==0"
text: "Camera feedback needs to be enabled and configured via CAM_CAP_* parameters."
exclude_from_actuator_testing: true
PPS_Input:
start: 2064
note:
condition: "PPS_CAP_ENABLE==0"
text: "PPS needs to be enabled via PPS_CAP_ENABLE parameter."
exclude_from_actuator_testing: true

0 comments on commit 25207a9

Please sign in to comment.