Skip to content
Snippets Groups Projects
Commit 3e9acee8 authored by DanielePettenuzzo's avatar DanielePettenuzzo Committed by Daniel Agar
Browse files

add camera capture support for av_x board (not timer capture but gpio capture)

parent b12b4e12
No related branches found
No related tags found
No related merge requests found
...@@ -20,6 +20,7 @@ px4_add_board( ...@@ -20,6 +20,7 @@ px4_add_board(
barometer # all available barometer drivers barometer # all available barometer drivers
batt_smbus batt_smbus
camera_trigger camera_trigger
camera_capture
differential_pressure # all available differential pressure drivers differential_pressure # all available differential pressure drivers
distance_sensor # all available distance sensor drivers distance_sensor # all available distance sensor drivers
gps gps
......
...@@ -50,6 +50,7 @@ CameraCapture *g_camera_capture; ...@@ -50,6 +50,7 @@ CameraCapture *g_camera_capture;
CameraCapture::CameraCapture() : CameraCapture::CameraCapture() :
_capture_enabled(false), _capture_enabled(false),
_gpio_capture(false),
_trigger_pub(nullptr), _trigger_pub(nullptr),
_command_ack_pub(nullptr), _command_ack_pub(nullptr),
_command_sub(-1), _command_sub(-1),
...@@ -100,6 +101,22 @@ CameraCapture::capture_callback(uint32_t chan_index, ...@@ -100,6 +101,22 @@ CameraCapture::capture_callback(uint32_t chan_index,
work_queue(HPWORK, &_work_publisher, (worker_t)&CameraCapture::publish_trigger_trampoline, this, 0); work_queue(HPWORK, &_work_publisher, (worker_t)&CameraCapture::publish_trigger_trampoline, this, 0);
} }
int
CameraCapture::gpio_interrupt_routine(int irq, void *context, void *arg)
{
CameraCapture *dev = reinterpret_cast<CameraCapture *>(arg);
dev->_trigger.chan_index = 0;
dev->_trigger.edge_time = hrt_absolute_time();
dev->_trigger.edge_state = 0;
dev->_trigger.overflow = 0;
work_queue(HPWORK, &_work_publisher, (worker_t)&CameraCapture::publish_trigger_trampoline, dev, 0);
return PX4_OK;
}
void void
CameraCapture::publish_trigger_trampoline(void *arg) CameraCapture::publish_trigger_trampoline(void *arg)
{ {
...@@ -116,7 +133,7 @@ CameraCapture::publish_trigger() ...@@ -116,7 +133,7 @@ CameraCapture::publish_trigger()
struct camera_trigger_s trigger {}; struct camera_trigger_s trigger {};
// MODES 1 and 2 are not fully tested // MODES 1 and 2 are not fully tested
if (_camera_capture_mode == 0) { if (_camera_capture_mode == 0 || _gpio_capture) {
trigger.timestamp = _trigger.edge_time - uint64_t(1000 * _strobe_delay); trigger.timestamp = _trigger.edge_time - uint64_t(1000 * _strobe_delay);
trigger.seq = _capture_seq++; trigger.seq = _capture_seq++;
_last_trig_time = trigger.timestamp; _last_trig_time = trigger.timestamp;
...@@ -248,6 +265,8 @@ CameraCapture::cycle() ...@@ -248,6 +265,8 @@ CameraCapture::cycle()
void void
CameraCapture::set_capture_control(bool enabled) CameraCapture::set_capture_control(bool enabled)
{ {
#if !defined CONFIG_ARCH_BOARD_AV_X_V1
int fd = -1; int fd = -1;
fd = ::open(PX4FMU_DEVICE_PATH, O_RDWR); fd = ::open(PX4FMU_DEVICE_PATH, O_RDWR);
...@@ -295,6 +314,7 @@ CameraCapture::set_capture_control(bool enabled) ...@@ -295,6 +314,7 @@ CameraCapture::set_capture_control(bool enabled)
if (::ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) { if (::ioctl(fd, INPUT_CAP_SET_CALLBACK, (unsigned long)&conf) == 0) {
_capture_enabled = enabled; _capture_enabled = enabled;
_gpio_capture = false;
} else { } else {
PX4_ERR("Unable to set capture callback for chan %u\n", conf.channel); PX4_ERR("Unable to set capture callback for chan %u\n", conf.channel);
...@@ -302,9 +322,21 @@ CameraCapture::set_capture_control(bool enabled) ...@@ -302,9 +322,21 @@ CameraCapture::set_capture_control(bool enabled)
goto err_out; goto err_out;
} }
#else
px4_arch_gpiosetevent(GPIO_TRIG_AVX, true, false, true, &CameraCapture::gpio_interrupt_routine, this);
_capture_enabled = enabled;
_gpio_capture = true;
#endif
reset_statistics(false); reset_statistics(false);
#if !defined CONFIG_ARCH_BOARD_AV_X_V1
err_out: err_out:
::close(fd); ::close(fd);
#endif
return; return;
} }
......
...@@ -66,6 +66,10 @@ ...@@ -66,6 +66,10 @@
#define PX4FMU_DEVICE_PATH "/dev/px4fmu" #define PX4FMU_DEVICE_PATH "/dev/px4fmu"
// For AV-X board
#define GPIO_TRIG_AVX /* PD14 */ (GPIO_INPUT|GPIO_FLOAT|GPIO_EXTI|GPIO_PORTD|GPIO_PIN14)
class CameraCapture class CameraCapture
{ {
public: public:
...@@ -110,6 +114,7 @@ public: ...@@ -110,6 +114,7 @@ public:
private: private:
bool _capture_enabled; bool _capture_enabled;
bool _gpio_capture;
// Publishers // Publishers
orb_advert_t _trigger_pub; orb_advert_t _trigger_pub;
...@@ -149,6 +154,9 @@ private: ...@@ -149,6 +154,9 @@ private:
void capture_callback(uint32_t chan_index, void capture_callback(uint32_t chan_index,
hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow); hrt_abstime edge_time, uint32_t edge_state, uint32_t overflow);
// GPIO interrupt routine (for AV_X board)
static int gpio_interrupt_routine(int irq, void *context, void *arg);
// Signal capture publish // Signal capture publish
static void publish_trigger_trampoline(void *arg); static void publish_trigger_trampoline(void *arg);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment