Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 1 | #ifndef BBB_CAPE_SRC_BBB_CAPE_CONTROL_H_ |
| 2 | #define BBB_CAPE_SRC_BBB_CAPE_CONTROL_H_ |
| 3 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 4 | #include <stdio.h> |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 5 | |
Daniel Petti | b23501c | 2014-01-06 16:57:52 -0800 | [diff] [blame] | 6 | #include "aos/common/macros.h" |
| 7 | |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 8 | // As it turns out, controlling the BBB's GPIO pins |
| 9 | // from C++ is kind of a pain. The purpose of this |
| 10 | // code is to provide a simple wrapper that masks |
| 11 | // all the ugly stuff and exposes a nice API. |
| 12 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 13 | // Based on example from |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 14 | // <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/> |
| 15 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 16 | // This is a base class for all gpio related stuff. |
| 17 | // Use either a gpi or gpo subclass if you want to do things. |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 18 | namespace bbb { |
| 19 | |
| 20 | class Pin { |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 21 | public: |
| 22 | // Not strictly necessary for this to be virtual, |
| 23 | // but it's a good idea. |
| 24 | virtual ~Pin(); |
Daniel Petti | b23501c | 2014-01-06 16:57:52 -0800 | [diff] [blame] | 25 | // When you don't define this and use the |
| 26 | // DISALLOW_COPY_AND_ASSIGN macro, the compiler |
| 27 | // doesn't seem to create a default one. |
| 28 | Pin(); |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 29 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 30 | protected: |
| 31 | // Set the pin direction. |
| 32 | // 1 makes it an input. |
| 33 | // 2 makes it an output and sets the initial state to low. |
| 34 | bool DoPinDirSet(int direction); |
| 35 | // Export the pin, so we can use it. |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 36 | // Here, for example, if you wanted to use |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 37 | // GPIO1_28, you would give it 1, 28 as arguments. |
| 38 | bool InitPin(int bank, int pin); |
| 39 | |
| 40 | FILE *handle_ = NULL; |
| 41 | int kernel_pin_ = -1; |
Daniel Petti | b23501c | 2014-01-06 16:57:52 -0800 | [diff] [blame] | 42 | |
| 43 | DISALLOW_COPY_AND_ASSIGN(Pin); |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 44 | }; |
| 45 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 46 | } // namespace bbb |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 47 | |
| 48 | #endif |