* GNAT/Ada on Raspberry Pi 3
@ 2018-07-06 21:15 dontspam@dontspam.no
2018-07-06 23:32 ` Philip Munts
` (4 more replies)
0 siblings, 5 replies; 7+ messages in thread
From: dontspam@dontspam.no @ 2018-07-06 21:15 UTC (permalink / raw)
Hi!
I have a Raspberry Pi 3 with
Linux 4.4.34-v7 armv7l / Raspbian GNU/Linux 8.0 (jessie)
I have successfully installed GNAT 4.9.2 and I have created and executed a "Hello World" program on the device.
From Python it is very convenient to operate the GPIOs but I haven't found something for Ada. Does it exists some package/library that can do this from Ada? It is not very important if it requires a different distro.
Frank
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
@ 2018-07-06 23:32 ` Philip Munts
2018-07-07 2:30 ` Dennis Lee Bieber
` (3 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Philip Munts @ 2018-07-06 23:32 UTC (permalink / raw)
On Friday, July 6, 2018 at 11:15:43 PM UTC+2, dont...@dontspam.no wrote:
> From Python it is very convenient to operate the GPIOs but I haven't found something for Ada. Does it exists some package/library that can do this from Ada? It is not very important if it requires a different distro.
Try my Linux Simple I/O LIbrary, which includes a lot of packages for Ada.
Source code is available at:
http://git.munts.com/libsimpleio
and binary packages for Debian Stretch (including Raspbian) are available at:
http://repo.munts.com/debian9
Finally, board specific Ada packages and test programs are available at:
http://git.munts.com/arm-linux-mcu/examples/ada
Phil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
2018-07-06 23:32 ` Philip Munts
@ 2018-07-07 2:30 ` Dennis Lee Bieber
2018-07-07 8:30 ` Dmitry A. Kazakov
` (2 subsequent siblings)
4 siblings, 0 replies; 7+ messages in thread
From: Dennis Lee Bieber @ 2018-07-07 2:30 UTC (permalink / raw)
On Fri, 6 Jul 2018 14:15:42 -0700 (PDT), "dontspam@dontspam.no"
<fjj@itema.no> declaimed the following:
>
From Python it is very convenient to operate the GPIOs but I haven't found something for Ada. Does it exists some package/library that can do this from Ada? It is not very important if it requires a different distro.
>
The basic GPIO access method is via the "sysfs"
http://www.auctoris.co.uk/2012/07/19/gpio-with-sysfs-on-a-raspberry-pi/
http://www.auctoris.co.uk/2012/08/23/gpio-with-sysfs-on-raspberry-pi-part-2/
(Part 2 is the C language example -- you would map the I/O calls [fopen,
fwrite, fclose, etc.] to Ada I/O [probably textio])
The Python library /might/ incorporate logic to map to the actual
hardware registers -- though that likely requires root privileges, whereas
sysfs typically just requires the user to be a member of the GPIO (as I
recall) group.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
2018-07-06 23:32 ` Philip Munts
2018-07-07 2:30 ` Dennis Lee Bieber
@ 2018-07-07 8:30 ` Dmitry A. Kazakov
2018-07-08 0:00 ` Philip Munts
2018-07-08 13:20 ` Björn Lundin
2018-07-08 16:53 ` dontspam@dontspam.no
4 siblings, 1 reply; 7+ messages in thread
From: Dmitry A. Kazakov @ 2018-07-07 8:30 UTC (permalink / raw)
On 2018-07-06 23:15, dontspam@dontspam.no wrote:
> I have a Raspberry Pi 3 with
> Linux 4.4.34-v7 armv7l / Raspbian GNU/Linux 8.0 (jessie)
>
> I have successfully installed GNAT 4.9.2 and I have created and executed a "Hello World" program on the device.
>
> From Python it is very convenient to operate the GPIOs but I haven't found something for Ada. Does it exists some package/library that can do this from Ada? It is not very important if it requires a different distro.
RPI GPIO in Debian is just text files [*]. Several files per pin! (:-)).
Standard Ada.Text_IO should go.
--------------------
* Designed so that you never could guess which name corresponds to which
pin today. (:-))
--
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-07 8:30 ` Dmitry A. Kazakov
@ 2018-07-08 0:00 ` Philip Munts
0 siblings, 0 replies; 7+ messages in thread
From: Philip Munts @ 2018-07-08 0:00 UTC (permalink / raw)
Yes, the sysfs API for GPIO consists of just text files. But it isn't straightforward finding those files.
The sysfs text file API is now deprecated, in favor of a new ioctl() API that should have been used in the first place.
libsimpleio supports both (if the target kernel does).
Phil
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
` (2 preceding siblings ...)
2018-07-07 8:30 ` Dmitry A. Kazakov
@ 2018-07-08 13:20 ` Björn Lundin
2018-07-08 16:53 ` dontspam@dontspam.no
4 siblings, 0 replies; 7+ messages in thread
From: Björn Lundin @ 2018-07-08 13:20 UTC (permalink / raw)
On 2018-07-06 23:15, dontspam@dontspam.no wrote:
> Hi!
> I have a Raspberry Pi 3 with
> Linux 4.4.34-v7 armv7l / Raspbian GNU/Linux 8.0 (jessie)
>
> I have successfully installed GNAT 4.9.2 and I have created and executed a "Hello World" program on the device.
>
> From Python it is very convenient to operate the GPIOs but I haven't found something for Ada. Does it exists some package/library that can do this from Ada? It is not very important if it requires a different distro.
>
> Frank
>
It's easy to bind to the most comon c-api - http://wiringpi.com/
below is not the full api - just enough to write to a pin
call setup once first, then set pin-mode out, then write to it.
To read, set pin-mode in, and call read (which is not in the package yet)
http://wiringpi.com/ has good documentation
---spec
with Interfaces.C; use Interfaces.C;
package Gpio is
-- wiringPi modes
Wpi_Mode_Pins : constant Interfaces.C.Int := 0;
Wpi_Mode_Gpio : constant Interfaces.C.Int := 1;
Wpi_Mode_Gpio_Sys : constant Interfaces.C.Int := 2;
Wpi_Mode_Phys : constant Interfaces.C.Int := 3;
Wpi_Mode_Piface : constant Interfaces.C.Int := 4;
Wpi_Mode_Uninitialised : constant Interfaces.C.Int := -1;
-- Pin modes
Input : constant Interfaces.C.Int := 0;
Output : constant Interfaces.C.Int := 1;
Pwm_Output : constant Interfaces.C.Int := 2;
Gpio_Clock : constant Interfaces.C.Int := 3;
Soft_Pwm_Output : constant Interfaces.C.Int := 4;
Soft_Tone_Output : constant Interfaces.C.Int := 5;
Pwm_Tone_Output : constant Interfaces.C.Int := 6;
Low : constant Interfaces.C.Int := 0;
High : constant Interfaces.C.Int := 1;
-- Pull up/down/none
Pud_Off : constant Interfaces.C.Int := 0;
Pud_Down : constant Interfaces.C.Int := 1;
Pud_Up : constant Interfaces.C.Int := 2;
-- PWM
Pwm_Mode_Ms : constant Interfaces.C.Int := 0;
Pwm_Mode_Bal : constant Interfaces.C.Int := 1;
-- Interrupt levels
Int_Edge_Setup : constant Interfaces.C.Int := 0;
Int_Edge_Falling : constant Interfaces.C.Int := 1;
Int_Edge_Rising : constant Interfaces.C.Int := 2;
Int_Edge_Both : constant Interfaces.C.Int := 3;
Bad_Gpio_Call : exception;
procedure Setup ;
procedure Pin_Mode(Pin : Interfaces.C.Int ; Mode : Interfaces.C.Int) ;
procedure Digital_Write(Pin : Interfaces.C.Int; Value : Boolean);
private
pragma Import(C, Pin_Mode, "pinMode");
end Gpio;
----------
--body
with Ada.Environment_Variables;
package body Gpio is
---------------------------------------------------------
procedure Setup is
R : Int := 0;
function Wiring_Pi_Setup_Gpio return Interfaces.C.Int ;
pragma Import(C, Wiring_Pi_Setup_Gpio, "wiringPiSetupGpio");
begin --http://wiringpi.com/reference/setup/
-- If you want to restore the v1 behaviour, then you need to set the
environment variable: WIRINGPI_CODES
-- to any value
Ada.Environment_Variables.Set("WIRINGPI_CODES","1");
R := Wiring_Pi_Setup_Gpio;
if R /= 0 then
raise Bad_Gpio_Call with "Wiring_Pi_Setup_Gpio" & R'Img;
end if;
end Setup;
---------------------------------------------------------
procedure Digital_Write(Pin : Interfaces.C.Int; Value : Boolean) is
procedure Digital_Write(Pin : Interfaces.C.Int; Value
:Interfaces.C.Int);
pragma Import(C, Digital_Write, "digitalWrite");
begin
if Value then
Digital_Write(Pin, High);
else
Digital_Write(Pin, Low);
end if;
end Digital_Write;
------------------------------------------------------
end Gpio;
----------
--
--
Björn
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: GNAT/Ada on Raspberry Pi 3
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
` (3 preceding siblings ...)
2018-07-08 13:20 ` Björn Lundin
@ 2018-07-08 16:53 ` dontspam@dontspam.no
4 siblings, 0 replies; 7+ messages in thread
From: dontspam@dontspam.no @ 2018-07-08 16:53 UTC (permalink / raw)
Thanks for answer all.
I have tried the libsimpleio, and I think it works now (at least I can turn on/off a LED). I did of course miss the fact that this needed a newer version of Linux. But after some upgrade of Linux it started to work. (If you have some problems you should check that you have /dev/gpiochip0, 1 and 2 in your system).
Frank
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2018-07-08 16:53 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-07-06 21:15 GNAT/Ada on Raspberry Pi 3 dontspam@dontspam.no
2018-07-06 23:32 ` Philip Munts
2018-07-07 2:30 ` Dennis Lee Bieber
2018-07-07 8:30 ` Dmitry A. Kazakov
2018-07-08 0:00 ` Philip Munts
2018-07-08 13:20 ` Björn Lundin
2018-07-08 16:53 ` dontspam@dontspam.no
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox