A small portable-facing interface to target GPIO character devices.
Syntax
#include Once "gpiopins.bi"
Description
GpioPinOpen(pin) opens the NuttX device named /dev/gpioN. GpioPinOpenDevice(device) opens an explicit device path. Both return a non-negative handle or -1 on failure.
GpioPinRead(handle) returns GPIOPIN_LOW, GPIOPIN_HIGH, or -1. GpioPinWrite(handle, value) and GpioPinClose(handle) return zero on success and -1 on failure. GpioPinGetType and GpioPinSetType query or request one of the GPIOPIN_* input, output, open-drain, or interrupt modes declared by the header.
The current hardware implementation is the NuttX GPIO character-device backend. Other targets export predictable unsupported-operation stubs so a portable source can link. Hosted targets report ENOSYS through errno; Windows CE reports ERROR_CALL_NOT_IMPLEMENTED through GetLastError. Device numbering, pin mux, electrical limits, and interrupt registration remain board responsibilities.
Example
#include Once "gpiopins.bi"
Dim As Integer pin = GpioPinOpen( 0 )
If pin < 0 Then
Print "GPIO 0 is unavailable"
End 1
End If
If GpioPinSetType( pin, GPIOPIN_OUTPUT ) = 0 Then
GpioPinWrite( pin, GPIOPIN_HIGH )
End If
GpioPinClose( pin )
Version
See also