Skip to content

Raspberry.IO.GeneralPurpose.IGpioConnectionDriver

Eric Bézine edited this page Sep 24, 2013 · 7 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.

SetPinResistor

void SetPinResistor(ProcessorPin pin, PinResistor resistor);

Sets the resistor of an input pin.

Parameters
  • pin: the input pin, as numbered on processor
  • resistor: the resistor. Available values are None, PullUp and PullDown

Wait

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.

Parameters
  • 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
Exceptions

If pin status was not modified after the specified time, a TimeoutException exception is thrown.

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.

GpioConnectionDriver

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.

MemoryGpioConnectionDriver

This implementation access the GPIO pins through their memory address.

FileGpioConnectionDriver

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

Samples

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