コード例 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="CanSpiClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the CANSPIclick module is plugged</param>
        public CanSpiClick(Hardware.Socket socket)
        {
            _socket = socket;
            // Initialize SPI
            _canSpi = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode3,
                ClockFrequency = 2000000
            });

            _rst = GpioController.GetDefault().OpenPin(socket.Rst);
            _rst.SetDriveMode(GpioPinDriveMode.Output);
            _rst.Write(GpioPinValue.High);

            _int = GpioController.GetDefault().OpenPin(socket.Int);
            _int.SetDriveMode(GpioPinDriveMode.Input);
            _int.ValueChangedEdge = GpioPinEdge.FallingEdge;
            _int.ValueChanged    += INT_ValueChanged;

            if (!Reset(ResetModes.Hard))
            {
                throw new NotImplementedException("MCP2515 initialisation failed!");
            }
        }
コード例 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="OLEDCClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the OLEDc Click board is inserted on MikroBus.Net</param>
        /// <example>Example usage:
        /// <code language = "C#">
        ///	var _oled = new OLEDCClick(Hardware.SocketFour);
        /// </code>
        /// </example>
        public OLEDCClick(Hardware.Socket socket)
        {
            _socket = socket;
            SpiConnectionSettings settings = new SpiConnectionSettings
            {
                ChipSelectType        = SpiChipSelectType.Gpio,
                ChipSelectLine        = GpioController.GetDefault().OpenPin(socket.Cs),
                ChipSelectActiveState = false,
                Mode           = SpiMode.Mode3,
                ClockFrequency = 40 * 1000 * 1000
            };

            _oled = SpiController.FromName(socket.SpiBus).GetDevice(settings);

            _resetPin = GpioController.GetDefault().OpenPin(socket.Rst);
            _resetPin.SetDriveMode(GpioPinDriveMode.Output);
            _resetPin.Write(GpioPinValue.High);

            _dataCommandPin = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _dataCommandPin.SetDriveMode(GpioPinDriveMode.Output);
            _dataCommandPin.Write(GpioPinValue.High);

            _readWritePin = GpioController.GetDefault().OpenPin(socket.AnPin);
            _readWritePin.SetDriveMode(GpioPinDriveMode.Output);
            _readWritePin.Write(GpioPinValue.High);

            Canvas = new MikroBitmap(_canvasWidth, _canvasHeight);

            InitilizeOLED();
        }
コード例 #3
0
ファイル: StartupTask.cs プロジェクト: KiwiBryn/RFM9XLoRa-Net
        public void Run(IBackgroundTaskInstance taskInstance)
        {
#if CS0
            const int chipSelectPinNumber = 0;
#endif
#if CS1
            const int chipSelectPinNumber = 1;
#endif
            SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
            var           settings      = new SpiConnectionSettings(chipSelectPinNumber)
            {
                ClockFrequency = 500000,
                Mode           = SpiMode.Mode0,         // From SemTech docs pg 80 CPOL=0, CPHA=0
            };
            SpiDevice Device = spiController.GetDevice(settings);

            while (true)
            {
                byte[] writeBuffer = new byte[] { 0x42 };                 // RegVersion
                byte[] readBuffer  = new byte[1];

                // Read the RegVersion silicon ID to check SPI works
                Device.TransferSequential(writeBuffer, readBuffer);

                Debug.WriteLine("Register RegVer 0x{0:x2} - Value 0X{1:x2} - Bits {2}", writeBuffer[0], readBuffer[0], Convert.ToString(readBuffer[0], 2).PadLeft(8, '0'));

                Thread.Sleep(10000);
            }
        }
コード例 #4
0
ファイル: StartupTask.cs プロジェクト: KiwiBryn/RFM9XLoRa-Net
        public Rfm9XDevice(byte chipSelectPin, byte resetPin, byte interruptPin)
        {
            SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
            var           settings      = new SpiConnectionSettings(0)
            {
                ClockFrequency = 500000,
                Mode           = SpiMode.Mode0,
            };

            // Chip select pin configuration
            GpioController gpioController = GpioController.GetDefault();

            ChipSelectGpioPin = gpioController.OpenPin(chipSelectPin);
            ChipSelectGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            ChipSelectGpioPin.Write(GpioPinValue.High);

            // Reset pin configuration to do factory reset
            GpioPin resetGpioPin = gpioController.OpenPin(resetPin);

            resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            resetGpioPin.Write(GpioPinValue.Low);
            Task.Delay(10);
            resetGpioPin.Write(GpioPinValue.High);
            Task.Delay(10);

            // Interrupt pin for RX message & TX done notification
            InterruptGpioPin = gpioController.OpenPin(interruptPin);
            InterruptGpioPin.SetDriveMode(GpioPinDriveMode.Input);

            InterruptGpioPin.ValueChanged += InterruptGpioPin_ValueChanged;

            Rfm9XLoraModem = spiController.GetDevice(settings);
        }
