/// <summary> /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it. /// </summary> /// <param name="connection">A open SPI connection</param> /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param> /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param> public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (ReferenceEquals(connection, null)) { throw new ArgumentNullException("connection"); } if (numberOfDevices <= 0) { throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); } this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BITS_PER_WORD); connection.SetSpiMode(SPI_MODE_0); connection.SetMaxSpeed(SPEED); connection.SetDelay(DELAY); } var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE; transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices); }
/// <summary> /// Initializes a new instance of the <see cref="Tlc59711DeviceChain"/> class. /// </summary> /// <param name="connection">The connection.</param> /// <param name="initializeWithDefault">if set to <c>true</c> [initialize with default].</param> /// <param name="numberOfDevices">The number of devices.</param> /// <exception cref="ArgumentNullException">connection.</exception> /// <exception cref="ArgumentOutOfRangeException">numberOfDevices - You need at least one device.</exception> public Tlc59711DeviceChain(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (connection is null) { throw new ArgumentNullException("connection"); } if (numberOfDevices <= 0) { throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); } this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BitsPerWord); connection.SetSpiMode(SpiMode0); connection.SetMaxSpeed(Speed); connection.SetDelay(Delay); } var requiredMemorySize = numberOfDevices * Tlc59711Device.CommandSize; this.transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); this.deviceCluster = new Tlc59711Cluster(this.transferBuffer.Tx, numberOfDevices); }
public Ti430BoostAds1118Connection(INativeSpiConnection spi0, INativeSpiConnection spi1, IOutputBinaryPin lcdRegisterSelectGpio, IOutputBinaryPin lcdResetGpio) { this.singleShot = Ads1118SingleShot.SingleShot; this.pga = Ads1118ProgrammableGainAmplifier.TwoFiveSix; this.deviceOperatingMode = Ads1118DeviceOperatingMode.PowerDownSingleShotMode; this.dataRate = Ads1118DataRate.OneTwoEight; this.pullupEnabled = Ads1118PullupEnable.PullupEnabled; this.spi0 = spi0; this.spi1 = spi1; this.lcdRegisterSelectGpio = lcdRegisterSelectGpio; this.lcdResetGpio = lcdResetGpio; this.lcdRegisterSelectGpio.Write(true); this.lcdResetGpio.Write(true); }
/// <summary> /// Set up the MCP23S17 for the PiFace Digital board /// </summary> private void InitPiFace() { InputPins = new PiFaceInputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { InputPins[pinNo] = new PiFaceInputPin(pinNo); } OutputPins = new PiFaceOutputPin[8]; for (int pinNo = 0; pinNo < 8; pinNo++) { OutputPins[pinNo] = new PiFaceOutputPin(pinNo); } if (spiConnection == null) { SpiConnectionSettings spiSettings = new SpiConnectionSettings { BitsPerWord = 8, Delay = 1, MaxSpeed = 5000000, Mode = SpiMode.Mode0 }; spiConnection = new NativeSpiConnection(driverName, spiSettings); } Write(mcp23s17Register.IOCON, IOCON_SEQOP); SetAllOutputPins(0); // initialize output and input pins Write(mcp23s17Register.IODIRA, All_Pins_Output); Write(mcp23s17Register.IODIRB, All_Pins_Input); // set resistor on all input pins to pull up Write(mcp23s17Register.GPPUB, 0xFF); // set outputs UpdatePiFaceOutputPins(); // Create re-usable buffer for polling input pins CreateReusableBufferForInputPolling(); // Get the initial software input pin state and compare to actual inputs CachedInputState = PiFaceInputPin.AllPinState(InputPins); PollInputPins(); }
/// <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> /// Creates a new instance of the <see cref="Tlc59711Connection"/> class and initializes it. /// </summary> /// <param name="connection">A open SPI connection</param> /// <param name="initializeWithDefault">If <c>true</c> the SPI connection will be initialized with common data transfers settings.</param> /// <param name="numberOfDevices">Number of <see cref="ITlc59711Device"/>s connected together.</param> public Tlc59711Connection(INativeSpiConnection connection, bool initializeWithDefault, int numberOfDevices) { if (ReferenceEquals(connection, null)) throw new ArgumentNullException("connection"); if (numberOfDevices <= 0) throw new ArgumentOutOfRangeException("numberOfDevices", "You need at least one device."); this.connection = connection; if (initializeWithDefault) { connection.SetBitsPerWord(BITS_PER_WORD); connection.SetSpiMode(SPI_MODE_0); connection.SetMaxSpeed(SPEED); connection.SetDelay(DELAY); } var requiredMemorySize = numberOfDevices * Tlc59711Device.COMMAND_SIZE; transferBuffer = connection.CreateTransferBuffer(requiredMemorySize, SpiTransferMode.Write); deviceCluster = new Tlc59711Cluster(transferBuffer.Tx, numberOfDevices); }
/// <summary> /// Create the device injecting an SPI connection /// </summary> /// <param name="nativeSpiConnection">connection to the SPI driver.</param> public PiFaceDigitalDevice(INativeSpiConnection nativeSpiConnection) { spiConnection = nativeSpiConnection; InitPiFace(); }
public TransceiverSpiConnection(INativeSpiConnection spiConnection, IOutputBinaryPin ssPin, IOutputBinaryPin resetPin) { this.spiConnection = spiConnection; this.ssPin = ssPin; this.resetPin = resetPin; }