~tevo/rpio

Ada driver for the GPIO on BCM2835-based boards, such as the Raspberry Pi
a637da68 — Estevan Castilho a month ago
Oops
RPIO is now available from Alire as well

clone

read-only
https://git.sr.ht/~tevo/rpio
read/write
git@git.sr.ht:~tevo/rpio

You can also use your local clone with git send-email.

RPIO

Table of Contents


Summary

An Ada library for interfacing with the GPIO on BCM2835-based boards, such as the Raspberry Pi. RPIO:

  • Is written in Pure Ada, interfacing directly with /dev/gpiomem.
  • Implements Ada Drivers Library's HAL.GPIO interfaces, making it easier to move your project between boards.
  • Does NOT implement any logic related to advanced functionality or auxiliary devices connected to the GPIO, such as pin sensing, PWM, SPI or UART (patches welcome!).

To start off, get yourself an instance of RPIO.Driver:

declare
   use Ada.Text_IO;
   use HAL.GPIO;

   Driver : RPIO.Driver := RPIO.Make_Driver;

Then query it for a specific pin (indexes are BCM2835's, which may differ from the pin numbering on your board. For the Raspberry Pi, see https://pinout.xyz/):

   Pin : RPIO.GPIO_Pin := Driver.Pin (17);

We may query it for it's current state:

begin
   Put ("Pin "); Put (Pin.Index'Image); Put (" is ");
   Put (Pin.Set'Image);
   Put (" (");
   Put (GPIO_Mode (Pin.Mode)'Image);
   Put (")");
   New_Line;

And modify it for our own purposes:

   Put_Line ("Please press a button to continue.");

   Pin.Set_Mode (Input);
   Pin.Set_Pull_Resistor (Pull_Down);
   -- It might be better to use the BCM2835 pin-sensing capabilities here
   while not Pin.Set loop
      delay 0.01;
   end loop;

   Pin.Set_Mode (Output);
   for N in 1 .. 10 loop
      Pin.Toggle;
      delay 0.5;
   end loop;
end;

See example/ at the root of this repository for a complete project.

Installation

RPIO is available from the Alire Community Index. To add it as a dependency:

$ alr with rpio

Alternatively, one may either install it system-wide, or add it as a git submodule/subtree and specify the appropriate path on your GPRbuild file. For example:

$ git submodule add https://git.sr.ht/~tevo/rpio vendor/rpio

Then, at the top of your project's .gpr file:

with "vendor/rpio/rpio.gpr";

RPIO does not support being built as a shared library, because HAL doesn't support it.

Tested configurations

The library was originally developed for and tested on a Raspberry Pi 1 Model B, but it should work out of the box for every Raspberry Pi up to the Pi 4, as long as the running kernel exposes the GPIO as /dev/gpiomem (alternatively, it should be possible to drive the GPIO controller from /dev/mem, by explicitly overriding the device name and offset passed to Make_Driver). The Raspberry Pi 5 uses an incompatible controller for it's GPIO pins, and is not supported (patches welcome!).

License

RPIO is licensed under MIT, see LICENSE on the root of this repository for more details.

Do not follow this link