class BeagleBone::gpio: public BeagleBone::pin
This class provides an API for controlling GPIO pins.
To make the classes visible:
#include "bonelib/gpio.hpp"
static gpio* gpio::P8(unsigned char n)
Get the singleton instance that controls the GPIO function on pin #n on connector P8. This will automatically set the pin muxing to the GPIO functionality. Returns NULL if the pin does not offer a GPIO function.
static gpio* gpio::P9(unsigned char n)
Get the singleton instance that controls the GPIO function on pin #n on connector P9. This will automatically set the pin muxing to the GPIO functionality. Returns NULL if the pin does not offer a GPIO function.
int gpio::configure(pin::direction_t direction, pin::pulls_t pull = pin::NONE)
Configure the GPIO pin to the specified direction and pull resistors. The direction must be one of pin::IN or pin::OUT. The resistors must be one of pin::NONE, pin::PU or pin::PD.
pin::direction_t gpio::get_direction()
Return the current direction of the GPIO pin. The return value is one of pin::IN or pin::OUT.
pin::pulls_t gpio::get_pulls()
Return the current pull resistors on the pin. The return value is one of pin::NONE, pin::PU or pin::PD.
int gpio::set(unsigned char val)
Set the output value of the GPIO pin to the specified value (0 or 1). Return true it was succesful.
unsigned char gpio::get()
Return the current value of the GPIO pin. The value is one of 0 or 1.
See the limitations for [pinmux.hpp].
#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);
Wiki: C++ User Documentation
Wiki: PCD8544.hpp
Wiki: SSD1306.hpp
Wiki: pinmux.hpp