GPIO from C or C++

I wrote a C++ class to abstract those file operations (including pin muxing) and turn them into simple configure/set/get calls.

http://sourceforge.net/p/bonelib/wiki/gpio.hpp/

Example:

#include "bonelib/gpio.hpp"

BeagleBone::gpio* CS = BeagleBone::gpio::P8(2);
BeagleBone::gpio* DO = BeagleBone::gpio::P8(4);
BeagleBone::gpio* CLK = BeagleBone::gpio::P8(6);

CS->configure(BeagleBone::pin::OUT);
DO->configure(BeagleBone::pin::OUT);
CLK->configure(BeagleBone::pin::OUT);

CS->set(1);
for (int i = 0; i < 8; i++) {
   DO->set(txd & 0x01);
   CLK->set(1);
   CLK->set(0);
   txd >>= 1;
}
CS->set(0);

If runtime performance is not a big deal, it works great.

This library, works for MX and C4 series?

Don’t know. I’m using it with the stock Angstrom distribution on a BeagleBone A6a.

If any changes are required, it’s open source. Don’t hesitate to create a branch and I can give you write permission.

I have seen many such libraries. The biggest difference between
between my lib and other implementations is that mine supports
read/write operations on blocks of GPIOs. You can take a bunch of
random wires and use them in your app as an ordered set, i.e. allocate
a block of 8 wires and treat them as a byte. Another big difference is
that I wrote it to make porting applications easier, so they can be
developed on a high-end platform and then moved to a microcontroller.
Currently only Beaglebone is supported, but adding Beagleboard or RPi
should be trivial. Launchpad with Stellaris mcu is next in line.

j.