From 5254ee03c2a94d38c1d6d354bc41f61fe0462c78 Mon Sep 17 00:00:00 2001 From: Georgii Staroselskii Date: Tue, 31 Oct 2017 19:36:51 +0300 Subject: [PATCH] AP_HAL_Linux: use GPIO_Sysfs for Edge --- libraries/AP_HAL_Linux/GPIO.h | 3 ++- libraries/AP_HAL_Linux/GPIO_Edge.cpp | 28 ++++++++++++++++++++++ libraries/AP_HAL_Linux/GPIO_Edge.h | 20 ++++++++++++++++ libraries/AP_HAL_Linux/GPIO_RPI.cpp | 1 - libraries/AP_HAL_Linux/HAL_Linux_Class.cpp | 4 ++-- libraries/AP_HAL_Linux/Heat_Pwm.cpp | 5 ++-- 6 files changed, 55 insertions(+), 6 deletions(-) create mode 100644 libraries/AP_HAL_Linux/GPIO_Edge.cpp create mode 100644 libraries/AP_HAL_Linux/GPIO_Edge.h diff --git a/libraries/AP_HAL_Linux/GPIO.h b/libraries/AP_HAL_Linux/GPIO.h index e671e3414d..503cf4474b 100644 --- a/libraries/AP_HAL_Linux/GPIO.h +++ b/libraries/AP_HAL_Linux/GPIO.h @@ -24,7 +24,6 @@ private: CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BLUE #include "GPIO_BBB.h" #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \ - CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \ @@ -32,6 +31,8 @@ private: #include "GPIO_RPI.h" #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 #include "GPIO_Navio2.h" +#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE +#include "GPIO_Edge.h" #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE #include "GPIO_Minnow.h" #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP diff --git a/libraries/AP_HAL_Linux/GPIO_Edge.cpp b/libraries/AP_HAL_Linux/GPIO_Edge.cpp new file mode 100644 index 0000000000..4b49e1e9bb --- /dev/null +++ b/libraries/AP_HAL_Linux/GPIO_Edge.cpp @@ -0,0 +1,28 @@ +#include + +#include "GPIO_Edge.h" + +#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE + +const unsigned Linux::GPIO_Sysfs::pin_table[] = { + [EDGE_GPIO_PWM1] = 500, + [EDGE_GPIO_PWM2] = 501, + [EDGE_GPIO_PWM3] = 502, + [EDGE_GPIO_PWM4] = 503, + [EDGE_GPIO_PWM5] = 504, + [EDGE_GPIO_PWM6] = 505, + [EDGE_GPIO_PWM7] = 506, + [EDGE_GPIO_PWM8] = 507, + [EDGE_GPIO_PWM9] = 508, + [EDGE_GPIO_PWM10] = 509, + [EDGE_GPIO_PWM11] = 510, + [EDGE_GPIO_PWM12] = 511, + [EDGE_GPIO_HEAT_ENABLE] = 26, +}; + +const uint8_t Linux::GPIO_Sysfs::n_pins = _EDGE_GPIO_MAX; + +static_assert(ARRAY_SIZE(Linux::GPIO_Sysfs::pin_table) == _EDGE_GPIO_MAX, + "GPIO pin_table must have the same size of entries in enum gpio_minnow"); + +#endif diff --git a/libraries/AP_HAL_Linux/GPIO_Edge.h b/libraries/AP_HAL_Linux/GPIO_Edge.h new file mode 100644 index 0000000000..92f711f393 --- /dev/null +++ b/libraries/AP_HAL_Linux/GPIO_Edge.h @@ -0,0 +1,20 @@ +#pragma once + +#include "GPIO_Sysfs.h" + +enum gpio_edge { + EDGE_GPIO_PWM1, + EDGE_GPIO_PWM2, + EDGE_GPIO_PWM3, + EDGE_GPIO_PWM4, + EDGE_GPIO_PWM5, + EDGE_GPIO_PWM6, + EDGE_GPIO_PWM7, + EDGE_GPIO_PWM8, + EDGE_GPIO_PWM9, + EDGE_GPIO_PWM10, + EDGE_GPIO_PWM11, + EDGE_GPIO_PWM12, + EDGE_GPIO_HEAT_ENABLE, + _EDGE_GPIO_MAX, +}; diff --git a/libraries/AP_HAL_Linux/GPIO_RPI.cpp b/libraries/AP_HAL_Linux/GPIO_RPI.cpp index 6682b777ad..388df87c6c 100644 --- a/libraries/AP_HAL_Linux/GPIO_RPI.cpp +++ b/libraries/AP_HAL_Linux/GPIO_RPI.cpp @@ -4,7 +4,6 @@ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \ - CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI #include diff --git a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp index 610b004b22..c560f8b29b 100644 --- a/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp +++ b/libraries/AP_HAL_Linux/HAL_Linux_Class.cpp @@ -111,13 +111,13 @@ static GPIO_BBB gpioDriver; use the RPI gpio driver on Navio */ #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \ - CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI static GPIO_RPI gpioDriver; -#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 +#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \ + CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE static GPIO_Sysfs gpioDriver; #elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_MINLURE || \ CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BEBOP || \ diff --git a/libraries/AP_HAL_Linux/Heat_Pwm.cpp b/libraries/AP_HAL_Linux/Heat_Pwm.cpp index 5883387f63..75eafcb949 100644 --- a/libraries/AP_HAL_Linux/Heat_Pwm.cpp +++ b/libraries/AP_HAL_Linux/Heat_Pwm.cpp @@ -30,6 +30,7 @@ #include #include "Heat_Pwm.h" +#include "GPIO.h" extern const AP_HAL::HAL& hal; @@ -42,8 +43,8 @@ HeatPwm::HeatPwm(uint8_t pwm_num, float Kp, float Ki, uint32_t period_ns) : { #if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE _pwm = new PWM_Sysfs(0, pwm_num); - hal.gpio->pinMode(26, HAL_GPIO_OUTPUT); - hal.gpio->write(26, 1); + hal.gpio->pinMode(EDGE_GPIO_HEAT_ENABLE, HAL_GPIO_OUTPUT); + hal.gpio->write(EDGE_GPIO_HEAT_ENABLE, 1); #else _pwm = new PWM_Sysfs_Bebop(pwm_num); #endif