Skip to content

Commit 2bb2172

Browse files
committed
feat: add M5 CoreInk project
1 parent 6f18652 commit 2bb2172

File tree

7 files changed

+568
-183
lines changed

7 files changed

+568
-183
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

nanoFramework.CoreInk/M5CoreInk.cs

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
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.Rtc;
7+
using nanoFramework.Hardware.Esp32;
8+
using System;
9+
using System.Device.Adc;
10+
using System.Device.Gpio;
11+
using System.Device.I2c;
12+
13+
namespace nanoFramework.M5Stack
14+
{
15+
/// <summary>
16+
/// M5 CoreInk board
17+
/// </summary>
18+
public static class M5CoreInk
19+
{
20+
private readonly static I2cDevice _device;
21+
private static AdcController _adc;
22+
private static Buzzer _buzzer;
23+
private static GpioPin _led;
24+
private static GpioButton _button;
25+
private static GpioButton _left;
26+
private static GpioButton _center;
27+
private static GpioButton _right;
28+
private static GpioButton _power;
29+
private static GpioController _gpio;
30+
private static Pcf8563 _rtc;
31+
32+
#region properties
33+
34+
/// <summary>
35+
/// Gets the upper button.
36+
/// </summary>
37+
public static GpioButton RollerLeft
38+
{
39+
get
40+
{
41+
_left ??= new(37, GpioController, false, PinMode.Input);
42+
43+
return _left;
44+
}
45+
}
46+
47+
/// <summary>
48+
/// Gets the upper button.
49+
/// </summary>
50+
public static GpioButton RollerRight
51+
{
52+
get
53+
{
54+
_right ??= new(39, GpioController, false, PinMode.Input);
55+
56+
return _right;
57+
}
58+
}
59+
60+
/// <summary>
61+
/// Gets the upper button.
62+
/// </summary>
63+
public static GpioButton RollerButton
64+
{
65+
get
66+
{
67+
_center ??= new(38, GpioController, false, PinMode.Input);
68+
69+
return _center;
70+
}
71+
}
72+
73+
/// <summary>
74+
/// Gets the upper button.
75+
/// </summary>
76+
public static GpioButton Button
77+
{
78+
get
79+
{
80+
_button ??= new(5, GpioController, false);
81+
82+
return _button;
83+
}
84+
}
85+
86+
/// <summary>
87+
/// Gets the power button.
88+
/// </summary>
89+
public static GpioButton Power
90+
{
91+
get
92+
{
93+
_power ??= new(27, GpioController, false);
94+
95+
return _power;
96+
}
97+
}
98+
99+
/// <summary>
100+
/// Gets the green led.
101+
/// </summary>
102+
public static GpioPin Led
103+
{
104+
get
105+
{
106+
_led ??= GpioController.OpenPin(10, PinMode.Output);
107+
108+
return _led;
109+
}
110+
}
111+
112+
/// <summary>
113+
/// Gets the Buzzer.
114+
/// </summary>
115+
public static Buzzer Buzzer
116+
{
117+
get
118+
{
119+
// SetPinFunction already made in the static constructor
120+
_buzzer ??= new(2);
121+
122+
return _buzzer;
123+
}
124+
}
125+
126+
/// <summary>
127+
/// Gets the main <see cref="GpioController"/>.
128+
/// </summary>
129+
public static GpioController GpioController
130+
{
131+
get
132+
{
133+
_gpio ??= new();
134+
135+
return _gpio;
136+
}
137+
}
138+
139+
public static Pcf8563 RTC
140+
{
141+
get
142+
{
143+
_rtc ??= new(_device);
144+
145+
return _rtc;
146+
}
147+
}
148+
149+
#endregion
150+
151+
static M5CoreInk()
152+
{
153+
Configuration.SetPinFunction(2, DeviceFunction.PWM1);
154+
Configuration.SetPinFunction(18, DeviceFunction.SPI1_CLOCK);
155+
Configuration.SetPinFunction(23, DeviceFunction.SPI1_MOSI);
156+
157+
// RTC settings
158+
Configuration.SetPinFunction(21, DeviceFunction.I2C1_DATA);
159+
Configuration.SetPinFunction(22, DeviceFunction.I2C1_CLOCK);
160+
I2cConnectionSettings settings = new(1, Pcf8563.DefaultI2cAddress);
161+
_device = I2cDevice.Create(settings);
162+
}
163+
164+
/// <summary>
165+
/// Gets an ADC channel
166+
/// </summary>
167+
/// <param name="gpioNumber">The GPIO pin number</param>
168+
/// <returns>An AdcChannel</returns>
169+
public static AdcChannel GetAdcGpio(int gpioNumber)
170+
{
171+
_adc ??= new();
172+
173+
switch (gpioNumber)
174+
{
175+
case 35:
176+
Configuration.SetPinFunction(35, DeviceFunction.ADC1_CH7);
177+
return _adc.OpenChannel(7);
178+
case 36:
179+
Configuration.SetPinFunction(36, DeviceFunction.ADC1_CH0);
180+
return _adc.OpenChannel(0);
181+
case 2:
182+
Configuration.SetPinFunction(2, DeviceFunction.ADC1_CH12);
183+
return _adc.OpenChannel(12);
184+
case 12:
185+
Configuration.SetPinFunction(12, DeviceFunction.ADC1_CH15);
186+
return _adc.OpenChannel(15);
187+
case 15:
188+
Configuration.SetPinFunction(15, DeviceFunction.ADC1_CH13);
189+
return _adc.OpenChannel(13);
190+
case 25:
191+
Configuration.SetPinFunction(25, DeviceFunction.ADC1_CH18);
192+
return _adc.OpenChannel(18);
193+
case 26:
194+
Configuration.SetPinFunction(26, DeviceFunction.ADC1_CH19);
195+
return _adc.OpenChannel(19);
196+
case 13:
197+
Configuration.SetPinFunction(13, DeviceFunction.ADC1_CH14);
198+
return _adc.OpenChannel(14);
199+
case 0:
200+
Configuration.SetPinFunction(0, DeviceFunction.ADC1_CH11);
201+
return _adc.OpenChannel(11);
202+
case 34:
203+
Configuration.SetPinFunction(34, DeviceFunction.ADC1_CH6);
204+
return _adc.OpenChannel(6);
205+
default:
206+
throw new ArgumentException(nameof(gpioNumber));
207+
}
208+
}
209+
}
210+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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)]
15+
16+
/////////////////////////////////////////////////////////////////
17+
// This attribute is mandatory when building Interop libraries //
18+
// update this whenever the native assembly signature changes //
19+
[assembly: AssemblyNativeVersion("0.0.0.0")]
20+
/////////////////////////////////////////////////////////////////