コード例 #5
0
        /// <summary>
        ///     Create a new ADXL362 object using the specified SPI module.
        /// </summary>
        /// <param name="spiBus">Spi Bus object</param>
        /// <param name="chipSelect">Chip select pin.</param>
        public Adxl362(string spiBus, int chipSelect)
        {
            var gpio = GpioController.GetDefault();

            var chipSelectPort = gpio.OpenPin(chipSelect);

            chipSelectPort.SetDriveMode(GpioPinDriveMode.Output);
            //chipSelectPort.Write(GpioPinValue.Low);

            var settings = new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = chipSelectPort,
                Mode           = SpiMode.Mode1,
                ClockFrequency = 4_000_000,
            };

            var controller = SpiController.FromName(spiBus);

            _adxl362 = controller.GetDevice(settings);
            //
            //  ADXL362 works in SPI mode 0 (CPOL = 0, CPHA = 0).
            //
            //_adxl362 = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(chipSelect));
            Reset();
            Start();
        }
コード例 #6
0
        static async Task spifullduplex(string[] input)
        {
            try
            {
                UpBridge.Up   upb        = new UpBridge.Up();
                SpiController controller = await SpiController.GetDefaultAsync();

                SpiConnectionSettings settings = new SpiConnectionSettings(spi.ChipSelectLine);
                settings.ClockFrequency = spi.ClockFrequency;
                settings.DataBitLength  = spi.DataBitLength;
                settings.Mode           = spi.Mode;
                settings.SharingMode    = spi.SharingMode;
                byte[] wrtiebuf = new byte[input.Length - 1];
                byte[] readbuf  = new byte[wrtiebuf.Length];
                for (int i = 1; i < input.Length; i++)
                {
                    wrtiebuf[i - 1] = Convert.ToByte(input[i], 16);
                }
                controller.GetDevice(settings).TransferFullDuplex(wrtiebuf, readbuf);
                for (int i = 0; i < readbuf.Length; i++)
                {
                    Console.WriteLine(i + " byte: " + readbuf[i].ToString("X"));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #7
0
        // Setup the MCP3008 chip
        public async void Initialize()
        {
            Debug.WriteLine("Setting up the MCP3008.");
            try
            {
                // Settings for the SPI bus
                var SPI_settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
                SPI_settings.ClockFrequency = 3600000;
                SPI_settings.Mode           = SpiMode.Mode0;

                SpiController controller = await SpiController.GetDefaultAsync();     /* Get the default SPI controller */

                mcp_var = controller.GetDevice(SPI_settings);

                if (mcp_var == null)
                {
                    Debug.WriteLine("ERROR! SPI device may be in use.");
                    return;
                }
            }
            catch (Exception e)
            {
                Debug.WriteLine("EXEPTION CAUGHT: " + e.Message + "\n" + e.StackTrace);
                throw;
            }
        }
コード例 #8
0
        static void InitializeSPIDisplay()
        {
            var spi = SpiController.FromName(SC20100.SpiBus.Spi3);

            var gpio = GpioController.GetDefault();

            var csPin = gpio.OpenPin(SC20100.GpioPin.PD10);

            st7735 = new ST7735Controller(

                spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, csPin)), // CS PD10

                gpio.OpenPin(SC20100.GpioPin.PC4),                                                    // PE10 RS

                gpio.OpenPin(SC20100.GpioPin.PE15)                                                    // PE10 RESET

                );


            st7735.SetDataAccessControl(true, true, true, false);

            var bl = gpio.OpenPin(SC20100.GpioPin.PE5); // Backligth PC7

            bl.SetDriveMode(GpioPinDriveMode.Output);

            bl.Write(GpioPinValue.High);

            Graphics.OnFlushEvent += Graphics_OnFlushEvent;

            graphic = Graphics.FromImage(new Bitmap(160, 128));
        }
コード例 #9
0
ファイル: Program.cs プロジェクト: valoni/TinyCLR-Samples
        static void Main()
        {
            ////////// Set these to match your board //////////////
            var clickRstPin = SC20100.GpioPin.PD4;
            var clickCsPin  = SC20100.GpioPin.PD3;
            var spiBus      = SC20100.SpiBus.Spi3;
            ///////////////////////////////////////////////////////

            var controller = SpiController.FromName(spiBus);
            var ring       = new LedRingClick(controller, clickCsPin, clickRstPin);

            while (true)
            {
                uint fill = 1;
                for (var x = 0; x < 32; x++)
                {
                    ring.ledState += fill;
                    fill         <<= 1;
                    ring.Update();
                    Thread.Sleep(30);
                }

                uint del = 1;
                for (var x = 0; x < 32; x++)
                {
                    ring.ledState -= del;
                    del          <<= 1;
                    ring.Update();
                    Thread.Sleep(30);
                }
            }
        }
コード例 #10
0
        static void InitDisplay()
        {
            // Display Get Ready ////////////////////////////////////
            var spi  = SpiController.FromName(FEZBit.SpiBus.Display);
            var gpio = GpioController.GetDefault();

            st7735 = new ST7735Controller(
                spi.GetDevice(ST7735Controller.GetConnectionSettings
                                  (SpiChipSelectType.Gpio, GpioController.GetDefault().OpenPin(FEZBit.GpioPin.DisplayCs))), //CS pin.
                gpio.OpenPin(FEZBit.GpioPin.DisplayRs),                                                                     //RS pin.
                gpio.OpenPin(FEZBit.GpioPin.DisplayReset)                                                                   //RESET pin.
                );

            var backlight = gpio.OpenPin(FEZBit.GpioPin.Backlight);

            backlight.SetDriveMode(GpioPinDriveMode.Output);
            backlight.Write(GpioPinValue.High);

            st7735.SetDataAccessControl(true, true, false, false); //Rotate the screen.
            st7735.SetDrawWindow(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
            st7735.Enable();
            // Create flush event
            Graphics.OnFlushEvent += Graphics_OnFlushEvent;

            // Create bitmap buffer
            screen = Graphics.FromImage(new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT));

            font12 = Resource.GetFont(Resource.FontResources.droid_reg12);
            screen.Clear();
            screen.DrawRectangle(new Pen(new SolidBrush(Color.White)), 10, 10, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 20);
            screen.DrawString("FEZ Bit", font12, new SolidBrush(Color.Red), 55, 30);
            screen.DrawString("SITCore", font12, new SolidBrush(Color.Green), 50, 50);
            screen.DrawString("GHI Electronics", font12, new SolidBrush(Color.Blue), 25, 70);
            screen.Flush();
        }
コード例 #11
0
        /// <summary>
        /// Initializes a new instance of the <see cref="FlashMemory"/> class.
        /// </summary>
        /// <param name="socket">The socket on the MBN mainboard.</param>
        public FlashMemory(Hardware.Socket socket, Boolean detectParameters = true, Int32 hold = -1, Int32 wp = -1)
        {
            _flash = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 10000000
            });

            if (wp != -1)
            {
                GpioPin _wp = GpioController.GetDefault().OpenPin(wp);
                _wp.SetDriveMode(GpioPinDriveMode.Output);
                _wp.Write(GpioPinValue.High);
            }

            if (hold != -1)
            {
                GpioPin _hold = GpioController.GetDefault().OpenPin(hold);
                _hold.SetDriveMode(GpioPinDriveMode.Output);
                _hold.Write(GpioPinValue.High);
            }
            if (detectParameters)
            {
                DetectParameters();
            }
        }
