/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="busySocket">The busy <see cref="Socket"/> of the <see cref="Spi" /> interface. Can be null if not used.</param> /// <param name="busySocketPin">The busy pin to on the <paramref name="busySocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Socket busySocket, Socket.Pin busySocketPin, Module module) { socket.EnsureTypeIsSupported('S', module); Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin; Cpu.Pin reservedBusyPin = Socket.UnspecifiedPin; if (chipSelectSocket != null) { reservedSelectPin = chipSelectSocket.ReservePin(chipSelectSocketPin, module); } if (busySocket != null) { reservedBusyPin = busySocket.ReservePin(busySocketPin, module); } // reserved pins will be: // UnspecifiedPin if no chip select/busy pin is used // UnnumberedPin if a chip select/busy pin was used on an indirected (non-forwarded socket) // a valid Cpu.Pin otherwise if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing) { return(new NativeSpi(socket, spiConfiguration, sharingMode, reservedSelectPin, reservedBusyPin, module, socket.SPIModule)); } else { return(socket.SpiIndirector(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, busySocket, busySocketPin, module)); } }
/// <summary>Constructs a new instance.</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public DisplayN18(int socketNumber) : base(WpfMode.Separate) { this.byteArray = new byte[1]; this.shortArray = new ushort[2]; this.isBgr = true; this.socket = Socket.GetSocket(socketNumber, true, this, null); this.socket.EnsureTypeIsSupported('S', this); this.resetPin = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Three, false, this); this.backlightPin = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Four, true, this); this.rsPin = GTI.DigitalOutputFactory.Create(this.socket, Socket.Pin.Five, false, this); this.spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, true, 12000); this.netMFSpiConfig = new SPI.Configuration(this.socket.CpuPins[6], this.spiConfig.IsChipSelectActiveHigh, this.spiConfig.ChipSelectSetupTime, this.spiConfig.ChipSelectHoldTime, this.spiConfig.IsClockIdleHigh, this.spiConfig.IsClockSamplingEdgeRising, this.spiConfig.ClockRateKHz, this.socket.SPIModule); this.spi = GTI.SpiFactory.Create(this.socket, this.spiConfig, GTI.SpiSharing.Shared, this.socket, Socket.Pin.Six, this); this.Reset(); this.ConfigureDisplay(); base.OnDisplayConnected("Display N18", 128, 160, DisplayOrientation.Normal, null); this.Clear(); }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) _hardwareInstance.Interface = new Hardware.SPI(_configuration); }
public NativeSpi(Socket socket, SpiConfiguration configuration, SpiSharing sharing, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Module module, Hardware.SPI.SPI_module spiModule) { _hardwareInstance = GetAndUseInstance(socket, sharing, module, spiModule); _chipSelectPin = chipSelectPin; _busyPin = busyPin; _configuration = ToNativeConfiguration(configuration, chipSelectPin, busyPin, spiModule); if (_hardwareInstance.Interface == null && _configuration != null) { _hardwareInstance.Interface = new Hardware.SPI(_configuration); } }
private static Microsoft.SPOT.Hardware.SPI.Configuration ToNativeConfiguration(SpiConfiguration config, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Hardware.SPI.SPI_module spiModule) { if (config == null) return new Microsoft.SPOT.Hardware.SPI.Configuration(chipSelectPin, false, 0, 0, false, false, 0, spiModule, busyPin, false); return new Microsoft.SPOT.Hardware.SPI.Configuration( chipSelectPin, config.IsChipSelectActiveHigh, config.ChipSelectSetupTime, config.ChipSelectHoldTime, config.IsClockIdleHigh, config.IsClockSamplingEdgeRising, config.ClockRateKHz, spiModule, busyPin, config.IsBusyActiveHigh); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param> public CerbotController() { this.buzzer = new PWM(Cpu.PWMChannel.PWM_0, 1000, 0, false); this.leftSensor = new AnalogInput((Cpu.AnalogChannel) 8); this.rightSensor = new AnalogInput(Cpu.AnalogChannel.ANALOG_6); this.leftIRLED = new OutputPort(Generic.GetPin('B', 13), true); this.rightIRLED = new OutputPort(Generic.GetPin('B', 14), true); this.leftInverted = false; this.rightInverted = false; this.leftMotor = new PWM(Cpu.PWMChannel.PWM_4, CerbotController.MOTOR_BASE_FREQUENCY, 0, false); this.rightMotor = new PWM(Cpu.PWMChannel.PWM_5, CerbotController.MOTOR_BASE_FREQUENCY, 0, false); this.leftMotorDirection = new OutputPort(Generic.GetPin('A', 6), false); this.rightMotorDirection = new OutputPort(Generic.GetPin('C', 4), false); this.servo = new PWM(Cpu.PWMChannel.PWM_1, 20000, this.servoMinPulse, PWM.ScaleFactor.Microseconds, false); this.servoConfigured = false; var spiSocket = GT.Socket.GetSocket(3, true, null, null); var tempSocket = GT.Socket.SocketInterfaces.CreateNumberedSocket(10); tempSocket.SupportedTypes = new char[] { 'S' }; tempSocket.CpuPins[3] = Generic.GetPin('B', 2); tempSocket.CpuPins[4] = Generic.GetPin('B', 2); tempSocket.CpuPins[5] = Generic.GetPin('B', 2); tempSocket.CpuPins[6] = Generic.GetPin('B', 2); tempSocket.CpuPins[7] = spiSocket.CpuPins[7]; tempSocket.CpuPins[8] = spiSocket.CpuPins[8]; tempSocket.CpuPins[9] = spiSocket.CpuPins[9]; tempSocket.SPIModule = spiSocket.SPIModule; GT.Socket.SocketInterfaces.RegisterSocket(tempSocket); this.spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, true, 2000); this.forwardLEDs = GTI.SpiFactory.Create(tempSocket, this.spiConfig, GTI.SpiSharing.Shared, tempSocket, Socket.Pin.Six, null); this.enableFaderPin = new PWM((Cpu.PWMChannel) 13, 500, 500, PWM.ScaleFactor.Microseconds, true); this.enableFaderPin.Start(); this.SetLEDBitmask(0x0); }
/// <summary> /// Initializes SPI connection and control pins /// <param name="irqPin"> IRQ pin as a Socket.Pin /// <param name="cePin"> Chip Enable(CE) pin as a Socket.Pin /// <param name="irqPin"> Chip Select Not(CSN or CS\) pin as a Socket.Pin /// <param name="spiClockRateKHZ"> Clock rate in KHz (i.e. 1000 = 1MHz) /// </summary> public void Initialize(Socket.Pin irqPin, Socket.Pin csPin, byte config, uint spiClockRateKHZ = 1000) { _spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, false, spiClockRateKHZ); // Chip Select : Active Low // Clock : Active High, Data clocked in on rising edge //_socket = GTS.GetSocket(6, false, this, null); _spi = GTI.SpiFactory.Create(_socket, _spiConfig, GTI.SpiSharing.Shared, _socket, csPin, this); // Initialize Chip Enable Port _csPin = GTI.DigitalOutputFactory.Create(_socket, Socket.Pin.Four, true, this); // _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this); _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this); _irqPin.Interrupt += _irqPin_Interrupt; _initialized = true; _config = config; ResetConfig(); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param> public DisplayS22(int socketNumber)//, int socketNumberTwo) : base(DisplayModule.WpfMode.Separate) { // This finds the Socket instance from the user-specified socket number. // This will generate user-friendly error messages if the socket is invalid. // If there is more than one socket on this module, then instead of "null" for the last parameter, // put text that identifies the socket to the user (e.g. "S" if there is a socket type S) socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); socket.ReservePin(Socket.Pin.Three, this); // reset socket.ReservePin(Socket.Pin.Four, this); // back light socket.ReservePin(Socket.Pin.Five, this); // D/C socket.ReservePin(Socket.Pin.Six, this); // CS socket.ReservePin(Socket.Pin.Seven, this); // MOSI socket.ReservePin(Socket.Pin.Eight, this); // MISO socket.ReservePin(Socket.Pin.Nine, this); // SCK /* * Serial peripheral interface (SPI). * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line. * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities. */ pinReset = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Three, false, this); // pin 3 pinBacklight = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Four, false, this); // pin 4 pinDC = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Five, false, this); // pin 5 spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, true, spiSpeed); netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.IsChipSelectActiveHigh, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.IsClockIdleHigh, spiConfig.IsClockSamplingEdgeRising, spiConfig.ClockRateKHz, socket.SPIModule); spi = GTI.SpiFactory.Create(socket, spiConfig, GTI.SpiSharing.Shared, socket, Socket.Pin.Six, this); Reset(); ConfigureDisplay(); Clear(); SetBacklight(true); }
private uint spiSpeed = 8000; // kHz #endregion Fields #region Constructors //, int socketNumberTwo) // Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> /// <param name="socketNumberTwo">The second socket that this module is plugged in to.</param> public DisplayS22(int socketNumber) : base(DisplayModule.WpfMode.Separate) { // This finds the Socket instance from the user-specified socket number. // This will generate user-friendly error messages if the socket is invalid. // If there is more than one socket on this module, then instead of "null" for the last parameter, // put text that identifies the socket to the user (e.g. "S" if there is a socket type S) socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); socket.ReservePin(Socket.Pin.Three, this); // reset socket.ReservePin(Socket.Pin.Four, this); // back light socket.ReservePin(Socket.Pin.Five, this); // D/C socket.ReservePin(Socket.Pin.Six, this); // CS socket.ReservePin(Socket.Pin.Seven, this); // MOSI socket.ReservePin(Socket.Pin.Eight, this); // MISO socket.ReservePin(Socket.Pin.Nine, this); // SCK /* * Serial peripheral interface (SPI). * Pin 7 is MOSI line, pin 8 is MISO line, pin 9 is SCK line. * In addition, pins 3, 4 and 5 are general-purpose input/outputs, with pin 3 supporting interrupt capabilities. */ pinReset = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Three, false, this); // pin 3 pinBacklight = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Four, false, this); // pin 4 pinDC = GTI.DigitalOutputFactory.Create(socket, Socket.Pin.Five, false, this); // pin 5 spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, true, spiSpeed); netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.IsChipSelectActiveHigh, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.IsClockIdleHigh, spiConfig.IsClockSamplingEdgeRising, spiConfig.ClockRateKHz, socket.SPIModule); spi = GTI.SpiFactory.Create(socket, spiConfig, GTI.SpiSharing.Shared, socket, Socket.Pin.Six, this); Reset(); ConfigureDisplay(); Clear(); SetBacklight(true); }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="busySocket">The busy <see cref="Socket"/> of the <see cref="Spi" /> interface. Can be null if not used.</param> /// <param name="busySocketPin">The busy pin to on the <paramref name="busySocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Socket busySocket, Socket.Pin busySocketPin, Module module) { socket.EnsureTypeIsSupported('S', module); Cpu.Pin reservedSelectPin = Socket.UnspecifiedPin; Cpu.Pin reservedBusyPin = Socket.UnspecifiedPin; if (chipSelectSocket != null) reservedSelectPin = chipSelectSocket.ReservePin(chipSelectSocketPin, module); if (busySocket != null) reservedBusyPin = busySocket.ReservePin(busySocketPin, module); // reserved pins will be: // UnspecifiedPin if no chip select/busy pin is used // UnnumberedPin if a chip select/busy pin was used on an indirected (non-forwarded socket) // a valid Cpu.Pin otherwise if (socket.SPIModule != Socket.SocketInterfaces.SPIMissing) return new NativeSpi(socket, spiConfiguration, sharingMode, reservedSelectPin, reservedBusyPin, module, socket.SPIModule); else return socket.SpiIndirector(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, busySocket, busySocketPin, module); }
private static Microsoft.SPOT.Hardware.SPI.Configuration ToNativeConfiguration(SpiConfiguration config, Hardware.Cpu.Pin chipSelectPin, Hardware.Cpu.Pin busyPin, Hardware.SPI.SPI_module spiModule) { if (config == null) { return(new Microsoft.SPOT.Hardware.SPI.Configuration(chipSelectPin, false, 0, 0, false, false, 0, spiModule, busyPin, false)); } return(new Microsoft.SPOT.Hardware.SPI.Configuration( chipSelectPin, config.IsChipSelectActiveHigh, config.ChipSelectSetupTime, config.ChipSelectHoldTime, config.IsClockIdleHigh, config.IsClockSamplingEdgeRising, config.ClockRateKHz, spiModule, busyPin, config.IsBusyActiveHigh)); }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Module module) { return(Create(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, null, Socket.Pin.None, module)); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public LightningDetectorSPI(int socketNumber) { // This finds the Socket instance from the user-specified socket number. // This will generate user-friendly error messages if the socket is invalid. // If there is more than one socket on this module, then instead of "null" for the last parameter, // put text that identifies the socket to the user (e.g. "S" if there is a socket type S) var socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); _socket = socket; socket.ReservePin(Socket.Pin.Three, this); socket.ReservePin(Socket.Pin.Six, this); socket.ReservePin(Socket.Pin.Seven, this); socket.ReservePin(Socket.Pin.Eight, this); socket.ReservePin(Socket.Pin.Nine, this); // from as3935 datasheet Chip Select (active low) // data are sampled on the falling edge of SCLK (CPHA=1) spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, false, 2000); spi = GTI.SpiFactory.Create(socket, spiConfig, GTI.SpiSharing.Exclusive, socket, Socket.Pin.Six, this); Initialize(); }
/// <summary> /// Creates an instance of <see cref="Spi" /> for the given socket. /// </summary> /// <param name="socket">The <see cref="Socket"/> for the <see cref="Spi"/> interface.</param> /// <param name="spiConfiguration">The <see cref="SpiConfiguration"/> object for the <see cref="Spi"/> interface.</param> /// <param name="sharingMode">The <see cref="SpiSharing"/> mode of the <see cref="SPI"/> interface.</param> /// <param name="chipSelectSocket">The chip select <see cref="Socket"/> of the <see cref="Spi"/> interface. Can be null if not used.</param> /// <param name="chipSelectSocketPin">The chip select pin on <paramref name="chipSelectSocket"/>.</param> /// <param name="module">The <see cref="Module"/> that is connected to the <see cref="Spi"/> interface.</param> /// <returns></returns> public static Spi Create(Socket socket, SpiConfiguration spiConfiguration, SpiSharing sharingMode, Socket chipSelectSocket, Socket.Pin chipSelectSocketPin, Module module) { return Create(socket, spiConfiguration, sharingMode, chipSelectSocket, chipSelectSocketPin, null, Socket.Pin.None, module); }
/// <summary> /// Initializes SPI connection and control pins /// <param name="irqPin"> IRQ pin as a Socket.Pin /// <param name="cePin"> Chip Enable(CE) pin as a Socket.Pin /// <param name="irqPin"> Chip Select Not(CSN or CS\) pin as a Socket.Pin /// <param name="spiClockRateKHZ"> Clock rate in KHz (i.e. 1000 = 1MHz) /// </summary> public void Initialize(Socket.Pin irqPin, Socket.Pin csPin, byte config, uint spiClockRateKHZ = 1000) { _spiConfig = new GTI.SpiConfiguration(false, 0, 0, false, false, spiClockRateKHZ); // Chip Select : Active Low // Clock : Active High, Data clocked in on rising edge //_socket = GTS.GetSocket(6, false, this, null); _spi = GTI.SpiFactory.Create(_socket, _spiConfig, GTI.SpiSharing.Shared, _socket, csPin, this); // Initialize Chip Enable Port _csPin = GTI.DigitalOutputFactory.Create(_socket, Socket.Pin.Four, true, this); // _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this); _irqPin = GTI.InterruptInputFactory.Create(_socket, irqPin, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this); _irqPin.Interrupt += _irqPin_Interrupt; _initialized = true; _config = config; ResetConfig(); }