-
Notifications
You must be signed in to change notification settings - Fork 139
Raspberry.IO.GeneralPurpose.IGpioConnectionDriver
The IGpioConnectionDriver provides an interface for GPIO connection drivers. A connection driver manage access to input (read) and output (write) GPIO Pins, as well as use and release of related resources.
void Allocate(ProcessorPin pin, PinDirection direction);
Allocates a pin: activates the pin according to the given pin number and direction.
-
pin
: the pin, as numbered on processor -
direction
: the pin direction, eitherPinDirection.Input
orPinDirection.Output
void Release(ProcessorPin pin);
Releases a pin; that is, stops using of specified pin.
-
pin
: the pin, as numbered on processor
bool Read(ProcessorPin pin);
Reads the current status of the specified input pin.
-
pin
: the pin, as numbered on processor
The pin status (true
or false
).
ProcessorPins Read(ProcessorPins pins);
Reads the current status of the specified input pins.
-
pins
: a bit field representing the pins whose status must be retrieved
A bit field representing the pins whose status is true
.
void SetPinResistor(ProcessorPin pin, PinResistor resistor);
Sets the resistor of an input pin.
-
pin
: the input pin, as numbered on processor -
resistor
: the resistor. Available values areNone
,PullUp
andPullDown
void Wait(ProcessorPin pin, bool waitForUp = true, decimal timeout = 0);
Waits for an input pin to reach the specified status for the specified amount of time.
-
pin
: the input pin, as numbered on processor -
waitForUp
: execution will be blocked until pin reached up (high) level; otherwise, it will be blocked until the pin reached down (low) level -
timeout
: the maximum amount of time, in milliseconds, the execution will be blocked
If pin status was not modified after the specified time, a TimeoutException exception is thrown.
void Write(ProcessorPin pin, bool value);
Updates the status of the specified output pin to the given value.
-
pin
: the pin, as numbered on processor -
value
: the new pin state
There is currently two implementations of the IGpioConnectionDriver
interface.
This is the default implementation, accessing the GPIO pins through their memory address, and using a pseudo-interrupt mechanism to detect input pin status changes.
This implementation access the GPIO pins through their memory address.
This implementation uses the /sys/class/gpio
virtual files for accessing the GPIO pins.
The following sample declares a pin configuration and uses the default driver to update its status.
using Raspberry.IO.GeneralPurpose;
using System.Threading;
var led = ConnectorPin.P1Pin11.ToProcessor();
var driver = GpioConnectionSettings.DefaultDriver;
driver.Allocate(led, PinDirection.Output);
driver.Write(led, true);
Thread.Sleep(500);
driver.Write(led, false);
driver.Release(led);