コード例 #12
0
        static void TestWaveshareDisplay()
        {
            var spi  = SpiController.FromName(FEZBit.SpiBus.Edge);
            var gpio = GpioController.GetDefault();

            var display = new WaveShare18Display(
                gpio.OpenPin(FEZBit.GpioPin.EdgeP8),
                gpio.OpenPin(FEZBit.GpioPin.EdgeP12),
                gpio.OpenPin(FEZBit.GpioPin.EdgeP16),
                spi,
                gpio.OpenPin(FEZBit.GpioPin.EdgeP1));

            display.EnableBacklight(true);

            // Create bitmap buffer
            screen = Graphics.FromImage(new Bitmap(SCREEN_WIDTH, SCREEN_HEIGHT));

            font12 = Resource.GetFont(Resource.FontResources.droid_reg12);
            var i = 0;

            while (true)
            {
                screen.Clear();
                screen.DrawRectangle(new Pen(new SolidBrush(Color.White)), 10, 10, SCREEN_WIDTH - 20, SCREEN_HEIGHT - 20);
                screen.DrawString("FEZ Bit", font12, new SolidBrush(Color.Red), 55, 30);
                screen.DrawString("SITCore", font12, new SolidBrush(Color.Green), 50, 50);
                screen.DrawString(i++.ToString(), font12, new SolidBrush(Color.Blue), 25, 70);
                screen.Flush();
                Thread.Sleep(200);
            }
        }