nanoFramework.CoreInk/README.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
![nanoFramework logo](https://raw.githubusercontent.com/nanoframework/Home/main/resources/logo/nanoFramework-repo-logo.png)
2+
3+
-----
4+
5+
# Welcome to the .NET **nanoFramework** M5 CoreInk repository
6+
7+
## Firmware
8+
9+
The CoreInk can be flashed through `nanoff` flashing tool with the command line:
10+
11+
```shell
12+
nanoff --target ESP32_PICO --update --serialport COM3
13+
```
14+
15+
## Implementation
16+
17+
The static class `M5CoreInk` provides pre-configured properties for ready-to-go use of the core.
18+
19+
Here's a list of the current implementation
20+
21+
| Component | Property name | Implemented | Tested |
22+
|:-|---|---|---|
23+
| Left wheel button<sup>1</sup> | RollerLeft | :heavy_check_mark: | :heavy_check_mark: |
24+
| Middle wheel button<sup>1</sup> | RollerButton | :heavy_check_mark: | :heavy_check_mark: |
25+
| Right wheel button<sup>1</sup> | RollerRight | :heavy_check_mark: | :heavy_check_mark: |
26+
| Button (top position) | Button | :heavy_check_mark: | :heavy_check_mark: |
27+
| Power button | Power | :heavy_check_mark: | :x: |
28+
| Green led | Led | :heavy_check_mark: | :heavy_check_mark: |
29+
| Buzzer | Buzzer | :heavy_check_mark: | :x: |
30+
| BM8563 | RTC | :heavy_check_mark: | :heavy_check_mark: |
31+
| ADC/DAC pins | GetAdcGpio() | :heavy_check_mark: | :x: |
32+
| Screen | :x: | :x: | :x: |
33+
| EXT-PORT | :x: | :x: | :x: |
34+
35+
## Notes
36+
37+
<sup>1</sup> The implementation define the buttons as `PinMode.Input` as defined in the [specifications](https://m5stack.oss-cn-shenzhen.aliyuncs.com/resource/docs/datasheet/core/esp32_datasheet_en_v3.9.pdf) Table.26
38+
39+
```
40+
GPIO pins 34-39 are input-only.
41+
These pins do not feature an output driver or internal pull-up/pull-down circuitry.
42+
The pin names are: SENSOR_VP (GPIO36), SENSOR_CAPP (GPIO37), SENSOR_CAPN (GPIO38), SENSOR_VN (GPIO39), VDET_1 (GPIO34), VDET_2 (GPIO35).
43+
```
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<Project ToolsVersion="Current" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
3+
<PropertyGroup Label="Globals">
4+
<NanoFrameworkProjectSystemPath>$(MSBuildExtensionsPath)\nanoFramework\v1.0\</NanoFrameworkProjectSystemPath>
5+
</PropertyGroup>
6+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.Default.props')" />
7+
<PropertyGroup>
8+
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
9+
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
10+
<ProjectTypeGuids>{11A8DD76-328B-46DF-9F39-F559912D0360};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
11+
<ProjectGuid>de7ee9f2-38a0-42b6-945d-6215199ef35f</ProjectGuid>
12+
<OutputType>Library</OutputType>
13+
<AppDesignerFolder>Properties</AppDesignerFolder>
14+
<FileAlignment>512</FileAlignment>
15+
<RootNamespace>nanoFramework.M5Stack</RootNamespace>
16+
<AssemblyName>nanoFramework.CoreInk</AssemblyName>
17+
<TargetFrameworkVersion>v1.0</TargetFrameworkVersion>
18+
</PropertyGroup>
19+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.props" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.props')" />
20+
<ItemGroup>
21+
<Compile Include="M5CoreInk.cs" />
22+
<Compile Include="Properties\AssemblyInfo.cs" />
23+
</ItemGroup>
24+
<ItemGroup>
25+
<Reference Include="Iot.Device.Button">
26+
<HintPath>..\packages\nanoFramework.Iot.Device.Button.1.2.329\lib\Iot.Device.Button.dll</HintPath>
27+
</Reference>
28+
<Reference Include="Iot.Device.Buzzer">
29+
<HintPath>..\packages\nanoFramework.Iot.Device.Buzzer.1.2.403\lib\Iot.Device.Buzzer.dll</HintPath>
30+
</Reference>
31+
<Reference Include="Iot.Device.Common.NumberHelper">
32+
<HintPath>..\packages\nanoFramework.Iot.Device.Common.NumberHelper.1.2.325\lib\Iot.Device.Common.NumberHelper.dll</HintPath>
33+
</Reference>
34+
<Reference Include="Iot.Device.Rtc">
35+
<HintPath>..\packages\nanoFramework.Iot.Device.Rtc.1.2.403\lib\Iot.Device.Rtc.dll</HintPath>
36+
</Reference>
37+
<Reference Include="mscorlib">
38+
<HintPath>..\packages\nanoFramework.CoreLibrary.1.14.2\lib\mscorlib.dll</HintPath>
39+
</Reference>
40+
<Reference Include="nanoFramework.Hardware.Esp32">
41+
<HintPath>..\packages\nanoFramework.Hardware.Esp32.1.6.8\lib\nanoFramework.Hardware.Esp32.dll</HintPath>
42+
</Reference>
43+
<Reference Include="nanoFramework.Runtime.Events">
44+
<HintPath>..\packages\nanoFramework.Runtime.Events.1.11.6\lib\nanoFramework.Runtime.Events.dll</HintPath>
45+
</Reference>
46+
<Reference Include="System.Device.Adc">
47+
<HintPath>..\packages\nanoFramework.System.Device.Adc.1.1.6\lib\System.Device.Adc.dll</HintPath>
48+
</Reference>
49+
<Reference Include="System.Device.Gpio">
50+
<HintPath>..\packages\nanoFramework.System.Device.Gpio.1.1.28\lib\System.Device.Gpio.dll</HintPath>
51+
</Reference>
52+
<Reference Include="System.Device.I2c">
53+
<HintPath>..\packages\nanoFramework.System.Device.I2c.1.1.11\lib\System.Device.I2c.dll</HintPath>
54+
</Reference>
55+
<Reference Include="System.Device.Model">
56+
<HintPath>..\packages\nanoFramework.System.Device.Model.1.2.325\lib\System.Device.Model.dll</HintPath>
57+
</Reference>
58+
<Reference Include="System.Device.Pwm">
59+
<HintPath>..\packages\nanoFramework.System.Device.Pwm.1.1.6\lib\System.Device.Pwm.dll</HintPath>
60+
</Reference>
61+
<Reference Include="System.Device.Spi">
62+
<HintPath>..\packages\nanoFramework.System.Device.Spi.1.3.37\lib\System.Device.Spi.dll</HintPath>
63+
</Reference>
64+
<Reference Include="System.Math">
65+
<HintPath>..\packages\nanoFramework.System.Math.1.5.29\lib\System.Math.dll</HintPath>
66+
</Reference>
67+
<Reference Include="UnitsNet.Frequency">
68+
<HintPath>..\packages\UnitsNet.nanoFramework.Frequency.5.35.0\lib\UnitsNet.Frequency.dll</HintPath>
69+
</Reference>
70+
<Reference Include="UnitsNet.Temperature">
71+
<HintPath>..\packages\UnitsNet.nanoFramework.Temperature.5.35.0\lib\UnitsNet.Temperature.dll</HintPath>
72+
</Reference>
73+
</ItemGroup>
74+
<ItemGroup>
75+
<None Include="packages.config" />
76+
</ItemGroup>
77+
<Import Project="$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets" Condition="Exists('$(NanoFrameworkProjectSystemPath)NFProjectSystem.CSharp.targets')" />
78+
<ProjectExtensions>
79+
<ProjectCapabilities>
80+
<ProjectConfigurationsDeclaredAsItems />
81+
</ProjectCapabilities>
82+
</ProjectExtensions>
83+
</Project>

0 commit comments

Comments
 (0)