Skip to content

Commit

Permalink
#25
Browse files Browse the repository at this point in the history
  • Loading branch information
mstroh76 committed Feb 27, 2024
1 parent d9486ac commit 417d546
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion gpio/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1338,7 +1338,7 @@ static void doVersion (char *argv [])
}
}

if (stat ("/dev/gpiomem", &statBuf) == 0) // User level GPIO is GO
if (wiringPiUserLevelAccess()) // User level GPIO is GO
printf (" * This Raspberry Pi supports user-level GPIO access.\n") ;
else
printf (" * Root or sudo required for GPIO access.\n") ;
Expand Down
13 changes: 13 additions & 0 deletions wiringPi/wiringPi.c
Original file line number Diff line number Diff line change
Expand Up @@ -2553,6 +2553,19 @@ void wiringPiVersion (int *major, int *minor)
}


int wiringPiUserLevelAccess(void)
{
struct stat statBuf ;
const char* gpiomemModule = gpiomem_BCM;

if (PI_MODEL_5 == RaspberryPiModel) {
gpiomemModule = gpiomem_RP1;
}

return stat(gpiomemModule, &statBuf) == 0 ? 1 : 0;
}


/*
* wiringPiSetup:
* Must be called once at the start of your program execution.
Expand Down
1 change: 1 addition & 0 deletions wiringPi/wiringPi.h
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ extern struct wiringPiNodeStruct *wiringPiNewNode (int pinBase, int numPins) ;
extern int GPIOToSysFS(const int pin) ;

extern void wiringPiVersion (int *major, int *minor) ;
extern int wiringPiUserLevelAccess (void) ;
extern int wiringPiSetup (void) ;
extern int wiringPiSetupSys (void) ;
extern int wiringPiSetupGpio (void) ;
Expand Down

0 comments on commit 417d546

Please sign in to comment.