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 | |
| 6 | // As it turns out, controlling the BBB's GPIO pins |
| 7 | // from C++ is kind of a pain. The purpose of this |
| 8 | // code is to provide a simple wrapper that masks |
| 9 | // all the ugly stuff and exposes a nice API. |
| 10 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 11 | // Based on example from |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 12 | // <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/> |
| 13 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 14 | // This is a base class for all gpio related stuff. |
| 15 | // 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] | 16 | namespace bbb { |
| 17 | |
| 18 | class Pin { |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 19 | public: |
| 20 | // Not strictly necessary for this to be virtual, |
| 21 | // but it's a good idea. |
| 22 | virtual ~Pin(); |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 23 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 24 | protected: |
| 25 | // Set the pin direction. |
| 26 | // 1 makes it an input. |
| 27 | // 2 makes it an output and sets the initial state to low. |
| 28 | bool DoPinDirSet(int direction); |
| 29 | // Export the pin, so we can use it. |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 30 | // Here, for example, if you wanted to use |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame^] | 31 | // GPIO1_28, you would give it 1, 28 as arguments. |
| 32 | bool InitPin(int bank, int pin); |
| 33 | |
| 34 | FILE *handle_ = NULL; |
| 35 | int kernel_pin_ = -1; |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 36 | }; |
| 37 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 38 | } // namespace bbb |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 39 | |
| 40 | #endif |