Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update pin mapping and fixes #70

Merged
merged 4 commits into from
Jul 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 24 additions & 7 deletions source/nanoFramework.Hardware.Esp32/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
//

using System;
using Windows.Devices.Gpio;
using System.Runtime.CompilerServices;

namespace nanoFramework.Hardware.Esp32
{
Expand All @@ -14,19 +14,36 @@ namespace nanoFramework.Hardware.Esp32
public class Configuration
{
/// <summary>
/// Set the default function for a GPIO pin
/// Set the default function for a GPIO pin.
/// </summary>
/// <remarks>
/// Allows gpio pins to be assigned a device function.
/// For example setting the I2C1 data pin to use GPIO pin 17.
/// </remarks>
/// <param name="pin"></param>
/// <param name="value"></param>
/// <param name="pin">The pin number to set against function.</param>
/// <param name="value">The device function to be assigned the pin.</param>
public static void SetPinFunction(int pin, DeviceFunction value)
{
GpioPin gpioPin = GpioController.GetDefault().OpenPin(pin);
gpioPin.SetAlternateFunction((int)value);
gpioPin.Dispose();
NativeSetPinFunction(pin, (int)value);
}

/// <summary>
/// Returns the current pin number used by a device function.
/// </summary>
/// <param name="function"></param>
/// <returns>The pin number used by device function. If value is -1 then pins is not assigned.</returns>
public static int GetFunctionPin(DeviceFunction function)
{

return NativeGetPinFunction((int)function); ;
}

#region Native Calls
[MethodImpl(MethodImplOptions.InternalCall)]
private extern static void NativeSetPinFunction(int pin, int function);

[MethodImpl(MethodImplOptions.InternalCall)]
private extern static int NativeGetPinFunction(int function);
#endregion
}
}
107 changes: 103 additions & 4 deletions source/nanoFramework.Hardware.Esp32/DeviceTypePins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public enum DeviceTypes
/// PWM Device type
/// </summary>
PWM = 4 * ValueTypes.DeviceType,
/// <summary>
/// ADC Device type
/// </summary>
ADC = 5 * ValueTypes.DeviceType,
};

/// <summary>
Expand All @@ -52,9 +56,9 @@ public enum DeviceFunction
/// </summary>
SPI1_MOSI = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 0,
/// <summary>
/// Device function MISI for SPI1
/// Device function MISO for SPI1
/// </summary>
SPI1_MISI = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 1,
SPI1_MISO = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 1,
/// <summary>
/// Device function CLOCK for SPI1
/// </summary>
Expand All @@ -65,9 +69,9 @@ public enum DeviceFunction
/// </summary>
SPI2_MOSI = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 0,
/// <summary>
/// Device function MISI for SPI2
/// Device function MISO for SPI2
/// </summary>
SPI2_MISI = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 1,
SPI2_MISO = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 1,
/// <summary>
/// Device function CLOCK for SPI2
/// </summary>
Expand Down Expand Up @@ -206,5 +210,100 @@ public enum DeviceFunction
/// Device function PWM16
/// </summary>
PWM16 = DeviceTypes.PWM + (16 * ValueTypes.DeviceIndex) + 0,

/// <summary>
/// ADC1 channel 0
/// </summary>
ADC1_CH0 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 0,
/// <summary>
/// ADC1 channel 1
/// </summary>
ADC1_CH1 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 1,
/// <summary>
/// ADC1 channel 2
/// </summary>
ADC1_CH2 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 2,
/// <summary>
/// ADC1 channel 3
/// </summary>
ADC1_CH3 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 3,
/// <summary>
/// ADC1 channel 4
/// </summary>
ADC1_CH4 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 4,
/// <summary>
/// ADC1 channel 5
/// </summary>
ADC1_CH5 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 5,
/// <summary>
/// ADC1 channel 6
/// </summary>
ADC1_CH6 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 6,
/// <summary>
/// ADC1 channel 7
/// </summary>
ADC1_CH7 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 7,

/// <summary>
/// ADC1 channel 8
/// Internal Temperture sensor (VP)
/// </summary>
ADC1_CH8 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 8,
/// <summary>
/// ADC1 channel 9
/// Internal Hall Sensor (VN)
/// </summary>
ADC1_CH9 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 9,
/// <summary>
/// ADC1 channel 10
/// Internally ESP32 Adc2 channel 10
/// </summary>
ADC1_CH10 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 10,
/// <summary>
/// ADC1 channel 11
/// Internally ESP32 Adc2 channel 11
/// </summary>
ADC1_CH11 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 11,
/// <summary>
/// ADC1 channel 12
/// Internally ESP32 Adc2 channel 12
/// </summary>
ADC1_CH12 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 12,
/// <summary>
/// ADC1 channel 13
/// Internally ESP32 Adc2 channel 13
/// </summary>
ADC1_CH13 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 13,
/// <summary>
/// ADC1 channel 14
/// Internally ESP32 Adc2 channel 14
/// </summary>
ADC1_CH14 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 14,
/// <summary>
/// ADC1 channel 15
/// Internally ESP32 Adc2 channel 15
/// </summary>
ADC1_CH15 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 15,
/// <summary>
/// ADC1 channel 16
/// Internally ESP32 Adc2 channel 16
/// </summary>
ADC1_CH16 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 16,
/// <summary>
/// ADC1 channel 17
/// Internally ESP32 Adc2 channel 17
/// </summary>
ADC1_CH17 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 17,
/// <summary>
/// ADC1 channel 18
/// Internally ESP32 Adc2 channel 18
/// </summary>
ADC1_CH18 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 18,
/// <summary>
/// ADC1 channel 19
/// Internally ESP32 Adc2 channel 19
/// </summary>
ADC1_CH19 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 19,

};
}
181 changes: 181 additions & 0 deletions source/nanoFramework.Hardware.Esp32/GpioPins.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
//
// Copyright (c) 2019 The nanoFramework project contributors
// See LICENSE file in the project root for full license information.
//
using System;

