I've made a program using the wiringPi library that assigns GPIO pins to toggle at the press of associated number keys. I'd like my program to show the current status of the pins, even if they are toggled by external means (like another user running the program over SSH). Is it "safe" to read the status of a pin set to output?
The answerYes it's safe. Judging from the source code of the library, it doesn't cache the values but reads them each time you call DocumentationIt isn't really documented in the wiringPi documentation but at least the documentation also doesn't say it's forbidden (for example for Some backgroundWiringPi can control GPIO in two modes - using First option is a standard in Linux and it's documented here. Note that the documentation says:
So we at least know that it is safe. I've checked by experimenting that it is supported on RaspberryPi. This gives us a hint that reading output pin state is probably supported by the hardware itself but we can't be sure since it may be cached by the driver, for example. Lets check documentation:
And it doesn't mention that it has to be set to We can also check the [kernel driver] itself3:
So all it does is to indeed read the hardware register each time you read the state of the pin. And
|
||||
|
|