mirror of
https://github.com/ArduPilot/ardupilot
synced 2025-01-24 01:28:29 -04:00
AP_HAL_Linux: create GPIO_Navigator
This commit is contained in:
parent
6e14f14e09
commit
124721f42e
@ -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
|
||||
|
47
libraries/AP_HAL_Linux/GPIO_Navigator.cpp
Normal file
47
libraries/AP_HAL_Linux/GPIO_Navigator.cpp
Normal 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;
|
||||
}
|
21
libraries/AP_HAL_Linux/GPIO_Navigator.h
Normal file
21
libraries/AP_HAL_Linux/GPIO_Navigator.h
Normal 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);
|
||||
};
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user