コード例 #13
0
ファイル: Driver.cs プロジェクト: andylyonette/Test1
        public Driver(bool isLandscape,
                      int lcdChipSelectPin,
                      int dataCommandPin,
                      int resetPin,
                      int backlightPin,
                      string spiBus,
                      uint spiClockFrequency = 20000
                      )
        {
            _spiController  = SpiController.GetDefault();
            _gpioController = GpioController.GetDefault();
            SpiConnectionSettings _csConnectionSettings = new SpiConnectionSettings(lcdChipSelectPin);

            _spi = SpiDevice.FromId(spiBus, _csConnectionSettings);

            _dataCommandPort = _gpioController.OpenPin(dataCommandPin);
            _dataCommandPort.SetDriveMode(GpioPinDriveMode.Output);

            _resetPort = _gpioController.OpenPin(resetPin);
            _resetPort.SetDriveMode(GpioPinDriveMode.Output);

            _backlightPort = _gpioController.OpenPin(backlightPin);
            _backlightPort.SetDriveMode(GpioPinDriveMode.Output);

            InitializeScreen();
            SetOrientation(isLandscape);
        }
コード例 #14
0
ファイル: NRFcClick.cs プロジェクト: valoni/MBN-TinyCLR
        public NRFC(Hardware.Socket socket)
        {
            _socket = socket;
            // Initialize SPI
            _nrf = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Initialize IRQ Port
            _irqPin = GpioController.GetDefault().OpenPin(socket.Int);
            _irqPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            _irqPin.ValueChanged += IrqPin_ValueChanged;
            //_irqPin = new InterruptPort(socket.Int, false, Port.ResistorMode.PullUp, Port.InterruptMode.InterruptEdgeLow);

            // Initialize Chip Enable Port
            _cePin = GpioController.GetDefault().OpenPin(socket.Rst);
            _cePin.SetDriveMode(GpioPinDriveMode.Output);
            _cePin.Write(GpioPinValue.Low);

            // Module reset time
            Thread.Sleep(100);

            _initialized = true;

            _transmitSuccessFlag = new ManualResetEvent(false);
            _transmitFailedFlag  = new ManualResetEvent(false);
        }
コード例 #15
0
ファイル: Program.cs プロジェクト: lulzzz/RFM9XLoRa-TinyCLR
        public Rfm9XDevice(int chipSelectPin, int resetPin)
        {
            var settings = new SpiConnectionSettings()
            {
                ChipSelectType        = SpiChipSelectType.Gpio,
                ChipSelectLine        = chipSelectPin,
                Mode                  = SpiMode.Mode0,
                ClockFrequency        = 500000,
                DataBitLength         = 8,
                ChipSelectActiveState = false,
            };

            SpiController spiController = SpiController.FromName(FEZ.SpiBus.Spi1);

            rfm9XLoraModem = spiController.GetDevice(settings);

            // Factory reset pin configuration
            GpioController gpioController = GpioController.GetDefault();
            GpioPin        resetGpioPin   = gpioController.OpenPin(resetPin);

            resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            resetGpioPin.Write(GpioPinValue.Low);
            Thread.Sleep(10);
            resetGpioPin.Write(GpioPinValue.High);
            Thread.Sleep(10);
        }
コード例 #16
0
ファイル: x74595.cs プロジェクト: Gravicode/TinyCLR.Drivers
        /// <summary>
        ///     Constructor a ShiftRegister 74595 object.
        /// </summary>
        /// <param name="pins">Number of pins in the shift register (should be a multiple of 8 pins).</param>
        /// <param name="spiBus">SpiBus object</param>
        public x74595(string spiBus, int pinChipSelect, int pins = 8)
        {
            // if ((pins > 0) && ((pins % 8) == 0))
            if (pins == 8)
            {
                _numberOfChips = pins / 8;

                _latchData = new byte[_numberOfChips];

                var gpio = GpioController.GetDefault();

                var chipSelectPort = gpio.OpenPin(pinChipSelect);
                chipSelectPort.SetDriveMode(GpioPinDriveMode.Output);
                chipSelectPort.Write(GpioPinValue.Low);

                var settings = new SpiConnectionSettings()
                {
                    ChipSelectType = SpiChipSelectType.Gpio,
                    ChipSelectLine = chipSelectPort,
                    Mode           = SpiMode.Mode1,
                    ClockFrequency = 4_000_000,
                };

                var controller = SpiController.FromName(spiBus);
                _spi = controller.GetDevice(settings);
                //_spi = new SpiPeripheral(spiBus, device.CreateDigitalOutputPort(pinChipSelect));
            }
            else
            {
                throw new ArgumentOutOfRangeException(
                          "x74595: Size must be greater than zero and a multiple of 8 pins, driver is currently limited to one chip (8 pins)");
            }
        }
