From 423e0bbcd41e6bbac05bdbb5c52772d78784f950 Mon Sep 17 00:00:00 2001 From: YoungSoo Shin Date: Wed, 16 Apr 2025 17:15:59 +0900 Subject: [PATCH] ODROID-C5: Use wiringpi in sudo Signed-off-by: YoungSoo Shin Change-Id: I42bf4afda5a5cb6fc3996c12cb1cb192e58157d6 --- wiringPi/odroidc5.c | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) diff --git a/wiringPi/odroidc5.c b/wiringPi/odroidc5.c index e897faa..c9a8ae5 100644 --- a/wiringPi/odroidc5.c +++ b/wiringPi/odroidc5.c @@ -922,23 +922,15 @@ static void init_gpio_mmap (void) int fd = -1; void *mapped; - /* GPIO mmap setup */ - if (!getuid()) { - if ((fd = open ("/dev/mem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) + if (access("/dev/gpiomem",0) == 0) { + if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) msg (MSG_ERR, - "wiringPiSetup: Unable to open /dev/mem: %s\n", + "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", strerror (errno)); - } else { - if (access("/dev/gpiomem",0) == 0) { - if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) < 0) - msg (MSG_ERR, - "wiringPiSetup: Unable to open /dev/gpiomem: %s\n", - strerror (errno)); - setUsingGpiomem(TRUE); - } else - msg (MSG_ERR, - "wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n"); - } + setUsingGpiomem(TRUE); + } else + msg (MSG_ERR, + "wiringPiSetup: /dev/gpiomem doesn't exist. Please try again with sudo.\n"); if (fd < 0) { msg(MSG_ERR, "wiringPiSetup: Cannot open memory area for GPIO use. \n");