Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added samples/NXP/NXPGPIOSample/NXPGPIO.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
51 changes: 51 additions & 0 deletions samples/NXP/NXPGPIOSample/NXPGPIOSample.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.7.34302.85
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NXPGPIOSample", "NXPGPIOSample\NXPGPIOSample.csproj", "{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|ARM = Debug|ARM
Debug|ARM64 = Debug|ARM64
Debug|x64 = Debug|x64
Debug|x86 = Debug|x86
Release|ARM = Release|ARM
Release|ARM64 = Release|ARM64
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM.ActiveCfg = Debug|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM.Build.0 = Debug|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM.Deploy.0 = Debug|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM64.ActiveCfg = Debug|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM64.Build.0 = Debug|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|ARM64.Deploy.0 = Debug|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x64.ActiveCfg = Debug|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x64.Build.0 = Debug|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x64.Deploy.0 = Debug|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x86.ActiveCfg = Debug|x86
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x86.Build.0 = Debug|x86
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Debug|x86.Deploy.0 = Debug|x86
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM.ActiveCfg = Release|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM.Build.0 = Release|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM.Deploy.0 = Release|ARM
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM64.ActiveCfg = Release|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM64.Build.0 = Release|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|ARM64.Deploy.0 = Release|ARM64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x64.ActiveCfg = Release|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x64.Build.0 = Release|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x64.Deploy.0 = Release|x64
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x86.ActiveCfg = Release|x86
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x86.Build.0 = Release|x86
{A41EB9AB-5990-4B2F-9BB0-4DF9DECED77B}.Release|x86.Deploy.0 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {74AAC59C-4197-413B-9284-1623FFC7DF6D}
EndGlobalSection
EndGlobal
7 changes: 7 additions & 0 deletions samples/NXP/NXPGPIOSample/NXPGPIOSample/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<Application
x:Class="NXPGPIOSample.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NXPGPIOSample">

</Application>
100 changes: 100 additions & 0 deletions samples/NXP/NXPGPIOSample/NXPGPIOSample/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

namespace NXPGPIOSample
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
sealed partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="e">Details about the launch request and process.</param>
protected override void OnLaunched(LaunchActivatedEventArgs e)
{
Frame rootFrame = Window.Current.Content as Frame;

// Do not repeat app initialization when the Window already has content,
// just ensure that the window is active
if (rootFrame == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootFrame = new Frame();

rootFrame.NavigationFailed += OnNavigationFailed;

if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}

// Place the frame in the current Window
Window.Current.Content = rootFrame;
}

if (e.PrelaunchActivated == false)
{
if (rootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootFrame.Navigate(typeof(MainPage), e.Arguments);
}
// Ensure the current window is active
Window.Current.Activate();
}
}

/// <summary>
/// Invoked when Navigation to a certain page fails
/// </summary>
/// <param name="sender">The Frame which failed navigation</param>
/// <param name="e">Details about the navigation failure</param>
void OnNavigationFailed(object sender, NavigationFailedEventArgs e)
{
throw new Exception("Failed to load Page " + e.SourcePageType.FullName);
}

/// <summary>
/// Invoked when application execution is being suspended. Application state is saved
/// without knowing whether the application will be terminated or resumed with the contents
/// of memory still intact.
/// </summary>
/// <param name="sender">The source of the suspend request.</param>
/// <param name="e">Details about the suspend request.</param>
private void OnSuspending(object sender, SuspendingEventArgs e)
{
var deferral = e.SuspendingOperation.GetDeferral();
//TODO: Save application state and stop any background activity
deferral.Complete();
}
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
18 changes: 18 additions & 0 deletions samples/NXP/NXPGPIOSample/NXPGPIOSample/MainPage.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<Page
x:Class="NXPGPIOSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:NXPGPIOSample"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<Ellipse x:Name="LED" Fill="LightGray" Stroke="White" Width="100" Height="100" Margin="10"/>
<TextBlock x:Name="DelayText" Text="500ms" Margin="10" TextAlignment="Center" FontSize="26.667" />
<TextBlock x:Name="GpioStatus" Text="Waiting to initialize GPIO..." Margin="10,50,10,10" TextAlignment="Center" FontSize="26.667" />
</StackPanel>
</Grid>
</Page>
79 changes: 79 additions & 0 deletions samples/NXP/NXPGPIOSample/NXPGPIOSample/MainPage.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// Copyright (c) Microsoft. All rights reserved.

using System;
using Windows.Devices.Gpio;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Media;

namespace NXPGPIOSample
{
public sealed partial class MainPage : Page
{
private int[] LED_PINS = new int[] {147, 146, 141, 140, 139, 138, 137, 136, 87, 86, 85, 84, 83 };
private GpioPin[] pins;
private GpioPinValue[] pinValues;
private DispatcherTimer timer;
private SolidColorBrush redBrush = new SolidColorBrush(Windows.UI.Colors.Red);
private SolidColorBrush grayBrush = new SolidColorBrush(Windows.UI.Colors.LightGray);

public MainPage()
{
InitializeComponent();

timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += Timer_Tick;
InitGPIO();
if (pins != null)
{
timer.Start();
}
}

private void InitGPIO()
{
var gpio = GpioController.GetDefault();

// Show an error if there is no GPIO controller
if (gpio == null)
{
pins = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}

pins = new GpioPin[LED_PINS.Length];
pinValues = new GpioPinValue[LED_PINS.Length];
for (int i = 0; i < LED_PINS.Length; i++)
{
pins[i] = gpio.OpenPin(LED_PINS[i]);
pinValues[i] = GpioPinValue.High;
pins[i].Write(pinValues[i]);
pins[i].SetDriveMode(GpioPinDriveMode.Output);
}

GpioStatus.Text = "GPIO pins initialized correctly.";
}

private void Timer_Tick(object sender, object e)
{
for (int i = 0; i < LED_PINS.Length; i++)
{
if (pinValues[i] == GpioPinValue.High)
{
pinValues[i] = GpioPinValue.Low;
pins[i].Write(pinValues[i]);
LED.Fill = redBrush;
}
else
{
pinValues[i] = GpioPinValue.High;
pins[i].Write(pinValues[i]);
LED.Fill = grayBrush;
}
}
}
}
}
Loading