namespace nanoFramework.Hardware.Esp32
{
/// <summary>
/// ESP32 GPIO pins
/// </summary>
public static class Gpio
{
/// <summary>
/// Gpio IO00
/// </summary>
public const int IO00 = 0;
/// <summary>
/// Gpio IO01 (UART0 TXD)
/// </summary>
public const int IO01 = 1;
/// <summary>
/// Gpio IO02
/// </summary>
public const int IO02 = 2;
/// <summary>
/// Gpio IO03 (UART0 RXD)
/// </summary>
public const int IO03 = 3;
/// <summary>
/// Gpio IO04
/// </summary>
public const int IO04 = 4;
/// <summary>
/// Gpio IO05
/// </summary>
public const int IO05 = 5;
/// <summary>
/// Gpio IO06 (Reserved for SPI flash)
/// </summary>
public const int IO06 = 6;
/// <summary>
/// Gpio IO07 (Reserved for SPI flash)
/// </summary>
public const int IO07 = 7;
/// <summary>
/// Gpio IO08 (Reserved for SPI flash)
/// </summary>
public const int IO08 = 8;
/// <summary>
/// Gpio IO09 (Reserved for SPI flash)
/// </summary>
public const int IO09 = 9;
/// <summary>
/// Gpio IO10 (Reserved for SPI flash)
/// </summary>
public const int IO10 = 10;
/// <summary>
/// Gpio IO11 (Reserved for SPI flash)
/// </summary>
public const int IO11 = 11;
/// <summary>
/// Gpio IO12 (also used for JTAG TDI)
/// </summary>
public const int IO12 = 12;
/// <summary>
/// Gpio IO13 (also used for JTAG TCK)
/// </summary>
public const int IO13 = 13;
/// <summary>
/// Gpio IO14 (also used for JTAG TMS)
/// </summary>
public const int IO14 = 14;
/// <summary>
/// Gpio IO15 (also used for JTAG TDO)
/// </summary>
public const int IO15 = 15;
/// <summary>
/// Gpio IO16
/// </summary>
public const int IO16 = 16;
/// <summary>
/// Gpio IO17
/// </summary>
public const int IO17 = 17;
/// <summary>
/// Gpio IO18
/// </summary>
public const int IO18 = 18;
/// <summary>
/// Gpio IO19
/// </summary>
public const int IO19 = 19;

/// <summary>
/// Gpio IO20, No Physical pin for IO20
/// </summary>
public const int IO20 = 20;

/// <summary>
/// Gpio IO21
/// </summary>
public const int IO21 = 21;
/// <summary>
/// Gpio IO22
/// </summary>
public const int IO22 = 22;
/// <summary>
/// Gpio IO23
/// </summary>
public const int IO23 = 23;

/// <summary>
/// Gpio IO24, No Physical pin for IO24
/// </summary>
public const int IO24 = 24;

/// <summary>
/// Gpio IO25
/// </summary>
public const int IO25 = 25;
/// <summary>
/// Gpio IO26
/// </summary>
public const int IO26 = 26;
/// <summary>
/// Gpio IO27
/// </summary>
public const int IO27 = 27;

/// <summary>
/// Gpio IO28, No Physical pin for IO28
/// </summary>
public const int IO28 = 28;
/// <summary>
/// Gpio IO29, No Physical pin for IO29
/// </summary>
public const int IO29 = 29;
/// <summary>
/// Gpio IO30, No Physical pin for IO30
/// </summary>
public const int IO30 = 30;
/// <summary>
/// Gpio IO31, No Physical pin for IO31
/// </summary>
public const int IO31 = 31;

/// <summary>
/// Gpio IO32
/// </summary>
public const int IO32 = 32;
/// <summary>
/// Gpio IO33
/// </summary>
public const int IO33 = 33;
/// <summary>
/// Gpio IO34 (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO34 = 34;
/// <summary>
/// Gpio IO35 (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO35 = 35;
/// <summary>
/// Gpio IO36 SENSOR_VP (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO36 = 36;
/// <summary>
/// Gpio IO37 (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO37 = 37;
/// <summary>
/// Gpio IO38 (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO38 = 38;
/// <summary>
/// Gpio IO39 SENSOR_VN (Input Only, no software pullup/pulldown functions)
/// </summary>
public const int IO39 = 39;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
[assembly: AssemblyTitle("nanoFramework.Hardware.Esp32")]
[assembly: AssemblyCompany("nanoFramework Contributors")]
[assembly: AssemblyProduct("nanoFramework.Hardware.Esp32")]
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2018")]
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2019")]

////////////////////////////////////////////////////////////////
// update this whenever the native assembly signature changes //
[assembly: AssemblyNativeVersion("100.0.6.0")]
[assembly: AssemblyNativeVersion("100.0.7.0")]
////////////////////////////////////////////////////////////////

// Setting ComVisible to false makes the types in this assembly not visible
Expand Down
Loading