Skip to content

Commit 0dc3081

Browse files
AdrianSoundyjosesimoes
authored andcommitted
Update pin mapping and fixes (#70)
1 parent 3410eee commit 0dc3081

File tree

6 files changed

+312
-19
lines changed

6 files changed

+312
-19
lines changed

source/nanoFramework.Hardware.Esp32/Configuration.cs

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//
55

66
using System;
7-
using Windows.Devices.Gpio;
7+
using System.Runtime.CompilerServices;
88

99
namespace nanoFramework.Hardware.Esp32
1010
{
@@ -14,19 +14,36 @@ namespace nanoFramework.Hardware.Esp32
1414
public class Configuration
1515
{
1616
/// <summary>
17-
/// Set the default function for a GPIO pin
17+
/// Set the default function for a GPIO pin.
1818
/// </summary>
1919
/// <remarks>
2020
/// Allows gpio pins to be assigned a device function.
2121
/// For example setting the I2C1 data pin to use GPIO pin 17.
2222
/// </remarks>
23-
/// <param name="pin"></param>
24-
/// <param name="value"></param>
23+
/// <param name="pin">The pin number to set against function.</param>
24+
/// <param name="value">The device function to be assigned the pin.</param>
2525
public static void SetPinFunction(int pin, DeviceFunction value)
2626
{
27-
GpioPin gpioPin = GpioController.GetDefault().OpenPin(pin);
28-
gpioPin.SetAlternateFunction((int)value);
29-
gpioPin.Dispose();
27+
NativeSetPinFunction(pin, (int)value);
3028
}
29+
30+
/// <summary>
31+
/// Returns the current pin number used by a device function.
32+
/// </summary>
33+
/// <param name="function"></param>
34+
/// <returns>The pin number used by device function. If value is -1 then pins is not assigned.</returns>
35+
public static int GetFunctionPin(DeviceFunction function)
36+
{
37+
38+
return NativeGetPinFunction((int)function); ;
39+
}
40+
41+
#region Native Calls
42+
[MethodImpl(MethodImplOptions.InternalCall)]
43+
private extern static void NativeSetPinFunction(int pin, int function);
44+
45+
[MethodImpl(MethodImplOptions.InternalCall)]
46+
private extern static int NativeGetPinFunction(int function);
47+
#endregion
3148
}
3249
}

source/nanoFramework.Hardware.Esp32/DeviceTypePins.cs

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,10 @@ public enum DeviceTypes
3939
/// PWM Device type
4040
/// </summary>
4141
PWM = 4 * ValueTypes.DeviceType,
42+
/// <summary>
43+
/// ADC Device type
44+
/// </summary>
45+
ADC = 5 * ValueTypes.DeviceType,
4246
};
4347

