Skip to content

Commit 5417a2b

Browse files
xasEllerbach
andauthored
add M5 CoreInk project (#304)
Co-authored-by: Laurent Ellerbach <laurelle@microsoft.com>
1 parent e00829f commit 5417a2b

File tree

11 files changed

+812
-184
lines changed

11 files changed

+812
-184
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| 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/) |
1919
| 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/) |
2020
| 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/) |
21+
| 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/) |
2122

2223
## Usage
2324

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

3537
> 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.
3638
> 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.
@@ -62,7 +64,7 @@ For the M5Core2, Tough and Fire:
6264
nanoff --target M5Core2 --update --serialport COM3
6365
```
6466

65-
For the Atom Lite and Matrix:
67+
For the Atom Lite, Matrix and CoreInk:
6668

6769
```shell
6870
nanoff --target ESP32_PICO --update --serialport COM3

azure-pipelines.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,10 @@ steps:
8989
- template: azure-pipelines-templates/class-lib-package.yml@templates
9090
parameters:
9191
nugetPackageName: 'nanoFramework.Tough'
92-
92+
93+
- template: azure-pipelines-templates/class-lib-package.yml@templates
94+
parameters:
95+
nugetPackageName: 'nanoFramework.CoreInk'
9396
- template: azure-pipelines-templates/class-lib-publish.yml@templates
9497

9598
# create GitHub release from main branche

nanoFramework.CoreInk.nuspec

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<package xmlns="http://schemas.microsoft.com/packaging/2012/06/nuspec.xsd">
3+
<metadata>
4+
<id>nanoFramework.CoreInk</id>
5+
<version>$version$</version>
6+
<title>nanoFramework.CoreInk</title>
7+
<authors>nanoframework</authors>
8+
<requireLicenseAcceptance>false</requireLicenseAcceptance>
9+
<license type="file">LICENSE.md</license>
10+
<releaseNotes>
11+
</releaseNotes>
12+
<readme>docs\README.md</readme>
13+
<developmentDependency>false</developmentDependency>
14+
<projectUrl>https://github.com/nanoframework/nanoFramework.M5Stack</projectUrl>
15+
<icon>images\nf-logo.png</icon>
16+
<repository type="git" url="https://github.com/nanoframework/nanoFramework.M5Stack" commit="$commit$" />
17+
<copyright>Copyright (c) .NET Foundation and Contributors</copyright>
18+
<description>This package includes the nanoFramework.CoreInk assembly for .NET nanoFramework C# projects.</description>
19+
<tags>nanoFramework C# csharp netmf netnf m5stack CoreInk</tags>
20+
<dependencies>
21+
<dependency id="nanoFramework.CoreLibrary" version="1.15.5" />
22+
<dependency id="nanoFramework.Graphics.Core" version="1.2.21" />
23+
<dependency id="nanoFramework.Hardware.Esp32" version="1.6.19" />
24+
<dependency id="nanoFramework.Iot.Device.Button" version="1.2.631" />
25+
<dependency id="nanoFramework.Iot.Device.Buzzer" version="1.2.656" />
26+
<dependency id="nanoFramework.Iot.Device.Common.NumberHelper" version="1.2.628" />
27+
<dependency id="nanoFramework.Iot.Device.ePaper" version="1.0.487" />
28+
<dependency id="nanoFramework.Iot.Device.Rtc" version="1.2.656" />
29+
<dependency id="nanoFramework.System.Device.Adc" version="1.1.11" />
30+
<dependency id="nanoFramework.System.Device.I2c" version="1.1.16" />
31+
<dependency id="nanoFramework.System.Device.Spi" version="1.3.52" />
32+
</dependencies>
33+
</metadata>
34+
<files>
35+
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.dll" target="lib\nanoFramework.CoreInk.dll" />
36+
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pdb" target="lib\nanoFramework.CoreInk.pdb" />
37+
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pdbx" target="lib\nanoFramework.CoreInk.pdbx" />
38+
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.pe" target="lib\nanoFramework.CoreInk.pe" />
39+
<file src="nanoFramework.CoreInk\bin\Release\nanoFramework.CoreInk.xml" target="lib\nanoFramework.CoreInk.xml" />
40+
<file src="assets\readme.txt" target="" />
41+
<file src="README.md" target="docs\" />
42+
<file src="assets\nf-logo.png" target="images\" />
43+
<file src="LICENSE.md" target="" />
44+
</files>
45+
</package>

