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 | |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 8 | // Controlling GPIO pins |
| 9 | // from C++ is a pain. This code provides a simple wrapper that makes it easy to |
| 10 | // use cleanly. |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 11 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 12 | // Based on example from |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 13 | // <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/> |
| 14 | |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 15 | // This is a base class for all gpio related stuff. |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 16 | // Use either the Gpi or the Gpo subclass if you want to do things. |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 17 | namespace bbb { |
| 18 | |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 19 | class GpioPin { |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 20 | protected: |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 21 | // initial_value only matters if input is false. |
| 22 | GpioPin(int bank, int pin, bool input, bool initial_value = false); |
| 23 | virtual ~GpioPin(); |
Daniel Petti | d6ff3d5 | 2014-01-02 11:24:39 -0800 | [diff] [blame] | 24 | |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 25 | FILE *value_handle_ = NULL; |
| 26 | const int bank_, pin_, kernel_pin_; |
Daniel Petti | b23501c | 2014-01-06 16:57:52 -0800 | [diff] [blame] | 27 | |
Brian Silverman | 0aa48a9 | 2014-01-25 17:10:17 -0800 | [diff] [blame^] | 28 | private: |
| 29 | DISALLOW_COPY_AND_ASSIGN(GpioPin); |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 30 | }; |
| 31 | |
Brian Silverman | 1662a0e | 2013-12-19 17:50:01 -0800 | [diff] [blame] | 32 | } // namespace bbb |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 33 | |
| 34 | #endif |