forked from nanoframework/Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStm32.GpioController.Extensions.cs
59 lines (55 loc) · 2.67 KB
/
Stm32.GpioController.Extensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//
// Copyright (c) 2018 Eclo Solutions
// See LICENSE file in the project root for full license information.
//
using System;
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// using the same namespace makes the extensions usable out of the box, without requiring adding other using //
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
namespace Windows.Devices.Gpio
{
public static class GpioControllerExtensions
{
/// <summary>
/// Opens a connection to the specified general-purpose I/O (GPIO) pin of a STM32 MCU in exclusive mode.
/// </summary>
/// <param name="controller"></param>
/// <param name="port">The port letter, as it's refereed to in the product documentation.</param>
/// <param name="pin">The pin number of the specified port.</param>
/// <returns>The opened GPIO pin.</returns>
/// <remarks>
/// This extension is valid for STM32 MCUs and relies on the port naming used by STM, such as PA2 or PB9.
/// </remarks>
public static Windows.Devices.Gpio.GpioPin OpenStm32Pin(
this Windows.Devices.Gpio.GpioController controller,
char port,
byte pin)
{
return controller.OpenStm32Pin(port, pin, Windows.Devices.Gpio.GpioSharingMode.Exclusive);
}
/// <summary>
/// Opens a connection to the specified general-purpose I/O (GPIO) pin of a STM32 target in exclusive mode.
/// </summary>
/// <param name="controller"></param>
/// <param name="port">The port letter, as it's refereed to in the product documentation.</param>
/// <param name="pin">The pin number of the specified port.</param>
/// <param name="sharingMode">The mode in which you want to open the GPIO pin, which determines whether other connections to the pin can be opened while you have the pin open.</param>
/// <returns>The opened GPIO pin.</returns>
/// <remarks>
/// This extension is valid for STM32 MCUs and relies on the port naming used by STM, such as PA2 or PB9.
/// </remarks>
public static Windows.Devices.Gpio.GpioPin OpenStm32Pin(
this Windows.Devices.Gpio.GpioController controller,
char port,
byte pin,
Windows.Devices.Gpio.GpioSharingMode sharingMode)
{
if ((port < 'A' || port > 'J') ||
(pin > 15))
{
throw new ArgumentException();
}
return controller.OpenPin(((port - 'A') * 16) + pin, sharingMode);
}
}
}