My gpiomem class. Uses /dev/gpiomem for non root access

Here is the code on github, this is my first repo so will over time get laid out better. I want to turn it into a lib at some point that also includes a SysFS gpio class for userland interrupts.

I wrote it as I could not find a working example use of /dev/gpiomem
Some of the examples are wrong or as in the case of wiringPI not finished yet. (it lacks the edge detection)

The good thing about /dev/gpiomem is that you don’t need to use sudo, just make sure your user is in the gpio group. Should be with the current Raspbian builds. Also you don’t need to care about what version of pi you’re on, the address mapped with mmap is always the same.

Although it does not have Arduino style interrupts it does use the hardware edge detection features which means you don’t need to deal with debounce. Also if an edge detection event happens whilst you’re doing something else the event is not lost. It is reset when you check for one. Of cause if many events may happen without checking for one then you’re only see one event. It’s a kind of halfway house between polling and real events. As far as I know you can’t do real Arduino events in userland without using something like SysFS. And some argue that even that is not the same.

Hope it is of some use. :)

Was going to post on the foundations forum but it’s too hostile there for my liking.