Skip to content

Instantly share code, notes, and snippets.

@joperezr
Last active October 2, 2018 17:35
Show Gist options
  • Save joperezr/fd991b723d146aa110d5adfa6fd2ebfe to your computer and use it in GitHub Desktop.
Save joperezr/fd991b723d146aa110d5adfa6fd2ebfe to your computer and use it in GitHub Desktop.
Full System.Device.Gpio proposal
using System.Collections.Generic;
namespace System.Device.Gpio
{
public enum PinNumberingScheme
{
/// <summary>
/// Board numbering based on the physical location of the board.
/// </summary>
Board = 0,
/// <summary>
/// Gpio numbering based on the datasheet of the microcontroller.
/// </summary>
Logic = 1
}
public enum PinMode
{
Pull_Down,
Pull_Up,
PWM,
Input,
Output,
SPI,
I2C,
UART,
Unknown
}
public enum PWMMode
{
MARK_SPACE,
BALANCED
}
[System.FlagsAttribute]
public enum PinEvent
{
FallingEdge = 0x01,
RisingEdge = 0x02
}
public enum GpioDriverKind
{
RaspberryPi3,
Unix,
WindowsIOT,
ODroid,
HummingboardEdge
}
public abstract class GpioDriver
{
protected internal GpioPin OpenPin(int pinNumber, PinMode mode) { throw null; }
protected internal bool TryOpenPin(int pinNumber, PinMode mode, out GpioPin newPin) { throw null; }
protected internal void ClosePin(int pinNumber) { throw null; }
protected internal int Read(byte[] buffer, int offset, int count) { throw null; }
protected internal void Write(byte[] value, int offset, int count) { }
}
public class GpioController : IDisposable
{
private GpioController() { }
protected internal GpioDriver driver { get; private set; }
public static GpioController Open(PinNumberingScheme numbering = PinNumberingScheme.Logic) { throw null; }
public static GpioController Open(GpioDriver driver, PinNumberingScheme numbering = PinNumberingScheme.Logic) { throw null; }
public static GpioController Open(GpioDriverKind kind, PinNumberingScheme numbering = PinNumberingScheme.Logic) { throw null; }
public PinNumberingScheme Numbering { get; set; }
public IEnumerable<GpioConnection> OpenConnections { get; }
public int PinCount { get; }
public bool isPinOpen(int pinNumber) { throw null; }
public bool isPinModeSupported(int pinNumber, PinMode mode) { throw null; }
public void Dispose() { }
public void CloseAllPins() { }
}
public abstract class GpioConnection : IDisposable
{
public IDictionary<int, PinMode> Pins { get; }
public void Write(byte[] value, int offset, int count) { }
public int Read(byte[] buffer, int offset, int count) { throw null; }
public void Dispose() { }
}
public class GpioPin : GpioConnection
{
// Core Functionality of a Pin
public GpioPin(GpioController controller, int gpioNumber, PinMode mode) { }
public GpioPin(GpioController controller, int gpioNumber, PinMode mode, bool initialValue) { }
public new void Dispose() { }
public bool ReadValue() { throw null; }
public void WriteValue(bool value) { }
// PWM
public int PWMFrequency { get; set; }
public float PWMDutyCycle { get; set; }
public int PWMRange { get; set; }
public PWMMode PWMMode { get; set; }
// Analog RW
public int AnalogRead() { throw null; }
public void AnalogWrite(int value) { }
public int AnalogReadWait(TimeSpan timeout) { throw null; }
// Eventing
public TimeSpan DebounceTimeout { get; set; }
public bool EnableRaisingEvents { get; set; }
public PinEvent NotifyFilter { get; set; }
public event EventHandler<EventArgs> ValueChanged { add { } remove { } }
public bool WaitForEvent(TimeSpan timeout) { throw null; }
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment