Родитель
eeee88b1d6
Коммит
002c2b52ea
48
README.md
48
README.md
|
@ -27,6 +27,7 @@ These NuGet packages provide a support for M5Stack products:
|
|||
- [M5StickC](https://docs.m5stack.com/en/core/m5stickc)
|
||||
- [M5StickCPlus](https://docs.m5stack.com/en/core/m5stickc_plus)
|
||||
- [M5Core2](https://docs.m5stack.com/en/core/core2)
|
||||
- [Atom Lite](https://docs.m5stack.com/en/core/atom_lite)
|
||||
|
||||
> Note 1: Before trying to add NuGet packages to your projects and/or before flashing the devices (see next section) using MS Visual Studio (VS), open VS > Tools > Options > NuGet Package Manager > Package Sources and make sure that it contains an entry pointing to <https://api.nuget.org/v3/index.json> , otherwise add it.
|
||||
> Note 2: When invoking VS > Project > Manage NuGet Packages make sure that in the Package source drop-down menu (right upper corner) "nuget.org" is selected. Also if you're using preview version the "include prerelease" checkbox should be clicked/selected as well.
|
||||
|
@ -58,6 +59,12 @@ For the M5Core2:
|
|||
nanoff --target M5Core2 --update --preview --serialport COM3
|
||||
```
|
||||
|
||||
For the M5AtomLite:
|
||||
|
||||
```shell
|
||||
nanoff --target ESP32_PICO --update --preview --serialport COM3
|
||||
```
|
||||
|
||||
> Note 3: If the `nanoff` commands fails, make sure you have followed instruction from Note 1 above.
|
||||
|
||||
Once you have the NuGets, you can then enjoy accessing the screen, the accelerometer, get a Grove I2C connecter, add events on the buttons. And you don't even need to think about anything, all is done for you in the most transparent way!
|
||||
|
@ -158,6 +165,28 @@ M5StickC.M5Button.Holding += (sender, e) =>
|
|||
};
|
||||
```
|
||||
|
||||
On the Atom Lite it's called `Button`. You can get access to the status of the button, the events and everything you need. For example:
|
||||
|
||||
```csharp
|
||||
M5AtomLite.Button.Press +=> (sender, e)
|
||||
{
|
||||
var color = M5AtomLite.NeoPixel.GetColor();
|
||||
if(color.R > 0)
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 255, 0));
|
||||
}
|
||||
else if (color.G > 0)
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 0, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 255, 0, 0));
|
||||
}
|
||||
};
|
||||
```
|
||||
|
||||
|
||||
> Note: The M5Core2 has touch screen and the buttons are "virtual"". See next section to see how to use them.
|
||||
|
||||
### M5Core2 touch panel and buttons
|
||||
|
@ -289,10 +318,10 @@ Refer to the [SerialPort documentation](https://github.com/nanoframework/System.
|
|||
|
||||
### ADC Channels
|
||||
|
||||
ADC Channels are pre setup on the M5Core, access them like this:
|
||||
ADC Channels are pre setup on the M5Core, M5Core2 and Atom Lite, access them like this:
|
||||
|
||||
```csharp
|
||||
// This will give you the ADC1 channel 7 which is on pin 35
|
||||
// This will give you the ADC1 channel 7 which is on pin 35 of M5Core
|
||||
AdcChannel myChannel = M5Core.GetAdcGpio(35);
|
||||
```
|
||||
|
||||
|
@ -310,7 +339,7 @@ I2cDevice myDevice = M5Core.GetGrove(0x42);
|
|||
|
||||
### SPI Device
|
||||
|
||||
The M5Core provides as well an SpiDevice:
|
||||
The M5Core, M5Core2 and Atom Lite provides as well an `SpiDevice`:
|
||||
|
||||
```csharp
|
||||
// In this case GPIO5 will be used as chip select:
|
||||
|
@ -328,7 +357,7 @@ var pin5 = M5StickC.GpioController.OpenPin(36, PinMode.Output);
|
|||
|
||||
### DAC
|
||||
|
||||
The M5Core exposes 2 DAC and you can access them thru the `Dac1` and `Dac2` properties. Refer to the [DAC documentation](https://github.com/nanoframework/System.Device.Dac) for more information.
|
||||
The M5Core, M5Core2 and Atom Lite exposes 2 DAC and you can access them thru the `Dac1` and `Dac2` properties. Refer to the [DAC documentation](https://github.com/nanoframework/System.Device.Dac) for more information.
|
||||
|
||||
### Led
|
||||
|
||||
|
@ -341,7 +370,16 @@ M5StickC.Led.Toggle();
|
|||
|
||||
### Infrared Led
|
||||
|
||||
The M5StickC/CPlus exposes an infrared led. You can access it thru the `InfraredLed` property. This will give you a `TransmitterChannel`. Check out the [sample pack](https://github.com/nanoframework/Samples/tree/main/samples/Hardware.Esp32.Rmt) to understand how to use it.
|
||||
The M5StickC/CPlus and M5AtomLite exposes an infrared led. You can access it thru the `InfraredLed` property. This will give you a `TransmitterChannel`. Check out the [sample pack](https://github.com/nanoframework/Samples/tree/main/samples/Hardware.Esp32.Rmt) to understand how to use it.
|
||||
|
||||
### NeoPixel
|
||||
|
||||
The M5AtomLite exposes a rgb led. You can access it thru the `NeoPixel` property:
|
||||
|
||||
```csharp
|
||||
// This will set NeoPixel to green:
|
||||
M5AtomLite.NeoPixel.SetColor(Color.Green);
|
||||
```
|
||||
|
||||
## Feedback and documentation
|
||||
|
||||
|
|
|
@ -0,0 +1,61 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>7533c164-9d3e-461b-beed-888c91ac640b</ProjectGuid>
|
||||
<OutputType>Exe</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<RootNamespace>M5AtomLiteTestApp</RootNamespace>
|
||||
<AssemblyName>M5AtomLiteTestApp</AssemblyName>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
|
||||
<ItemGroup>
|
||||
<Compile Include="Program.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\..\nanoFramework.M5AtomLite\nanoFramework.M5AtomLite.nfproj" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Iot.Device.Button, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\..\packages\nanoFramework.Iot.Device.Button.1.0.288-preview.29\lib\Iot.Device.Button.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib, Version=1.12.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\..\packages\nanoFramework.CoreLibrary.1.12.0-preview.5\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Runtime.Events, Version=1.10.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\..\packages\nanoFramework.Runtime.Events.1.10.0-preview.6\lib\nanoFramework.Runtime.Events.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Gpio, Version=1.0.3.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\..\packages\nanoFramework.System.Device.Gpio.1.0.3-preview.8\lib\System.Device.Gpio.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<HintPath>..\..\packages\nanoFramework.System.Drawing.1.0.288-preview.20\lib\System.Drawing.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
|
||||
<ProjectExtensions>
|
||||
<ProjectCapabilities>
|
||||
<ProjectConfigurationsDeclaredAsItems />
|
||||
</ProjectCapabilities>
|
||||
</ProjectExtensions>
|
||||
</Project>
|
|
@ -0,0 +1,44 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
using nanoFramework.M5AtomLite;
|
||||
|
||||
namespace M5AtomLiteTestApp
|
||||
{
|
||||
public class Program
|
||||
{
|
||||
public static void Main()
|
||||
{
|
||||
var button = M5AtomLite.Button;
|
||||
var rgb = M5AtomLite.NeoPixel;
|
||||
rgb.SetColor(Color.FromArgb(255, 255, 0, 0));
|
||||
|
||||
button.Press += Button_Press;
|
||||
|
||||
Debug.WriteLine("Hello from nanoFramework!");
|
||||
|
||||
Thread.Sleep(Timeout.Infinite);
|
||||
}
|
||||
|
||||
private static void Button_Press(object sender, EventArgs e)
|
||||
{
|
||||
var color = M5AtomLite.NeoPixel.GetColor();
|
||||
if(color.R > 0)
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 255, 0));
|
||||
}
|
||||
else if (color.G > 0)
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 0, 0, 255));
|
||||
}
|
||||
else
|
||||
{
|
||||
M5AtomLite.NeoPixel.SetColor(Color.FromArgb(255, 255, 0, 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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 © ")]
|
||||
[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")]
|
|
@ -0,0 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.12.0-preview.5" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Iot.Device.Button" version="1.0.288-preview.29" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Runtime.Events" version="1.10.0-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Gpio" version="1.0.3-preview.8" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Drawing" version="1.0.288-preview.20" targetFramework="netnanoframework10" />
|
||||
</packages>
|
|
@ -0,0 +1,46 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>nanoFramework.M5AtomLite</id>
|
||||
<version>$version$</version>
|
||||
<title>nanoFramework.M5AtomLite</title>
|
||||
<authors>nanoFramework project contributors</authors>
|
||||
<owners>nanoFramework,dotnetfoundation</owners>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<license type="file">LICENSE.md</license>
|
||||
<releaseNotes>
|
||||
</releaseNotes>
|
||||
<readme>docs\README.md</readme>
|
||||
<developmentDependency>false</developmentDependency>
|
||||
<projectUrl>https://github.com/nanoframework/nanoFramework.M5Stack</projectUrl>
|
||||
<icon>images\nf-logo.png</icon>
|
||||
<repository type="git" url="https://github.com/nanoframework/nanoFramework.M5Stack" commit="$commit$" />
|
||||
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
|
||||
<description>This package includes the nanoFramework.M5AtomLite assembly for .NET nanoFramework C# projects.</description>
|
||||
<tags>nanoFramework C# csharp netmf netnf nanoFramework.M5AtomLite</tags>
|
||||
<dependencies>
|
||||
<dependency id="nanoFramework.CoreLibrary" version="1.12.0-preview.5" />
|
||||
<dependency id="nanoFramework.Hardware.Esp32" version="1.3.5-preview.6" />
|
||||
<dependency id="nanoFramework.Hardware.Esp32.Rmt" version="1.2.2-preview.6" />
|
||||
<dependency id="nanoFramework.Iot.Device.Button" version="1.0.288-preview.29" />
|
||||
<dependency id="nanoFramework.Runtime.Events" version="1.10.0-preview.6" />
|
||||
<dependency id="nanoFramework.System.Device.Gpio" version="1.0.3-preview.8" />
|
||||
<dependency id="nanoFramework.System.Device.Dac" version="1.4.3-preview.6" />
|
||||
<dependency id="nanoFramework.System.Device.Adc" version="1.0.2-preview.6" />
|
||||
<dependency id="nanoFramework.System.Device.I2c" version="1.0.3-preview.6" />
|
||||
<dependency id="nanoFramework.System.Device.Spi" version="1.0.3-preview.17" />
|
||||
<dependency id="nanoFramework.System.Drawing" version="1.0.288-preview.20" />
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="nanoFramework.M5AtomLite\bin\Release\nanoFramework.M5AtomLite.dll" target="lib\nanoFramework.M5AtomLite.dll" />
|
||||
<file src="nanoFramework.M5AtomLite\bin\Release\nanoFramework.M5AtomLite.pdb" target="lib\nanoFramework.M5AtomLite.pdb" />
|
||||
<file src="nanoFramework.M5AtomLite\bin\Release\nanoFramework.M5AtomLite.pdbx" target="lib\nanoFramework.M5AtomLite.pdbx" />
|
||||
<file src="nanoFramework.M5AtomLite\bin\Release\nanoFramework.M5AtomLite.pe" target="lib\nanoFramework.M5AtomLite.pe" />
|
||||
<file src="nanoFramework.M5AtomLite\bin\Release\nanoFramework.M5AtomLite.xml" target="lib\nanoFramework.M5AtomLite.xml" />
|
||||
<file src="assets\readme.txt" target="" />
|
||||
<file src="README.md" target="docs\" />
|
||||
<file src="assets\nf-logo.png" target="images\" />
|
||||
<file src="LICENSE.md" target="" />
|
||||
</files>
|
||||
</package>
|
|
@ -0,0 +1,174 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using Iot.Device.Button;
|
||||
using System;
|
||||
using System.Device.Gpio;
|
||||
using System.Device.Dac;
|
||||
using System.Device.Adc;
|
||||
using nanoFramework.Hardware.Esp32.Rmt;
|
||||
using System.Device.I2c;
|
||||
using nanoFramework.Hardware.Esp32;
|
||||
using System.Device.Spi;
|
||||
|
||||
namespace nanoFramework.M5AtomLite
|
||||
{
|
||||
/// <summary>
|
||||
/// The M5AtomLite B=board
|
||||
/// </summary>
|
||||
public static class M5AtomLite
|
||||
{
|
||||
private static GpioButton _button;
|
||||
private static RgbLed _rgbLed;
|
||||
private static GpioController _gpio;
|
||||
private static DacChannel _dac1;
|
||||
private static DacChannel _dac2;
|
||||
private static AdcController _adc;
|
||||
private static TransmitterChannel _irLed;
|
||||
|
||||
/// <summary>
|
||||
/// Main button.
|
||||
/// </summary>
|
||||
public static GpioButton Button
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_button == null)
|
||||
{
|
||||
_button = new(39, _gpio, false);
|
||||
}
|
||||
|
||||
return _button;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// RGB NeoPixel led
|
||||
/// </summary>
|
||||
public static RgbLed NeoPixel
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_rgbLed == null)
|
||||
{
|
||||
_rgbLed = new();
|
||||
}
|
||||
|
||||
return _rgbLed;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the main GPIO Controller.
|
||||
/// </summary>
|
||||
public static GpioController GpioController => _gpio;
|
||||
|
||||
/// <summary>
|
||||
/// Gets DAC1 which is GPIO 25.
|
||||
/// </summary>
|
||||
public static DacChannel Dac1
|
||||
{
|
||||
get
|
||||
{
|
||||
// We are creating it on demand
|
||||
if (_dac1 == null)
|
||||
{
|
||||
_dac1 = DacController.GetDefault().OpenChannel(0);
|
||||
}
|
||||
|
||||
return _dac1;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets DAC1 which is GPIO 26.
|
||||
/// </summary>
|
||||
public static DacChannel Dac2
|
||||
{
|
||||
get
|
||||
{
|
||||
// We are creating it on demand
|
||||
if (_dac2 == null)
|
||||
{
|
||||
|
||||
_dac2 = DacController.GetDefault().OpenChannel(1);
|
||||
}
|
||||
|
||||
return _dac2;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an I2C device.
|
||||
/// </summary>
|
||||
/// <param name="i2cDeviceAddress">The I2C device address on the bus.</param>
|
||||
/// <returns>The I2cDevice.</returns>
|
||||
public static I2cDevice GetI2cDevice(int i2cDeviceAddress) => new(new I2cConnectionSettings(1, i2cDeviceAddress));
|
||||
|
||||
/// <summary>
|
||||
/// Gets an I2C device.
|
||||
/// </summary>
|
||||
/// <param name="i2cDeviceAddress">The I2C device address on the bus.</param>
|
||||
/// <returns>The I2cDevice.</returns>
|
||||
public static I2cDevice GetGrove(int i2cDeviceAddress) => new(new I2cConnectionSettings(1, i2cDeviceAddress));
|
||||
|
||||
/// <summary>
|
||||
/// Gets the infrared led as a RMT transmitter channel.
|
||||
/// </summary>
|
||||
public static TransmitterChannel InfraredLed
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_irLed == null)
|
||||
{
|
||||
_irLed = new(12);
|
||||
}
|
||||
|
||||
return _irLed;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets an SPI Device.
|
||||
/// </summary>
|
||||
/// <param name="chipSelect">The chip select of the device, needs to be any valid GPIO.</param>
|
||||
/// <returns>An SpiDevice.</returns>
|
||||
public static SpiDevice GetSpiDevice(int chipSelect) => new(new SpiConnectionSettings(1, chipSelect));
|
||||
|
||||
/// <summary>
|
||||
/// Gets an ADC channel
|
||||
/// </summary>
|
||||
/// <param name="gpioNumber">The GPIO pin number</param>
|
||||
/// <returns>An AdcChannel</returns>
|
||||
public static AdcChannel GetAdcGpio(int gpioNumber)
|
||||
{
|
||||
if (_adc == null)
|
||||
{
|
||||
_adc = new();
|
||||
}
|
||||
|
||||
switch (gpioNumber)
|
||||
{
|
||||
case 33:
|
||||
Configuration.SetPinFunction(12, DeviceFunction.ADC1_CH5);
|
||||
return _adc.OpenChannel(5);
|
||||
case 32:
|
||||
Configuration.SetPinFunction(25, DeviceFunction.ADC1_CH4);
|
||||
return _adc.OpenChannel(4);
|
||||
default:
|
||||
throw new ArgumentException(nameof(gpioNumber));
|
||||
}
|
||||
}
|
||||
|
||||
static M5AtomLite()
|
||||
{
|
||||
// Setup first the I2C bus
|
||||
Configuration.SetPinFunction(32, DeviceFunction.I2C1_CLOCK);
|
||||
Configuration.SetPinFunction(26, DeviceFunction.I2C1_DATA);
|
||||
|
||||
// Setup buttons
|
||||
_gpio = new();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,21 @@
|
|||
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("nanoFramework.AtomLite")]
|
||||
[assembly: AssemblyCompany("nanoFramework Contributors")]
|
||||
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
|
||||
|
||||
// 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)]
|
||||
|
||||
/////////////////////////////////////////////////////////////////
|
||||
// This attribute is mandatory when building Interop libraries //
|
||||
// update this whenever the native assembly signature changes //
|
||||
[assembly: AssemblyNativeVersion("0.0.0.0")]
|
||||
/////////////////////////////////////////////////////////////////
|
|
@ -0,0 +1,92 @@
|
|||
// Licensed to the .NET Foundation under one or more agreements.
|
||||
// The .NET Foundation licenses this file to you under the MIT license.
|
||||
|
||||
using nanoFramework.Hardware.Esp32.Rmt;
|
||||
using System.Drawing;
|
||||
|
||||
namespace nanoFramework.M5AtomLite
|
||||
{
|
||||
/// <summary>
|
||||
/// The RGB Led controller for M5Stack Atom Lite.
|
||||
/// </summary>
|
||||
public class RgbLed
|
||||
{
|
||||
protected const int RgbLedPin = 27;
|
||||
// 80MHz / 4 => min pulse 0.00us
|
||||
protected const byte ClockDivider = 4;
|
||||
// one pulse duration in us
|
||||
protected const float MinPulse = 1000000.0f / (80000000 / ClockDivider);
|
||||
|
||||
// default datasheet values
|
||||
protected readonly RmtCommand OnePulse =
|
||||
new RmtCommand((ushort)(0.7 / MinPulse), true, (ushort)(0.6 / MinPulse), false);
|
||||
|
||||
protected readonly RmtCommand ZeroPulse =
|
||||
new RmtCommand((ushort)(0.35 / MinPulse), true, (ushort)(0.8 / MinPulse), false);
|
||||
|
||||
protected readonly RmtCommand ResCommand =
|
||||
new RmtCommand((ushort)(25 / MinPulse), false, (ushort)(26 / MinPulse), false);
|
||||
|
||||
protected Color Pixel;
|
||||
private readonly int _gpioPin;
|
||||
|
||||
internal RgbLed(int gpioPin = RgbLedPin)
|
||||
{
|
||||
_gpioPin = gpioPin;
|
||||
Pixel = Color.Black;
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Sets the NeoPixel to the specified rgb color.
|
||||
/// </summary>
|
||||
/// <param name="color">The color that is used</param>
|
||||
public void SetColor(Color color)
|
||||
{
|
||||
Pixel = color;
|
||||
Update();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the rgb color from the NeoPixel.
|
||||
/// </summary>
|
||||
/// <returns>The rgb color</returns>
|
||||
public Color GetColor()
|
||||
{
|
||||
return Pixel;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
using (var commandList = new TransmitterChannel(_gpioPin))
|
||||
{
|
||||
ConfigureTransmitter(commandList);
|
||||
|
||||
SerializeColor(Pixel.G, commandList);
|
||||
SerializeColor(Pixel.R, commandList);
|
||||
SerializeColor(Pixel.B, commandList);
|
||||
|
||||
commandList.AddCommand(ResCommand); // RET
|
||||
commandList.Send(true);
|
||||
}
|
||||
}
|
||||
|
||||
private void SerializeColor(byte b, TransmitterChannel commandList)
|
||||
{
|
||||
for (var i = 0; i < 8; ++i)
|
||||
{
|
||||
commandList.AddCommand(((b & (1u << 7)) != 0) ? OnePulse : ZeroPulse);
|
||||
b <<= 1;
|
||||
}
|
||||
}
|
||||
|
||||
protected void ConfigureTransmitter(TransmitterChannel commandList)
|
||||
{
|
||||
commandList.CarrierEnabled = false;
|
||||
commandList.ClockDivider = ClockDivider;
|
||||
commandList.SourceClock = SourceClock.APB;
|
||||
commandList.IdleLevel = false;
|
||||
commandList.IsChannelIdle = true;
|
||||
}
|
||||
}
|
||||
}
|
Двоичный файл не отображается.
|
@ -0,0 +1,102 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Label="Globals">
|
||||
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<ProjectGuid>c20734a9-c944-4b2a-9cea-a9b3f855b132</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<RootNamespace>nanoFramework.M5AtomLite</RootNamespace>
|
||||
<AssemblyName>nanoFramework.M5AtomLite</AssemblyName>
|
||||
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
|
||||
<DocumentationFile>bin\$(Configuration)\nanoFramework.M5AtomLite.xml</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<DelaySign>false</DelaySign>
|
||||
</PropertyGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
|
||||
<ItemGroup>
|
||||
<Compile Include="M5AtomLite.cs" />
|
||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||
<Compile Include="RgbLed.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="Iot.Device.Button, Version=0.0.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.Iot.Device.Button.1.0.288-preview.29\lib\Iot.Device.Button.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="mscorlib, Version=1.12.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.CoreLibrary.1.12.0-preview.5\lib\mscorlib.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Hardware.Esp32">
|
||||
<HintPath>..\packages\nanoFramework.Hardware.Esp32.1.3.5-preview.6\lib\nanoFramework.Hardware.Esp32.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Hardware.Esp32.Rmt, Version=1.2.2.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.Hardware.Esp32.Rmt.1.2.2-preview.6\lib\nanoFramework.Hardware.Esp32.Rmt.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="nanoFramework.Runtime.Events, Version=1.10.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.Runtime.Events.1.10.0-preview.6\lib\nanoFramework.Runtime.Events.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Adc, Version=1.0.2.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.Adc.1.0.2-preview.6\lib\System.Device.Adc.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Dac, Version=1.4.3.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.Dac.1.4.3-preview.6\lib\System.Device.Dac.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Gpio, Version=1.0.3.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.Gpio.1.0.3-preview.8\lib\System.Device.Gpio.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.I2c">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.0.3-preview.6\lib\System.Device.I2c.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System.Device.Spi, Version=1.0.3.0, Culture=neutral, PublicKeyToken=c07d481e9758c731">
|
||||
<HintPath>..\packages\nanoFramework.System.Device.Spi.1.0.3-preview.17\lib\System.Device.Spi.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
<SpecificVersion>True</SpecificVersion>
|
||||
</Reference>
|
||||
<Reference Include="System.Drawing">
|
||||
<HintPath>..\packages\nanoFramework.System.Drawing.1.0.288-preview.20\lib\System.Drawing.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
|
||||
<ProjectExtensions>
|
||||
<ProjectCapabilities>
|
||||
<ProjectConfigurationsDeclaredAsItems />
|
||||
</ProjectCapabilities>
|
||||
</ProjectExtensions>
|
||||
<Import Project="..\packages\Nerdbank.GitVersioning.3.4.203\build\Nerdbank.GitVersioning.targets" Condition="Exists('..\packages\Nerdbank.GitVersioning.3.4.203\build\Nerdbank.GitVersioning.targets')" />
|
||||
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
|
||||
<PropertyGroup>
|
||||
<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>
|
||||
</PropertyGroup>
|
||||
<Error Condition="!Exists('..\packages\Nerdbank.GitVersioning.3.4.203\build\Nerdbank.GitVersioning.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Nerdbank.GitVersioning.3.4.203\build\Nerdbank.GitVersioning.targets'))" />
|
||||
</Target>
|
||||
</Project>
|
|
@ -0,0 +1,15 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="nanoFramework.CoreLibrary" version="1.12.0-preview.5" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Hardware.Esp32" version="1.3.5-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Hardware.Esp32.Rmt" version="1.2.2-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Iot.Device.Button" version="1.0.288-preview.29" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.Runtime.Events" version="1.10.0-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Adc" version="1.0.2-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Dac" version="1.4.3-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Gpio" version="1.0.3-preview.8" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.I2c" version="1.0.3-preview.6" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Device.Spi" version="1.0.3-preview.17" targetFramework="netnanoframework10" />
|
||||
<package id="nanoFramework.System.Drawing" version="1.0.288-preview.20" targetFramework="netnanoframework10" />
|
||||
<package id="Nerdbank.GitVersioning" version="3.4.203" targetFramework="netnanoframework10" developmentDependency="true" />
|
||||
</packages>
|
|
@ -1,11 +1,12 @@
|
|||
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||
# Visual Studio Version 17
|
||||
VisualStudioVersion = 17.0.32014.148
|
||||
# Visual Studio Version 16
|
||||
VisualStudioVersion = 16.0.31105.61
|
||||
MinimumVisualStudioVersion = 10.0.40219.1
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.M5Core", "nanoFramework.M5Core\nanoFramework.M5Core.nfproj", "{2C78D035-DBDA-4C38-AB58-8ADC22D763C3}"
|
||||
EndProject
|
||||
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{0A689EB3-86E0-448E-99F4-3D644EC3D8C5}"
|
||||
ProjectSection(SolutionItems) = preProject
|
||||
nanoFramework.M5AtomLite.nuspec = nanoFramework.M5AtomLite.nuspec
|
||||
nanoFramework.M5Core.nuspec = nanoFramework.M5Core.nuspec
|
||||
nanoFramework.M5Core2.nuspec = nanoFramework.M5Core2.nuspec
|
||||
nanoFramework.M5StickC.nuspec = nanoFramework.M5StickC.nuspec
|
||||
|
@ -36,6 +37,10 @@ Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "nanoFramework.M5StackCore",
|
|||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "M5Core2TestApp", "Tests\M5Core2TestApp\M5Core2TestApp.nfproj", "{20266750-53F3-46D5-8626-1438AC985033}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.M5AtomLite", "nanoFramework.M5AtomLite\nanoFramework.M5AtomLite.nfproj", "{C20734A9-C944-4B2A-9CEA-A9B3F855B132}"
|
||||
EndProject
|
||||
Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "M5AtomLiteTestApp", "Tests\M5AtomLiteTestApp\M5AtomLiteTestApp.nfproj", "{7533C164-9D3E-461B-BEED-888C91AC640B}"
|
||||
EndProject
|
||||
Global
|
||||
GlobalSection(SharedMSBuildProjectFiles) = preSolution
|
||||
M5StackCommon\M5StackCommon.projitems*{00e23322-2401-4087-abae-24f90c8a0422}*SharedItemsImports = 13
|
||||
|
@ -89,6 +94,18 @@ Global
|
|||
{20266750-53F3-46D5-8626-1438AC985033}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{20266750-53F3-46D5-8626-1438AC985033}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{20266750-53F3-46D5-8626-1438AC985033}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{C20734A9-C944-4B2A-9CEA-A9B3F855B132}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Debug|Any CPU.Deploy.0 = Debug|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B}.Release|Any CPU.Deploy.0 = Release|Any CPU
|
||||
EndGlobalSection
|
||||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
|
@ -100,6 +117,7 @@ Global
|
|||
{48E3FD52-1D13-422D-AF3F-B6AEA2C72800} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437}
|
||||
{E2A94F3C-EE7F-4075-A98A-A19CABE82C0F} = {FFF3F871-7600-480E-B378-95AD0F9FC0F1}
|
||||
{20266750-53F3-46D5-8626-1438AC985033} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437}
|
||||
{7533C164-9D3E-461B-BEED-888C91AC640B} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437}
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {DD82D7FF-B798-48A4-8506-2FBA0001D32F}
|
||||
|
|
Загрузка…
Ссылка в новой задаче