private void ConnectWifi() { var enablePin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PA8); enablePin.SetDriveMode(GpioPinDriveMode.Output); enablePin.Write(GpioPinValue.High); var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings(); var cs = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault(). OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PA6); var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings() { ChipSelectLine = cs, ClockFrequency = 4000000, Mode = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0, ChipSelectType = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio, ChipSelectHoldTime = TimeSpan.FromTicks(10), ChipSelectSetupTime = TimeSpan.FromTicks(10) }; networkCommunicationInterfaceSettings.SpiApiName = SC20260.SpiBus.Spi3; networkCommunicationInterfaceSettings.GpioApiName = SC20260.GpioPin.Id; networkCommunicationInterfaceSettings.SpiSettings = settings; networkCommunicationInterfaceSettings.InterruptPin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PF10); networkCommunicationInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge; networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp; networkCommunicationInterfaceSettings.ResetPin = GpioController.GetDefault().OpenPin(SC20260.GpioPin.PF8); networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low; var networkController = NetworkController.FromName ("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController"); var networkInterfaceSetting = new WiFiNetworkInterfaceSettings() { Ssid = this.ssidTextBox.Text, Password = this.passwordTextBox.Text, }; networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 122 }); networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }); networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }); networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[] { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) }; networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 }; networkInterfaceSetting.IsDhcpEnabled = true; networkInterfaceSetting.IsDynamicDnsEnabled = true; networkInterfaceSetting.TlsEntropy = new byte[] { 0, 1, 2, 3 }; networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings); networkController.SetAsDefaultController(); networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged; networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged; networkController.Enable(); }
public WifiDevice(NetworkController networkController, GpioPin resetPin) : base(networkController, resetPin) { Settings = new WiFiNetworkInterfaceSettings { Address = new IPAddress(new byte[] { 192, 168, 1, 100 }), SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }), GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }), }; networkController.SetInterfaceSettings(Settings); var enablePin = HardwareProvider.Gpio.OpenPin(SC20100.GpioPin.PA8); enablePin.SetDriveMode(GpioPinDriveMode.Output); enablePin.Write(GpioPinValue.High); Reset(); }
static void SetupWiFi7Click_SC20100_MicroBus1() { var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8); enablePin.SetDriveMode(GpioPinDriveMode.Output); enablePin.Write(GpioPinValue.High); SpiNetworkCommunicationInterfaceSettings networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings(); var cs = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault(). OpenPin(GHIElectronics.TinyCLR.Pins.SC20260.GpioPin.PD15); var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings() { ChipSelectLine = cs, ClockFrequency = 4000000, Mode = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0, ChipSelectType = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio, ChipSelectHoldTime = TimeSpan.FromTicks(10), ChipSelectSetupTime = TimeSpan.FromTicks(10) }; networkCommunicationInterfaceSettings.SpiApiName = GHIElectronics.TinyCLR.Pins.SC20100.SpiBus.Spi3; networkCommunicationInterfaceSettings.GpioApiName = GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.Id; networkCommunicationInterfaceSettings.SpiSettings = settings; networkCommunicationInterfaceSettings.InterruptPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault(). OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PB12); networkCommunicationInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge; networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp; networkCommunicationInterfaceSettings.ResetPin = GHIElectronics.TinyCLR.Devices.Gpio.GpioController.GetDefault(). OpenPin(GHIElectronics.TinyCLR.Pins.SC20100.GpioPin.PB13); networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low; networkController = NetworkController.FromName ("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController"); WiFiNetworkInterfaceSettings networkInterfaceSetting = new WiFiNetworkInterfaceSettings() { Ssid = wiFiSSID_1, Password = wiFiKey_1, }; networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 122 }); networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }); networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }); // networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[] // { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) }; //networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x4, 0x00, 0x00, 0x00, 0x00 }; networkInterfaceSetting.MacAddress = new byte[] { 0x4A, 0x28, 0x05, 0x2A, 0xA4, 0x0F }; networkInterfaceSetting.DhcpEnable = true; networkInterfaceSetting.TlsEntropy = new byte[] { 1, 2, 3, 4 }; networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.SetCommunicationInterfaceSettings (networkCommunicationInterfaceSettings); networkController.SetAsDefaultController(); networkController.NetworkAddressChanged += NetworkController_NetworkAddressChanged; networkController.NetworkLinkConnectedChanged += NetworkController_NetworkLinkConnectedChanged; networkController.Enable(); while (linkReady == false) { ; } // Network is ready to used }
public static void Initialize() { if (_initialized) { return; } lock (_lock) { if (_initialized) { return; } var _dhcpEvent = new AutoResetEvent(false); // Create GPIO reset pin var resetPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB13); resetPin.SetDriveMode(GpioPinDriveMode.Output); // Toggle reset pin and wait for reset completion resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); resetPin.Write(GpioPinValue.High); Thread.Sleep(100); // Create spi settings var spiSettings = new SpiConnectionSettings() { ChipSelectLine = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PD15), ClockFrequency = 4000000, Mode = SpiMode.Mode0, ChipSelectType = SpiChipSelectType.Gpio, ChipSelectHoldTime = TimeSpan.FromTicks(10), ChipSelectSetupTime = TimeSpan.FromTicks(10) }; // Create network settngs var spiNetworkSettings = new SpiNetworkCommunicationInterfaceSettings() { SpiApiName = SC20100.SpiBus.Spi3, GpioApiName = SC20100.GpioPin.Id, InterruptPin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PB12), InterruptEdge = GpioPinEdge.FallingEdge, InterruptDriveMode = GpioPinDriveMode.InputPullUp, ResetPin = resetPin, ResetActiveState = GpioPinValue.Low, SpiSettings = spiSettings }; // Create WiFi settings var wifiNetworkSettings = new WiFiNetworkInterfaceSettings() { Ssid = "crytek", Password = "******", }; // Create network controller Controller = NetworkController.FromName(SC20100.NetworkController.ATWinc15x0); Controller.SetCommunicationInterfaceSettings(spiNetworkSettings); Controller.SetInterfaceSettings(wifiNetworkSettings); Controller.SetAsDefaultController(); Controller.NetworkLinkConnectedChanged += NetworkLinkConnectedChanged; Controller.NetworkAddressChanged += NetworkAddressChanged; // Create GPIO enable pin var enablePin = GpioController.GetDefault().OpenPin(SC20100.GpioPin.PA8); enablePin.SetDriveMode(GpioPinDriveMode.Output); enablePin.Write(GpioPinValue.High); Controller.Enable(); _initialized = true; } }
private extern void SetInterfaceSettings(WiFiNetworkInterfaceSettings settings);
private bool DoTestWifi() { this.UpdateStatusText("Checking wifi firmware...", true); if (this.doTestWifiPassed) { return(true); } var gpioController = GpioController.GetDefault(); var resetPin = gpioController.OpenPin(SC20260.GpioPin.PC3); var csPin = gpioController.OpenPin(SC20260.GpioPin.PA6); var intPin = gpioController.OpenPin(SC20260.GpioPin.PF10); var enPin = gpioController.OpenPin(SC20260.GpioPin.PA8); enPin.SetDriveMode(GpioPinDriveMode.Output); resetPin.SetDriveMode(GpioPinDriveMode.Output); enPin.Write(GpioPinValue.Low); resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); enPin.Write(GpioPinValue.High); resetPin.Write(GpioPinValue.High); var result = false; var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings() { ChipSelectLine = csPin, ClockFrequency = 4000000, Mode = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0, ChipSelectType = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio, ChipSelectHoldTime = TimeSpan.FromTicks(10), ChipSelectSetupTime = TimeSpan.FromTicks(10) }; var networkCommunicationInterfaceSettings = new SpiNetworkCommunicationInterfaceSettings { SpiApiName = SC20260.SpiBus.Spi3, GpioApiName = "GHIElectronics.TinyCLR.NativeApis.STM32H7.GpioController\\0", SpiSettings = settings, InterruptPin = intPin, InterruptEdge = GpioPinEdge.FallingEdge, InterruptDriveMode = GpioPinDriveMode.InputPullUp, ResetPin = resetPin, ResetActiveState = GpioPinValue.Low }; var networkInterfaceSetting = new WiFiNetworkInterfaceSettings() { Ssid = " ", Password = "******", }; networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 122 }); networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }); networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }); networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[] { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) }; //networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 }; networkInterfaceSetting.IsDhcpEnabled = true; networkInterfaceSetting.IsDynamicDnsEnabled = true; var networkController = NetworkController.FromName("GHIElectronics.TinyCLR.NativeApis.ATWINC15xx.NetworkController"); networkController.SetInterfaceSettings(networkInterfaceSetting); networkController.SetCommunicationInterfaceSettings(networkCommunicationInterfaceSettings); networkController.SetAsDefaultController(); var firmware = Winc15x0Interface.GetFirmwareVersion(); if (firmware.IndexOf("19.5.") == 0 || (firmware.IndexOf("19.6.") == 0)) { result = true; } resetPin.Dispose(); csPin.Dispose(); intPin.Dispose(); enPin.Dispose(); this.doTestWifiPassed = result; return(result); }
private void CreateEthernet() { this.isRunning = true; // MikroBus 1 var gpioController = GpioController.GetDefault(); var start = DateTime.Now; try { Thread.Sleep(100); this.resetPin = gpioController.OpenPin(SC20260.GpioPin.PC3); this.csPin = gpioController.OpenPin(SC20260.GpioPin.PA6); this.intPin = gpioController.OpenPin(SC20260.GpioPin.PF10); this.enPin = gpioController.OpenPin(SC20260.GpioPin.PA8); this.enPin.SetDriveMode(GpioPinDriveMode.Output); this.resetPin.SetDriveMode(GpioPinDriveMode.Output); this.enPin.Write(GpioPinValue.Low); this.resetPin.Write(GpioPinValue.Low); Thread.Sleep(100); this.enPin.Write(GpioPinValue.High); this.resetPin.Write(GpioPinValue.High); var settings = new GHIElectronics.TinyCLR.Devices.Spi.SpiConnectionSettings() { ChipSelectLine = this.csPin, ClockFrequency = 4000000, Mode = GHIElectronics.TinyCLR.Devices.Spi.SpiMode.Mode0, ChipSelectType = GHIElectronics.TinyCLR.Devices.Spi.SpiChipSelectType.Gpio, ChipSelectHoldTime = TimeSpan.FromTicks(10), ChipSelectSetupTime = TimeSpan.FromTicks(10) }; this.networkCommunicationInterfaceSettings.SpiApiName = SC20260.SpiBus.Spi3; this.networkCommunicationInterfaceSettings.GpioApiName = "GHIElectronics.TinyCLR.NativeApis.STM32H7.GpioController\\0"; this.networkCommunicationInterfaceSettings.SpiSettings = settings; this.networkCommunicationInterfaceSettings.InterruptPin = this.intPin; this.networkCommunicationInterfaceSettings.InterruptEdge = GpioPinEdge.FallingEdge; this.networkCommunicationInterfaceSettings.InterruptDriveMode = GpioPinDriveMode.InputPullUp; this.networkCommunicationInterfaceSettings.ResetPin = this.resetPin; this.networkCommunicationInterfaceSettings.ResetActiveState = GpioPinValue.Low; var networkInterfaceSetting = new WiFiNetworkInterfaceSettings() { Ssid = this.ssid.Text, Password = this.password.Text, }; networkInterfaceSetting.Address = new IPAddress(new byte[] { 192, 168, 1, 122 }); networkInterfaceSetting.SubnetMask = new IPAddress(new byte[] { 255, 255, 255, 0 }); networkInterfaceSetting.GatewayAddress = new IPAddress(new byte[] { 192, 168, 1, 1 }); networkInterfaceSetting.DnsAddresses = new IPAddress[] { new IPAddress(new byte[] { 75, 75, 75, 75 }), new IPAddress(new byte[] { 75, 75, 75, 76 }) }; //networkInterfaceSetting.MacAddress = new byte[] { 0x00, 0x04, 0x00, 0x00, 0x00, 0x00 }; networkInterfaceSetting.IsDhcpEnabled = true; networkInterfaceSetting.IsDynamicDnsEnabled = true; this.networkController.SetInterfaceSettings(networkInterfaceSetting); this.networkController.SetCommunicationInterfaceSettings(this.networkCommunicationInterfaceSettings); this.networkController.SetAsDefaultController(); this.networkController.NetworkAddressChanged += this.NetworkController_NetworkAddressChanged; this.networkController.NetworkLinkConnectedChanged += this.NetworkController_NetworkLinkConnectedChanged; var firmware = Winc15x0Interface.GetFirmwareVersion(); if (firmware.IndexOf("255.255.255.65535") == 0) { this.resetPin.Dispose(); this.csPin.Dispose(); this.intPin.Dispose(); this.enPin.Dispose(); Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.canvas.Children.Remove(this.status); Canvas.SetLeft(this.status, this.Width / 2 - this.Width / 4 - this.Width / 8 - this.Width / 16); Canvas.SetTop(this.status, this.Height - 40); this.canvas.Children.Add(this.status); this.status.TextContent = "Please reset application and type ssid, password correctly!"; this.status.Invalidate(); return(null); }, null); goto _return; } this.networkController.Enable(); } catch { } while ((DateTime.Now - start).TotalSeconds < 20) { if (this.isWifiConnected) { break; } Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.status.TextContent = "Please wait..." + (int)((DateTime.Now - start).TotalSeconds) + " / 20"; this.status.Invalidate(); return(null); }, null); Thread.Sleep(1000); } if (this.isWifiConnected == false) { Application.Current.Dispatcher.Invoke(TimeSpan.FromMilliseconds(100), _ => { this.status.TextContent = "Wifi connection failed."; this.status.Invalidate(); return(null); }, null); this.resetPin.Dispose(); this.csPin.Dispose(); this.intPin.Dispose(); this.enPin.Dispose(); //var gpioControllerApi = new GpioControllerApiWrapper(NativeApi.Find(NativeApi.GetDefaultName(NativeApiType.GpioController), NativeApiType.GpioController)); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB3); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB4); //gpioControllerApi.ClosePin(SC20260.GpioPin.PB5); //gpioController.Dispose(); } _return: this.isRunning = false; }