nanoFramework.CoreInk/M5CoreInk.cs

Lines changed: 256 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,256 @@
1+
// Licensed to the .NET Foundation under one or more agreements.
2+
// The .NET Foundation licenses this file to you under the MIT license.
3+
4+
using Iot.Device.Button;
5+
using Iot.Device.Buzzer;
6+
using Iot.Device.EPaper.Drivers.Jd796xx;
7+
using Iot.Device.Rtc;
8+
using nanoFramework.Hardware.Esp32;
9+
using System;
10+
using System.Device.Adc;
11+
using System.Device.Gpio;
12+
using System.Device.I2c;
13+
using System.Device.Spi;
14+
15+
namespace nanoFramework.M5Stack
16+
{
17+
/// <summary>
18+
/// M5 CoreInk board.
19+
/// </summary>
20+
public static class M5CoreInk
21+
{
22+
private readonly static I2cDevice _device;
23+
private static SpiDevice _spi;
24+
private static AdcController _adc;
25+
private static Buzzer _buzzer;
26+
private static GpioPin _led;
27+
private static GpioButton _button;
28+
private static GpioButton _left;
29+
private static GpioButton _center;
30+
private static GpioButton _right;
31+
private static GpioButton _power;
32+
private static GpioController _gpio;
33+
private static Pcf8563 _rtc;
34+
private static Gdew0154m09 _screen;
35+
36+
private const int ScreenBusyPin = 4;
37+
private const int ScreenResetPin = 0;
38+
private const int ScreenDCPin = 15;
39+
40+
#region properties
41+
42+
/// <summary>
43+
/// Gets the upper button.
44+
/// </summary>
45+
public static GpioButton RollerLeft
46+
{
47+
get
48+
{
49+
_left ??= new(37, GpioController, false, PinMode.Input);
50+
51+
return _left;
52+
}
53+
}
54+
55+
/// <summary>
56+
/// Gets the upper button.
57+
/// </summary>
58+
public static GpioButton RollerRight
59+
{
60+
get
61+
{
62+
_right ??= new(39, GpioController, false, PinMode.Input);
63+
64+
return _right;
65+
}
66+
}
67+
68+
/// <summary>
69+
/// Gets the upper button.
70+
/// </summary>
71+
public static GpioButton RollerButton
72+
{
73+
get
74+
{
75+
_center ??= new(38, GpioController, false, PinMode.Input);
76+
77+
return _center;
78+
}
79+
}
80+
81+
/// <summary>
82+
/// Gets the upper button.
83+
/// </summary>
84+
public static GpioButton Button
85+
{
86+
get
87+
{
88+
_button ??= new(5, GpioController, false);
89+
90+
return _button;
91+
}
92+
}
93+
94+
/// <summary>
95+
/// Gets the power button.
96+
/// </summary>
97+
public static GpioButton Power
98+
{
99+
get
100+
{
101+
_power ??= new(27, GpioController, false);
102+
103+
return _power;
104+
}
105+
}
106+
107+
/// <summary>
108+
/// Gets the green led.
109+
/// </summary>
110+
public static GpioPin Led
111+
{
112+
get
113+
{
114+
_led ??= GpioController.OpenPin(10, PinMode.Output);
115+
116+
return _led;
117+
}
118+
}
119+
120+
/// <summary>
121+
/// Gets the Buzzer.
122+
/// </summary>
123+
public static Buzzer Buzzer
124+
{
125+
get
126+
{
127+
// SetPinFunction already made in the static constructor
128+
_buzzer ??= new(2);
129+
130+
return _buzzer;
131+
}
132+
}
133+
134+
/// <summary>
135+
/// Gets the main <see cref="GpioController"/>.
136+
/// </summary>
137+
public static GpioController GpioController
138+
{
139+
get
140+
{
141+
_gpio ??= new();
142+
143+
return _gpio;
144+
}
145+
}
146+
147+
/// <summary>
148+
/// Gets the internal clock.
149+
/// </summary>
150+
public static Pcf8563 RTC
151+
{
152+
get
153+
{
154+
_rtc ??= new(_device);
155+
156+
return _rtc;
157+
}
158+
}
159+
160+
/// <summary>
161+
/// Get the ePaper screen.
162+
/// </summary>
163+
public static Gdew0154m09 Screen
164+
{
165+
get
166+
{
167+
InitializeScreen();
168+
169+
return _screen;
170+
}
171+
}
172+
173+
#endregion
174+
175+
static M5CoreInk()
176+
{
177+
Configuration.SetPinFunction(2, DeviceFunction.PWM1);
178+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
179+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
180+
181+
// RTC settings
182+
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
183+
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
184+
I2cConnectionSettings settings = new(1, Pcf8563.DefaultI2cAddress);
185+
_device = I2cDevice.Create(settings);
186+
}
187+
188+
/// <summary>
189+
/// Gets an ADC channel.
190+
/// </summary>
191+
/// <param name="gpioNumber">The GPIO pin number.</param>
192+
/// <returns>An AdcChannel</returns>
193+
public static AdcChannel GetAdcGpio(int gpioNumber)
194+
{
195+
_adc ??= new();
196+
197+
switch (gpioNumber)
198+
{
199+
case 35:
200+
Configuration.SetPinFunction(35, DeviceFunction.ADC1_CH7);
201+
return _adc.OpenChannel(7);
202+
case 36:
203+
Configuration.SetPinFunction(36, DeviceFunction.ADC1_CH0);
204+
return _adc.OpenChannel(0);
205+
case 2:
206+
Configuration.SetPinFunction(2, DeviceFunction.ADC1_CH12);
207+
return _adc.OpenChannel(12);
208+
case 12:
209+
Configuration.SetPinFunction(12, DeviceFunction.ADC1_CH15);
210+
return _adc.OpenChannel(15);
211+
case 15:
212+
Configuration.SetPinFunction(15, DeviceFunction.ADC1_CH13);
213+
return _adc.OpenChannel(13);
214+
case 25:
215+
Configuration.SetPinFunction(25, DeviceFunction.ADC1_CH18);
216+
return _adc.OpenChannel(18);
217+
case 26:
218+
Configuration.SetPinFunction(26, DeviceFunction.ADC1_CH19);
219+
return _adc.OpenChannel(19);
220+
case 13:
221+
Configuration.SetPinFunction(13, DeviceFunction.ADC1_CH14);
222+
return _adc.OpenChannel(14);
223+
case 0:
224+
Configuration.SetPinFunction(0, DeviceFunction.ADC1_CH11);
225+
return _adc.OpenChannel(11);
226+
case 34:
227+
Configuration.SetPinFunction(34, DeviceFunction.ADC1_CH6);
228+
return _adc.OpenChannel(6);
229+
default:
230+
throw new ArgumentException(nameof(gpioNumber));
231+
}
232+
}
233+
234+
/// <summary>
235+
/// Initialize the eInk screen.
236+
/// </summary>
237+
/// <returns>An instance of the <see cref="Gdew0154m09"/> driver.</returns>
238+
private static void InitializeScreen()
239+
{
240+
if (_screen == null)
241+
{
242+
var spiConnectionSettings = new SpiConnectionSettings(busId: 1, chipSelectLine: 9)
243+
{
244+
ClockFrequency = Gdew0154m09.SpiClockFrequency,
245+
Mode = Gdew0154m09.SpiMode,
246+
ChipSelectLineActiveState = PinValue.Low,
247+
Configuration = SpiBusConfiguration.HalfDuplex,
248+
DataFlow = DataFlow.MsbFirst,
249+
};
250+
251+
_spi = new SpiDevice(spiConnectionSettings);
252+
_screen = new Gdew0154m09(_spi, ScreenResetPin, ScreenBusyPin, ScreenDCPin, _gpio);
253+
}
254+
}
255+
}
256+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System.Reflection;
2+
using System.Runtime.InteropServices;
3+
4+
// General Information about an assembly is controlled through the following
5+
// set of attributes. Change these attribute values to modify the information
6+
// associated with an assembly.
7+
[assembly: AssemblyTitle("nanoFramework.CoreInk")]
8+
[assembly: AssemblyCompany("nanoFramework Contributors")]
9+
[assembly: AssemblyCopyright("Copyright(c).NET Foundation and Contributors")]
10+
11+
// Setting ComVisible to false makes the types in this assembly not visible
12+
// to COM components. If you need to access a type in this assembly from
13+
// COM, set the ComVisible attribute to true on that type.
14+
[assembly: ComVisible(false)]

0 commit comments

Comments
 (0)