// This example implements a driver in managed code for a simple Gadgeteer module. This module uses a // single GTI.InterruptInput to interact with a button that can be in either of two states: pressed or released. // The example code shows the recommended code pattern for exposing a property (IsPressed). // The example also uses the recommended code pattern for exposing two events: Pressed and Released. // The triple-slash "///" comments shown will be used in the build process to create an XML file named // GTM.BrainardTechnologies.MAX31865. This file will provide IntelliSense and documentation for the // interface and make it easier for developers to use the MAX31865 module. // -- CHANGE FOR MICRO FRAMEWORK 4.2 and higher -- // If you want to use Serial, SPI, or DaisyLink (which includes GTI.SoftwareI2C), you must do a few more steps // since these have been moved to separate assemblies for NETMF 4.2 (to reduce the minimum memory footprint of Gadgeteer) // 1) add a reference to the assembly (named Gadgeteer.[interfacename]) // 2) in GadgeteerHardware.xml, uncomment the lines under <Assemblies> so that end user apps using this module also add a reference. // 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 MAX31865(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) _socket = Socket.GetSocket(socketNumber, true, this, null); _socket.EnsureTypeIsSupported('S', this); }
// Interrupt event //public event InterruptHandler InterruptEvent; // 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 IO60P16(int socketNumber) { _socket = Socket.GetSocket(socketNumber, true, this, null); char[] types = new char[] { 'X', 'Y' }; _socket.EnsureTypeIsSupported(types, this); i2c = new GHIOSH.Hardware.SoftwareI2CBus((Cpu.Pin)_socket.CpuPins[4], (Cpu.Pin)_socket.CpuPins[5]); i2cdevice = i2c.CreateI2CDevice(DEV_ADDR, 100); }
/// <summary></summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public FEZtive(int socketNumber) { _socket = Socket.GetSocket(socketNumber, true, this, null); _socket.EnsureTypeIsSupported('S', this); Red = new Color(127, 0, 0); Blue = new Color(0, 0, 127); Green = new Color(0, 127, 0); White = new Color(127, 127, 127); Black = new Color(0, 0, 0); }
// The triple-slash "///" comments shown will be used in the build process to create an XML file named // GTM.DevhammerEnterprises.StarBoard. This file will provide IntelliSense and documentation for the // interface and make it easier for developers to use the StarBoard 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 StarBoard(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) socket = Socket.GetSocket(socketNumber, true, this, "S"); socket.EnsureTypeIsSupported('S', this); int NumberOfLeds = 13; // Initialize the strip : the SPI_Module of the current socket and 800Khz model and using the linear human perceived luminosity PWM conversion factor of 2.25 MyWS2811Strip = new WS2811Led(NumberOfLeds, socket.SPIModule, WS2811Led.WS2811Speed.S800KHZ, 2.25); }
// Note: A constructor summary is auto-generated by the doc builder. /// <summary></summary> /// <param name="socketNumber">The mainboard socket that has the module plugged into it.</param> public PresenceSensor(int socketNumber) { GT.Socket socket = GT.Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported(new char[] { 'X', 'Y' }, this); // These calls will throw GT.Socket.InvalidSocketException if a pin conflict or error is encountered this.input = GTI.InterruptInputFactory.Create(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.On, GTI.ResistorMode.PullUp, GTI.InterruptMode.RisingEdge, this); //this.input.Interrupt += (this._input_Interrupt); this.led = GTI.DigitalOutputFactory.Create(socket, GT.Socket.Pin.Four, false, this); LEDMode = LEDModes.Off; t = new Thread(monitoringLastTime); t.Start(); }
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(WPFRenderOptions.Intercept) { // 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 = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3 pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this); // pin 4 pinDC = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this); // pin 5 spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, spiSpeed); //netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule); spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this); Reset(); ConfigureDisplay(); Clear(); SetBacklight(true); }
// 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); }
// 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 NRF24(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) socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); socket.ReservePin(Socket.Pin.Three, this); // IRQ socket.ReservePin(Socket.Pin.Five, this); // CSN socket.ReservePin(Socket.Pin.Six, this); // CE socket.ReservePin(Socket.Pin.Seven, this); // MOSI socket.ReservePin(Socket.Pin.Eight, this); // MISO socket.ReservePin(Socket.Pin.Nine, this); // SCK GTI.SPI.Configuration spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, spiSpeed); spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, pinCSN, this); pinCE = new GTI.DigitalOutput(socket, Socket.Pin.Six, false, this); // pin 6 pinIRQ = new GTI.InterruptInput(socket, GT.Socket.Pin.Three, GTI.GlitchFilterMode.Off, GTI.ResistorMode.PullUp, GTI.InterruptMode.FallingEdge, this); pinIRQ.Interrupt += new GTI.InterruptInput.InterruptEventHandler(pinIRQ_Interrupt); // Must allow the radio time to settle else configuration bits will not necessarily stick. // This is actually only required following power up but some settling time also appears to // be required after resets too. For full coverage, we'll always assume the worst. // Enabling 16b CRC is by far the most obvious case if the wrong timing is used - or skipped. // Technically we require 4.5ms + 14us as a worst case. We'll just call it 5ms for good measure. // WARNING: Delay is based on P-variant whereby non-P *may* require different timing. //Thread.Sleep(5); Thread.Sleep(100); IsEnabled = false; Initialize(); }
/// <summary>Constructor</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public Display(ModelType model, int socketNumber) : base(WPFRenderOptions.Intercept) { #region UTFT ushort[] dsx = {239, 239, 239, 239, 239, 239, 175, 175, 239, 127, 127, 239, 271, 479, 239, 239, 239, 239, 239, 239, 479, 319, 239, 175, 127, 239, 239, 319, 319}; ushort[] dsy = {319, 399, 319, 319, 319, 319, 219, 219, 399, 159, 127, 319, 479, 799, 319, 319, 319, 319, 319, 319, 799, 479, 319, 219, 159, 319, 319, 479, 479}; byte[] dtm = { 16, 16, 16, 8, 8, 16, 8, (byte)DisplayTransferMode.SERIAL_4PIN, 16, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, 16, 16, 16, 8, 16, (byte)DisplayTransferMode.LATCHED_16, 8, 16, 8, 16, 16, 16, 8, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_4PIN, 16, 16 }; disp_x_size = dsx[(byte)model]; disp_y_size = dsy[(byte)model]; display_transfer_mode = dtm[(byte)model]; display_model = (byte)model; if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_4PIN) { display_transfer_mode = 1; display_serial_mode = (byte)DisplayTransferMode.SERIAL_4PIN; } if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_5PIN) { display_transfer_mode = 1; display_serial_mode = (byte)DisplayTransferMode.SERIAL_5PIN; } if (display_transfer_mode != 1) { //_set_direction_registers(display_transfer_mode); //P_RS = portOutputRegister(digitalPinToPort(RS)); //B_RS = digitalPinToBitMask(RS); //P_WR = portOutputRegister(digitalPinToPort(WR)); //B_WR = digitalPinToBitMask(WR); //P_CS = portOutputRegister(digitalPinToPort(CS)); //B_CS = digitalPinToBitMask(CS); //P_RST = portOutputRegister(digitalPinToPort(RST)); //B_RST = digitalPinToBitMask(RST); //if (display_transfer_mode == LATCHED_16) //{ // P_ALE = portOutputRegister(digitalPinToPort(SER)); // B_ALE = digitalPinToBitMask(SER); // pinMode(SER, OUTPUT); // cbi(P_ALE, B_ALE); // pinMode(8, OUTPUT); // digitalWrite(8, LOW); //} //pinMode(RS, OUTPUT); //pinMode(WR, OUTPUT); //pinMode(CS, OUTPUT); //pinMode(RST, OUTPUT); } else { //P_SDA = portOutputRegister(digitalPinToPort(RS)); //B_SDA = digitalPinToBitMask(RS); //P_SCL = portOutputRegister(digitalPinToPort(WR)); //B_SCL = digitalPinToBitMask(WR); //P_CS = portOutputRegister(digitalPinToPort(CS)); //B_CS = digitalPinToBitMask(CS); //P_RST = portOutputRegister(digitalPinToPort(RST)); //B_RST = digitalPinToBitMask(RST); //if (display_serial_mode != SERIAL_4PIN) //{ // P_RS = portOutputRegister(digitalPinToPort(SER)); // B_RS = digitalPinToBitMask(SER); // pinMode(SER, OUTPUT); //} //pinMode(RS, OUTPUT); //pinMode(WR, OUTPUT); //pinMode(CS, OUTPUT); //pinMode(RST, OUTPUT); } #endregion socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); /* * 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 = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3 pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this); // pin 4 pinDc = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this); // pin 5 spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, 12000); netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule); spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this); Reset(); ConfigureDisplay(); Clear(); SetBacklight(true); }
/// <summary>Constructor</summary> /// <param name="socketNumber">The socket that this module is plugged in to.</param> public Display(ModelType model, int socketNumber) : base(WPFRenderOptions.Intercept) { #region UTFT ushort[] dsx = { 239, 239, 239, 239, 239, 239, 175, 175, 239, 127, 127, 239, 271, 479, 239, 239, 239, 239, 239, 239, 479, 319, 239, 175, 127, 239, 239, 319, 319 }; ushort[] dsy = { 319, 399, 319, 319, 319, 319, 219, 219, 399, 159, 127, 319, 479, 799, 319, 319, 319, 319, 319, 319, 799, 479, 319, 219, 159, 319, 319, 479, 479 }; byte[] dtm = { 16, 16, 16, 8, 8, 16, 8, (byte)DisplayTransferMode.SERIAL_4PIN, 16, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, 16, 16, 16, 8, 16, (byte)DisplayTransferMode.LATCHED_16, 8, 16, 8, 16, 16, 16, 8, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_5PIN, (byte)DisplayTransferMode.SERIAL_4PIN, 16, 16 }; disp_x_size = dsx[(byte)model]; disp_y_size = dsy[(byte)model]; display_transfer_mode = dtm[(byte)model]; display_model = (byte)model; if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_4PIN) { display_transfer_mode = 1; display_serial_mode = (byte)DisplayTransferMode.SERIAL_4PIN; } if (display_transfer_mode == (byte)DisplayTransferMode.SERIAL_5PIN) { display_transfer_mode = 1; display_serial_mode = (byte)DisplayTransferMode.SERIAL_5PIN; } if (display_transfer_mode != 1) { //_set_direction_registers(display_transfer_mode); //P_RS = portOutputRegister(digitalPinToPort(RS)); //B_RS = digitalPinToBitMask(RS); //P_WR = portOutputRegister(digitalPinToPort(WR)); //B_WR = digitalPinToBitMask(WR); //P_CS = portOutputRegister(digitalPinToPort(CS)); //B_CS = digitalPinToBitMask(CS); //P_RST = portOutputRegister(digitalPinToPort(RST)); //B_RST = digitalPinToBitMask(RST); //if (display_transfer_mode == LATCHED_16) //{ // P_ALE = portOutputRegister(digitalPinToPort(SER)); // B_ALE = digitalPinToBitMask(SER); // pinMode(SER, OUTPUT); // cbi(P_ALE, B_ALE); // pinMode(8, OUTPUT); // digitalWrite(8, LOW); //} //pinMode(RS, OUTPUT); //pinMode(WR, OUTPUT); //pinMode(CS, OUTPUT); //pinMode(RST, OUTPUT); } else { //P_SDA = portOutputRegister(digitalPinToPort(RS)); //B_SDA = digitalPinToBitMask(RS); //P_SCL = portOutputRegister(digitalPinToPort(WR)); //B_SCL = digitalPinToBitMask(WR); //P_CS = portOutputRegister(digitalPinToPort(CS)); //B_CS = digitalPinToBitMask(CS); //P_RST = portOutputRegister(digitalPinToPort(RST)); //B_RST = digitalPinToBitMask(RST); //if (display_serial_mode != SERIAL_4PIN) //{ // P_RS = portOutputRegister(digitalPinToPort(SER)); // B_RS = digitalPinToBitMask(SER); // pinMode(SER, OUTPUT); //} //pinMode(RS, OUTPUT); //pinMode(WR, OUTPUT); //pinMode(CS, OUTPUT); //pinMode(RST, OUTPUT); } #endregion socket = Socket.GetSocket(socketNumber, true, this, null); socket.EnsureTypeIsSupported('S', this); /* * 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 = new GTI.DigitalOutput(socket, Socket.Pin.Three, false, this); // pin 3 pinBacklight = new GTI.DigitalOutput(socket, Socket.Pin.Four, false, this); // pin 4 pinDc = new GTI.DigitalOutput(socket, Socket.Pin.Five, false, this); // pin 5 spiConfig = new GTI.SPI.Configuration(false, 0, 0, false, true, 12000); netMFSpiConfig = new SPI.Configuration(socket.CpuPins[6], spiConfig.ChipSelectActiveState, spiConfig.ChipSelectSetupTime, spiConfig.ChipSelectHoldTime, spiConfig.ClockIdleState, spiConfig.ClockEdge, spiConfig.ClockRateKHz, socket.SPIModule); spi = new GTI.SPI(socket, spiConfig, GTI.SPI.Sharing.Shared, socket, Socket.Pin.Six, this); Reset(); ConfigureDisplay(); Clear(); SetBacklight(true); }