APM:Libraries
GPIO.h
Go to the documentation of this file.
1 /*
2  * This file is free software: you can redistribute it and/or modify it
3  * under the terms of the GNU General Public License as published by the
4  * Free Software Foundation, either version 3 of the License, or
5  * (at your option) any later version.
6  *
7  * This file is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License along
13  * with this program. If not, see <http://www.gnu.org/licenses/>.
14  *
15  * Code by Andrew Tridgell and Siddharth Bharat Purohit
16  */
17 #pragma once
18 
19 #include "AP_HAL_ChibiOS.h"
20 
21 #ifndef HAL_GPIO_LED_ON
22 #define HAL_GPIO_LED_ON 0
23 #endif
24 
25 #ifndef HAL_GPIO_LED_OFF
26 #define HAL_GPIO_LED_OFF 1
27 #endif
28 
29 class ChibiOS::GPIO : public AP_HAL::GPIO {
30 public:
31  GPIO();
32  void init();
33  void pinMode(uint8_t pin, uint8_t output);
34  int8_t analogPinToDigitalPin(uint8_t pin);
35  uint8_t read(uint8_t pin);
36  void write(uint8_t pin, uint8_t value);
37  void toggle(uint8_t pin);
38 
39  /* Alternative interface: */
40  AP_HAL::DigitalSource* channel(uint16_t n);
41 
42  /* Interrupt interface: */
43  bool attach_interrupt(uint8_t interrupt_num, AP_HAL::Proc p,
44  uint8_t mode);
45 
46  /* return true if USB cable is connected */
47  bool usb_connected(void) override;
48 
49  void set_usb_connected() { _usb_connected = true; }
50 
51  /* attach interrupt via ioline_t */
52  bool _attach_interrupt(ioline_t line, AP_HAL::Proc p, uint8_t mode);
53 
54 private:
57 };
58 
60 public:
61  DigitalSource(ioline_t line);
62  void mode(uint8_t output);
63  uint8_t read();
64  void write(uint8_t value);
65  void toggle();
66 private:
67  ioline_t line;
68 };
void pinMode(uint8_t pin, uint8_t output)
Definition: GPIO.cpp:73
bool attach_interrupt(uint8_t interrupt_num, AP_HAL::Proc p, uint8_t mode)
Definition: GPIO.cpp:209
void write(uint8_t pin, uint8_t value)
Definition: GPIO.cpp:96
void(* Proc)(void)
void set_usb_connected()
Definition: GPIO.h:49
void init()
Definition: GPIO.cpp:61
int8_t analogPinToDigitalPin(uint8_t pin)
Definition: GPIO.cpp:81
AP_HAL::DigitalSource * channel(uint16_t n)
Definition: GPIO.cpp:117
bool _attach_interrupt(ioline_t line, AP_HAL::Proc p, uint8_t mode)
Definition: GPIO.cpp:131
bool _ext_started
Definition: GPIO.h:56
bool _usb_connected
Definition: GPIO.h:55
bool usb_connected(void) override
Definition: GPIO.cpp:218
uint8_t read(uint8_t pin)
Definition: GPIO.cpp:87
ioline_t line
Definition: GPIO.h:67
void toggle(uint8_t pin)
Definition: GPIO.cpp:108
float value
static int8_t pin
Definition: AnalogIn.cpp:15