Skip to content

Raspberry.IO.GeneralPurpose.IGpioConnectionDriver

raspberry-sharp edited this page Oct 23, 2012 · 3 revisions

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.

Methods

Allocate

void Allocate(ProcessorPin pin, PinDirection direction);

Allocates a pin: activates the pin according to the given pin number and direction.

Parameters
  • pin: the pin, as numbered on processor
  • direction: the pin direction, either PinDirection.Input or PinDirection.Output

Release

void Release(ProcessorPin pin);

Releases a pin; that is, stops using of specified pin.

Parameters
  • pin: the pin, as numbered on processor

Read

bool Read(ProcessorPin pin);

Reads the current status of the specified input pin.

Parameters
  • pin: the pin, as numbered on processor
Return value

The pin status (true or false).

ProcessorPins Read(ProcessorPins pins);

Reads the current status of the specified input pins.

Parameters
  • pins: a bit field representing the pins whose status must be retrieved
Return value

A bit field representing the pins whose status is true.

Write

void Write(ProcessorPin pin, bool value);

Updates the status of the specified output pin to the given value.

Parameters
  • pin: the pin, as numbered on processor
  • value: the new pin state

Implementations

There is currently two implementations of the IGpioConnectionDriver interface.

FileGpioConnectionDriver

This implementation uses the /sys/class/gpio virtual files for accessing the GPIO pins.

MemoryGpioConnectionDriver

This implementation uses the BMC2835 C Library for accessing the GPIO pins through their memory address.

Samples

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);