blob: 1494da2f905d15820e616eeb9d011a89e5272d7f [file] [log] [blame]
Daniel Petti23dcf6c2013-12-19 08:56:41 -08001#ifndef BBB_CAPE_SRC_BBB_CAPE_CONTROL_H_
2#define BBB_CAPE_SRC_BBB_CAPE_CONTROL_H_
3
4#include <cstdint>
5#include <cstring>
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
15namespace bbb {
16
17class Pin {
18 FILE *handle_;
19 int direction_;
20 int kernel_pin_;
21 bool exported_;
22
23 int DoPinDirSet(int direction);
24 int DoExport();
25
26public:
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
38} // bbb
39
40#endif