io pins: avoid using GPIO_GPIOx_OUTPUT, use timer_io_channels instead

The whole system now uses timer_io_channels, which will allow the redundant
GPIO_GPIOx_OUTPUT definitions to be removed.
This commit is contained in:
Beat Küng
2020-02-13 03:49:16 -08:00
committed by David Sidrane
parent 62b4f3487a
commit 685be9b3d1
8 changed files with 91 additions and 42 deletions
@@ -2,13 +2,12 @@
#include "gpio.h"
#include <cstring>
constexpr uint32_t CameraInterfaceGPIO::_gpios[ngpios];
#include <px4_arch/io_timer.h>
CameraInterfaceGPIO::CameraInterfaceGPIO():
CameraInterface(),
_trigger_invert(false),
_triggers{0}
_triggers{}
{
_p_polarity = param_find("TRIG_POLARITY");
@@ -25,10 +24,9 @@ void CameraInterfaceGPIO::setup()
{
for (unsigned i = 0, t = 0; i < arraySize(_pins); i++) {
// Pin range is from 1 to 5 or 6, indexes are 0 to 4 or 5
if (_pins[i] >= 0 && _pins[i] < (int)arraySize(_gpios)) {
uint32_t gpio = _gpios[_pins[i]];
// Pin range is from 0 to num_gpios - 1
if (_pins[i] >= 0 && t < (int)arraySize(_triggers) && _pins[i] < num_gpios) {
uint32_t gpio = io_timer_channel_get_gpio_output(_pins[i]);
_triggers[t++] = gpio;
px4_arch_configgpio(gpio);
px4_arch_gpiowrite(gpio, false ^ _trigger_invert);
@@ -50,17 +48,13 @@ void CameraInterfaceGPIO::trigger(bool trigger_on_true)
void CameraInterfaceGPIO::info()
{
if (ngpios == 6) {
PX4_INFO("GPIO trigger mode, pins enabled : [%d][%d][%d][%d][%d][%d], polarity : %s",
_pins[5], _pins[4], _pins[3], _pins[2], _pins[1], _pins[0],
_trigger_invert ? "ACTIVE_LOW" : "ACTIVE_HIGH");
PX4_INFO_RAW("GPIO trigger mode, pins enabled: ");
for (unsigned i = 0; i < arraySize(_pins); ++i) {
PX4_INFO_RAW("[%d]", _pins[i]);
}
if (ngpios == 5) {
PX4_INFO("GPIO trigger mode, pins enabled : [%d][%d][%d][%d][%d], polarity : %s",
_pins[4], _pins[3], _pins[2], _pins[1], _pins[0],
_trigger_invert ? "ACTIVE_LOW" : "ACTIVE_HIGH");
}
PX4_INFO_RAW(", polarity : %s\n", _trigger_invert ? "ACTIVE_LOW" : "ACTIVE_HIGH");
}
#endif /* ifdef __PX4_NUTTX */
@@ -21,13 +21,9 @@ public:
void trigger(bool trigger_on_true);
void info();
#if defined(GPIO_GPIO5_OUTPUT)
static const int ngpios = 6;
#else
static const int ngpios = 5;
#endif
private:
static const int num_gpios = DIRECT_PWM_OUTPUT_CHANNELS > 6 ? 6 : DIRECT_PWM_OUTPUT_CHANNELS;
void setup();
@@ -35,18 +31,7 @@ private:
bool _trigger_invert;
static constexpr uint32_t _gpios[ngpios] = {
GPIO_GPIO0_OUTPUT,
GPIO_GPIO1_OUTPUT,
GPIO_GPIO2_OUTPUT,
GPIO_GPIO3_OUTPUT,
GPIO_GPIO4_OUTPUT,
#if defined(GPIO_GPIO5_OUTPUT)
GPIO_GPIO5_OUTPUT
#endif
};
uint32_t _triggers[arraySize(_gpios)];
uint32_t _triggers[num_gpios];
};
#endif /* ifdef __PX4_NUTTX */