blob: a377d6800aed717bd24dd31a97e7cb84f1966344 [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
Brian Silverman1662a0e2013-12-19 17:50:01 -08004#include <stdint.h>
5#include <stdio.h>
Daniel Petti23dcf6c2013-12-19 08:56:41 -08006
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
Brian Silverman1662a0e2013-12-19 17:50:01 -080038} // namespace bbb
Daniel Petti23dcf6c2013-12-19 08:56:41 -080039
40#endif