4448
/// <summary>
@@ -52,9 +56,9 @@ public enum DeviceFunction
5256
/// </summary>
5357
SPI1_MOSI = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 0,
5458
/// <summary>
55-
/// Device function MISI for SPI1
59+
/// Device function MISO for SPI1
5660
/// </summary>
57-
SPI1_MISI = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 1,
61+
SPI1_MISO = DeviceTypes.SPI + (1 * ValueTypes.DeviceIndex) + 1,
5862
/// <summary>
5963
/// Device function CLOCK for SPI1
6064
/// </summary>
@@ -65,9 +69,9 @@ public enum DeviceFunction
6569
/// </summary>
6670
SPI2_MOSI = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 0,
6771
/// <summary>
68-
/// Device function MISI for SPI2
72+
/// Device function MISO for SPI2
6973
/// </summary>
70-
SPI2_MISI = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 1,
74+
SPI2_MISO = DeviceTypes.SPI + (2 * ValueTypes.DeviceIndex) + 1,
7175
/// <summary>
7276
/// Device function CLOCK for SPI2
7377
/// </summary>
@@ -206,5 +210,100 @@ public enum DeviceFunction
206210
/// Device function PWM16
207211
/// </summary>
208212
PWM16 = DeviceTypes.PWM + (16 * ValueTypes.DeviceIndex) + 0,
213+
214+
/// <summary>
215+
/// ADC1 channel 0
216+
/// </summary>
217+
ADC1_CH0 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 0,
218+
/// <summary>
219+
/// ADC1 channel 1
220+
/// </summary>
221+
ADC1_CH1 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 1,
222+
/// <summary>
223+
/// ADC1 channel 2
224+
/// </summary>
225+
ADC1_CH2 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 2,
226+
/// <summary>
227+
/// ADC1 channel 3
228+
/// </summary>
229+
ADC1_CH3 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 3,
230+
/// <summary>
231+
/// ADC1 channel 4
232+
/// </summary>
233+
ADC1_CH4 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 4,
234+
/// <summary>
235+
/// ADC1 channel 5
236+
/// </summary>
237+
ADC1_CH5 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 5,
238+
/// <summary>
239+
/// ADC1 channel 6
240+
/// </summary>
241+
ADC1_CH6 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 6,
242+
/// <summary>
243+
/// ADC1 channel 7
244+
/// </summary>
245+
ADC1_CH7 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 7,
246+
247+
/// <summary>
248+
/// ADC1 channel 8
249+
/// Internal Temperture sensor (VP)
250+
/// </summary>
251+
ADC1_CH8 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 8,
252+
/// <summary>
253+
/// ADC1 channel 9
254+
/// Internal Hall Sensor (VN)
255+
/// </summary>
256+
ADC1_CH9 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 9,
257+
/// <summary>
258+
/// ADC1 channel 10
259+
/// Internally ESP32 Adc2 channel 10
260+
/// </summary>
261+
ADC1_CH10 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 10,
262+
/// <summary>
263+
/// ADC1 channel 11
264+
/// Internally ESP32 Adc2 channel 11
265+
/// </summary>
266+
ADC1_CH11 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 11,
267+
/// <summary>
268+
/// ADC1 channel 12
269+
/// Internally ESP32 Adc2 channel 12
270+
/// </summary>
271+
ADC1_CH12 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 12,
272+
/// <summary>
273+
/// ADC1 channel 13
274+
/// Internally ESP32 Adc2 channel 13
275+
/// </summary>
276+
ADC1_CH13 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 13,
277+
/// <summary>
278+
/// ADC1 channel 14
279+
/// Internally ESP32 Adc2 channel 14
280+
/// </summary>
281+
ADC1_CH14 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 14,
282+
/// <summary>
283+
/// ADC1 channel 15
284+
/// Internally ESP32 Adc2 channel 15
285+
/// </summary>
286+
ADC1_CH15 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 15,
287+
/// <summary>
288+
/// ADC1 channel 16
289+
/// Internally ESP32 Adc2 channel 16
290+
/// </summary>
291+
ADC1_CH16 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 16,
292+
/// <summary>
293+
/// ADC1 channel 17
294+
/// Internally ESP32 Adc2 channel 17
295+
/// </summary>
296+
ADC1_CH17 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 17,
297+
/// <summary>
298+
/// ADC1 channel 18
299+
/// Internally ESP32 Adc2 channel 18
300+
/// </summary>
301+
ADC1_CH18 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 18,
302+
/// <summary>
303+
/// ADC1 channel 19
304+
/// Internally ESP32 Adc2 channel 19
305+
/// </summary>
306+
ADC1_CH19 = DeviceTypes.ADC + (1 * ValueTypes.DeviceIndex) + 19,
307+
209308
};
210309
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
//
2+
// Copyright (c) 2019 The nanoFramework project contributors
3+
// See LICENSE file in the project root for full license information.
4+
//
5+
using System;
6+
7+
namespace nanoFramework.Hardware.Esp32
8+
{
9+
/// <summary>
10+
/// ESP32 GPIO pins
11+
/// </summary>
12+
public static class Gpio
13+
{
14+
/// <summary>
15+
/// Gpio IO00
16+
/// </summary>
17+
public const int IO00 = 0;
18+
/// <summary>
19+
/// Gpio IO01 (UART0 TXD)
20+
/// </summary>
21+
public const int IO01 = 1;
22+
/// <summary>
23+
/// Gpio IO02
24+
/// </summary>
25+
public const int IO02 = 2;
26+
/// <summary>
27+
/// Gpio IO03 (UART0 RXD)
28+
/// </summary>
29+
public const int IO03 = 3;
30+
/// <summary>
31+
/// Gpio IO04
32+
/// </summary>
33+
public const int IO04 = 4;
34+
/// <summary>
35+
/// Gpio IO05
36+
/// </summary>
37+
public const int IO05 = 5;
38+
/// <summary>
39+
/// Gpio IO06 (Reserved for SPI flash)
40+
/// </summary>
41+
public const int IO06 = 6;
42+
/// <summary>
43+
/// Gpio IO07 (Reserved for SPI flash)
44+
/// </summary>
45+
public const int IO07 = 7;
46+
/// <summary>
47+
/// Gpio IO08 (Reserved for SPI flash)
48+
/// </summary>
49+
public const int IO08 = 8;
50+
/// <summary>
51+
/// Gpio IO09 (Reserved for SPI flash)
52+
/// </summary>
53+
public const int IO09 = 9;
54+
/// <summary>
55+
/// Gpio IO10 (Reserved for SPI flash)
56+
/// </summary>
57+
public const int IO10 = 10;
58+
/// <summary>
59+
/// Gpio IO11 (Reserved for SPI flash)
60+
/// </summary>
61+
public const int IO11 = 11;
62+
/// <summary>
63+
/// Gpio IO12 (also used for JTAG TDI)
64+
/// </summary>
65+
public const int IO12 = 12;
66+
/// <summary>
67+
/// Gpio IO13 (also used for JTAG TCK)
68+
/// </summary>
69+
public const int IO13 = 13;
70+
/// <summary>
71+
/// Gpio IO14 (also used for JTAG TMS)
72+
/// </summary>
73+
public const int IO14 = 14;
74+
/// <summary>
75+
/// Gpio IO15 (also used for JTAG TDO)
76+
/// </summary>
77+
public const int IO15 = 15;
78+
/// <summary>
79+
/// Gpio IO16
80+
/// </summary>
81+
public const int IO16 = 16;
82+
/// <summary>
83+
/// Gpio IO17
84+
/// </summary>
85+
public const int IO17 = 17;
86+
/// <summary>
87+
/// Gpio IO18
88+
/// </summary>
89+
public const int IO18 = 18;
90+
/// <summary>
91+
/// Gpio IO19
92+
/// </summary>
93+
public const int IO19 = 19;
94+
95+
/// <summary>
96+
/// Gpio IO20, No Physical pin for IO20
97+
/// </summary>
98+
public const int IO20 = 20;
99+
100+
/// <summary>
101+
/// Gpio IO21
102+
/// </summary>
103+
public const int IO21 = 21;
104+
/// <summary>
105+
/// Gpio IO22
106+
/// </summary>
107+
public const int IO22 = 22;
108+
/// <summary>
109+
/// Gpio IO23
110+
/// </summary>
111+
public const int IO23 = 23;
112+
113+
/// <summary>
114+
/// Gpio IO24, No Physical pin for IO24
115+
/// </summary>
116+
public const int IO24 = 24;
117+
118+
/// <summary>
119+
/// Gpio IO25
120+
/// </summary>
121+
public const int IO25 = 25;
122+
/// <summary>
123+
/// Gpio IO26
124+
/// </summary>
125+
public const int IO26 = 26;
126+
/// <summary>
127+
/// Gpio IO27
128+
/// </summary>
129+
public const int IO27 = 27;
130+
131+
/// <summary>
132+
/// Gpio IO28, No Physical pin for IO28
133+
/// </summary>
134+
public const int IO28 = 28;
135+
/// <summary>
136+
/// Gpio IO29, No Physical pin for IO29
137+
/// </summary>
138+
public const int IO29 = 29;
139+
/// <summary>
140+
/// Gpio IO30, No Physical pin for IO30
141+
/// </summary>
142+
public const int IO30 = 30;
143+
/// <summary>
144+
/// Gpio IO31, No Physical pin for IO31
145+
/// </summary>
146+
public const int IO31 = 31;
147+
148+
/// <summary>
149+
/// Gpio IO32
150+
/// </summary>
151+
public const int IO32 = 32;
152+
/// <summary>
153+
/// Gpio IO33
154+
/// </summary>
155+
public const int IO33 = 33;
156+
/// <summary>
157+
/// Gpio IO34 (Input Only, no software pullup/pulldown functions)
158+
/// </summary>
159+
public const int IO34 = 34;
160+
/// <summary>
161+
/// Gpio IO35 (Input Only, no software pullup/pulldown functions)
162+
/// </summary>
163+
public const int IO35 = 35;
164+
/// <summary>
165+
/// Gpio IO36 SENSOR_VP (Input Only, no software pullup/pulldown functions)
166+
/// </summary>
167+
public const int IO36 = 36;
168+
/// <summary>
169+
/// Gpio IO37 (Input Only, no software pullup/pulldown functions)
170+
/// </summary>
171+
public const int IO37 = 37;
172+
/// <summary>
173+
/// Gpio IO38 (Input Only, no software pullup/pulldown functions)
174+
/// </summary>
175+
public const int IO38 = 38;
176+
/// <summary>
177+
/// Gpio IO39 SENSOR_VN (Input Only, no software pullup/pulldown functions)
178+
/// </summary>
179+
public const int IO39 = 39;
180+
}
181+
}

source/nanoFramework.Hardware.Esp32/Properties/AssemblyInfo.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,11 @@
88
[assembly: AssemblyTitle("nanoFramework.Hardware.Esp32")]
99
[assembly: AssemblyCompany("nanoFramework Contributors")]
1010
[assembly: AssemblyProduct("nanoFramework.Hardware.Esp32")]
11-
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2018")]
11+
[assembly: AssemblyCopyright("Copyright © nanoFramework Contributors 2019")]
1212

1313
////////////////////////////////////////////////////////////////
1414
// update this whenever the native assembly signature changes //
15-
[assembly: AssemblyNativeVersion("100.0.6.0")]
15+
[assembly: AssemblyNativeVersion("100.0.7.0")]
1616
////////////////////////////////////////////////////////////////
1717

1818
// Setting ComVisible to false makes the types in this assembly not visible

0 commit comments

Comments
 (0)