-
Notifications
You must be signed in to change notification settings - Fork 0
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 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 implementation uses the /sys/class/gpio
virtual files for accessing the GPIO pins.
This implementation uses the BMC2835 C Library for accessing the GPIO pins through their memory address.
The following sample declares a pin configuration and creates a MemoryGpioConnectionDriver
that uses it.
using Raspberry.IO.GeneralPurpose;
using System.Threading;
var led = ConnectorPin.P1Pin11.ToProcessor();
var driver = new MemoryGpioConnectionDriver();
driver.Allocate(led, PinDirection.Output);
driver.Write(led, true);
Thread.Sleep(500);
driver.Write(led, false);
driver.Release(led);