2016-02-17 21:25:25 -04:00
|
|
|
#pragma once
|
2012-08-20 15:37:46 -03:00
|
|
|
|
2012-08-23 19:22:24 -03:00
|
|
|
#include <stdint.h>
|
|
|
|
|
2012-08-20 15:37:46 -03:00
|
|
|
#include "AP_HAL_Namespace.h"
|
|
|
|
|
2014-06-01 20:24:52 -03:00
|
|
|
#define HAL_GPIO_INPUT 0
|
|
|
|
#define HAL_GPIO_OUTPUT 1
|
2015-08-17 22:18:21 -03:00
|
|
|
#define HAL_GPIO_ALT 2
|
2012-08-23 19:22:24 -03:00
|
|
|
|
2012-10-02 01:55:52 -03:00
|
|
|
class AP_HAL::DigitalSource {
|
|
|
|
public:
|
|
|
|
virtual void mode(uint8_t output) = 0;
|
|
|
|
virtual uint8_t read() = 0;
|
2013-08-08 10:14:06 -03:00
|
|
|
virtual void write(uint8_t value) = 0;
|
|
|
|
virtual void toggle() = 0;
|
2012-10-02 01:55:52 -03:00
|
|
|
};
|
|
|
|
|
2012-08-20 15:37:46 -03:00
|
|
|
class AP_HAL::GPIO {
|
|
|
|
public:
|
|
|
|
GPIO() {}
|
2012-08-23 19:22:24 -03:00
|
|
|
virtual void init() = 0;
|
|
|
|
virtual void pinMode(uint8_t pin, uint8_t output) = 0;
|
2015-08-19 06:18:54 -03:00
|
|
|
|
|
|
|
// optional interface on some boards
|
|
|
|
virtual void pinMode(uint8_t pin, uint8_t output, uint8_t alt) {};
|
|
|
|
|
2012-08-23 19:22:24 -03:00
|
|
|
virtual uint8_t read(uint8_t pin) = 0;
|
|
|
|
virtual void write(uint8_t pin, uint8_t value) = 0;
|
2013-08-08 10:14:06 -03:00
|
|
|
virtual void toggle(uint8_t pin) = 0;
|
2013-03-21 22:31:14 -03:00
|
|
|
|
2012-10-02 01:55:52 -03:00
|
|
|
/* Alternative interface: */
|
2012-12-06 14:45:45 -04:00
|
|
|
virtual AP_HAL::DigitalSource* channel(uint16_t n) = 0;
|
2012-10-11 21:24:56 -03:00
|
|
|
|
2018-07-04 02:36:37 -03:00
|
|
|
enum INTERRUPT_TRIGGER_TYPE {
|
|
|
|
INTERRUPT_NONE,
|
|
|
|
INTERRUPT_FALLING,
|
|
|
|
INTERRUPT_RISING,
|
|
|
|
INTERRUPT_BOTH,
|
|
|
|
};
|
|
|
|
|
2012-10-11 21:24:56 -03:00
|
|
|
/* Interrupt interface: */
|
2018-07-04 02:36:37 -03:00
|
|
|
// ret , pin , state,timestamp
|
|
|
|
// where:
|
|
|
|
// ret indicates the functor must return void
|
|
|
|
// pin is the pin which has triggered the interrupt
|
|
|
|
// state is the new state of the pin
|
|
|
|
// timestamp is the time in microseconds the interrupt occured
|
|
|
|
FUNCTOR_TYPEDEF(irq_handler_fn_t, void, uint8_t, bool, uint32_t);
|
|
|
|
virtual bool attach_interrupt(uint8_t pin,
|
|
|
|
irq_handler_fn_t fn,
|
2018-08-21 08:39:11 -03:00
|
|
|
INTERRUPT_TRIGGER_TYPE mode) {
|
|
|
|
return false;
|
|
|
|
}
|
2018-07-04 02:36:37 -03:00
|
|
|
|
|
|
|
virtual bool attach_interrupt(uint8_t pin,
|
|
|
|
AP_HAL::Proc proc,
|
|
|
|
INTERRUPT_TRIGGER_TYPE mode) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
bool detach_interrupt(uint8_t pin) {
|
|
|
|
if (attach_interrupt(pin, (irq_handler_fn_t)nullptr, AP_HAL::GPIO::INTERRUPT_NONE)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return attach_interrupt(pin, (AP_HAL::Proc)nullptr, AP_HAL::GPIO::INTERRUPT_NONE);
|
|
|
|
}
|
2013-09-19 03:23:40 -03:00
|
|
|
|
2020-05-11 02:54:48 -03:00
|
|
|
/*
|
|
|
|
block waiting for a pin to change. A timeout of 0 means wait
|
|
|
|
forever. Return true on pin change, false on timeout
|
|
|
|
*/
|
|
|
|
virtual bool wait_pin(uint8_t pin, INTERRUPT_TRIGGER_TYPE mode, uint32_t timeout_us) { return false; }
|
|
|
|
|
2013-09-19 03:23:40 -03:00
|
|
|
/* return true if USB cable is connected */
|
|
|
|
virtual bool usb_connected(void) = 0;
|
2012-08-20 15:37:46 -03:00
|
|
|
};
|