コード例 #17
0
        static async Task spiread(string[] input)
        {
            try
            {
                if (input.Length == 2)
                {
                    UpBridge.Up   upb        = new UpBridge.Up();
                    SpiController controller = await SpiController.GetDefaultAsync();

                    SpiConnectionSettings settings = new SpiConnectionSettings(spi.ChipSelectLine);
                    settings.ClockFrequency = spi.ClockFrequency;
                    settings.DataBitLength  = spi.DataBitLength;
                    settings.Mode           = spi.Mode;
                    settings.SharingMode    = spi.SharingMode;
                    byte[] readbuf = new byte[Convert.ToInt32(input[1])];
                    controller.GetDevice(settings).Read(readbuf);
                    for (int i = 0; i < readbuf.Length; i++)
                    {
                        Console.WriteLine(i + " byte: " + readbuf[i].ToString("X"));
                    }
                }
                else
                {
                    Console.WriteLine("please input : read N");
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #18
0
        /// <summary>
        /// Constructor of MfRc522 module
        /// </summary>
        /// <param name="spiBus">Spi bus</param>
        /// <param name="resetPin">Reset Pin (RST)</param>
        /// <param name="csPin">ChipSelect Pin(SDA)</param>
        public MfRc522(string spiBus, int resetPin, int csPin)
        {
            _dummyBuffer2        = new byte[2];
            _registerWriteBuffer = new byte[2];

            var gpioCtl = GpioController.GetDefault();

            _resetPin = gpioCtl.OpenPin(resetPin);
            _resetPin.SetDriveMode(GpioPinDriveMode.Output);
            _resetPin.Write(GpioPinValue.High);

            //if (irqPin != -1)
            //{
            //    _irqPin = gpioCtl.OpenPin(irqPin);
            //    _irqPin.SetDriveMode(GpioPinDriveMode.Input);
            //    _irqPin.ValueChanged += _irqPin_ValueChanged;
            //}

            var settings = new SpiConnectionSettings()
            {
                ChipSelectActiveState = false,
                ChipSelectLine        = csPin,
                ChipSelectType        = SpiChipSelectType.Gpio,
                ClockFrequency        = 10_000_000,
                DataBitLength         = 8,
                Mode = SpiMode.Mode0
            };

            _spi = SpiController.FromName(spiBus).GetDevice(settings);

            HardReset();
            SetDefaultValues();
        }
コード例 #19
0
        public static void Execute()
        {
            var settings = BME280Driver.GetSpiConnectionSettings(G120E.GpioPin.P2_27);

            var controller = SpiController.FromName(G120E.SpiBus.Spi0);

            var device = controller.GetDevice(settings);

            var driver = new BME280Driver(device);

            driver.Initialize();

            driver.ChangeSettings(
                BME280SensorMode.Forced,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280OverSample.X1,
                BME280Filter.Off);

            driver.Read();

            Debug.WriteLine("Pressure: " + driver.Pressure);
            Debug.WriteLine("Humidity: " + driver.Humidity);
            Debug.WriteLine("Temperature:" + driver.Temperature);
        }
コード例 #20
0
        /// <summary>
        /// Constructor of LedStrip
        /// </summary>
        /// <param name="size">Size of strip in led number</param>
        /// <param name="spiBus">Id of spi bus</param>
        /// <param name="chipSelect">ChipSelect pin. May be a dummy pin (as not connected) as it don't be used</param>
        /// <param name="order">Order of colors</param>
        public LedStrip(int size, string spiBus, int chipSelect, ColorOrder order)
        {
            if (size < 1)
            {
                throw new ArgumentOutOfRangeException(nameof(size), "must be greater than 0");
            }
            Size  = size;
            _leds = new Led[size];
            for (int i = 0; i < size; i++)
            {
                _leds[i] = new Led(order);
            }
            _dummy = new byte[4 + 4 * size + size / 8 / 2];
            _data  = new byte[4 + 4 * size + size / 8 / 2];
            SpiConnectionSettings settings = new SpiConnectionSettings()
            {
                ChipSelectLine = chipSelect,
                DataBitLength  = 8,
                ClockFrequency = 10 * 1000 * 1000
            };

            _spi = SpiController.FromName(spiBus).GetDevice(settings);
            PrepareStart();
            PrepareEnd();
        }
コード例 #21
0
ファイル: Program.cs プロジェクト: KiwiBryn/RFM9XLoRa-TinyCLR
        public Rfm9XDevice(string spiPortName, int chipSelectPin, int resetPin, int interruptPin)
        {
            GpioController gpioController = GpioController.GetDefault();

            GpioPin chipSelectGpio = gpioController.OpenPin(chipSelectPin);

            var settings = new SpiConnectionSettings()
            {
                ChipSelectType        = SpiChipSelectType.Gpio,
                ChipSelectLine        = chipSelectGpio,
                Mode                  = SpiMode.Mode0,
                ClockFrequency        = 500000,
                ChipSelectActiveState = false,
                ChipSelectHoldTime    = new TimeSpan(1),
            };

            SpiController spiController = SpiController.FromName(spiPortName);

            rfm9XLoraModem = spiController.GetDevice(settings);

            // Factory reset pin configuration
            GpioPin resetGpioPin = gpioController.OpenPin(resetPin);

            resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            resetGpioPin.Write(GpioPinValue.Low);
            Thread.Sleep(10);
            resetGpioPin.Write(GpioPinValue.High);
            Thread.Sleep(10);

            // Interrupt pin for RX message & TX done notification
            InterruptGpioPin = gpioController.OpenPin(interruptPin);
            InterruptGpioPin.SetDriveMode(GpioPinDriveMode.Input);

            InterruptGpioPin.ValueChanged += InterruptGpioPin_ValueChanged;
        }
コード例 #22
0
        /// <summary>
        /// Initializes a new instance of the <see cref="RotaryClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the module is plugged.</param>
        public RotaryClick(Hardware.Socket socket)
        {
            _rot = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Initialize the display and the internal counter
            Write(0);
            InternalCounter = 0;

            // First encoder
            _encA = GpioController.GetDefault().OpenPin(socket.PwmPin);
            _encA.SetDriveMode(GpioPinDriveMode.Input);
            _aLastState         = _encA.Read();
            _encA.ValueChanged += EncA_ValueChanged;

            // Second encoder
            _encB = GpioController.GetDefault().OpenPin(socket.AnPin);
            _encB.SetDriveMode(GpioPinDriveMode.Input);

            // Button switch
            _sw = GpioController.GetDefault().OpenPin(socket.Int);
            _sw.SetDriveMode(GpioPinDriveMode.InputPullDown);
            _sw.ValueChanged += Sw_ValueChanged;
        }
コード例 #23
0
        private async Task InitSpi()
        {
            try
            {
                var adcSettings = new SpiConnectionSettings(0)                      // Chip Select line 0
                {
                    ClockFrequency = 500 * 1000,                                    // Don't exceed 3.6 MHz
                    Mode           = SpiMode.Mode0,
                    SharingMode    = SpiSharingMode.Shared
                };

                var controller = await SpiController.GetDefaultAsync(); /* Find the SPI bus controller device with our selector string  */

                ADC = controller.GetDevice(adcSettings);                /* Create an SpiDevice with our bus controller and SPI settings */
                System.Diagnostics.Debug.WriteLine("Init ADC successful");

                var gyroSettings = new SpiConnectionSettings(1)                    // Chip Select line 0
                {
                    ClockFrequency = 500 * 100,                                    // Don't exceed 3.6 MHz
                    Mode           = SpiMode.Mode3,
                    SharingMode    = SpiSharingMode.Shared
                };

                Gyro = controller.GetDevice(gyroSettings);   /* Create an SpiDevice with our bus controller and SPI settings */
                System.Diagnostics.Debug.WriteLine("Init Gyro successful");
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("InitSpi threw " + ex);
            }
        }
コード例 #24
0
        public static void InitializeDisplay()
        {
            var spi  = SpiController.FromName(SC20100.SpiBus.Spi4);
            var gpio = GpioController.GetDefault();

            DisplayController = new ST7735Controller(
                spi.GetDevice(ST7735Controller.GetConnectionSettings(SpiChipSelectType.Gpio, gpio.OpenPin(SC20100.GpioPin.PD10))), // ChipSelect
                gpio.OpenPin(SC20100.GpioPin.PC4),                                                                                 // Pin RS
                gpio.OpenPin(SC20100.GpioPin.PE15)                                                                                 // Pin RESET

                );

            var bl = gpio.OpenPin(SC20100.GpioPin.PA15); // back light

            bl.Write(GpioPinValue.High);
            bl.SetDriveMode(GpioPinDriveMode.Output);

            DisplayController.SetDataAccessControl(true, true, false, false); //Rotate the screen.
            DisplayController.SetDrawWindow(0, 0, Width, Height);
            DisplayController.Enable();


            // Create flush event
            Graphics.OnFlushEvent += Graphics_OnFlushEvent;
        }
コード例 #25
0
ファイル: Program.cs プロジェクト: lulzzz/RFM9XLoRa-TinyCLR
        static void Main()
        {
            var settings = new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = FEZ.GpioPin.D10,
                Mode           = SpiMode.Mode0,
                //Mode = SpiMode.Mode1,
                //Mode = SpiMode.Mode2,
                //Mode = SpiMode.Mode3,
                ClockFrequency = 500000,
                DataBitLength  = 8,
                //ChipSelectActiveState = true
                ChipSelectActiveState = false,
                //ChipSelectHoldTime = new TimeSpan(0, 0, 0, 0, 500),
                //ChipSelectSetupTime = new TimeSpan(0, 0, 0, 0, 500),
            };

            var controller = SpiController.FromName(FEZ.SpiBus.Spi1);
            var device     = controller.GetDevice(settings);

            Thread.Sleep(500);

            while (true)
            {
                byte   register;
                byte[] writeBuffer;
                byte[] readBuffer;

                // Silicon Version info
                register = 0x42; // RegVersion expecting 0x12

                // Frequency
                //register = 0x06; // RegFrfMsb expecting 0x6C
                //register = 0x07; // RegFrfMid expecting 0x80
                //register = 0x08; // RegFrfLsb expecting 0x00

                //register = 0x17; //RegPayoadLength expecting 0x47

                // Preamble length
                //register = 0x18; // RegPreambleMsb expecting 0x32
                //register = 0x19; // RegPreambleLsb expecting 0x3E

                //register <<= 1;
                //register |= 0x80;

                //writeBuffer = new byte[] { register };
                writeBuffer = new byte[] { register, 0x0 };
                //writeBuffer = new byte[] { register, register, 0x0 };

                readBuffer = new byte[writeBuffer.Length];

                //device.TransferSequential(writeBuffer, readBuffer);
                device.TransferFullDuplex(writeBuffer, readBuffer);

                Debug.WriteLine("Value = 0x" + BytesToHexString(readBuffer));

                Thread.Sleep(1000);
            }
        }
コード例 #26
0
        /// <summary>
        ///     Create a new ST7565 object using the default parameters for
        /// </summary>
        public St7565(string spiBus, int chipSelectPin, int dcPin, int resetPin,
                      uint width = 128, uint height = 64)
        {
            var gpio = GpioController.GetDefault();

            dataCommandPort = gpio.OpenPin(dcPin);
            dataCommandPort.SetDriveMode(GpioPinDriveMode.Output);
            dataCommandPort.Write(GpioPinValue.Low);

            resetPort = gpio.OpenPin(resetPin);
            resetPort.SetDriveMode(GpioPinDriveMode.Output);
            resetPort.Write(GpioPinValue.Low);

            chipSelectPort = gpio.OpenPin(chipSelectPin);
            chipSelectPort.SetDriveMode(GpioPinDriveMode.Output);


            var settings = new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = chipSelectPort,
                Mode           = SpiMode.Mode1,
                ClockFrequency = 4_000_000,
            };

            var controller = SpiController.FromName(spiBus);

            spiPerihperal = controller.GetDevice(settings);

            Width  = width;
            Height = height;

            InitST7565();
        }
コード例 #27
0
ファイル: StartupTask.cs プロジェクト: KiwiBryn/RFM9XLoRa-Net
        public void Run(IBackgroundTaskInstance taskInstance)
        {
            GpioPin   ChipSelectGpioPin   = null;
            const int chipSelectPinNumber = 25;

            SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
            var           settings      = new SpiConnectionSettings(1)
            {
                ClockFrequency = 500000,
                Mode           = SpiMode.Mode0,         // From SemTech docs pg 80 CPOL=0, CPHA=0
            };

            // Chip select pin configuration
            GpioController gpioController = GpioController.GetDefault();

            ChipSelectGpioPin = gpioController.OpenPin(chipSelectPinNumber);
            ChipSelectGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            ChipSelectGpioPin.Write(GpioPinValue.High);

            SpiDevice Device = spiController.GetDevice(settings);

            while (true)
            {
                byte[] writeBuffer = new byte[] { 0x42 };                 // RegVersion
                byte[] readBuffer  = new byte[1];

                // Read the RegVersion silicon ID to check SPI works
                ChipSelectGpioPin.Write(GpioPinValue.Low);
                Device.TransferSequential(writeBuffer, readBuffer);
                ChipSelectGpioPin.Write(GpioPinValue.High);
                Debug.WriteLine("Register RegVer 0x{0:x2} - Value 0X{1:x2} - Bits {2}", writeBuffer[0], readBuffer[0], Convert.ToString(readBuffer[0], 2).PadLeft(8, '0'));

                Thread.Sleep(10000);
            }
        }
コード例 #28
0
ファイル: ThunderClick.cs プロジェクト: valoni/MBN-TinyCLR
        /// <summary>
        /// Initializes a new instance of the <see cref="ThunderClick"/> class.
        /// </summary>
        /// <param name="socket">The socket on which the Thunder Click board is plugged on MikroBus.Net board</param>
        public ThunderClick(Hardware.Socket socket)
        {
            _socket = socket;
            IRQ     = GpioController.GetDefault().OpenPin(socket.Int);
            IRQ.SetDriveMode(GpioPinDriveMode.Input);
            IRQ.ValueChanged += IRQ_ValueChanged;

            // Initialize SPI
            _thunder = SpiController.FromName(socket.SpiBus).GetDevice(new SpiConnectionSettings()
            {
                ChipSelectType = SpiChipSelectType.Gpio,
                ChipSelectLine = GpioController.GetDefault().OpenPin(socket.Cs),
                Mode           = SpiMode.Mode0,
                ClockFrequency = 2000000
            });

            // Direct commands
            lock (_socket.LockSpi)
            {
                _thunder.Write(new Byte[] { PRESET_DEFAULT, 0x96 });                     // Set all registers in default mode
                _thunder.Write(new Byte[] { CALIB_RCO, 0x96 });                          // Calibrate internal oscillators
            }
            _nfl                = 2;                                                     // Noise floor level
            _mode               = AFE.Indoor;                                            // Default mode is Indoor
            _spikeRejection     = 2;                                                     // Default value for spike rejection
            _minNumberLightning = 0;                                                     // Minimum number of detected lightnings
            INL_Indoor          = new[] { 28, 45, 62, 78, 95, 112, 130, 146 };           // Indoor continuous input noise level values (µV rms)
            INL_Outdoor         = new[] { 390, 630, 860, 1100, 1140, 1570, 1800, 2000 }; // Outdoor continuous input noise level values (µV rms)
            _powerMode          = PowerModes.On;
        }
コード例 #29
0
ファイル: Program.cs プロジェクト: dobova86/TinyCLR_Test_Wifi
        public static void Main()
        {
            var cont = GpioController.GetDefault();

            //FEZ
            //var reset = cont.OpenPin(FEZ.GpioPin.WiFiReset);
            //var irq = cont.OpenPin(FEZ.GpioPin.WiFiInterrupt);
            //var scont = SpiController.FromName(FEZ.SpiBus.WiFi);
            //var spi = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, FEZ.GpioPin.WiFiChipSelect));
            //led1 = cont.OpenPin(FEZ.GpioPin.Led1);
            //btn1 = cont.OpenPin(FEZ.GpioPin.Btn1);

            //UC5550
            var reset = cont.OpenPin(UC5550.GpioPin.PG12);
            var irq   = cont.OpenPin(UC5550.GpioPin.PB11);
            var scont = SpiController.FromName(UC5550.SpiBus.Spi5);
            var spi   = scont.GetDevice(SPWF04SxInterface.GetConnectionSettings(SpiChipSelectType.Gpio, UC5550.GpioPin.PB10));

            led1 = cont.OpenPin(UC5550.GpioPin.PD3);
            btn1 = cont.OpenPin(UC5550.GpioPin.PB2);

            led1.SetDriveMode(GpioPinDriveMode.Output);
            btn1.SetDriveMode(GpioPinDriveMode.InputPullUp);

            wifi = new SPWF04SxInterface(spi, irq, reset);

            wifi.IndicationReceived += (s, e) => Debug.WriteLine($"WIND: {Program.WindToName(e.Indication)} {e.Message}");
            wifi.ErrorReceived      += (s, e) => Debug.WriteLine($"ERROR: {e.Error} {e.Message}");

            wifi.TurnOn();

            NetworkInterface.ActiveNetworkInterface = wifi;

            Run();
        }
コード例 #30
0
        public Rfm9XDevice(int chipSelectPin, int resetPin)
        {
            SpiController spiController = SpiController.GetDefaultAsync().AsTask().GetAwaiter().GetResult();
            var           settings      = new SpiConnectionSettings(0)
            {
                ClockFrequency = 500000,
                Mode           = SpiMode.Mode0,
            };

            // Chip select pin configuration
            GpioController gpioController = GpioController.GetDefault();

            ChipSelectGpioPin = gpioController.OpenPin(chipSelectPin);
            ChipSelectGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            ChipSelectGpioPin.Write(GpioPinValue.High);

            // Factory reset pin configuration
            GpioPin resetGpioPin = gpioController.OpenPin(resetPin);

            resetGpioPin.SetDriveMode(GpioPinDriveMode.Output);
            resetGpioPin.Write(GpioPinValue.Low);
            Task.Delay(10);
            resetGpioPin.Write(GpioPinValue.High);
            Task.Delay(10);

            Rfm9XLoraModem = spiController.GetDevice(settings);
        }