/// <summary> /// Set up the MCP23S17 for the PiFace Digital board. /// </summary> private void InitPiFace() { this.InputPins = new PiFaceInputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { this.InputPins[pinNo] = new PiFaceInputPin(pinNo); } this.OutputPins = new PiFaceOutputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { this.OutputPins[pinNo] = new PiFaceOutputPin(pinNo); } if (this.spiConnection == null) { SpiConnectionSettings spiSettings = new SpiConnectionSettings { BitsPerWord = 8, Delay = 1, MaxSpeed = 5000000, Mode = SpiMode.Mode0 }; this.spiConnection = new NativeSpiConnection(this.driverName, spiSettings); } this.Write(Mcp23S17Register.Iocon, IoconSeqop); this.SetAllOutputPins(0); // initialize output and input pins this.Write(Mcp23S17Register.Iodira, AllPinsOutput); this.Write(Mcp23S17Register.Iodirb, AllPinsInput); // set resistor on all input pins to pull up this.Write(Mcp23S17Register.Gppub, 0xFF); // set outputs this.UpdatePiFaceOutputPins(); // Create re-usable buffer for polling input pins this.CreateReusableBufferForInputPolling(); // Get the initial software input pin state and compare to actual inputs this.cachedInputState = PiFacePin.AllPinState(this.InputPins); this.PollInputPins(); }
/// <summary> /// Update PiFace board with the current vales of the software output pins. /// </summary> public void UpdatePiFaceOutputPins() { this.Write(Mcp23S17Register.Gpioa, PiFacePin.AllPinState(this.OutputPins)); }