Skip to content
Draft
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
73 changes: 73 additions & 0 deletions Projects/IO Expander/Microchip/Microchip.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props" Condition="Exists('packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{40EE1C99-A152-4AF9-ADCE-453967FEA98A}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>Microchip</RootNamespace>
<AssemblyName>Microchip</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<LangVersion>9</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="GHIElectronics.TinyCLR.Devices.Gpio">
<HintPath>..\..\..\..\TinyCLR-Libraries\GHIElectronics.TinyCLR.Devices.Gpio\bin\Debug\GHIElectronics.TinyCLR.Devices.Gpio.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.I2c">
<HintPath>..\..\..\..\TinyCLR-Libraries\GHIElectronics.TinyCLR.Devices.I2c\bin\Debug\GHIElectronics.TinyCLR.Devices.I2c.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.Spi">
<HintPath>..\..\..\..\TinyCLR-Libraries\GHIElectronics.TinyCLR.Devices.Spi\bin\Debug\GHIElectronics.TinyCLR.Devices.Spi.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Drivers.Microchip.Mcp23xxx">
<HintPath>..\..\..\..\TinyCLR-Drivers\Microchip\Mcp23xxx\GHIElectronics.TinyCLR.Drivers.Microchip.Mcp23xxx\bin\Debug\GHIElectronics.TinyCLR.Drivers.Microchip.Mcp23xxx.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Native, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Native.2.1.0\lib\net452\GHIElectronics.TinyCLR.Native.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Pins, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Pins.2.1.0\lib\net452\GHIElectronics.TinyCLR.Pins.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props'))" />
</Target>
</Project>
27 changes: 27 additions & 0 deletions Projects/IO Expander/Microchip/Microchip.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31424.327
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microchip", "Microchip.csproj", "{40EE1C99-A152-4AF9-ADCE-453967FEA98A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Release|Any CPU.Build.0 = Release|Any CPU
{40EE1C99-A152-4AF9-ADCE-453967FEA98A}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {0CFB69D5-28BC-4BAE-9E7D-8D5523B5CDB1}
EndGlobalSection
EndGlobal
78 changes: 78 additions & 0 deletions Projects/IO Expander/Microchip/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
using System;
using System.Diagnostics;
using System.Threading;

using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Spi;
using GHIElectronics.TinyCLR.Pins;

using GHIElectronics.TinyCLR.Drivers.Microchip.Mcp23xxx.Device;
using static GHIElectronics.TinyCLR.Drivers.Microchip.Mcp23xxx.Mcp23Xxx;

// ReSharper disable InconsistentNaming
#pragma warning disable IDE1006 // Naming Styles


namespace Microchip
{
internal static class Program
{
private static Timer _outTimer;

/// <summary>
/// Using the Microchip Mcp23S18 gpio expander as a native like TinyClr Gpio Pin
/// </summary>
private static void Main()
{
// use default GPIO controller to setup pins for Mcp23xxx IO Expander
var gpioController = GpioController.GetDefault();
var reset = gpioController.OpenPin(SC13048.GpioPin.PA2);
var chipSelect = gpioController.OpenPin(SC13048.GpioPin.PA3);
var interruptPin = gpioController.OpenPin(SC13048.GpioPin.PB8);
interruptPin.SetDriveMode(GpioPinDriveMode.InputPullUp);

// create a Microchip MCP23S18 GPIO expander provider using the SPI bus on the FLEA
var mcp23S18 = new Mcp23GpioProvider(Product.Mcp23X18, SpiController.FromName(SC13048.SpiBus.Spi2), chipSelect, reset: reset, interruptPin: interruptPin);
// use the Mcp23S18 provider to create a 'native' GpioController
var externalGpioController = GpioController.FromProvider(mcp23S18);

// use the external GpioController to set up an external LED
// use port A, pin 0, set as output, no pull-up (using external pull up resistor as Mcp23S18 has open drain outputs)
var exLed = externalGpioController.OpenPin(ExternalGpioPin.GpA0);
exLed.SetDriveMode(GpioPinDriveMode.OutputOpenDrain);

// use the external GpioController to set up an external Button
// use port A, pin 1 set as input, using internal pull-up and 30ms debounce timing, set with a callback when either rising or falling edge is detected
var exButton = externalGpioController.OpenPin(ExternalGpioPin.GpA1);
exButton.SetDriveMode(GpioPinDriveMode.InputPullUp);
exButton.DebounceTimeout = TimeSpan.FromMilliseconds(30);
exButton.ValueChangedEdge = GpioPinEdge.FallingEdge | GpioPinEdge.RisingEdge;
exButton.ValueChanged += (_, args) =>
{
Debug.WriteLine($"change: edge:{(args.Edge == GpioPinEdge.RisingEdge ? "rise" : "fall")} ts:{args.Timestamp}");
exLed.Write(exLed.Read() == GpioPinValue.Low ? GpioPinValue.High : GpioPinValue.Low);
};

// now you can use an expanded GPIO pin wherever a standard GpioPin is required; without need to extend the sealed GpioPin class
var exChipSelect = externalGpioController.OpenPin(ExternalGpioPin.GpB0);
exChipSelect.SetDriveMode(GpioPinDriveMode.Output);
var s = SpiController.FromName(SC13048.SpiBus.Spi1);
s.GetDevice(new SpiConnectionSettings{ ChipSelectType = SpiChipSelectType.Gpio, ChipSelectLine = exLed });


// finally use default GPIO controller to blink the internal LED and ensure things are running as expected :-)
var onBoardLed = gpioController.OpenPin(SC13048.GpioPin.PA8);
onBoardLed.SetDriveMode(GpioPinDriveMode.Output);

_outTimer = new Timer(_ =>
{
onBoardLed.Write(onBoardLed.Read() == GpioPinValue.High ? GpioPinValue.Low : GpioPinValue.High);
_outTimer.Change(TimeSpan.FromSeconds(2), TimeSpan.FromMilliseconds(-1));

}, null, TimeSpan.FromSeconds(1), TimeSpan.FromMilliseconds(-1));

// put main thread to sleep
Thread.Sleep(Timeout.Infinite);
}
}
}
36 changes: 36 additions & 0 deletions Projects/IO Expander/Microchip/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Microchip")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Microchip")]
[assembly: AssemblyCopyright("Copyright © 2021")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("40ee1c99-a152-4af9-adce-453967fea98a")]

// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
6 changes: 6 additions & 0 deletions Projects/IO Expander/Microchip/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="GHIElectronics.TinyCLR.Core" version="2.1.0" targetFramework="net452" />
<package id="GHIElectronics.TinyCLR.Native" version="2.1.0" targetFramework="net452" />
<package id="GHIElectronics.TinyCLR.Pins" version="2.1.0" targetFramework="net452" />
</packages>
70 changes: 70 additions & 0 deletions Projects/TinyCLR/MemoryManager/MemoryManager.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props" Condition="Exists('packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props')" />
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{2F8637E4-D64F-4EA1-B6A1-F93088280A67}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>MemoryManager</RootNamespace>
<AssemblyName>MemoryManager</AssemblyName>
<TargetFrameworkVersion>v4.5.2</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<ProjectTypeGuids>{A1948822-69DD-4150-919B-F3F42EFB71CC};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<LangVersion>9</LangVersion>
<NuGetPackageImportStamp>
</NuGetPackageImportStamp>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Reference Include="GHIElectronics.TinyCLR.Cryptography, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Cryptography.2.1.0\lib\net452\GHIElectronics.TinyCLR.Cryptography.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.Rtc, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Devices.Rtc.2.1.0\lib\net452\GHIElectronics.TinyCLR.Devices.Rtc.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Devices.SecureStorage, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Devices.SecureStorage.2.1.0\lib\net452\GHIElectronics.TinyCLR.Devices.SecureStorage.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Drivers.MemoryManager">
<HintPath>..\..\..\..\TinyCLR-Drivers\MemoryManager\GHIElectronics.TinyCLR.Drivers.MemoryManager\bin\Debug\GHIElectronics.TinyCLR.Drivers.MemoryManager.dll</HintPath>
</Reference>
<Reference Include="GHIElectronics.TinyCLR.Native, Version=2.1.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>packages\GHIElectronics.TinyCLR.Native.2.1.0\lib\net452\GHIElectronics.TinyCLR.Native.dll</HintPath>
</Reference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
<PropertyGroup>
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup>
<Error Condition="!Exists('packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\GHIElectronics.TinyCLR.Core.2.1.0\build\net452\GHIElectronics.TinyCLR.Core.props'))" />
</Target>
</Project>
27 changes: 27 additions & 0 deletions Projects/TinyCLR/MemoryManager/MemoryManager.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.31624.102
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "MemoryManager", "MemoryManager.csproj", "{2F8637E4-D64F-4EA1-B6A1-F93088280A67}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Release|Any CPU.Build.0 = Release|Any CPU
{2F8637E4-D64F-4EA1-B6A1-F93088280A67}.Release|Any CPU.Deploy.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {D82A7AC9-3B46-47A8-86E9-8C18FC655172}
EndGlobalSection
EndGlobal
Loading