Differences
This shows you the differences between two versions of the page.
gpiomem [2017/02/03 10:34] brian.kim created |
gpiomem [2017/02/03 10:44] (current) brian.kim |
||
---|---|---|---|
Line 21: | Line 21: | ||
SUBSYSTEM=="exynos-gpiomem", GROUP="gpio", MODE="0660" | SUBSYSTEM=="exynos-gpiomem", GROUP="gpio", MODE="0660" | ||
</code> | </code> | ||
+ | ==== Example ==== | ||
+ | Hardkernel's wiringPi library which is for GPIO control uses ///dev/gpiomem// device file for rootless gpio control. Usage is very simple. Just open ///dev/gpiomem// device file instead of ///dev/mem//. | ||
+ | * [[https://github.com/hardkernel/wiringPi/blob/master/wiringPi/wiringPi.c#L2868-L2879|($HK_WIRINGPI)/wiringPi/wiringPi.c]] | ||
+ | <code> | ||
+ | // Open the master /dev/memory device | ||
+ | if (access("/dev/gpiomem",0) == 0) { | ||
+ | if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) | ||
+ | return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)) ; | ||
+ | } | ||
+ | else { | ||
+ | if (geteuid () != 0) | ||
+ | (void)wiringPiFailure (WPI_FATAL, "wiringPiSetup: Must be root. (Did you forget sudo?)\n") ; | ||
- | + | if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) | |
+ | return wiringPiFailure (WPI_ALMOST, "wiringPiSetup: Unable to open /dev/mem: %s\n", strerror (errno)) ; | ||
+ | } | ||
+ | </code> | ||