diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Program.cs b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Program.cs new file mode 100644 index 0000000..ba120e7 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Program.cs @@ -0,0 +1,22 @@ +using nanoFramework.Benchmark; +using System; +using System.Diagnostics; +using System.Threading; + +namespace nanoFramework.Hardware.Esp32.Rmt.Benchmarks +{ + public class Program + { + public static void Main() + { +#if DEBUG + Console.WriteLine("Benchmarks should be run in a release build."); + Debugger.Break(); + return; +#endif + + BenchmarkRunner.RunClass(typeof(SerializeCommandsBenchmark)); + Thread.Sleep(Timeout.Infinite); + } + } +} diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Properties/AssemblyInfo.cs b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..c76ba91 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/Properties/AssemblyInfo.cs @@ -0,0 +1,33 @@ +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("CSharp.BlankApplication")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("CSharp.BlankApplication")] +[assembly: AssemblyCopyright("Copyright © 2025")] +[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)] + +// 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")] diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/SerializeCommandsBenchmark.cs b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/SerializeCommandsBenchmark.cs new file mode 100644 index 0000000..ce753fb --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/SerializeCommandsBenchmark.cs @@ -0,0 +1,98 @@ +using System.Collections; +using nanoFramework.Benchmark; +using nanoFramework.Benchmark.Attributes; + +// ReSharper disable InconsistentNaming +namespace nanoFramework.Hardware.Esp32.Rmt.Benchmarks +{ + + [IterationCount(2000)] + public class SerializeCommandsBenchmark + { + public static readonly RmtCommand Sk6812_OnePulse = new(14, true, 12, false); + public static readonly RmtCommand Sk6812_ZeroPulse = new(7, true, 16, false); + public static readonly RmtCommand Sk6812_ResetCommand = new(500, false, 520, false); + + public static readonly RmtCommand Ws2808_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2808_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2808_ResetCommand = new(1400, false, 1400, false); + + public static readonly RmtCommand Ws2812b_OnePulse = new(32, true, 18, false); + public static readonly RmtCommand Ws2812b_ZeroPulse = new(16, true, 34, false); + public static readonly RmtCommand Ws2812b_ResetCommand = new(2000, false, 2000, false); + + public static readonly RmtCommand Ws2812c_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2812c_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2812c_ResetCommand = new(1400, false, 1400, false); + + public static readonly RmtCommand Ws2815b_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2815b_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2815b_ResetCommand = new(1400, false, 1400, false); + + public static readonly ArrayList RmtCommandsArrayList = new() + { + Sk6812_OnePulse, + Sk6812_ZeroPulse, + Sk6812_ResetCommand, + + Ws2808_OnePulse, + Ws2808_ZeroPulse, + Ws2808_ResetCommand, + + Ws2812b_OnePulse, + Ws2812b_ZeroPulse, + Ws2812b_ResetCommand, + + Ws2812c_OnePulse, + Ws2812c_ZeroPulse, + Ws2812c_ResetCommand, + + Ws2815b_OnePulse, + Ws2815b_ZeroPulse, + Ws2815b_ResetCommand + }; + + [Benchmark] + public void SerializeCommands_Current() + { + var serializedCommands = RmtCommandSerializer.SerializeCommands(RmtCommandsArrayList); + } + + [Benchmark] + public void SerializeCommands_Original() + { + int i = 0; + int remaining; + byte[] binaryCommands = new byte[RmtCommandsArrayList.Count * 4]; + foreach (var cmd in RmtCommandsArrayList) + { + // First pair + if ((cmd as RmtCommand).Duration0 <= 255) + { + binaryCommands[0 + i] = (byte)(cmd as RmtCommand).Duration0; + binaryCommands[1 + i] = (byte)((cmd as RmtCommand).Level0 == true ? 128 : 0); + } + else + { + remaining = (cmd as RmtCommand).Duration0 % 256; + binaryCommands[0 + i] = (byte)(remaining); + binaryCommands[1 + i] = (byte)(((cmd as RmtCommand).Level0 ? 128 : 0) + (((cmd as RmtCommand).Duration0 - remaining) / 256)); + } + + // Second pair + if ((cmd as RmtCommand).Duration1 <= 255) + { + binaryCommands[2 + i] = (byte)(cmd as RmtCommand).Duration1; + binaryCommands[3 + i] = (byte)((cmd as RmtCommand).Level1 ? 128 : 0); + } + else + { + remaining = (cmd as RmtCommand).Duration1 % 256; + binaryCommands[2 + i] = (byte)(remaining); + binaryCommands[3 + i] = (byte)(((cmd as RmtCommand).Level1 ? 128 : 0) + (((cmd as RmtCommand).Duration1 - remaining) / 256)); + } + i += 4; + } + } + } +} diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/nanoFramework.Hardware.Esp32.Rmt.Benchmarks.nfproj b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/nanoFramework.Hardware.Esp32.Rmt.Benchmarks.nfproj new file mode 100644 index 0000000..7f7d571 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/nanoFramework.Hardware.Esp32.Rmt.Benchmarks.nfproj @@ -0,0 +1,73 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 7c2bc423-f2d8-41dc-a5af-90cfd014ca07 + Exe + Properties + 512 + nanoFramework.Hardware.Esp32.Rmt.Benchmarks + nanoFramework.Hardware.Esp32.Rmt.Benchmarks + v1.0 + true + + + true + + + ..\nanoFramework.Hardware.Esp32.Rmt\key.snk + + + false + + + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.17.1\lib\mscorlib.dll + + + ..\packages\nanoFramework.Benchmark.1.0.102\lib\nanoFramework.Benchmark.dll + + + ..\packages\nanoFramework.Logging.1.1.142\lib\nanoFramework.Logging.dll + + + ..\packages\nanoFramework.Runtime.Native.1.7.9\lib\nanoFramework.Runtime.Native.dll + + + ..\packages\nanoFramework.System.Collections.1.5.62\lib\nanoFramework.System.Collections.dll + + + ..\packages\nanoFramework.System.Text.1.3.29\lib\nanoFramework.System.Text.dll + + + ..\packages\nanoFramework.System.Diagnostics.Stopwatch.1.2.815\lib\System.Diagnostics.Stopwatch.dll + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.config b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.config new file mode 100644 index 0000000..67bc981 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.config @@ -0,0 +1,10 @@ + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.lock.json b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.lock.json new file mode 100644 index 0000000..c364353 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.Benchmarks/packages.lock.json @@ -0,0 +1,49 @@ +{ + "version": 1, + "dependencies": { + ".NETnanoFramework,Version=v1.0": { + "nanoFramework.Benchmark": { + "type": "Direct", + "requested": "[1.0.102, 1.0.102]", + "resolved": "1.0.102", + "contentHash": "J7G0Yq5Ms9Cms/ZZDcmRN/MnFiDs52vQvL7CVcJZ5BcpI9NwdNT/p2ymckkejMPu5bo7watVrcXM/ni3sblx6g==" + }, + "nanoFramework.CoreLibrary": { + "type": "Direct", + "requested": "[1.17.1, 1.17.1]", + "resolved": "1.17.1", + "contentHash": "T/iPvP8AeZs/5UeZgVa2cZVbl79ioeRyBJLzx4qvKbE9RE+984AR5WPY4tjGIdXugs1AFUYYnydvuGCpy+P1ww==" + }, + "nanoFramework.Logging": { + "type": "Direct", + "requested": "[1.1.142, 1.1.142]", + "resolved": "1.1.142", + "contentHash": "rHeUDLgtYN/PLsJg5kuQdCeT0gBAZRtJbopZvShlVHS88UGMYHjBmr8LvBAIJmq611wDTMqacqG3dxtfjiME3w==" + }, + "nanoFramework.Runtime.Native": { + "type": "Direct", + "requested": "[1.7.9, 1.7.9]", + "resolved": "1.7.9", + "contentHash": "ekjQ4lTNVZ5FNrgry6XV0e7ydOSvcDGuAnSaNQewiBQAfSbpTZx3njCwU5SU5wcO+tBqT4wP7K1LNtw7unaUkg==" + }, + "nanoFramework.System.Collections": { + "type": "Direct", + "requested": "[1.5.62, 1.5.62]", + "resolved": "1.5.62", + "contentHash": "tqYYxVHnfJU+v4aOwtW5u6oI3DWYx+njaTa2gY3LXkcltHlaNCXD4c5q314Zb17isZiizKXIB+X9vJnwxw1oLA==" + }, + "nanoFramework.System.Diagnostics.Stopwatch": { + "type": "Direct", + "requested": "[1.2.815, 1.2.815]", + "resolved": "1.2.815", + "contentHash": "tzJyaSZZ6qrO6lVuo6XwZ8gao57IK3tsVoBlYFNGvTqwsn6CQQzGMBw4GkFbJv71ldFlwh0mGMic2fDvYDZRjA==" + }, + "nanoFramework.System.Text": { + "type": "Direct", + "requested": "[1.3.29, 1.3.29]", + "resolved": "1.3.29", + "contentHash": "h7Jbjd8vmNrro/co6s+Zth+OvStgvOiT3RQtlaqa2t6FmnLZGXkF7LAykjLqWeNfHTafGbBLkSMqHw2VHo4Dmg==" + } + } + } +} \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/Properties/AssemblyInfo.cs b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..a3735af --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/Properties/AssemblyInfo.cs @@ -0,0 +1,31 @@ +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: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyCopyright("Copyright (c) 2021 nanoFramework contributors")] +[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)] + +// 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")] diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/RmtCommandSerializerTests.cs b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/RmtCommandSerializerTests.cs new file mode 100644 index 0000000..7066e09 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/RmtCommandSerializerTests.cs @@ -0,0 +1,121 @@ +using System.Collections; +using nanoFramework.TestFramework; +// ReSharper disable InconsistentNaming + +namespace nanoFramework.Hardware.Esp32.Rmt.UnitTests +{ + [TestClass] + internal class RmtCommandSerializerTests + { + public static readonly RmtCommand Sk6812_OnePulse = new(14, true, 12, false); + public static readonly RmtCommand Sk6812_ZeroPulse = new(7, true, 16, false); + public static readonly RmtCommand Sk6812_ResetCommand = new(500, false, 520, false); + + public static readonly RmtCommand Ws2808_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2808_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2808_ResetCommand = new(1400, false, 1400, false); + + public static readonly RmtCommand Ws2812b_OnePulse = new(32, true, 18, false); + public static readonly RmtCommand Ws2812b_ZeroPulse = new(16, true, 34, false); + public static readonly RmtCommand Ws2812b_ResetCommand = new(2000, false, 2000, false); + + public static readonly RmtCommand Ws2812c_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2812c_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2812c_ResetCommand = new(1400, false, 1400, false); + + public static readonly RmtCommand Ws2815b_OnePulse = new(52, true, 52, false); + public static readonly RmtCommand Ws2815b_ZeroPulse = new(14, true, 52, false); + public static readonly RmtCommand Ws2815b_ResetCommand = new(1400, false, 1400, false); + + [TestMethod] + public void SerializeCommands_correctly_serializes_commands() + { + var commands = new ArrayList + { + Sk6812_OnePulse, + Sk6812_ZeroPulse, + Sk6812_ResetCommand, + + Ws2808_OnePulse, + Ws2808_ZeroPulse, + Ws2808_ResetCommand, + + Ws2812b_OnePulse, + Ws2812b_ZeroPulse, + Ws2812b_ResetCommand, + + Ws2812c_OnePulse, + Ws2812c_ZeroPulse, + Ws2812c_ResetCommand, + + Ws2815b_OnePulse, + Ws2815b_ZeroPulse, + Ws2815b_ResetCommand + }; + + var result = RmtCommandSerializer.SerializeCommands(commands); + + Assert.AreEqual(60, result.Length); + Assert.AreEqual((byte)14, result[0]); + Assert.AreEqual((byte)128, result[1]); + Assert.AreEqual((byte)12, result[2]); + Assert.AreEqual((byte)0, result[3]); + Assert.AreEqual((byte)7, result[4]); + Assert.AreEqual((byte)128, result[5]); + Assert.AreEqual((byte)16, result[6]); + Assert.AreEqual((byte)0, result[7]); + Assert.AreEqual((byte)244, result[8]); + Assert.AreEqual((byte)1, result[9]); + Assert.AreEqual((byte)8, result[10]); + Assert.AreEqual((byte)2, result[11]); + Assert.AreEqual((byte)52, result[12]); + Assert.AreEqual((byte)128, result[13]); + Assert.AreEqual((byte)52, result[14]); + Assert.AreEqual((byte)0, result[15]); + Assert.AreEqual((byte)14, result[16]); + Assert.AreEqual((byte)128, result[17]); + Assert.AreEqual((byte)52, result[18]); + Assert.AreEqual((byte)0, result[19]); + Assert.AreEqual((byte)120, result[20]); + Assert.AreEqual((byte)5, result[21]); + Assert.AreEqual((byte)120, result[22]); + Assert.AreEqual((byte)5, result[23]); + Assert.AreEqual((byte)32, result[24]); + Assert.AreEqual((byte)128, result[25]); + Assert.AreEqual((byte)18, result[26]); + Assert.AreEqual((byte)0, result[27]); + Assert.AreEqual((byte)16, result[28]); + Assert.AreEqual((byte)128, result[29]); + Assert.AreEqual((byte)34, result[30]); + Assert.AreEqual((byte)0, result[31]); + Assert.AreEqual((byte)208, result[32]); + Assert.AreEqual((byte)7, result[33]); + Assert.AreEqual((byte)208, result[34]); + Assert.AreEqual((byte)7, result[35]); + Assert.AreEqual((byte)52, result[36]); + Assert.AreEqual((byte)128, result[37]); + Assert.AreEqual((byte)52, result[38]); + Assert.AreEqual((byte)0, result[39]); + Assert.AreEqual((byte)14, result[40]); + Assert.AreEqual((byte)128, result[41]); + Assert.AreEqual((byte)52, result[42]); + Assert.AreEqual((byte)0, result[43]); + Assert.AreEqual((byte)120, result[44]); + Assert.AreEqual((byte)5, result[45]); + Assert.AreEqual((byte)120, result[46]); + Assert.AreEqual((byte)5, result[47]); + Assert.AreEqual((byte)52, result[48]); + Assert.AreEqual((byte)128, result[49]); + Assert.AreEqual((byte)52, result[50]); + Assert.AreEqual((byte)0, result[51]); + Assert.AreEqual((byte)14, result[52]); + Assert.AreEqual((byte)128, result[53]); + Assert.AreEqual((byte)52, result[54]); + Assert.AreEqual((byte)0, result[55]); + Assert.AreEqual((byte)120, result[56]); + Assert.AreEqual((byte)5, result[57]); + Assert.AreEqual((byte)120, result[58]); + Assert.AreEqual((byte)5, result[59]); + } + } +} diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nano.runsettings b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nano.runsettings new file mode 100644 index 0000000..93ce85e --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nano.runsettings @@ -0,0 +1,17 @@ + + + + + .\TestResults + 120000 + net48 + x64 + + + None + False + COM3 + + + + \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nanoFramework.Hardware.Esp32.Rmt.UnitTests.nfproj b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nanoFramework.Hardware.Esp32.Rmt.UnitTests.nfproj new file mode 100644 index 0000000..98067c6 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/nanoFramework.Hardware.Esp32.Rmt.UnitTests.nfproj @@ -0,0 +1,65 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + c91d222a-af5b-4ba2-b4d6-f4999031aaf9 + Library + Properties + 512 + nanoFramework.Hardware.Esp32.Rmt.UnitTests + NFUnitTest + False + true + UnitTest + v1.0 + true + + + true + + + ..\nanoFramework.Hardware.Esp32.Rmt\key.snk + + + false + + + + $(MSBuildProjectDirectory)\nano.runsettings + + + + + + + + ..\packages\nanoFramework.CoreLibrary.1.17.1\lib\mscorlib.dll + + + ..\packages\nanoFramework.TestFramework.3.0.68\lib\nanoFramework.TestFramework.dll + + + ..\packages\nanoFramework.TestFramework.3.0.68\lib\nanoFramework.UnitTestLauncher.exe + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.config b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.config new file mode 100644 index 0000000..324e837 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.config @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.lock.json b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.lock.json new file mode 100644 index 0000000..510c5a2 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt.UnitTests/packages.lock.json @@ -0,0 +1,19 @@ +{ + "version": 1, + "dependencies": { + ".NETnanoFramework,Version=v1.0": { + "nanoFramework.CoreLibrary": { + "type": "Direct", + "requested": "[1.17.1, 1.17.1]", + "resolved": "1.17.1", + "contentHash": "T/iPvP8AeZs/5UeZgVa2cZVbl79ioeRyBJLzx4qvKbE9RE+984AR5WPY4tjGIdXugs1AFUYYnydvuGCpy+P1ww==" + }, + "nanoFramework.TestFramework": { + "type": "Direct", + "requested": "[3.0.68, 3.0.68]", + "resolved": "3.0.68", + "contentHash": "K+CKHTFqUW0H46CjkcLOCHcrLJDGmwErisQDXIKvUEgp0gE7rrsAat072aCcjXxojotSwa34hD/NIV4OF7vXgQ==" + } + } + } +} \ No newline at end of file diff --git a/nanoFramework.Hardware.Esp32.Rmt.sln b/nanoFramework.Hardware.Esp32.Rmt.sln index 56b59b4..4ea2c5c 100644 --- a/nanoFramework.Hardware.Esp32.Rmt.sln +++ b/nanoFramework.Hardware.Esp32.Rmt.sln @@ -11,6 +11,10 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution EndProject Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Hardware.Esp32.Rmt", "nanoFramework.Hardware.Esp32.Rmt\nanoFramework.Hardware.Esp32.Rmt.nfproj", "{D8B1966C-881F-48AB-A821-7B1F83303259}" EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Hardware.Esp32.Rmt.UnitTests", "nanoFramework.Hardware.Esp32.Rmt.UnitTests\nanoFramework.Hardware.Esp32.Rmt.UnitTests.nfproj", "{C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}" +EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Hardware.Esp32.Rmt.Benchmarks", "nanoFramework.Hardware.Esp32.Rmt.Benchmarks\nanoFramework.Hardware.Esp32.Rmt.Benchmarks.nfproj", "{7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -23,6 +27,18 @@ Global {D8B1966C-881F-48AB-A821-7B1F83303259}.Release|Any CPU.ActiveCfg = Release|Any CPU {D8B1966C-881F-48AB-A821-7B1F83303259}.Release|Any CPU.Build.0 = Release|Any CPU {D8B1966C-881F-48AB-A821-7B1F83303259}.Release|Any CPU.Deploy.0 = Release|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Release|Any CPU.Build.0 = Release|Any CPU + {C91D222A-AF5B-4BA2-B4D6-F4999031AAF9}.Release|Any CPU.Deploy.0 = Release|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Debug|Any CPU.Build.0 = Debug|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Release|Any CPU.ActiveCfg = Release|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Release|Any CPU.Build.0 = Release|Any CPU + {7C2BC423-F2D8-41DC-A5AF-90CFD014CA07}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/nanoFramework.Hardware.Esp32.Rmt/Properties/AssemblyInfo.cs b/nanoFramework.Hardware.Esp32.Rmt/Properties/AssemblyInfo.cs index 313ad05..b489304 100644 --- a/nanoFramework.Hardware.Esp32.Rmt/Properties/AssemblyInfo.cs +++ b/nanoFramework.Hardware.Esp32.Rmt/Properties/AssemblyInfo.cs @@ -1,4 +1,5 @@ using System.Reflection; +using System.Runtime.CompilerServices; using System.Runtime.InteropServices; // General Information about an assembly is controlled through the following @@ -11,10 +12,13 @@ //////////////////////////////////////////////////////////////// // update this whenever the native assembly signature changes // -[assembly: AssemblyNativeVersion("100.0.5.0")] +[assembly: AssemblyNativeVersion("100.0.5.1")] //////////////////////////////////////////////////////////////// // 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)] + +[assembly: InternalsVisibleTo("nanoFramework.Hardware.Esp32.Rmt.Benchmarks, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] +[assembly: InternalsVisibleTo("NFUnitTest, PublicKey=00240000048000009400000006020000002400005253413100040000010001001120aa3e809b3da4f65e1b1f65c0a3a1bf6335c39860ca41acb3c48de278c6b63c5df38239ec1f2e32d58cb897c8c174a5f8e78a9c0b6087d3aef373d7d0f3d9be67700fc2a5a38de1fb71b5b6f6046d841ff35abee2e0b0840a6291a312be184eb311baff5fef0ff6895b9a5f2253aed32fb06b819134f6bb9d531488a87ea2")] diff --git a/nanoFramework.Hardware.Esp32.Rmt/RmtCommandSerializer.cs b/nanoFramework.Hardware.Esp32.Rmt/RmtCommandSerializer.cs new file mode 100644 index 0000000..7e479c6 --- /dev/null +++ b/nanoFramework.Hardware.Esp32.Rmt/RmtCommandSerializer.cs @@ -0,0 +1,39 @@ +using System.Collections; +using System.Runtime.CompilerServices; + +#nullable enable +namespace nanoFramework.Hardware.Esp32.Rmt +{ + [ExcludeType] + internal static class RmtCommandSerializer + { + /// + /// Serialize commands to rmt_item32_t native byte format + /// + /// The serialized commands + public static byte[] SerializeCommands(ArrayList commands) + { + var index = 0; + var serializedCommands = new byte[commands.Count * 4]; + + for (var i = 0; i < commands.Count; i++) + { + var command = (RmtCommand) commands[i]; + + var highByte1 = (byte)(command.Duration0 >> 8); + var lowByte1 = (byte)(command.Duration0 & 0xFF); + var highByte2 = (byte)(command.Duration1 >> 8); + var lowByte2 = (byte)(command.Duration1 & 0xFF); + var level1 = (byte)(command.Level0 ? 0x80 : 0); + var level2 = (byte)(command.Level1 ? 0x80 : 0); + + serializedCommands[index++] = lowByte1; + serializedCommands[index++] = (byte)(highByte1 | level1); + serializedCommands[index++] = lowByte2; + serializedCommands[index++] = (byte)(highByte2 | level2); + } + + return serializedCommands; + } + } +} diff --git a/nanoFramework.Hardware.Esp32.Rmt/TransmitterChannel.cs b/nanoFramework.Hardware.Esp32.Rmt/TransmitterChannel.cs index ce84f0d..0d72f96 100644 --- a/nanoFramework.Hardware.Esp32.Rmt/TransmitterChannel.cs +++ b/nanoFramework.Hardware.Esp32.Rmt/TransmitterChannel.cs @@ -170,7 +170,7 @@ public void ClearCommands() /// /// If true wait the TX process to end, false function returns without waiting, but if another command is send before the end of the previous process an error will occur. public void Send(bool waitTxDone) - => SendData(SerializeCommands(), waitTxDone); + => SendData(RmtCommandSerializer.SerializeCommands(_commands), waitTxDone); /// /// Send a RAW data to RMT module @@ -181,48 +181,6 @@ public void Send(bool waitTxDone) public void SendData(byte[] data, bool waitTxDone) => NativeTxWriteItems(data, waitTxDone); #pragma warning restore S4200 // Native methods should be wrapped - - /// - /// Serialize commands to rmt_item32_t native byte format - /// - /// - private byte[] SerializeCommands() - { - int i = 0; - int remaining; - byte[] binaryCommands = new byte[_commands.Count * 4]; - foreach (var cmd in _commands) - { - // First pair - if ((cmd as RmtCommand).Duration0 <= 255) - { - binaryCommands[0 + i] = (byte)(cmd as RmtCommand).Duration0; - binaryCommands[1 + i] = (byte)((cmd as RmtCommand).Level0 == true ? 128 : 0); - } - else - { - remaining = (cmd as RmtCommand).Duration0 % 256; - binaryCommands[0 + i] = (byte)(remaining); - binaryCommands[1 + i] = (byte)(((cmd as RmtCommand).Level0 ? 128 : 0) + (((cmd as RmtCommand).Duration0 - remaining) / 256)); - } - - // Second pair - if ((cmd as RmtCommand).Duration1 <= 255) - { - binaryCommands[2 + i] = (byte)(cmd as RmtCommand).Duration1; - binaryCommands[3 + i] = (byte)((cmd as RmtCommand).Level1 ? 128 : 0); - } - else - { - remaining = (cmd as RmtCommand).Duration1 % 256; - binaryCommands[2 + i] = (byte)(remaining); - binaryCommands[3 + i] = (byte)(((cmd as RmtCommand).Level1 ? 128 : 0) + (((cmd as RmtCommand).Duration1 - remaining) / 256)); - } - i += 4; - } - return binaryCommands; - } - #endregion Methods #region Destructors diff --git a/nanoFramework.Hardware.Esp32.Rmt/nanoFramework.Hardware.Esp32.Rmt.nfproj b/nanoFramework.Hardware.Esp32.Rmt/nanoFramework.Hardware.Esp32.Rmt.nfproj index 85f510b..8339d14 100644 --- a/nanoFramework.Hardware.Esp32.Rmt/nanoFramework.Hardware.Esp32.Rmt.nfproj +++ b/nanoFramework.Hardware.Esp32.Rmt/nanoFramework.Hardware.Esp32.Rmt.nfproj @@ -13,7 +13,7 @@ Library Properties 512 - + nanoFramework.Hardware.Esp32.Rmt nanoFramework.Hardware.Esp32.Rmt True v1.0 @@ -35,6 +35,10 @@ bin\$(Configuration)\Stubs nanoFramework_hardware_esp32_rmt_native nanoFramework.Hardware.Esp32.Rmt + false + true + direct + low @@ -48,20 +52,13 @@ + - - - ..\packages\nanoFramework.CoreLibrary.1.17.1\lib\mscorlib.dll - - - ..\packages\nanoFramework.Runtime.Events.1.11.30\lib\nanoFramework.Runtime.Events.dll - - @@ -69,6 +66,14 @@ + + + ..\packages\nanoFramework.CoreLibrary.1.17.1\lib\mscorlib.dll + + + ..\packages\nanoFramework.Runtime.Events.1.11.30\lib\nanoFramework.Runtime.Events.dll + +