blob: ba5da009d2c5ea27ba575231a651a794b1b9cdbf [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 <stdio.h>
Daniel Petti23dcf6c2013-12-19 08:56:41 -08005
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 Pettid6ff3d52014-01-02 11:24:39 -080011// Based on example from
Daniel Petti23dcf6c2013-12-19 08:56:41 -080012// <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/>
13
Daniel Pettid6ff3d52014-01-02 11:24:39 -080014// 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 Petti23dcf6c2013-12-19 08:56:41 -080016namespace bbb {
17
18class Pin {
Daniel Pettid6ff3d52014-01-02 11:24:39 -080019 public:
20 // Not strictly necessary for this to be virtual,
21 // but it's a good idea.
22 virtual ~Pin();
Daniel Petti23dcf6c2013-12-19 08:56:41 -080023
Daniel Pettid6ff3d52014-01-02 11:24:39 -080024 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 Petti23dcf6c2013-12-19 08:56:41 -080030 // Here, for example, if you wanted to use
Daniel Pettid6ff3d52014-01-02 11:24:39 -080031 // 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 Petti23dcf6c2013-12-19 08:56:41 -080036};
37
Brian Silverman1662a0e2013-12-19 17:50:01 -080038} // namespace bbb
Daniel Petti23dcf6c2013-12-19 08:56:41 -080039
40#endif