AP_HAL_Linux: create GPIO_Navigator

This commit is contained in:
Willian Galvani 2022-08-30 15:15:11 -03:00
parent 6e14f14e09
commit 124721f42e
4 changed files with 72 additions and 2 deletions

View File

@ -28,9 +28,10 @@ private:
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 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
#include "GPIO_RPI.h"
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
#include "GPIO_Navigator.h"
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO
#include "GPIO_Navio.h"
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2

View File

@ -0,0 +1,47 @@
#include "GPIO_Navigator.h"
uint8_t GPIO_Navigator::read(uint8_t pin)
{
if (pinAllowed(pin)) {
return GPIO_RPI::read(pin);
}
if (hal.rcout->supports_gpio()) {
return (uint8_t)hal.rcout->read(pin - 1);
}
return 0;
}
void GPIO_Navigator::write(uint8_t pin, uint8_t value)
{
if (pinAllowed(pin)) {
GPIO_RPI::write(pin, value);
return;
}
if (hal.rcout->supports_gpio()) {
hal.rcout->write_gpio(pin - 1, value);
}
}
void GPIO_Navigator::pinMode(uint8_t pin, uint8_t output)
{
if (pinAllowed(pin)) {
GPIO_RPI::pinMode(pin, output);
}
}
void GPIO_Navigator::pinMode(uint8_t pin, uint8_t output, uint8_t alt)
{
if (pinAllowed(pin)) {
GPIO_RPI::pinMode(pin, output, alt);
}
}
bool GPIO_Navigator::pinAllowed(uint8_t pin)
{
for (const auto &gpio : AllowedGPIOS) {
if (pin == gpio) {
return true;
}
}
return false;
}

View File

@ -0,0 +1,21 @@
#pragma once
#include "GPIO_RPI.h"
using namespace Linux;
extern const AP_HAL::HAL& hal;
class GPIO_Navigator : public GPIO_RPI
{
public:
void pinMode(uint8_t pin, uint8_t output) override;
void pinMode(uint8_t pin, uint8_t output, uint8_t alt) override;
uint8_t read(uint8_t pin) override;
void write(uint8_t pin, uint8_t value) override;
private:
uint8_t AllowedGPIOS[1] = {RPI_GPIO_<26>()};
bool pinAllowed(uint8_t pin);
};

View File

@ -121,9 +121,10 @@ static GPIO_BBB gpioDriver;
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 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1
static GPIO_RPI gpioDriver;
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR
static GPIO_Navigator gpioDriver;
#elif CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIO2 || \
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_EDGE