blob: 4925f1b88f5e4528c9bb8bbee924d000b79bf76e [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
Daniel Pettib23501c2014-01-06 16:57:52 -08006#include "aos/common/macros.h"
7
Daniel Petti23dcf6c2013-12-19 08:56:41 -08008// As it turns out, controlling the BBB's GPIO pins
9// from C++ is kind of a pain. The purpose of this
10// code is to provide a simple wrapper that masks
11// all the ugly stuff and exposes a nice API.
12
Daniel Pettid6ff3d52014-01-02 11:24:39 -080013// Based on example from
Daniel Petti23dcf6c2013-12-19 08:56:41 -080014// <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/>
15
Daniel Pettid6ff3d52014-01-02 11:24:39 -080016// This is a base class for all gpio related stuff.
17// Use either a gpi or gpo subclass if you want to do things.
Daniel Petti23dcf6c2013-12-19 08:56:41 -080018namespace bbb {
19
20class Pin {
Daniel Pettid6ff3d52014-01-02 11:24:39 -080021 public:
22 // Not strictly necessary for this to be virtual,
23 // but it's a good idea.
24 virtual ~Pin();
Daniel Pettib23501c2014-01-06 16:57:52 -080025 // When you don't define this and use the
26 // DISALLOW_COPY_AND_ASSIGN macro, the compiler
27 // doesn't seem to create a default one.
28 Pin();
Daniel Petti23dcf6c2013-12-19 08:56:41 -080029
Daniel Pettid6ff3d52014-01-02 11:24:39 -080030 protected:
31 // Set the pin direction.
32 // 1 makes it an input.
33 // 2 makes it an output and sets the initial state to low.
34 bool DoPinDirSet(int direction);
35 // Export the pin, so we can use it.
Daniel Petti23dcf6c2013-12-19 08:56:41 -080036 // Here, for example, if you wanted to use
Daniel Pettid6ff3d52014-01-02 11:24:39 -080037 // GPIO1_28, you would give it 1, 28 as arguments.
38 bool InitPin(int bank, int pin);
39
40 FILE *handle_ = NULL;
41 int kernel_pin_ = -1;
Daniel Pettib23501c2014-01-06 16:57:52 -080042
43 DISALLOW_COPY_AND_ASSIGN(Pin);
Daniel Petti23dcf6c2013-12-19 08:56:41 -080044};
45
Brian Silverman1662a0e2013-12-19 17:50:01 -080046} // namespace bbb
Daniel Petti23dcf6c2013-12-19 08:56:41 -080047
48#endif