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 <stdint.h> |
| 5 | #include <stdio.h> |
Daniel Petti | 23dcf6c | 2013-12-19 08:56:41 -0800 | [diff] [blame] | 6 | |
| 7 | // As it turns out, controlling the BBB's GPIO pins |
| 8 | // from C++ is kind of a pain. The purpose of this |
| 9 | // code is to provide a simple wrapper that masks |
| 10 | // all the ugly stuff and exposes a nice API. |
| 11 | |
| 12 | // Based on example from |
| 13 | // <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/> |
| 14 | |
| 15 | namespace bbb { |
| 16 | |
| 17 | class Pin { |
| 18 | FILE *handle_; |
| 19 | int direction_; |
| 20 | int kernel_pin_; |
| 21 | bool exported_; |
| 22 | |
| 23 | int DoPinDirSet(int direction); |
| 24 | int DoExport(); |
| 25 | |
| 26 | public: |
| 27 | // Here, for example, if you wanted to use |
| 28 | // GPIO1_28, you would give the ctor |
| 29 | // 1, 28 as arguments. |
| 30 | Pin(int bank, int pin); |
| 31 | ~Pin(); |
| 32 | int MakeInput(); |
| 33 | int MakeOutput(); |
| 34 | int Write(uint8_t value); |
| 35 | int Read(); |
| 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 |