PX4 Firmware
PX4 Autopilot Software http://px4.io
pwm.cpp
Go to the documentation of this file.
1 #ifdef __PX4_NUTTX
2 
3 #include <sys/ioctl.h>
4 #include <lib/mathlib/mathlib.h>
5 #include <parameters/param.h>
6 
7 
9 #include "pwm.h"
10 
11 
12 CameraInterfacePWM::CameraInterfacePWM():
14 {
15  param_get(param_find("TRIG_PWM_SHOOT"), &_pwm_camera_shoot);
16  param_get(param_find("TRIG_PWM_NEUTRAL"), &_pwm_camera_neutral);
17  get_pins();
18  setup();
19 }
20 
21 CameraInterfacePWM::~CameraInterfacePWM()
22 {
23  // Deinitialise trigger channels
25 }
26 
27 void CameraInterfacePWM::setup()
28 {
29  // Precompute the bitmask for enabled channels
30  uint8_t pin_bitmask = 0;
31 
32  for (unsigned i = 0; i < arraySize(_pins); i++) {
33  if (_pins[i] >= 0) {
34  pin_bitmask |= (1 << _pins[i]);
35  }
36  }
37 
38  // Initialize and arm channels
39  up_pwm_trigger_init(pin_bitmask);
40 
41  // Set neutral pulsewidths
42  for (unsigned i = 0; i < arraySize(_pins); i++) {
43  if (_pins[i] >= 0) {
44  up_pwm_trigger_set(_pins[i], math::constrain(_pwm_camera_neutral, 0, 2000));
45  }
46  }
47 
48 }
49 
50 void CameraInterfacePWM::trigger(bool trigger_on_true)
51 {
52  for (unsigned i = 0; i < arraySize(_pins); i++) {
53  if (_pins[i] >= 0) {
54  // Set all valid pins to shoot or neutral levels
55  up_pwm_trigger_set(_pins[i], math::constrain(trigger_on_true ? _pwm_camera_shoot : _pwm_camera_neutral, 0, 2000));
56  }
57  }
58 }
59 
61 {
62  PX4_INFO("PWM trigger mode (generic), pins enabled : [%d][%d][%d][%d][%d][%d]",
63  _pins[5], _pins[4], _pins[3], _pins[2], _pins[1], _pins[0]);
64 }
65 
66 #endif /* ifdef __PX4_NUTTX */
__EXPORT void up_pwm_trigger_deinit(void)
De-initialise the PWM trigger outputs.
constexpr _Tp constrain(_Tp val, _Tp min_val, _Tp max_val)
Definition: Limits.hpp:66
Interface with cameras via pwm.
__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
Global flash based parameter store.
__EXPORT param_t param_find(const char *name)
Look up a parameter by name.
Definition: parameters.cpp:370
__BEGIN_DECLS __EXPORT int up_pwm_trigger_init(uint32_t channel_mask)
Intialise the PWM servo outputs using the specified configuration.
#define arraySize(a)
__EXPORT int up_pwm_trigger_set(unsigned channel, uint16_t value)
Set the current output value for a channel.
virtual void setup()
setup the interface