-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: Laurent Ellerbach <[email protected]>
- Loading branch information
Showing
11 changed files
with
812 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)] |
Oops, something went wrong.