blob: 1471b43b3faa13a812dd5abf3bab9e493103089f [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
Brian Silverman0aa48a92014-01-25 17:10:17 -08008// Controlling GPIO pins
9// from C++ is a pain. This code provides a simple wrapper that makes it easy to
10// use cleanly.
Daniel Petti23dcf6c2013-12-19 08:56:41 -080011
Daniel Pettid6ff3d52014-01-02 11:24:39 -080012// Based on example from
Daniel Petti23dcf6c2013-12-19 08:56:41 -080013// <http://learnbuildshare.wordpress.com/2013/05/29/beaglebone-black-digital-ouput/>
14
Daniel Pettid6ff3d52014-01-02 11:24:39 -080015// This is a base class for all gpio related stuff.
Brian Silverman0aa48a92014-01-25 17:10:17 -080016// Use either the Gpi or the Gpo subclass if you want to do things.
Daniel Petti23dcf6c2013-12-19 08:56:41 -080017namespace bbb {
18
Brian Silverman0aa48a92014-01-25 17:10:17 -080019class GpioPin {
Daniel Pettid6ff3d52014-01-02 11:24:39 -080020 protected:
Brian Silverman0aa48a92014-01-25 17:10:17 -080021 // initial_value only matters if input is false.
22 GpioPin(int bank, int pin, bool input, bool initial_value = false);
23 virtual ~GpioPin();
Daniel Pettid6ff3d52014-01-02 11:24:39 -080024
Brian Silverman0aa48a92014-01-25 17:10:17 -080025 FILE *value_handle_ = NULL;
26 const int bank_, pin_, kernel_pin_;
Daniel Pettib23501c2014-01-06 16:57:52 -080027
Brian Silverman0aa48a92014-01-25 17:10:17 -080028 private:
29 DISALLOW_COPY_AND_ASSIGN(GpioPin);
Daniel Petti23dcf6c2013-12-19 08:56:41 -080030};
31
Brian Silverman1662a0e2013-12-19 17:50:01 -080032} // namespace bbb
Daniel Petti23dcf6c2013-12-19 08:56:41 -080033
34#endif