diff --git a/README.md b/README.md index 9d541b3b..8c8be5b9 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,8 @@ | nanoFramework.M5StickCPlus (preview) | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop) | [![NuGet](https://img.shields.io/nuget/vpre/nanoFramework.M5StickCPlus.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5StickCPlus/) | | nanoFramework.M5Core2 | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.M5Core2.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5Core2/) | | nanoFramework.M5Core2 (preview) | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop) | [![NuGet](https://img.shields.io/nuget/vpre/nanoFramework.M5Core2.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.M5Core2/) | +| nanoFramework.Fire | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.Fire.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Fire/) | +| nanoFramework.Fire (preview) | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop) | [![NuGet](https://img.shields.io/nuget/vpre/nanoFramework.Fire.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Fire/) | | nanoFramework.AtomLite | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.AtomLite.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.AtomLite/) | | nanoFramework.AtomLite (preview) | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=develop) | [![NuGet](https://img.shields.io/nuget/vpre/nanoFramework.AtomLite.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.AtomLite/) | | nanoFramework.AtomMatrix | [![Build Status](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_apis/build/status/nanoFramework.M5Stack?repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main)](https://dev.azure.com/nanoframework/nanoFramework.M5Stack/_build/latest?definitionId=52&repoName=nanoframework%2FnanoFramework.M5Stack&branchName=main) | [![NuGet](https://img.shields.io/nuget/v/nanoFramework.AtomMatrix.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.AtomMatrix/) | @@ -31,6 +33,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) +- [Fire](https://docs.m5stack.com/en/core/fire) - [Atom Lite](https://docs.m5stack.com/en/core/atom_lite) - [Atom Matrix](https://docs.m5stack.com/en/core/atom_matrix) @@ -58,7 +61,7 @@ For the M5StickCPlus: nanoff --target M5StickCPlus --update --preview --serialport COM3 ``` -For the M5Core2: +For the M5Core2 and Fire: ```shell nanoff --target M5Core2 --update --preview --serialport COM3 @@ -137,13 +140,13 @@ nanoFramework.Console.Write("This is white on black again and on 9th line"); > Note: You can change the default font as well, you need to provide it as a property. The Cursor positions are calculated with the largest possible character. -M5Core2 has SPRAM, so you can get a full screen buffer as well. Refer to the [Graphics samples](https://github.com/nanoframework/Samples#graphics-for-screens) to understand all you can do with it. +M5Core2 and Fire have SPRAM, so you can get a full screen buffer as well. Refer to the [Graphics samples](https://github.com/nanoframework/Samples#graphics-for-screens) to understand all you can do with it. ### Buttons The main buttons except the power buttons are exposed. -On the M5Stack they are called `ButtonLeft`, `ButtonCenter` and `ButtonRight`. You can get access to the events as well. For example: +On the M5Stack and Fire they are called `ButtonLeft`, `ButtonCenter` and `ButtonRight`. You can get access to the events as well. For example: ```csharp M5Stack.ButtonLeft.Press += (sender, e) => @@ -272,7 +275,7 @@ The `TouchEventCategory` enum is a flag and can combine buttons and states. The The M5Core and M5StickC/CPlus are exposing their power management elements. It is not recommended to change any default value except if you know what you are doing. -Please refer to the detailed examples for the [AXP192](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Axp192/README.md) used in the M5StickC/CPlus; M5Core2 and [IP5306](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Ip5306/README.md) for the M5Core. +Please refer to the detailed examples for the [AXP192](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Axp192/README.md) used in the M5StickC/CPlus; M5Core2 and [IP5306](https://github.com/nanoframework/nanoFramework.IoT.Device/blob/develop/devices/Ip5306/README.md) for the M5Core and Fire. ### Accelerometer and Gyroscope @@ -322,7 +325,7 @@ Refer to the [SerialPort documentation](https://github.com/nanoframework/System. ### ADC Channels -ADC Channels are pre setup on the M5Core, M5Core2 and Atom Lite/Matrix, access them like this: +ADC Channels are pre setup on the M5Core, M5Core2, Fire and Atom Lite/Matrix, access them like this: ```csharp // This will give you the ADC1 channel 7 which is on pin 35 of M5Core @@ -343,7 +346,7 @@ I2cDevice myDevice = M5Core.GetGrove(0x42); ### SPI Device -The M5Core, M5Core2 and Atom Lite/Matrix provides as well an `SpiDevice`: +The M5Core, M5Core2, Fire and Atom Lite/Matrix provides as well an `SpiDevice`: ```csharp // In this case GPIO5 will be used as chip select: @@ -352,7 +355,7 @@ SpiDevice mySpi = M5Core.GetSpiDevice(5); ### GPIO Controller -Similar as previously, you can get the `GpioController` on any of the M5Core, M5Core2 and M5StickC/CPlus: +Similar as previously, you can get the `GpioController` on any of the M5Core, M5Core2, Fire and M5StickC/CPlus: ```csharp // This will open the GPIO 36 as output @@ -361,7 +364,7 @@ var pin5 = M5StickC.GpioController.OpenPin(36, PinMode.Output); ### DAC -The M5Core, M5Core2 and Atom Lite/Matrix 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, Fire and Atom Lite/Matrix 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 diff --git a/Tests/FireTestApp/FireTestApp.nfproj b/Tests/FireTestApp/FireTestApp.nfproj new file mode 100644 index 00000000..7fe8f2fd --- /dev/null +++ b/Tests/FireTestApp/FireTestApp.nfproj @@ -0,0 +1,110 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 5ff00f7c-8ed8-4468-9959-497ce8c5b1af + Exe + Properties + 512 + FiteTestApp + FiteTestApp + v1.0 + + + + + + + + + + + + ..\..\packages\nanoFramework.Iot.Device.Bmm150.1.0.288-preview.86\lib\Iot.Device.Bmm150.dll + + + ..\..\packages\nanoFramework.Iot.Device.Button.1.0.288-preview.86\lib\Iot.Device.Button.dll + + + ..\..\packages\nanoFramework.Iot.Device.Buzzer.1.0.288-preview.86\lib\Iot.Device.Buzzer.dll + + + ..\..\packages\nanoFramework.Iot.Device.Ip5306.1.0.288-preview.86\lib\Iot.Device.Ip5306.dll + + + ..\..\packages\nanoFramework.Iot.Device.Mpu6886.1.0.288-preview.86\lib\Iot.Device.Mpu6886.dll + + + ..\..\packages\nanoFramework.CoreLibrary.1.12.0-preview.9\lib\mscorlib.dll + + + ..\..\packages\nanoFramework.Graphics.1.0.2-preview.15\lib\nanoFramework.Graphics.dll + + + ..\..\packages\nanoFramework.ResourceManager.1.1.4-preview.8\lib\nanoFramework.ResourceManager.dll + + + ..\..\packages\nanoFramework.Runtime.Events.1.10.0-preview.8\lib\nanoFramework.Runtime.Events.dll + + + ..\..\packages\nanoFramework.Runtime.Native.1.5.4-preview.5\lib\nanoFramework.Runtime.Native.dll + + + ..\..\packages\nanoFramework.System.Collections.1.4.0-preview.21\lib\nanoFramework.System.Collections.dll + + + ..\..\packages\nanoFramework.System.Buffers.Binary.BinaryPrimitives.1.0.288-preview.64\lib\System.Buffers.Binary.BinaryPrimitives.dll + + + ..\..\packages\nanoFramework.System.Device.Adc.1.0.2-preview.8\lib\System.Device.Adc.dll + + + ..\..\packages\nanoFramework.System.Device.Dac.1.4.3-preview.8\lib\System.Device.Dac.dll + + + ..\..\packages\nanoFramework.System.Device.Gpio.1.0.3-preview.14\lib\System.Device.Gpio.dll + + + ..\..\packages\nanoFramework.System.Device.I2c.1.0.3-preview.8\lib\System.Device.I2c.dll + + + ..\..\packages\nanoFramework.System.Device.Model.1.0.288-preview.64\lib\System.Device.Model.dll + + + ..\..\packages\nanoFramework.System.Device.Pwm.1.0.1-preview.8\lib\System.Device.Pwm.dll + + + ..\..\packages\nanoFramework.System.Device.Spi.1.0.4-preview.3\lib\System.Device.Spi.dll + + + ..\..\packages\nanoFramework.System.Math.1.4.4-preview.15\lib\System.Math.dll + + + ..\..\packages\nanoFramework.System.Numerics.1.0.288-preview.64\lib\System.Numerics.dll + + + ..\..\packages\UnitsNet.nanoFramework.ElectricCurrent.4.125.0\lib\UnitsNet.ElectricCurrent.dll + + + ..\..\packages\UnitsNet.nanoFramework.Frequency.4.125.0\lib\UnitsNet.Frequency.dll + + + ..\..\packages\UnitsNet.nanoFramework.Temperature.4.125.0\lib\UnitsNet.Temperature.dll + + + + + + + + + + + + \ No newline at end of file diff --git a/Tests/FireTestApp/Program.cs b/Tests/FireTestApp/Program.cs new file mode 100644 index 00000000..48ab90eb --- /dev/null +++ b/Tests/FireTestApp/Program.cs @@ -0,0 +1,125 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using nanoFramework.M5Stack; +using nanoFramework.Presentation.Media; +using System; +using System.Diagnostics; +using System.Numerics; +using System.Threading; +using Console = nanoFramework.M5Stack.Console; + +Debug.WriteLine("Hello from nanoFramework!"); + +Fire.InitializeScreen(); +Console.Clear(); + +// Test the console display +Console.Write("This is a short text. "); +Console.ForegroundColor = Color.Red; +Console.WriteLine("This one displays in red after the previous one and is already at the next line."); +Console.BackgroundColor = Color.Yellow; +Console.ForegroundColor = Color.RoyalBlue; +Console.WriteLine("And this is really ugly but it's like that"); +Console.ResetColor(); +Console.Write("*@$+=}"); +Console.WriteLine("*@$+=}"); +Console.WriteLine(""); +Console.WriteLine("1 line empty before"); +Console.WriteLine("Press left button to continue"); + +while (!Fire.ButtonLeft.IsPressed) +{ + Thread.Sleep(10); +} + +Console.Clear(); + +Console.WriteLine("Calibrating the accelerator, do not touch it!"); +var acc = Fire.AccelerometerGyroscope; +acc.Calibrate(100); +Console.WriteLine(""); +Console.WriteLine("Calibrating the magnetometer, please move it all around"); +var mag = Fire.Magnetometer; +mag.CalibrateMagnetometer(100); + +Fire.ButtonLeft.Press += (sender, e) => +{ + Console.ForegroundColor = Color.Yellow; + Console.CursorLeft = 0; + Console.CursorTop = 0; + Console.Write($"Left Pressed "); +}; + +Fire.ButtonCenter.Press += (sender, e) => +{ + Console.ForegroundColor = Color.Yellow; + Console.CursorLeft = 0; + Console.CursorTop = 0; + Console.Write($"Center Pressed"); +}; + +Fire.ButtonRight.Press += (sender, e) => +{ + Console.ForegroundColor = Color.Yellow; + Console.CursorLeft = 0; + Console.CursorTop = 0; + Console.Write($"Right Pressed "); +}; + +Console.Clear(); + +var power = Fire.Power; +Vector3 accVal; +Vector3 gyroVal; +Vector3 magVal; + +while (true) +{ + accVal = acc.GetAccelerometer(); + gyroVal = acc.GetGyroscope(); + magVal = mag.ReadMagnetometer(); + var headDir = Math.Atan2(magVal.X, magVal.Y) * 180.0 / Math.PI; + Console.ForegroundColor = Color.Green; + Console.CursorLeft = 0; + Console.CursorTop = 1; + Console.WriteLine("Accelerator:"); + Console.WriteLine($" x={accVal.X:N2} "); + Console.WriteLine($" y={accVal.Y:N2} "); + Console.WriteLine($" z={accVal.Z:N2} "); + Console.ForegroundColor = Color.AliceBlue; + Console.WriteLine("Gyroscope:"); + Console.WriteLine($" x={gyroVal.X:N2} "); + Console.WriteLine($" y={gyroVal.Y:N2} "); + Console.WriteLine($" z={gyroVal.Z:N2} "); + Console.ForegroundColor = Color.Coral; + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop = 1; + Console.Write("Magnetometer:"); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.Write($" x={magVal.X:N2} "); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.Write($" y={magVal.Y:N2} "); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.Write($" z={magVal.Z:N2} "); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.Write($" h={headDir:N2} "); + Console.ForegroundColor = Color.DarkBlue; + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop = 6; + Console.Write("Power:"); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.BackgroundColor = power.IsCharging ? Color.Black : Color.Red; + Console.Write($" Charging {power.IsCharging}"); + Console.BackgroundColor = Color.Black; + Console.Write(" "); + Console.CursorLeft = Console.WindowWidth / 2 - 2; + Console.CursorTop++; + Console.Write($" Full {power.IsBatteryFull} "); + Thread.Sleep(20); +} diff --git a/Tests/FireTestApp/Properties/AssemblyInfo.cs b/Tests/FireTestApp/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..262254df --- /dev/null +++ b/Tests/FireTestApp/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 © ")] +[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/Tests/FireTestApp/packages.config b/Tests/FireTestApp/packages.config new file mode 100644 index 00000000..750a8685 --- /dev/null +++ b/Tests/FireTestApp/packages.config @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Fire.nuspec b/nanoFramework.Fire.nuspec new file mode 100644 index 00000000..c9924a07 --- /dev/null +++ b/nanoFramework.Fire.nuspec @@ -0,0 +1,62 @@ + + + + nanoFramework.Fire + $version$ + nanoFramework.Fire + nanoframework + false + LICENSE.md + + + docs\README.md + false + https://github.com/nanoframework/nanoFramework.M5Stack + images\nf-logo.png + + Copyright (c) .NET Foundation and Contributors + This package includes the nanoFramework.Fire assembly for .NET nanoFramework C# projects. + nanoFramework C# csharp netmf netnf m5stack Fire + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Fire/Fire.cs b/nanoFramework.Fire/Fire.cs new file mode 100644 index 00000000..753860fc --- /dev/null +++ b/nanoFramework.Fire/Fire.cs @@ -0,0 +1,212 @@ +// 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 Iot.Device.Buzzer; +using Iot.Device.Ip5306; +using nanoFramework.Fire; +using nanoFramework.Hardware.Esp32; +using System; +using System.Device.Adc; +using System.Device.I2c; +using UnitsNet; + +namespace nanoFramework.M5Stack +{ + /// + /// Fire board + /// + public static partial class Fire + { + private static readonly Ip5306 _power; + private static GpioButton _left; + private static GpioButton _center; + private static GpioButton _right; + private static Buzzer _buzzer; + + #region properties + + /// + /// Left button. + /// + public static GpioButton ButtonLeft + { + get + { + if (_left == null) + { + _left = new(39, _gpio, false); + } + + return _left; + } + } + + /// + /// Center button. + /// + public static GpioButton ButtonCenter + { + get + { + if (_center == null) + { + _center = new(38, _gpio, false); + } + + return _center; + } + } + + /// + /// Right button. + /// + public static GpioButton ButtonRight + { + get + { + if (_right == null) + { + _right = new(37, _gpio, false); + } + + return _right; + } + } + + /// + /// Gets the power management of the M5 Stack. + /// + /// Please make sure to read the documentation before adjusting any element. + public static Ip5306 Power { get => _power; } + + /// + /// Gets the Buzzer. + /// + public static Buzzer Buzzer + { + get + { + // We do this in case you prefer to use the DAC channels which are using the same pins + if (_buzzer == null) + { + // Setup buzzer + Configuration.SetPinFunction(25, DeviceFunction.PWM1); + _buzzer = new(25); + } + + return _buzzer; + } + } + + #endregion + + /// + /// Gets the screen. + /// + /// The screen initialization takes a little bit of time, if you need the screen consider using it as early as possible in your code. + public static void InitializeScreen() + { + // If the screen is not needed, it's not going to be created + // Note: initialization may take a little bit of time + if (_screen == null) + { + _screen = new(); + Console.Font = Resource.GetFont(Resource.FontResources.consolas_regular_16); + } + } + + static Fire() + { + // Setup first the I2C bus + Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK); + Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA); + // Same for PortA than for the internal one + _portANumber = 1; + + // Create the energy management device + I2cDevice i2c = new(new I2cConnectionSettings(1, Ip5306.SecondaryI2cAddress)); + _power = new(i2c); + + // Configuration for M5Stack + _power.ButtonOffEnabled = true; + _power.BoostOutputEnabled = false; + _power.AutoPowerOnEnabled = true; + _power.ChargerEnabled = true; + _power.BoostEnabled = true; + _power.LowPowerOffEnabled = true; + _power.FlashLightBehavior = ButtonPress.Doubleclick; + _power.SwitchOffBoostBehavior = ButtonPress.LongPress; + _power.BoostWhenVinUnpluggedEnabled = true; + _power.ChargingUnderVoltage = ChargingUnderVoltage.V4_55; + _power.ChargingLoopSelection = ChargingLoopSelection.Vin; + _power.ChargingCurrent = ElectricCurrent.FromMilliamperes(2250); + _power.ConstantChargingVoltage = ConstantChargingVoltage.Vm28; + _power.ChargingCuttOffVoltage = ChargingCutOffVoltage.V4_17; + _power.LightDutyShutdownTime = LightDutyShutdownTime.S32; + _power.ChargingCutOffCurrent = ChargingCutOffCurrent.C500mA; + _power.ChargingCuttOffVoltage = ChargingCutOffVoltage.V4_2; + + // Setup buttons + _gpio = new(); + + // Config GPIOs for SPI (screen and SD Card) + Configuration.SetPinFunction(23, DeviceFunction.SPI2_MOSI); + Configuration.SetPinFunction(19, DeviceFunction.SPI2_MISO); + Configuration.SetPinFunction(18, DeviceFunction.SPI2_CLOCK); + + // Second serial port + Configuration.SetPinFunction(16, DeviceFunction.COM2_RX); + Configuration.SetPinFunction(17, DeviceFunction.COM2_TX); + } + + /// + /// Gets an ADC channel + /// + /// The GPIO pin number + /// An AdcChannel + public static AdcChannel GetAdcGpio(int gpioNumber) + { + if (_adc == null) + { + _adc = new(); + } + + switch (gpioNumber) + { + case 35: + Configuration.SetPinFunction(35, DeviceFunction.ADC1_CH7); + return _adc.OpenChannel(7); + case 36: + Configuration.SetPinFunction(36, DeviceFunction.ADC1_CH0); + return _adc.OpenChannel(0); + case 2: + Configuration.SetPinFunction(2, DeviceFunction.ADC1_CH12); + return _adc.OpenChannel(12); + case 12: + Configuration.SetPinFunction(12, DeviceFunction.ADC1_CH15); + return _adc.OpenChannel(15); + case 15: + Configuration.SetPinFunction(15, DeviceFunction.ADC1_CH13); + return _adc.OpenChannel(13); + case 25: + Configuration.SetPinFunction(25, DeviceFunction.ADC1_CH18); + return _adc.OpenChannel(18); + case 26: + Configuration.SetPinFunction(26, DeviceFunction.ADC1_CH19); + return _adc.OpenChannel(19); + case 13: + Configuration.SetPinFunction(13, DeviceFunction.ADC1_CH14); + return _adc.OpenChannel(14); + case 0: + Configuration.SetPinFunction(0, DeviceFunction.ADC1_CH11); + return _adc.OpenChannel(11); + case 34: + Configuration.SetPinFunction(34, DeviceFunction.ADC1_CH6); + return _adc.OpenChannel(6); + default: + throw new ArgumentException(nameof(gpioNumber)); + } + } + } +} diff --git a/nanoFramework.Fire/Properties/AssemblyInfo.cs b/nanoFramework.Fire/Properties/AssemblyInfo.cs new file mode 100644 index 00000000..61f731f9 --- /dev/null +++ b/nanoFramework.Fire/Properties/AssemblyInfo.cs @@ -0,0 +1,39 @@ +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")] + +///////////////////////////////////////////////////////////////// +// This attribute is mandatory when building Interop libraries // +// update this whenever the native assembly signature changes // +[assembly: AssemblyNativeVersion("1.0.0.0")] +///////////////////////////////////////////////////////////////// diff --git a/nanoFramework.Fire/Resource.Designer.cs b/nanoFramework.Fire/Resource.Designer.cs new file mode 100644 index 00000000..e7061d2f --- /dev/null +++ b/nanoFramework.Fire/Resource.Designer.cs @@ -0,0 +1,38 @@ +//------------------------------------------------------------------------------ +// +// This code was generated by a tool. +// Runtime Version:4.0.30319.42000 +// +// Changes to this file may cause incorrect behavior and will be lost if +// the code is regenerated. +// +//------------------------------------------------------------------------------ + +namespace nanoFramework.Fire +{ + + internal partial class Resource + { + private static System.Resources.ResourceManager manager; + internal static System.Resources.ResourceManager ResourceManager + { + get + { + if ((Resource.manager == null)) + { + Resource.manager = new System.Resources.ResourceManager("nanoFramework.Fire.Resource", typeof(Resource).Assembly); + } + return Resource.manager; + } + } + internal static nanoFramework.UI.Font GetFont(Resource.FontResources id) + { + return ((nanoFramework.UI.Font)(nanoFramework.Runtime.Native.ResourceUtility.GetObject(ResourceManager, id))); + } + [System.SerializableAttribute()] + internal enum FontResources : short + { + consolas_regular_16 = 10023, + } + } +} diff --git a/nanoFramework.Fire/Resource.resx b/nanoFramework.Fire/Resource.resx new file mode 100644 index 00000000..0c6a0dd1 --- /dev/null +++ b/nanoFramework.Fire/Resource.resx @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + + Resources\consolas_regular_16.tinyfnt;System.Byte[], mscorlib, Version=1.12.0.0, Culture=neutral, PublicKeyToken=c07d481e9758c731 + + \ No newline at end of file diff --git a/nanoFramework.Fire/Resources/consolas_regular_16.tinyfnt b/nanoFramework.Fire/Resources/consolas_regular_16.tinyfnt new file mode 100644 index 00000000..2331827a Binary files /dev/null and b/nanoFramework.Fire/Resources/consolas_regular_16.tinyfnt differ diff --git a/nanoFramework.Fire/Screen.cs b/nanoFramework.Fire/Screen.cs new file mode 100644 index 00000000..4c74ea9e --- /dev/null +++ b/nanoFramework.Fire/Screen.cs @@ -0,0 +1,42 @@ +// Licensed to the .NET Foundation under one or more agreements. +// The .NET Foundation licenses this file to you under the MIT license. + +using nanoFramework.UI; +using System.Device.Gpio; + +namespace nanoFramework.M5Stack +{ + /// + /// M5 Stack screen class + /// + public class Screen : ScreenBase + { + private const int ChipSelect = 14; + private const int DataCommand = 27; + private const int Reset = 33; + private static bool _isInitialized = false; + + /// + /// Initializes the screen + /// + public Screen() + { + if (_isInitialized) + { + return; + } + +#if M5CORE2 || FIRE + MemoryAllocationBitmap = 2 * 1024 * 1024; +#else + MemoryAllocationBitmap = 1024; +#endif + BackLightPin = 32; + Controller = new(); + Controller.OpenPin(BackLightPin, PinMode.Output); + Enabled = true; + DisplayControl.Initialize(new SpiConfiguration(2, ChipSelect, DataCommand, Reset, BackLightPin), new ScreenConfiguration(0, 0, 320, 240), (uint)MemoryAllocationBitmap); + _isInitialized = true; + } + } +} diff --git a/nanoFramework.Fire/nanoFramework.Fire.nfproj b/nanoFramework.Fire/nanoFramework.Fire.nfproj new file mode 100644 index 00000000..f663f869 --- /dev/null +++ b/nanoFramework.Fire/nanoFramework.Fire.nfproj @@ -0,0 +1,136 @@ + + + + $(MSBuildExtensionsPath)\nanoFramework\v1.0\ + + + + Debug + AnyCPU + {11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + 2550d7fc-bba7-4173-9071-8606dd600a2c + Library + Properties + 512 + nanoFramework.Fire + nanoFramework.Fire + v1.0 + $(DefineConstants);FIRE + bin\$(Configuration)\nanoFramework.Fire.xml + + + + + + + True + True + Resource.resx + + + + + + ..\packages\nanoFramework.Iot.Device.Bmm150.1.0.288-preview.86\lib\Iot.Device.Bmm150.dll + + + ..\packages\nanoFramework.Iot.Device.Button.1.0.288-preview.86\lib\Iot.Device.Button.dll + + + ..\packages\nanoFramework.Iot.Device.Buzzer.1.0.288-preview.90\lib\Iot.Device.Buzzer.dll + + + ..\packages\nanoFramework.Iot.Device.Ip5306.1.0.288-preview.86\lib\Iot.Device.Ip5306.dll + + + ..\packages\nanoFramework.Iot.Device.Mpu6886.1.0.288-preview.86\lib\Iot.Device.Mpu6886.dll + + + ..\packages\nanoFramework.CoreLibrary.1.12.0-preview.9\lib\mscorlib.dll + + + ..\packages\nanoFramework.Graphics.1.0.2-preview.15\lib\nanoFramework.Graphics.dll + + + ..\packages\nanoFramework.Hardware.Esp32.1.3.5-preview.7\lib\nanoFramework.Hardware.Esp32.dll + + + ..\packages\nanoFramework.ResourceManager.1.1.4-preview.8\lib\nanoFramework.ResourceManager.dll + + + ..\packages\nanoFramework.Runtime.Events.1.10.0-preview.8\lib\nanoFramework.Runtime.Events.dll + + + ..\packages\nanoFramework.Runtime.Native.1.5.4-preview.5\lib\nanoFramework.Runtime.Native.dll + + + ..\packages\nanoFramework.System.Collections.1.4.0-preview.21\lib\nanoFramework.System.Collections.dll + + + ..\packages\nanoFramework.System.Text.1.1.3-preview.15\lib\nanoFramework.System.Text.dll + + + ..\packages\nanoFramework.System.Buffers.Binary.BinaryPrimitives.1.0.288-preview.64\lib\System.Buffers.Binary.BinaryPrimitives.dll + + + ..\packages\nanoFramework.System.Device.Adc.1.0.2-preview.8\lib\System.Device.Adc.dll + + + ..\packages\nanoFramework.System.Device.Dac.1.4.3-preview.8\lib\System.Device.Dac.dll + + + ..\packages\nanoFramework.System.Device.Gpio.1.0.3-preview.14\lib\System.Device.Gpio.dll + + + ..\packages\nanoFramework.System.Device.I2c.1.0.3-preview.8\lib\System.Device.I2c.dll + + + ..\packages\nanoFramework.System.Device.Model.1.0.288-preview.64\lib\System.Device.Model.dll + + + ..\packages\nanoFramework.System.Device.Pwm.1.0.1-preview.8\lib\System.Device.Pwm.dll + + + ..\packages\nanoFramework.System.Device.Spi.1.0.4-preview.3\lib\System.Device.Spi.dll + + + ..\packages\nanoFramework.System.IO.Ports.1.0.3-preview.33\lib\System.IO.Ports.dll + + + ..\packages\nanoFramework.System.IO.Streams.1.0.0-preview.12\lib\System.IO.Streams.dll + + + ..\packages\nanoFramework.System.Math.1.4.4-preview.15\lib\System.Math.dll + + + ..\packages\nanoFramework.System.Numerics.1.0.288-preview.64\lib\System.Numerics.dll + + + ..\packages\UnitsNet.nanoFramework.ElectricCurrent.4.125.0\lib\UnitsNet.ElectricCurrent.dll + + + ..\packages\UnitsNet.nanoFramework.Frequency.4.125.0\lib\UnitsNet.Frequency.dll + + + ..\packages\UnitsNet.nanoFramework.Temperature.4.125.0\lib\UnitsNet.Temperature.dll + + + + + + + + + nFResXFileCodeGenerator + Resource.Designer.cs + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.Fire/packages.config b/nanoFramework.Fire/packages.config new file mode 100644 index 00000000..5a7dd30e --- /dev/null +++ b/nanoFramework.Fire/packages.config @@ -0,0 +1,32 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/nanoFramework.M5Core.nuspec b/nanoFramework.M5Core.nuspec index 65f9d253..77f240c8 100644 --- a/nanoFramework.M5Core.nuspec +++ b/nanoFramework.M5Core.nuspec @@ -26,19 +26,23 @@ - - - + + + + + - - + + - + + + diff --git a/nanoFramework.M5Core/Screen.cs b/nanoFramework.M5Core/Screen.cs index d2ff6f81..4c74ea9e 100644 --- a/nanoFramework.M5Core/Screen.cs +++ b/nanoFramework.M5Core/Screen.cs @@ -26,7 +26,7 @@ public Screen() return; } -#if M5CORE2 +#if M5CORE2 || FIRE MemoryAllocationBitmap = 2 * 1024 * 1024; #else MemoryAllocationBitmap = 1024; diff --git a/nanoFramework.M5Core2.nuspec b/nanoFramework.M5Core2.nuspec index 49175d69..c5137660 100644 --- a/nanoFramework.M5Core2.nuspec +++ b/nanoFramework.M5Core2.nuspec @@ -24,24 +24,29 @@ + - - - + + + + + - - + + - - + + + + diff --git a/nanoFramework.M5Core2/M5Core2.cs b/nanoFramework.M5Core2/M5Core2.cs index 77cff7cd..b6a11c58 100644 --- a/nanoFramework.M5Core2/M5Core2.cs +++ b/nanoFramework.M5Core2/M5Core2.cs @@ -264,7 +264,7 @@ static M5Core2() _power.SetBatteryHighTemperatureThreshold(ElectricPotential.FromVolts(3.2256)); // Enable bat detection _power.SetShutdownBatteryDetectionControl(false, true, ShutdownBatteryPinFunction.HighResistance, true, ShutdownBatteryTiming.S2); - // Set Power off voltage 3.0v + // Set Power off voltage 3.0v _power.VoffVoltage = VoffVoltage.V3_0; // This part of the code will handle the button behavior _power.EnableButtonPressed(ButtonPressed.LongPressed | ButtonPressed.ShortPressed); diff --git a/nanoFramework.M5Core2/Screen.cs b/nanoFramework.M5Core2/Screen.cs index 65a7d35d..20a177d9 100644 --- a/nanoFramework.M5Core2/Screen.cs +++ b/nanoFramework.M5Core2/Screen.cs @@ -27,7 +27,7 @@ public class Screen : ScreenBase /// public Screen() { - if(_isInitialized) + if (_isInitialized) { return; } diff --git a/nanoFramework.M5Stack.sln b/nanoFramework.M5Stack.sln index fcfe1fd9..95a330a1 100644 --- a/nanoFramework.M5Stack.sln +++ b/nanoFramework.M5Stack.sln @@ -1,6 +1,6 @@ Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.31105.61 +# Visual Studio Version 17 +VisualStudioVersion = 17.0.32126.317 MinimumVisualStudioVersion = 10.0.40219.1 Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.M5Core", "nanoFramework.M5Core\nanoFramework.M5Core.nfproj", "{2C78D035-DBDA-4C38-AB58-8ADC22D763C3}" EndProject @@ -48,6 +48,10 @@ Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "AtomMatrixTestApp", "Tests\ EndProject Project("{D954291E-2A0B-460D-934E-DC6B0785DB48}") = "AtomCommon", "AtomCommon\AtomCommon.shproj", "{79F09006-AB5D-4E3E-AD12-2EFBEE536CA9}" EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "FireTestApp", "Tests\FireTestApp\FireTestApp.nfproj", "{5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}" +EndProject +Project("{11A8DD76-328B-46DF-9F39-F559912D0360}") = "nanoFramework.Fire", "nanoFramework.Fire\nanoFramework.Fire.nfproj", "{2550D7FC-BBA7-4173-9071-8606DD600A2C}" +EndProject Global GlobalSection(SharedMSBuildProjectFiles) = preSolution M5StackCommon\M5StackCommon.projitems*{00e23322-2401-4087-abae-24f90c8a0422}*SharedItemsImports = 13 @@ -126,6 +130,18 @@ Global {88F1D73A-1ADF-4444-A031-024E570945CC}.Release|Any CPU.ActiveCfg = Release|Any CPU {88F1D73A-1ADF-4444-A031-024E570945CC}.Release|Any CPU.Build.0 = Release|Any CPU {88F1D73A-1ADF-4444-A031-024E570945CC}.Release|Any CPU.Deploy.0 = Release|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Release|Any CPU.Build.0 = Release|Any CPU + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF}.Release|Any CPU.Deploy.0 = Release|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Debug|Any CPU.Deploy.0 = Debug|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Release|Any CPU.Build.0 = Release|Any CPU + {2550D7FC-BBA7-4173-9071-8606DD600A2C}.Release|Any CPU.Deploy.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -140,6 +156,7 @@ Global {7533C164-9D3E-461B-BEED-888C91AC640B} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437} {88F1D73A-1ADF-4444-A031-024E570945CC} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437} {79F09006-AB5D-4E3E-AD12-2EFBEE536CA9} = {FFF3F871-7600-480E-B378-95AD0F9FC0F1} + {5FF00F7C-8ED8-4468-9959-497CE8C5B1AF} = {5972CDE6-43B4-42F0-9276-6B70B7EF6437} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {DD82D7FF-B798-48A4-8506-2FBA0001D32F} diff --git a/nanoFramework.M5StackCore/M5CoreBase.cs b/nanoFramework.M5StackCore/M5CoreBase.cs index 79b60438..fcdb5dce 100644 --- a/nanoFramework.M5StackCore/M5CoreBase.cs +++ b/nanoFramework.M5StackCore/M5CoreBase.cs @@ -17,6 +17,11 @@ namespace nanoFramework.M5Stack /// M5Core2 board /// public static partial class M5Core2 +#elif FIRE + /// + /// Fire board + /// + public static partial class Fire #else /// /// M5Stack board