[fpc-pascal] Access GPIO pins on RPi2 without root? [lenghty and very [OT] ]

Lukasz Sokol el.es.cr at gmail.com
Fri Oct 9 11:41:43 CEST 2015

On 09/10/15 08:50, Bo Berglund wrote:
> On Thu, 08 Oct 2015 22:01:49 +0000, Mark Morgan Lloyd
> <markMLl.fpc-pascal at telemetry.co.uk> wrote:
>>> Sorry for causing a problem here...
>>> The lists you refer to are not present in the Gmane newsserver as a
>>> newsgroup so I cannot access it.
>> I suggest setting up a direct subscription using the instructions given 
>> at http://www.freepascal.org/maillist.var  Things like Gmane are really 
>> only useful as long-term archives.
> Well, I don't like to have my inbox receive the number of emails on a
> list like this. The new interface is a much better way in my view.
> I already receive 100+ emails every day so doubling this seems not to
> be a good way for me....
I second that,
especially thread.gmane.org is nice - also one can use the mail to news gateway,
through any news/reader/mua (like I use thunderbird).

Bo, how about if we petition the gmane admins to subscribe to fpc-other?
There is a lot of discussion that seems to be going on there. 
 If you write one like that, you've got my vote too.

(and sorry to the list admins, for bringing it on this list/topic, 
gmane tries to obfuscate senders emails when using the mail-to-news gateway)

>>> I will try to locate an updated pigpio.pas file by asking in the
>>> Lazarus forum instead.
>> I would strongly suggest going through /sys/class/gpio first, since you 
>> can exercise it using  echo  and there are fewer things to get wrong.
> I have seen you mention "echo" a number of times and I have gone back
> (in the Gmane gmane.comp.compilers.free-pascal.general news archive in
> my newsreader) to locate the exact method for this but I failed.

(again sorry to the admins here that this may be lengthy and ot, but Bo's email has been garbled by Gmane)

'echo' is a distribution-contained (usually a separate program, but that depends on the distribution)
that writes its given parameters to std-output, as text, then the '>' redirects it to a file.

Long story short, most you need to remember, in unix-like systems everything that can be, is treated as a file,
placed under the single virtual file system (VFS) hierarchy. No 'drive letters', etc.

When you issue a command 'echo something > /path/to/file' there are several things that may happen;
The '>' operation tells the shell to take the echo's std-output and write it to the file.
  (OT: if you used >> instead, it would have been added/appended to file; only really works on disk for this reason)

In higher-level compiled languages like c or pascal you achieve this by
opening the file, writing to it (possibly preceded by doing a 'rewrite' it, but not sure) and then closing.
(remember that either of these 3 operations may throw an error which you need to handle)

in case of GPIO, the in-kernel driver has VFS hooks that tell it :
 - someone has 'just' replaced the content of the file
in its virtual filesystem hierarchy under /sys/class/gpio/* with 'something', 
so it intercepts that write, interprets/sanitizes what it has been given, 
and handles the userspace programs writing to that file.

It also detects 'reads' from the file similarly, 
some drivers support just reading from a file in a loop, 
by means of likes of: 'open-repeat-read-sleep-untilneeded-close';
but some may need an 'repeat-open-read-close-sleep-untilneeded' pattern; 

there is also a family of *notify system functions/calls, 
but that seems to not be as loved by the system/kernel developers as the simpl(istic) open-read-close chain.

It really can't be done any simpler to the userspace, at least in Unix-like/Linux world.
it also has interesting implications (regarding permissions)
that this space is really too small and off-topic to contain.

> And I am a total noob in this low level handling of Linux...
> I will continue searching for your echo examples after I return home
> again.

It's not as low-level as kernel, so don't worry ;) 
and yes the information is all over the place and incredibly scattered.
But that's the 'feature' with all the FOSS stuff, it's a myriad of independent projects.

el es

More information about the fpc-pascal mailing list