+ if (piModel2)
+ RASPBERRY_PI_PERI_BASE = 0x3F000000 ;
+ else
+ RASPBERRY_PI_PERI_BASE = 0x20000000 ;
+
+// Open the master /dev/ memory control device
+
+// See if /dev/gpiomem exists and we can open it...
+
+ if ((fd = open ("/dev/gpiomem", O_RDWR | O_SYNC | O_CLOEXEC) ) >= 0)
+ RASPBERRY_PI_PERI_BASE = 0 ;
+
+// ... otherwise fall back to the original /dev/mem which requires root level access
+
+ else
+ {
+
+// This check is here because people are too stupid to check for themselves or read
+// error messages.
+
+ 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)) ;
+ }
+
+// Set the offsets into the memory interface.