2018-01-05 02:19:51 -04:00
|
|
|
/*
|
|
|
|
* This file is free software: you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation, either version 3 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This file is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
2019-10-20 10:31:12 -03:00
|
|
|
*
|
2018-01-05 02:19:51 -04:00
|
|
|
* Code by Andrew Tridgell and Siddharth Bharat Purohit
|
|
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "AP_HAL_ChibiOS.h"
|
|
|
|
|
2018-02-11 04:28:43 -04:00
|
|
|
#ifndef HAL_GPIO_LED_ON
|
|
|
|
#define HAL_GPIO_LED_ON 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef HAL_GPIO_LED_OFF
|
|
|
|
#define HAL_GPIO_LED_OFF 1
|
2018-01-05 02:19:51 -04:00
|
|
|
#endif
|
|
|
|
|
2020-10-27 22:01:14 -03:00
|
|
|
/*
|
|
|
|
pin types for alternative configuration
|
|
|
|
*/
|
|
|
|
enum class PERIPH_TYPE : uint8_t {
|
|
|
|
UART_RX,
|
|
|
|
UART_TX,
|
|
|
|
I2C_SDA,
|
|
|
|
I2C_SCL,
|
|
|
|
OTHER,
|
2021-09-23 15:06:03 -03:00
|
|
|
GPIO,
|
2020-10-27 22:01:14 -03:00
|
|
|
};
|
|
|
|
|
2018-01-13 00:02:05 -04:00
|
|
|
class ChibiOS::GPIO : public AP_HAL::GPIO {
|
2018-01-05 02:19:51 -04:00
|
|
|
public:
|
2018-01-13 00:02:05 -04:00
|
|
|
GPIO();
|
2018-11-07 06:58:46 -04:00
|
|
|
void init() override;
|
|
|
|
void pinMode(uint8_t pin, uint8_t output) override;
|
|
|
|
uint8_t read(uint8_t pin) override;
|
|
|
|
void write(uint8_t pin, uint8_t value) override;
|
|
|
|
void toggle(uint8_t pin) override;
|
2018-01-05 02:19:51 -04:00
|
|
|
|
|
|
|
/* Alternative interface: */
|
2018-11-07 06:58:46 -04:00
|
|
|
AP_HAL::DigitalSource* channel(uint16_t n) override;
|
2018-01-05 02:19:51 -04:00
|
|
|
|
2018-08-06 01:18:52 -03:00
|
|
|
/* Interrupt interface - fast, for RCOutput and SPI radios */
|
|
|
|
bool attach_interrupt(uint8_t interrupt_num,
|
|
|
|
AP_HAL::Proc p,
|
|
|
|
INTERRUPT_TRIGGER_TYPE mode) override;
|
|
|
|
|
|
|
|
/* Interrupt interface - for AP_HAL::GPIO */
|
|
|
|
bool attach_interrupt(uint8_t pin,
|
|
|
|
irq_handler_fn_t fn,
|
|
|
|
INTERRUPT_TRIGGER_TYPE mode) override;
|
2018-01-05 02:19:51 -04:00
|
|
|
|
|
|
|
/* return true if USB cable is connected */
|
|
|
|
bool usb_connected(void) override;
|
|
|
|
|
|
|
|
void set_usb_connected() { _usb_connected = true; }
|
2018-03-16 18:49:40 -03:00
|
|
|
|
2018-04-06 20:58:57 -03:00
|
|
|
/* attach interrupt via ioline_t */
|
|
|
|
bool _attach_interrupt(ioline_t line, AP_HAL::Proc p, uint8_t mode);
|
2019-10-20 10:31:12 -03:00
|
|
|
|
2020-04-22 02:57:36 -03:00
|
|
|
/*
|
|
|
|
block waiting for a pin to change. A timeout of 0 means wait
|
|
|
|
forever. Return true on pin change, false on timeout
|
|
|
|
*/
|
|
|
|
bool wait_pin(uint8_t pin, INTERRUPT_TRIGGER_TYPE mode, uint32_t timeout_us) override;
|
2020-09-21 05:29:40 -03:00
|
|
|
|
|
|
|
#ifndef IOMCU_FW
|
|
|
|
// timer tick
|
|
|
|
void timer_tick(void) override;
|
|
|
|
#endif
|
2020-10-27 22:01:14 -03:00
|
|
|
|
2021-07-20 01:19:40 -03:00
|
|
|
// check if a pin number is valid
|
|
|
|
bool valid_pin(uint8_t pin) const override;
|
|
|
|
|
2020-10-27 22:01:14 -03:00
|
|
|
/*
|
|
|
|
resolve an ioline to take account of alternative configurations
|
|
|
|
*/
|
|
|
|
static ioline_t resolve_alt_config(ioline_t base, PERIPH_TYPE ptype, uint8_t instance);
|
|
|
|
|
2018-01-05 02:19:51 -04:00
|
|
|
private:
|
2018-03-16 18:49:40 -03:00
|
|
|
bool _usb_connected;
|
|
|
|
bool _ext_started;
|
2018-08-06 01:18:52 -03:00
|
|
|
|
2020-04-22 02:57:36 -03:00
|
|
|
bool _attach_interruptI(ioline_t line, palcallback_t cb, void *p, uint8_t mode);
|
2018-08-06 01:18:52 -03:00
|
|
|
bool _attach_interrupt(ioline_t line, palcallback_t cb, void *p, uint8_t mode);
|
2019-12-29 04:08:56 -04:00
|
|
|
#ifdef HAL_PIN_ALT_CONFIG
|
|
|
|
void setup_alt_config(void);
|
2020-10-27 22:01:14 -03:00
|
|
|
static uint8_t alt_config;
|
2019-12-29 04:08:56 -04:00
|
|
|
#endif
|
2018-01-05 02:19:51 -04:00
|
|
|
};
|
|
|
|
|
2018-01-13 00:02:05 -04:00
|
|
|
class ChibiOS::DigitalSource : public AP_HAL::DigitalSource {
|
2018-01-05 02:19:51 -04:00
|
|
|
public:
|
2018-03-28 06:41:08 -03:00
|
|
|
DigitalSource(ioline_t line);
|
2018-11-07 06:58:46 -04:00
|
|
|
void mode(uint8_t output) override;
|
|
|
|
uint8_t read() override;
|
|
|
|
void write(uint8_t value) override;
|
|
|
|
void toggle() override;
|
2018-01-05 02:19:51 -04:00
|
|
|
private:
|
2018-03-28 06:41:08 -03:00
|
|
|
ioline_t line;
|
2018-01-05 02:19:51 -04:00
|
|
|
};
|
2021-09-20 10:44:46 -03:00
|
|
|
|
|
|
|
#if HAL_WITH_IO_MCU
|
|
|
|
class ChibiOS::IOMCU_DigitalSource : public AP_HAL::DigitalSource {
|
|
|
|
public:
|
|
|
|
IOMCU_DigitalSource(uint8_t _pin);
|
|
|
|
void write(uint8_t value) override;
|
|
|
|
void toggle() override;
|
|
|
|
// IOMCU GPIO is write only
|
|
|
|
void mode(uint8_t output) override {};
|
|
|
|
uint8_t read() override { return 0; }
|
|
|
|
private:
|
|
|
|
uint8_t pin;
|
|
|
|
};
|
|
|
|
#endif
|