An Ada library for interfacing with the GPIO on BCM2835-based boards, such as the Raspberry Pi. RPIO:
/dev/gpiomem
.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.
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.
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!).
RPIO is licensed under MIT, see LICENSE on the root of this repository for more details.