2015-08-11 03:28:43 -03:00
|
|
|
#include <AP_HAL/AP_HAL.h>
|
2014-09-18 10:35:22 -03:00
|
|
|
|
2017-11-02 10:45:18 -03:00
|
|
|
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_ERLEBRAIN2 || \
|
2016-01-05 06:28:27 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_BH || \
|
2016-10-17 15:02:48 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_DARK || \
|
2020-01-10 15:25:03 -04:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_PXFMINI || \
|
2021-09-07 02:17:32 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_NAVIGATOR || \
|
2023-10-22 14:50:57 -03:00
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_OBAL_V1 || \
|
|
|
|
CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_LINUX_CANZERO
|
2014-09-18 10:35:22 -03:00
|
|
|
|
2016-05-17 23:26:57 -03:00
|
|
|
#include "GPIO.h"
|
2024-05-09 09:56:42 -03:00
|
|
|
#include "GPIO_RPI.h"
|
|
|
|
#include "GPIO_RPI_BCM.h"
|
|
|
|
#include "GPIO_RPI_RP1.h"
|
2016-05-17 23:26:57 -03:00
|
|
|
#include "Util_RPI.h"
|
2015-03-28 10:46:08 -03:00
|
|
|
|
2020-03-01 19:50:34 -04:00
|
|
|
extern const AP_HAL::HAL& hal;
|
2016-06-20 11:10:59 -03:00
|
|
|
|
2024-05-09 09:56:42 -03:00
|
|
|
using namespace Linux;
|
2020-03-24 17:09:18 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
GPIO_RPI::GPIO_RPI()
|
2016-06-20 11:10:59 -03:00
|
|
|
{
|
|
|
|
}
|
2014-09-18 10:35:22 -03:00
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void GPIO_RPI::init()
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
2023-06-01 09:38:09 -03:00
|
|
|
const LINUX_BOARD_TYPE rpi_version = UtilRPI::from(hal.util)->detect_linux_board_type();
|
2020-03-24 17:09:18 -03:00
|
|
|
|
2024-05-09 09:56:42 -03:00
|
|
|
switch (rpi_version) {
|
|
|
|
case LINUX_BOARD_TYPE::RPI_ZERO_1:
|
|
|
|
case LINUX_BOARD_TYPE::RPI_2_3_ZERO2:
|
|
|
|
case LINUX_BOARD_TYPE::RPI_4:
|
|
|
|
gpioDriver = new GPIO_RPI_BCM();
|
|
|
|
gpioDriver->init();
|
|
|
|
break;
|
|
|
|
case LINUX_BOARD_TYPE::RPI_5:
|
|
|
|
gpioDriver = new GPIO_RPI_RP1();
|
|
|
|
gpioDriver->init();
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
AP_HAL::panic("Unknown rpi_version, cannot locate peripheral base address");
|
|
|
|
return;
|
2014-11-05 09:56:12 -04:00
|
|
|
}
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void GPIO_RPI::pinMode(uint8_t pin, uint8_t output)
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
2024-05-09 09:56:42 -03:00
|
|
|
gpioDriver->pinMode(pin, output);
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void GPIO_RPI::pinMode(uint8_t pin, uint8_t output, uint8_t alt)
|
2015-08-17 23:32:29 -03:00
|
|
|
{
|
2024-05-09 09:56:42 -03:00
|
|
|
gpioDriver->pinMode(pin, output, alt);
|
2015-08-17 23:32:29 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
uint8_t GPIO_RPI::read(uint8_t pin)
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
2024-05-09 09:56:42 -03:00
|
|
|
return gpioDriver->read(pin);
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void GPIO_RPI::write(uint8_t pin, uint8_t value)
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
2024-05-09 09:56:42 -03:00
|
|
|
gpioDriver->write(pin, value);
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
void GPIO_RPI::toggle(uint8_t pin)
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
2024-05-09 09:56:42 -03:00
|
|
|
gpioDriver->toggle(pin);
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Alternative interface: */
|
2016-06-20 11:10:59 -03:00
|
|
|
AP_HAL::DigitalSource* GPIO_RPI::channel(uint16_t n)
|
|
|
|
{
|
2015-10-20 18:13:25 -03:00
|
|
|
return new DigitalSource(n);
|
2014-09-18 10:35:22 -03:00
|
|
|
}
|
|
|
|
|
2015-10-20 18:13:25 -03:00
|
|
|
bool GPIO_RPI::usb_connected(void)
|
2014-09-18 10:35:22 -03:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-01-05 13:33:45 -04:00
|
|
|
#endif
|