GPIO

Background

We use sysfs GPIO because it is easy to understand and instructive. It is deprecated and unmaintained in the kernel though. See this post for much information about this.

The replacement for sysfs GPIO is libgpiod (source and docs).

Class Description

class SysFS_GPIO_Pin

A GPIO pin, as represented in /sys/class/gpio/gpio25/

Encapsulates an exported sysfs GPIO pin. It does not export the pin itself (by writing to /sys/class/gpio/export); rather, you have to make sure that the pin directory exists, and is configured correctly.

Public Functions

SysFS_GPIO_Pin(const std::string &pindir)

Constructor

Parameters:

pindir – The sysfs pin directory; e.g. /sys/class/gpio/gpio25

Direction direction()

Get direction

bool state()

Get state

void set_state(bool)

Set state

Note that it does not make sense to set the state of a GPIO pin that is configured as input.