PX4 Firmware
PX4 Autopilot Software http://px4.io
gpio.cpp
Go to the documentation of this file.
1 #ifdef __PX4_NUTTX
2 
3 #include "gpio.h"
4 #include <cstring>
5 
6 constexpr uint32_t CameraInterfaceGPIO::_gpios[ngpios];
7 
8 CameraInterfaceGPIO::CameraInterfaceGPIO():
10  _trigger_invert(false),
11  _triggers{0}
12 {
13  _p_polarity = param_find("TRIG_POLARITY");
14 
15  // polarity of the trigger (0 = active low, 1 = active high )
16  int32_t polarity;
17  param_get(_p_polarity, &polarity);
18  _trigger_invert = (polarity == 0);
19 
20  get_pins();
21  setup();
22 }
23 
24 void CameraInterfaceGPIO::setup()
25 {
26  for (unsigned i = 0, t = 0; i < arraySize(_pins); i++) {
27 
28  // Pin range is from 1 to 5 or 6, indexes are 0 to 4 or 5
29 
30  if (_pins[i] >= 0 && _pins[i] < (int)arraySize(_gpios)) {
31  uint32_t gpio = _gpios[_pins[i]];
32  _triggers[t++] = gpio;
33  px4_arch_configgpio(gpio);
34  px4_arch_gpiowrite(gpio, false ^ _trigger_invert);
35  }
36  }
37 }
38 
39 void CameraInterfaceGPIO::trigger(bool trigger_on_true)
40 {
41  bool trigger_state = trigger_on_true ^ _trigger_invert;
42 
43  for (unsigned i = 0; i < arraySize(_triggers); i++) {
44 
45  if (_triggers[i] == 0) { break; }
46 
47  px4_arch_gpiowrite(_triggers[i], trigger_state);
48  }
49 }
50 
52 {
53  if (ngpios == 6) {
54  PX4_INFO("GPIO trigger mode, pins enabled : [%d][%d][%d][%d][%d][%d], polarity : %s",
55  _pins[5], _pins[4], _pins[3], _pins[2], _pins[1], _pins[0],
56  _trigger_invert ? "ACTIVE_LOW" : "ACTIVE_HIGH");
57  }
58 
59  if (ngpios == 5) {
60  PX4_INFO("GPIO trigger mode, pins enabled : [%d][%d][%d][%d][%d], polarity : %s",
61  _pins[4], _pins[3], _pins[2], _pins[1], _pins[0],
62  _trigger_invert ? "ACTIVE_LOW" : "ACTIVE_HIGH");
63  }
64 }
65 
66 #endif /* ifdef __PX4_NUTTX */
__EXPORT int param_get(param_t param, void *val)
Copy the value of a parameter.
Definition: parameters.cpp:589
int info()
Print a little info about the driver.
void get_pins()
get the hardware configuration
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
Definition: parameters.cpp:370
#define arraySize(a)
virtual void setup()
setup the interface