APM:Libraries
GPIO_Sysfs.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "AP_HAL_Linux.h"
4 #include <AP_HAL/AP_HAL.h>
5 
6 #include "GPIO.h"
7 
8 namespace Linux {
9 
11  friend class GPIO_Sysfs;
12 public:
14  uint8_t read();
15  void write(uint8_t value);
16  void mode(uint8_t output);
17  void toggle();
18 private:
19  /* Only GPIO_Sysfs will be able to instantiate */
20  DigitalSource_Sysfs(unsigned pin, int value_fd);
21  int _value_fd;
22  unsigned _pin;
23 };
24 
28 class GPIO_Sysfs : public AP_HAL::GPIO {
29  friend class DigitalSource_Sysfs;
30 public:
31  /* Fill this table with the real pin numbers. */
32  static const unsigned pin_table[];
33  static const uint8_t n_pins;
34 
35  static GPIO_Sysfs *from(AP_HAL::GPIO *gpio) {
36  return static_cast<GPIO_Sysfs*>(gpio);
37  }
38 
39  void init();
40 
41  void pinMode(uint8_t vpin, uint8_t output) override;
42  uint8_t read(uint8_t vpin) override;
43  void write(uint8_t vpin, uint8_t value) override;
44  void toggle(uint8_t vpin) override;
45 
46  /*
47  * Export pin, instantiate a new DigitalSource_Sysfs and return its
48  * pointer.
49  */
50  AP_HAL::DigitalSource *channel(uint16_t vpin) override;
51 
52  /*
53  * Currently this function always returns -1.
54  */
55  int8_t analogPinToDigitalPin(uint8_t vpin) override;
56 
57  /*
58  * Currently this function always returns false.
59  */
60  bool attach_interrupt(uint8_t interrupt_num, AP_HAL::Proc p, uint8_t mode) override;
61 
62  /*
63  * Currently this function always returns false.
64  */
65  bool usb_connected() override;
66 
67 protected:
68  void _pinMode(unsigned int pin, uint8_t output);
69  int _open_pin_value(unsigned int pin, int flags);
70 
71  /*
72  * Make pin available for use. This function should be called before
73  * calling functions that use the pin number as parameter.
74  *
75  * Returns true if pin is exported successfully and false otherwise.
76  *
77  * Note: the pin is ignored if already exported.
78  */
79  static bool _export_pin(uint8_t vpin);
80 };
81 
82 }
static const uint8_t n_pins
Definition: GPIO_Sysfs.h:33
static GPIO_Sysfs * from(AP_HAL::GPIO *gpio)
Definition: GPIO_Sysfs.h:35
DigitalSource_Sysfs(unsigned pin, int value_fd)
Definition: GPIO_Sysfs.cpp:38
void(* Proc)(void)
void write(uint8_t value)
Definition: GPIO_Sysfs.cpp:62
static U8 usb_connected
Definition: usb.c:184
void mode(uint8_t output)
Definition: GPIO_Sysfs.cpp:70
void init()
Generic board initialization function.
Definition: system.cpp:136
float value
static int8_t pin
Definition: AnalogIn.cpp:15