Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use /dev/gpiomem instead of /dev/mem #35

Closed
wants to merge 2 commits into from

Conversation

hariseldon78
Copy link
Contributor

using the /dev/gpiomem allows to run applications to all users in the gpio group, limiting the risk of granting permission on /dev/mem.

using the /dev/gpiomem allows to run applications to all users in the gpio group, limiting the risk of granting permission on /dev/mem.
use /dev/gpiomem instead of /dev/mem
@uraimo
Copy link
Owner

uraimo commented Dec 12, 2016

Thanks @hariseldon78 for this PR, gpiomem has been added to Raspbian with raspberrypi/linux#1112 , can you confirm that you are using the latest Raspbian and that this works out of the box without adding udev rules and creating the gpio group[1]? It looks like you just need to add the pi user to the gpio group.

A lot of people are using Ubuntu as OS and since the bcm2835_gpiomem kernel driver it's needed for this to work (available from release 4.1 onward) after this commit the library will work only from Ubuntu 15.10, 14.04LTS will still be ok but it will need an updated kernel. I'm going to test this a bit before merging and I'll update the docs with a small configuration guide.

But the gpiomem approach it's still not ideal, the GPIO API has received numerous improvement since 4.8 (available in Ubuntu 16.10+) and will some day, once widely available, become a better alternative to the memory and sysfs interface. Both ways of accessing gpios are now generally discouraged.

[1] https://sourceforge.net/p/raspberry-gpio-python/tickets/115/ , https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=9667#p734582 , https://arcanesciencelab.wordpress.com/2016/03/31/running-rpi3-applications-that-use-gpio-without-being-root/ , https://stackoverflow.com/questions/30938991/access-gpio-sys-class-gpio-as-non-root/30940526#30940526

@hariseldon78
Copy link
Contributor Author

I am using ubuntu xenial and this work out of the box for me, on raspbian i wasn't able to correctly compile or run swift. Maybe you could make it configurable in the while adding an optional parameter to the SwiftyGPIO.GPIOs(for: .RaspberryPi2) call, with default to /dev/mem. I can implement it this evening if you like it.

@uraimo
Copy link
Owner

uraimo commented Dec 12, 2016

I haven't used Raspbian in a while, but the release from May 2016 was also incompatible with any image built by iachievedit. Xenial seems the better choice, getting that module to work with 14.04 is too cumbersome.

Instead of modifying the constructor, can you fall-back to opening /dev/mem for mem_fd <=0?

@hariseldon78
Copy link
Contributor Author

hariseldon78 commented Dec 12, 2016

Instead of modifying the constructor, can you fall-back to opening /dev/mem for mem_fd <=0?

Sure, that's a better approach: try /dev/gpiomem, if it fails try /dev/mem, if it fails print error. I'll do it tonight.

@hariseldon78
Copy link
Contributor Author

Hi. I replaced this pull request with this: #36 (sorry, didn't know how to add commits to this one...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants