Skip to content

Commit

Permalink
add M5 CoreInk project (#304)
Browse files Browse the repository at this point in the history
Co-authored-by: Laurent Ellerbach <[email protected]>
  • Loading branch information
xas and Ellerbach authored Oct 12, 2024
1 parent e00829f commit 5417a2b
Show file tree
Hide file tree
Showing 11 changed files with 812 additions and 184 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
| 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.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/) |
| nanoFramework.Tough | [![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.Tough.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.Tough/) |
| nanoFramework.CoreInk | [![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.CoreInk.svg?label=NuGet&style=flat&logo=nuget)](https://www.nuget.org/packages/nanoFramework.CoreInk/) |

## Usage

Expand All @@ -31,6 +32,7 @@ These NuGet packages provide a support for M5Stack products:
- [Atom Lite](https://docs.m5stack.com/en/core/atom_lite)
- [Atom Matrix](https://docs.m5stack.com/en/core/atom_matrix)
- [Tough](https://docs.m5stack.com/en/core/tough)
- [CoreInk](https://docs.m5stack.com/en/core/coreink)

> 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.
Expand Down Expand Up @@ -62,7 +64,7 @@ For the M5Core2, Tough and Fire:
nanoff --target M5Core2 --update --serialport COM3
```

For the Atom Lite and Matrix:
For the Atom Lite, Matrix and CoreInk:

```shell
nanoff --target ESP32_PICO --update --serialport COM3
Expand Down
5 changes: 4 additions & 1 deletion azure-pipelines.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ steps:
- template: azure-pipelines-templates/class-lib-package.yml@templates
parameters:
nugetPackageName: 'nanoFramework.Tough'


- template: azure-pipelines-templates/class-lib-package.yml@templates
parameters:
nugetPackageName: 'nanoFramework.CoreInk'
- template: azure-pipelines-templates/class-lib-publish.yml@templates

# create GitHub release from main branche
Expand Down
45 changes: 45 additions & 0 deletions nanoFramework.CoreInk.nuspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
<metadata>
<id>nanoFramework.CoreInk</id>
<version>$version$</version>
<title>nanoFramework.CoreInk</title>
<authors>nanoframework</authors>
<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.CoreInk assembly for .NET nanoFramework C# projects.</description>
<tags>nanoFramework C# csharp netmf netnf m5stack CoreInk</tags>
<dependencies>
<dependency id="nanoFramework.CoreLibrary" version="1.15.5" />
<dependency id="nanoFramework.Graphics.Core" version="1.2.21" />
<dependency id="nanoFramework.Hardware.Esp32" version="1.6.19" />
<dependency id="nanoFramework.Iot.Device.Button" version="1.2.631" />
<dependency id="nanoFramework.Iot.Device.Buzzer" version="1.2.656" />
<dependency id="nanoFramework.Iot.Device.Common.NumberHelper" version="1.2.628" />
<dependency id="nanoFramework.Iot.Device.ePaper" version="1.0.487" />
<dependency id="nanoFramework.Iot.Device.Rtc" version="1.2.656" />
<dependency id="nanoFramework.System.Device.Adc" version="1.1.11" />
<dependency id="nanoFramework.System.Device.I2c" version="1.1.16" />
<dependency id="nanoFramework.System.Device.Spi" version="1.3.52" />
</dependencies>
</metadata>
<files>
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.dll" target="lib\nanoFramework.CoreInk.dll" />
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pdb" target="lib\nanoFramework.CoreInk.pdb" />
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pdbx" target="lib\nanoFramework.CoreInk.pdbx" />
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pe" target="lib\nanoFramework.CoreInk.pe" />
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.xml" target="lib\nanoFramework.CoreInk.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>
256 changes: 256 additions & 0 deletions nanoFramework.CoreInk/M5CoreInk.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,256 @@
// 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.EPaper.Drivers.Jd796xx;
using Iot.Device.Rtc;
using nanoFramework.Hardware.Esp32;
using System;
using System.Device.Adc;
using System.Device.Gpio;
using System.Device.I2c;
using System.Device.Spi;

namespace nanoFramework.M5Stack
{
/// <summary>
/// M5 CoreInk board.
/// </summary>
public static class M5CoreInk
{
private readonly static I2cDevice _device;
private static SpiDevice _spi;
private static AdcController _adc;
private static Buzzer _buzzer;
private static GpioPin _led;
private static GpioButton _button;
private static GpioButton _left;
private static GpioButton _center;
private static GpioButton _right;
private static GpioButton _power;
private static GpioController _gpio;
private static Pcf8563 _rtc;
private static Gdew0154m09 _screen;

private const int ScreenBusyPin = 4;
private const int ScreenResetPin = 0;
private const int ScreenDCPin = 15;

#region properties

/// <summary>
/// Gets the upper button.
/// </summary>
public static GpioButton RollerLeft
{
get
{
_left ??= new(37, GpioController, false, PinMode.Input);

return _left;
}
}

/// <summary>
/// Gets the upper button.
/// </summary>
public static GpioButton RollerRight
{
get
{
_right ??= new(39, GpioController, false, PinMode.Input);

return _right;
}
}

/// <summary>
/// Gets the upper button.
/// </summary>
public static GpioButton RollerButton
{
get
{
_center ??= new(38, GpioController, false, PinMode.Input);

return _center;
}
}

/// <summary>
/// Gets the upper button.
/// </summary>
public static GpioButton Button
{
get
{
_button ??= new(5, GpioController, false);

return _button;
}
}

/// <summary>
/// Gets the power button.
/// </summary>
public static GpioButton Power
{
get
{
_power ??= new(27, GpioController, false);

return _power;
}
}

/// <summary>
/// Gets the green led.
/// </summary>
public static GpioPin Led
{
get
{
_led ??= GpioController.OpenPin(10, PinMode.Output);

return _led;
}
}

/// <summary>
/// Gets the Buzzer.
/// </summary>
public static Buzzer Buzzer
{
get
{
// SetPinFunction already made in the static constructor
_buzzer ??= new(2);

return _buzzer;
}
}

/// <summary>
/// Gets the main <see cref="GpioController"/>.
/// </summary>
public static GpioController GpioController
{
get
{
_gpio ??= new();

return _gpio;
}
}

/// <summary>
/// Gets the internal clock.
/// </summary>
public static Pcf8563 RTC
{
get
{
_rtc ??= new(_device);

return _rtc;
}
}

/// <summary>
/// Get the ePaper screen.
/// </summary>
public static Gdew0154m09 Screen
{
get
{
InitializeScreen();

return _screen;
}
}

#endregion

static M5CoreInk()
{
Configuration.SetPinFunction(2, DeviceFunction.PWM1);
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);

// RTC settings
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
I2cConnectionSettings settings = new(1, Pcf8563.DefaultI2cAddress);
_device = I2cDevice.Create(settings);
}

/// <summary>
/// Gets an ADC channel.
/// </summary>
/// <param name="gpioNumber">The GPIO pin number.</param>
/// <returns>An AdcChannel</returns>
public static AdcChannel GetAdcGpio(int gpioNumber)
{
_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));
}
}

/// <summary>
/// Initialize the eInk screen.
/// </summary>
/// <returns>An instance of the <see cref="Gdew0154m09"/> driver.</returns>
private static void InitializeScreen()
{
if (_screen == null)
{
var spiConnectionSettings = new SpiConnectionSettings(busId: 1, chipSelectLine: 9)
{
ClockFrequency = Gdew0154m09.SpiClockFrequency,
Mode = Gdew0154m09.SpiMode,
ChipSelectLineActiveState = PinValue.Low,
Configuration = SpiBusConfiguration.HalfDuplex,
DataFlow = DataFlow.MsbFirst,
};

_spi = new SpiDevice(spiConnectionSettings);
_screen = new Gdew0154m09(_spi, ScreenResetPin, ScreenBusyPin, ScreenDCPin, _gpio);
}
}
}
}
14 changes: 14 additions & 0 deletions nanoFramework.CoreInk/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Reflection;
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.CoreInk")]
[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)]
Loading

0 comments on commit 5417a2b

Please sign in to comment.