Skip to content

Commit b1c5834

Browse files
Migrate Tlc1543 device to nanoFramework (#211)
* Copy device files (unchanged) * Migrate code. Update packages and update README * Update nuspec and remove unused dependency * Re-add class comment * bugfix: Add nullable annotation to remove warnings * Review Markups * Add strong names to all package references * Add a comment to the Samples regarding setting GPIO pins accordingly * Fix file paths for static files in nuspec * Review Markups * Remove old version of the code Co-authored-by: José Simões <[email protected]>
1 parent 217cc51 commit b1c5834

17 files changed

+79
-121
lines changed
File renamed without changes.

src/devices_generated/Tlc1543/README.md renamed to devices/Tlc1543/README.md

+1-13
Original file line numberDiff line numberDiff line change
@@ -15,21 +15,9 @@ This sample shows how to calculate position of line under matrix of 5 IR sensors
1515
### Initialization
1616

1717
```csharp
18-
SoftwareSpi spi = new SoftwareSpi(
19-
clk: 25,
20-
sdi: 23,
21-
sdo: 24,
22-
cs: 5,
23-
settings: new SpiConnectionSettings(-1) { DataBitLength = Tlc1543.SpiDataBitLength });
24-
25-
Tlc1543 adc = new Tlc1543(spi);
18+
SpiDevice spi = SpiDevice.Create(new SpiConnectionSettings(1, 5) { DataBitLength = Tlc1543.SpiDataBitLength });
2619
```
2720

28-
- 24 is our address pin,
29-
- 5 chip select,
30-
- 23 data out pin
31-
- and 25 is input output clock.
32-
3321
### Changing Charge Channel
3422

3523
```csharp

src/devices_generated/Tlc1543/Tlc1543.cs renamed to devices/Tlc1543/Tlc1543.cs

+4-12
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,12 @@
44
using System;
55
using System.Device;
66
using System.Device.Gpio;
7-
using System.Collections.Generic;
87
using System.Device.Spi;
98

109
namespace Iot.Device.Tlc1543
1110
{
1211
/// <summary>
13-
/// Add documentation here
12+
/// Tlc1543 device
1413
/// </summary>
1514
public class Tlc1543 : IDisposable
1615
{
@@ -79,16 +78,9 @@ public int ReadPreviousAndChargeChannel(Channel channelToCharge)
7978
_spiDevice.TransferFullDuplex(writeBuffer, readBuffer);
8079

8180
int previousReading = ((readBuffer[0] & 0b11111) << 5) | (readBuffer[1] & 0b11111);
82-
if (_endOfConversion != -1)
83-
{
84-
// Wait for ADC to report end of conversion or timeout at max conversion time
85-
_controller.WaitForEvent(_endOfConversion, PinEventTypes.Rising, _conversionTime);
86-
}
87-
else
88-
{
89-
// Max conversion time (21us) as seen in table on page 10 in TLC1543 documentation
90-
DelayHelper.Delay(_conversionTime, false);
91-
}
81+
82+
// Max conversion time (21us) as seen in table on page 10 in TLC1543 documentation
83+
DelayHelper.Delay(_conversionTime, false);
9284

9385
return previousReading;
9486
}

src/devices_generated/Tlc1543/Tlc1543.nfproj renamed to devices/Tlc1543/Tlc1543.nfproj

+23-30
Original file line numberDiff line numberDiff line change
@@ -17,45 +17,38 @@
1717
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
1818
<DocumentationFile>bin\$(Configuration)\Iot.Device.Tlc1543.xml</DocumentationFile>
1919
<LangVersion>9.0</LangVersion>
20+
<Nullable>enable</Nullable>
2021
</PropertyGroup>
2122
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
22-
<ItemGroup>
23-
<Reference Include="mscorlib">
24-
<HintPath>packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
25-
<Private>True</Private>
26-
</Reference>
27-
<Reference Include="System.Device.Gpio">
28-
<HintPath>packages\nanoFramework.System.Device.Gpio.1.0.0-preview.40\lib\System.Device.Gpio.dll</HintPath>
29-
<Private>True</Private>
30-
</Reference>
31-
<Reference Include="nanoFramework.Runtime.Events">
32-
<HintPath>packages\nanoFramework.Runtime.Events.1.9.0-preview.26\lib\nanoFramework.Runtime.Events.dll</HintPath>
33-
<Private>True</Private>
34-
</Reference>
35-
<Reference Include="System.Device.Spi">
36-
<HintPath>packages\nanoFramework.System.Device.Spi.1.0.0-preview.38\lib\System.Device.Spi.dll</HintPath>
37-
<Private>True</Private>
38-
</Reference>
39-
<Reference Include="UnitsNet.Length">
40-
<HintPath>packages\UnitsNet.nanoFramework.Length.4.92.0\lib\UnitsNet.Length.dll</HintPath>
41-
<Private>True</Private>
42-
</Reference>
43-
<Reference Include="System.Math">
44-
<HintPath>packages\nanoFramework.System.Math.1.4.0-preview.7\lib\System.Math.dll</HintPath>
45-
<Private>True</Private>
46-
</Reference>
47-
</ItemGroup>
4823
<ItemGroup>
4924
<None Include="packages.config" />
50-
<Compile Include="*.cs" />
51-
<Compile Include="../Common/System/Device/DelayHelper.cs" />
5225
<None Include="README.md" />
5326
</ItemGroup>
5427
<ItemGroup>
5528
<Compile Include="Properties\AssemblyInfo.cs" />
5629
<Compile Include="*.cs" />
5730
<None Include="*.md" />
5831
</ItemGroup>
32+
<ItemGroup>
33+
<Reference Include="mscorlib, Version=1.11.7.2, Culture=neutral, PublicKeyToken=c07d481e9758c731">
34+
<HintPath>packages\nanoFramework.CoreLibrary.1.11.7\lib\mscorlib.dll</HintPath>
35+
</Reference>
36+
<Reference Include="nanoFramework.Runtime.Events, Version=1.9.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
37+
<HintPath>packages\nanoFramework.Runtime.Events.1.9.2\lib\nanoFramework.Runtime.Events.dll</HintPath>
38+
</Reference>
39+
<Reference Include="System.Device.Gpio, Version=1.0.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
40+
<HintPath>packages\nanoFramework.System.Device.Gpio.1.0.2\lib\System.Device.Gpio.dll</HintPath>
41+
</Reference>
42+
<Reference Include="System.Device.Spi, Version=1.0.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
43+
<HintPath>packages\nanoFramework.System.Device.Spi.1.0.2\lib\System.Device.Spi.dll</HintPath>
44+
</Reference>
45+
<Reference Include="System.Diagnostics.Stopwatch, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
46+
<HintPath>packages\nanoFramework.System.Diagnostics.Stopwatch.1.0.259\lib\System.Diagnostics.Stopwatch.dll</HintPath>
47+
</Reference>
48+
<Reference Include="System.Math, Version=1.4.3.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
49+
<HintPath>packages\nanoFramework.System.Math.1.4.3\lib\System.Math.dll</HintPath>
50+
</Reference>
51+
</ItemGroup>
5952
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
6053
<Import Project="..\..\src\System.Runtime.CompilerService\System.Runtime.CompilerService.projitems" Label="Shared" />
6154
<ProjectExtensions>
@@ -64,10 +57,10 @@
6457
</ProjectCapabilities>
6558
</ProjectExtensions>
6659
<Import Project="packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets" Condition="Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" />
67-
<Target Name = "EnsureNuGetPackageBuildImports" BeforeTargets = "PrepareForBuild">
60+
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
6861
<PropertyGroup>
6962
<ErrorText> This project references NuGet package(s) that are missing on this computer.Enable NuGet Package Restore to download them.For more information, see http://go.microsoft.com/fwlink/?LinkID=322105.The missing file is {0}.</ErrorText>
7063
</PropertyGroup>
71-
<Error Condition = "!Exists('packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets')" Text = "$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.4.194\build\Nerdbank.GitVersioning.targets'))" />
64+
<Error Condition="!Exists('packages\Nerdbank.GitVersioning.3.4.244\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\Nerdbank.GitVersioning.3.4.244\build\Nerdbank.GitVersioning.targets'))" />
7265
</Target>
7366
</Project>

src/devices_generated/Tlc1543/Tlc1543.nuspec renamed to devices/Tlc1543/Tlc1543.nuspec

+8-4
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,12 @@
2020
<summary>Iot.Device.Tlc1543 assembly for .NET nanoFramework C# projects</summary>
2121
<tags>nanoFramework C# csharp netmf netnf Iot.Device.Tlc1543</tags>
2222
<dependencies>
23-
<dependency id="nanoFramework.CoreLibrary" version="1.10.4-preview.11" />
23+
<dependency id="nanoFramework.CoreLibrary" version="1.11.7" />
24+
<dependency id="nanoFramework.Runtime.Events" version="1.9.2" />
25+
<dependency id="nanoFramework.System.Device.Gpio" version="1.0.2" />
26+
<dependency id="nanoFramework.System.Device.Spi" version="1.0.2" />
27+
<dependency id="nanoFramework.System.Diagnostics.Stopwatch" version="1.0.259" />
28+
<dependency id="nanoFramework.System.Math" version="1.4.3" />
2429
</dependencies>
2530
</metadata>
2631
<files>
@@ -29,9 +34,8 @@
2934
<file src="bin\Release\Iot.Device.Tlc1543.pdbx" target="lib\Iot.Device.Tlc1543.pdbx" />
3035
<file src="bin\Release\Iot.Device.Tlc1543.pe" target="lib\Iot.Device.Tlc1543.pe" />
3136
<file src="bin\Release\Iot.Device.Tlc1543.xml" target="lib\Iot.Device.Tlc1543.xml" />
32-
3337
<file src="README.md" target="docs\" />
34-
<file src="..\assets\nf-logo.png" target="images" />
35-
<file src="..\LICENSE.md" target="" />
38+
<file src="..\..\assets\nf-logo.png" target="images" />
39+
<file src="..\..\LICENSE.md" target="" />
3640
</files>
3741
</package>

devices/Tlc1543/packages.config

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="nanoFramework.CoreLibrary" version="1.11.7" targetFramework="netnanoframework10" />
4+
<package id="nanoFramework.Runtime.Events" version="1.9.2" targetFramework="netnanoframework10" />
5+
<package id="nanoFramework.System.Device.Gpio" version="1.0.2" targetFramework="netnanoframework10" />
6+
<package id="nanoFramework.System.Device.Spi" version="1.0.2" targetFramework="netnanoframework10" />
7+
<package id="nanoFramework.System.Diagnostics.Stopwatch" version="1.0.259" targetFramework="netnanoframework10" />
8+
<package id="nanoFramework.System.Math" version="1.4.3" targetFramework="netnanoframework10" />
9+
<package id="Nerdbank.GitVersioning" version="3.4.244" developmentDependency="true" targetFramework="netnanoframework10" />
10+
</packages>

src/devices_generated/Tlc1543/samples/Tlc1543.Sample.cs renamed to devices/Tlc1543/samples/Tlc1543.Sample.cs

+9-9
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33
// See the LICENSE file in the project root for more information.
44

5-
using System;
6-
using System.Collections.Generic;
75
using System.Device.Spi;
8-
using Iot.Device.Spi;
6+
using System.Diagnostics;
97

108
namespace Iot.Device.Tlc1543.Samples
119
{
@@ -19,12 +17,14 @@ public class Program
1917
/// </summary>
2018
public static void Main()
2119
{
22-
SoftwareSpi spi = new SoftwareSpi(
23-
clk: 25,
24-
sdi: 23,
25-
sdo: 24,
26-
cs: 5,
27-
settings: new SpiConnectionSettings(-1) { DataBitLength = Tlc1543.SpiDataBitLength });
20+
//////////////////////////////////////////////////////////////////////
21+
// when connecting to this device, you need to configure the SPI GPIOs
22+
// used for the bus
23+
// Configuration.SetPinFunction(24, DeviceFunction.SPI1_MOSI);
24+
// Configuration.SetPinFunction(23, DeviceFunction.SPI1_MISO);
25+
// Configuration.SetPinFunction(25, DeviceFunction.SPI1_CLOCK);
26+
//////////////////////////////////////////////////////////////////////
27+
SpiDevice spi = SpiDevice.Create(new SpiConnectionSettings(1, 5) { DataBitLength = Tlc1543.SpiDataBitLength });
2828

2929
Tlc1543 adc = new Tlc1543(spi);
3030
Channel[] channels = new Channel[]

src/devices_generated/Tlc1543/samples/Tlc1543.Samples.nfproj renamed to devices/Tlc1543/samples/Tlc1543.Samples.nfproj

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,29 @@
2020
</PropertyGroup>
2121
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
2222
<ItemGroup>
23-
<Reference Include="mscorlib">
24-
<HintPath>..\packages\nanoFramework.CoreLibrary.1.10.4-preview.11\lib\mscorlib.dll</HintPath>
25-
<Private>True</Private>
26-
</Reference>
27-
<Reference Include="System.Device.Spi">
28-
<HintPath>..\packages\nanoFramework.System.Device.Spi.1.0.0-preview.38\lib\System.Device.Spi.dll</HintPath>
29-
<Private>True</Private>
30-
</Reference>
31-
<Reference Include="UnitsNet.Length">
32-
<HintPath>..\packages\UnitsNet.nanoFramework.Length.4.92.0\lib\UnitsNet.Length.dll</HintPath>
33-
<Private>True</Private>
34-
</Reference>
23+
<Compile Include="Properties\AssemblyInfo.cs" />
24+
<Compile Include="*.cs" />
25+
<None Include="*.md" />
26+
<None Include="packages.config" />
3527
</ItemGroup>
3628
<ItemGroup>
37-
<None Include="packages.config" />
38-
<!-- INSERT FILE REFERENCES HERE -->
29+
<ProjectReference Include="..\Tlc1543.nfproj" />
3930
</ItemGroup>
4031
<ItemGroup>
41-
<Compile Include="Properties\AssemblyInfo.cs" />
42-
<Compile Include="*.cs" />
43-
<None Include="*.md" />
32+
<Reference Include="mscorlib, Version=1.11.7.2, Culture=neutral, PublicKeyToken=c07d481e9758c731">
33+
<HintPath>..\packages\nanoFramework.CoreLibrary.1.11.7\lib\mscorlib.dll</HintPath>
34+
</Reference>
35+
<Reference Include="nanoFramework.Runtime.Events, Version=1.9.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
36+
<HintPath>..\packages\nanoFramework.Runtime.Events.1.9.2\lib\nanoFramework.Runtime.Events.dll</HintPath>
37+
</Reference>
38+
<Reference Include="System.Device.Gpio, Version=1.0.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
39+
<HintPath>..\packages\nanoFramework.System.Device.Gpio.1.0.2\lib\System.Device.Gpio.dll</HintPath>
40+
</Reference>
41+
<Reference Include="System.Device.Spi, Version=1.0.2.3, Culture=neutral, PublicKeyToken=c07d481e9758c731">
42+
<HintPath>..\packages\nanoFramework.System.Device.Spi.1.0.2\lib\System.Device.Spi.dll</HintPath>
43+
</Reference>
4444
</ItemGroup>
4545
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
46-
<Import Project="..\..\src\System.Runtime.CompilerService\System.Runtime.CompilerService.projitems" Label="Shared" />
4746
<ProjectExtensions>
4847
<ProjectCapabilities>
4948
<ProjectConfigurationsDeclaredAsItems />
+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<packages>
3+
<package id="nanoFramework.CoreLibrary" version="1.11.7" targetFramework="netnanoframework10" />
4+
<package id="nanoFramework.Runtime.Events" version="1.9.2" targetFramework="netnanoframework10" />
5+
<package id="nanoFramework.System.Device.Gpio" version="1.0.2" targetFramework="netnanoframework10" />
6+
<package id="nanoFramework.System.Device.Spi" version="1.0.2" targetFramework="netnanoframework10" />
7+
</packages>

src/devices_generated/Tlc1543/packages.config

-10
This file was deleted.

src/devices_generated/Tlc1543/samples/packages.config

-6
This file was deleted.

src/devices_generated/Tlc1543/version.json

-19
This file was deleted.

0 commit comments

Comments
 (0)