/// <summary> /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { this.driver = driver; this.pin = pin; driver.Allocate(pin, PinDirection.Output); driver.SetPinResistor(pin, resistor); }
/// <summary> /// Initializes a new instance of the <see cref="GpioOutputBinaryPin"/> class. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public GpioOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { this.driver = driver; this.pin = pin; driver.Allocate(pin, PinDirection.Output); if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0) driver.SetPinResistor(pin, resistor); }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { // Set the pullup/down resistor for a pin // // The GPIO Pull-up/down Clock Registers control the actuation of internal pull-downs on // the respective GPIO pins. These registers must be used in conjunction with the GPPUD // register to effect GPIO Pull-up/down changes. The following sequence of events is // required: // 1. Write to GPPUD to set the required control signal (i.e. Pull-up or Pull-Down or neither // to remove the current Pull-up/down) // 2. Wait 150 cycles ? this provides the required set-up time for the control signal // 3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to // modify ? NOTE only the pads which receive a clock will be modified, all others will // retain their previous state. // 4. Wait 150 cycles ? this provides the required hold time for the control signal // 5. Write to GPPUD to remove the control signal // 6. Write to GPPUDCLK0/1 to remove the clock // // RPi has P1-03 and P1-05 with 1k8 pullup resistor uint pud; switch (resistor) { case PinResistor.None: pud = Interop.Bcm2835GpioPudOff; break; case PinResistor.PullDown: pud = Interop.Bcm2835GpioPudDown; break; case PinResistor.PullUp: pud = Interop.Bcm2835GpioPudUp; break; default: throw new ArgumentOutOfRangeException(nameof(resistor), resistor, string.Format(CultureInfo.InvariantCulture, "{0} is not a valid value for pin resistor", resistor)); } this.WriteResistor(pud); this.thread.Sleep(ResistorSetDelay); this.SetPinResistorClock(pin, true); this.thread.Sleep(ResistorSetDelay); this.WriteResistor(Interop.Bcm2835GpioPudOff); this.SetPinResistorClock(pin, false); this.pinResistors[pin] = PinResistor.None; }
/// <summary> /// Initializes a new instance of the <see cref="GpioInputBinaryPin"/> class. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public GpioInputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { this.driver = driver; this.pin = pin; driver.Allocate(pin, PinDirection.Input); if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0) { driver.SetPinResistor(pin, resistor); } if ((driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinDetectedEdges) > 0) { driver.SetPinDetectedEdges(pin, PinDetectedEdges.Both); } }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { // Set the pullup/down resistor for a pin // // The GPIO Pull-up/down Clock Registers control the actuation of internal pull-downs on // the respective GPIO pins. These registers must be used in conjunction with the GPPUD // register to effect GPIO Pull-up/down changes. The following sequence of events is // required: // 1. Write to GPPUD to set the required control signal (i.e. Pull-up or Pull-Down or neither // to remove the current Pull-up/down) // 2. Wait 150 cycles ? this provides the required set-up time for the control signal // 3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to // modify ? NOTE only the pads which receive a clock will be modified, all others will // retain their previous state. // 4. Wait 150 cycles ? this provides the required hold time for the control signal // 5. Write to GPPUD to remove the control signal // 6. Write to GPPUDCLK0/1 to remove the clock // // RPi has P1-03 and P1-05 with 1k8 pullup resistor uint pud; switch (resistor) { case PinResistor.None: pud = Interop.BCM2835_GPIO_PUD_OFF; break; case PinResistor.PullDown: pud = Interop.BCM2835_GPIO_PUD_DOWN; break; case PinResistor.PullUp: pud = Interop.BCM2835_GPIO_PUD_UP; break; default: throw new ArgumentOutOfRangeException("resistor"); } WriteResistor(pud); Timers.Timer.Sleep(1); SetPinResistorClock(pin, true); Timers.Timer.Sleep(1); WriteResistor(Interop.BCM2835_GPIO_PUD_OFF); SetPinResistorClock(pin, false); }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { // Set the pullup/down resistor for a pin // // The GPIO Pull-up/down Clock Registers control the actuation of internal pull-downs on // the respective GPIO pins. These registers must be used in conjunction with the GPPUD // register to effect GPIO Pull-up/down changes. The following sequence of events is // required: // 1. Write to GPPUD to set the required control signal (i.e. Pull-up or Pull-Down or neither // to remove the current Pull-up/down) // 2. Wait 150 cycles ? this provides the required set-up time for the control signal // 3. Write to GPPUDCLK0/1 to clock the control signal into the GPIO pads you wish to // modify ? NOTE only the pads which receive a clock will be modified, all others will // retain their previous state. // 4. Wait 150 cycles ? this provides the required hold time for the control signal // 5. Write to GPPUD to remove the control signal // 6. Write to GPPUDCLK0/1 to remove the clock // // RPi has P1-03 and P1-05 with 1k8 pullup resistor uint pud; switch(resistor) { case PinResistor.None: pud = Interop.BCM2835_GPIO_PUD_OFF; break; case PinResistor.PullDown: pud = Interop.BCM2835_GPIO_PUD_DOWN; break; case PinResistor.PullUp: pud = Interop.BCM2835_GPIO_PUD_UP; break; default: throw new ArgumentOutOfRangeException("resistor", resistor, string.Format(CultureInfo.InvariantCulture, "{0} is not a valid value for pin resistor", resistor)); } WriteResistor(pud); HighResolutionTimer.Sleep(0.005m); SetPinResistorClock(pin, true); HighResolutionTimer.Sleep(0.005m); WriteResistor(Interop.BCM2835_GPIO_PUD_OFF); SetPinResistorClock(pin, false); }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { throw new NotSupportedException(); }
/// <summary> /// Gets a bidirectional pin on the current driver. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> /// <returns> /// The GPIO input binary pin. /// </returns> public static GpioInputOutputBinaryPin InOut(this IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { return new GpioInputOutputBinaryPin(driver, pin, resistor); }
/// <summary> /// Gets a bidirectional pin on the current driver. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> /// <returns> /// The GPIO input binary pin. /// </returns> public static GpioInputOutputBinaryPin InOut(this IGpioConnectionDriver driver, ConnectorPin pin, PinResistor resistor = PinResistor.None) { return driver.InOut(pin.ToProcessor(), resistor); }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { throw new NotSupportedException("Resistor are not supported by file GPIO connection driver"); }
/// <summary> /// </summary> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { throw new NotImplementedException(); }
/// <summary> /// Gets a bidirectional pin on the current driver. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> /// <returns> /// The GPIO input binary pin. /// </returns> public static GpioInputOutputBinaryPin InOut(this IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { return(new GpioInputOutputBinaryPin(driver, pin, resistor)); }
/// <summary> /// Gets an input pin on the current driver. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> /// <returns> /// The GPIO input binary pin. /// </returns> public static GpioInputBinaryPin In(this IGpioConnectionDriver driver, ConnectorPin pin, PinResistor resistor = PinResistor.None) { return(driver.In(pin.ToProcessor(), resistor)); }
public GpioHal(IList<Pin> pins, string driverName = "", bool useProcessorPinsNames = false, PinResistor inputResistor = PinResistor.PullUp) { _inUse = false; _driver = GetDriver(driverName); // GPIO driver _inputResistor = inputResistor; // Pullup/pulldown input resistors _pins = new Dictionary<string, ProcessorPin>(); // Global pins foreach (var pin in pins) { ProcessorPin procPin; if (useProcessorPinsNames) { ConnectorPin userPin; if (!Enum.TryParse(pin.Source, true, out userPin)) { throw new HardwareException(string.Format("raspberry connector pin {0} not found", pin.Source)); } procPin = userPin.ToProcessor(); } else { if (!Enum.TryParse(pin.Source, true, out procPin)) { throw new HardwareException(string.Format("raspberry processor pin {0} not found", pin.Source)); } } switch (pin.Type) { case PinTypes.Input: case PinTypes.Counter: case PinTypes.Analog: //Allocate pin _driver.Allocate(procPin, PinDirection.Input); //Set pullup/pulldown resistor if (_inputResistor != PinResistor.None && (_driver.GetCapabilities() & GpioConnectionDriverCapabilities.CanSetPinResistor) > 0) _driver.SetPinResistor(procPin, _inputResistor); break; case PinTypes.Output: case PinTypes.Pwm: //Allocate output pin _driver.Allocate(procPin, PinDirection.Output); break; } //set input pins in global input pins _globalPins |= (ProcessorPins)((uint)1 << (int)procPin); //Add proessor pin _pins.Add(pin.Source, procPin); } Info = new HardwareInfo { Name = "Raspberry model " + Raspberry.Board.Current.Model + "GPIO HAL", Inputs = GpioConnectionSettings.ConnectorPinout == Raspberry.ConnectorPinout.Rev2 ? 26 : 17, Outputs = GpioConnectionSettings.ConnectorPinout == Raspberry.ConnectorPinout.Rev2 ? 26 : 17, Analogs = 0, Pwms = 0, Counters = 0, Vendor = "Raspberry foundation" }; }
/// <summary> /// Initializes a new instance of the <see cref="GpioInputOutputBinaryPin"/> class. /// </summary> /// <param name="driver">The driver.</param> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> public GpioInputOutputBinaryPin(IGpioConnectionDriver driver, ProcessorPin pin, PinResistor resistor = PinResistor.None) { this.driver = driver; this.pin = pin; this.resistor = resistor; }
/// <summary> /// Sets the pin resistor. /// </summary> /// <param name="pin">The pin.</param> /// <param name="resistor">The resistor.</param> /// <exception cref="NotSupportedException">Resistor are not supported by file GPIO connection driver.</exception> public void SetPinResistor(ProcessorPin pin, PinResistor resistor) { throw new NotSupportedException("Resistor are not supported by file GPIO connection driver"); }