使用 GPIOPins.cs来自 RaspberryPiDotNet 库

本文关键字:RaspberryPiDotNet 来自 cs GPIOPins 使用 | 更新日期: 2023-09-27 18:31:24

从这个站点,你可以下载一个Raspberry Pi的.NET库。

GPIOPins.cs 包含以下代码。在命名空间RaspberryPiDotNet下,有两个公共枚举对象,GPIOPinsGPIOPinMask 。GPIO 有单独的变量(例如 V2_GPIO_04 ) 和引脚(例如 V2_Pin_P1_18)。

GPIOPinsGPIOPinMask有什么区别?何时使用 GPIO 变量?引脚变量?似乎并非所有B+引脚都包含在这里。B+ 有 40 个引脚,代码最多只提供 26 个引脚,用于 B。如果我需要将该引脚用于 GPIO,是否可以改用 GPIO 变量?

namespace RaspberryPiDotNet
{
    /// <remarks>
    /// Refer to http://elinux.org/Rpi_Low-level_peripherals for diagram.
    /// P1-01 = bottom left, P1-02 = top left
    /// pi connector P1 pin    = GPIOnum
    ///                  P1-03 = GPIO0
    ///                  P1-05 = GPIO1
    ///                  P1-07 = GPIO4
    ///                  P1-08 = GPIO14 - alt function (UART0_TXD) on boot-up
    ///                  P1-10 = GPIO15 - alt function (UART0_TXD) on boot-up
    ///                  P1-11 = GPIO17
    ///                  P1-12 = GPIO18
    ///                  P1-13 = GPIO21
    ///                  P1-15 = GPIO22
    ///                  P1-16 = GPIO23
    ///                  P1-18 = GPIO24
    ///                  P1-19 = GPIO10
    ///                  P1-21 = GPIO9
    ///                  P1-22 = GPIO25
    ///                  P1-23 = GPIO11
    ///                  P1-24 = GPIO8
    ///                  P1-26 = GPIO7
    ///                  
    ///                  P5-03 = GPI28
    ///                  P5-04 = GPI29
    ///                  P5-05 = GPI30
    ///                  P5-06 = GPI31
    /// 
    /// So to turn on Pin7 on the GPIO connector, pass in enumGPIOPIN.gpio4 as the pin parameter
    /// </remarks>
    public enum GPIOPins : uint
    {
        GPIO_NONE = uint.MaxValue,
        //Revision 1
        GPIO_00 = 0,
        GPIO_01 = 1,
        GPIO_04 = 4,
        GPIO_07 = 7,
        GPIO_08 = 8,
        GPIO_09 = 9,
        GPIO_10 = 10,
        GPIO_11 = 11,
        GPIO_14 = 14,
        GPIO_15 = 15,
        GPIO_17 = 17,
        GPIO_18 = 18,
        GPIO_21 = 21,
        GPIO_22 = 22,
        GPIO_23 = 23,
        GPIO_24 = 24,
        GPIO_25 = 25,
        Pin_P1_03 = 0,
        Pin_P1_05 = 1,
        Pin_P1_07 = 4,
        Pin_P1_08 = 14,
        Pin_P1_10 = 15,
        Pin_P1_11 = 17,
        Pin_P1_12 = 18,
        Pin_P1_13 = 21,
        Pin_P1_15 = 22,
        Pin_P1_16 = 23,
        Pin_P1_18 = 24,
        Pin_P1_19 = 10,
        Pin_P1_21 = 9,
        Pin_P1_22 = 25,
        Pin_P1_23 = 11,
        Pin_P1_24 = 8,
        Pin_P1_26 = 7,
        LED = 16,
        //Revision 2
        V2_GPIO_00 = 0,
        V2_GPIO_02 = 2,
        V2_GPIO_03 = 3,
        V2_GPIO_01 = 1,
        V2_GPIO_04 = 4,
        V2_GPIO_07 = 7,
        V2_GPIO_08 = 8,
        V2_GPIO_09 = 9,
        V2_GPIO_10 = 10,
        V2_GPIO_11 = 11,
        V2_GPIO_14 = 14,
        V2_GPIO_15 = 15,
        V2_GPIO_17 = 17,
        V2_GPIO_18 = 18,
        V2_GPIO_21 = 21,
        V2_GPIO_22 = 22,
        V2_GPIO_23 = 23,
        V2_GPIO_24 = 24,
        V2_GPIO_25 = 25,
        V2_GPIO_27 = 27,
        //Revision 2, new plug P5
        V2_GPIO_28 = 28,
        V2_GPIO_29 = 29,
        V2_GPIO_30 = 30,
        V2_GPIO_31 = 31,
        V2_Pin_P1_03 = 2,
        V2_Pin_P1_05 = 3,
        V2_Pin_P1_07 = 4,
        V2_Pin_P1_08 = 14,
        V2_Pin_P1_10 = 15,
        V2_Pin_P1_11 = 17,
        V2_Pin_P1_12 = 18,
        V2_Pin_P1_13 = 27,
        V2_Pin_P1_15 = 22,
        V2_Pin_P1_16 = 23,
        V2_Pin_P1_18 = 24,
        V2_Pin_P1_19 = 10,
        V2_Pin_P1_21 = 9,
        V2_Pin_P1_22 = 25,
        V2_Pin_P1_23 = 11,
        V2_Pin_P1_24 = 8,
        V2_Pin_P1_26 = 7,
        V2_LED = 16,
        //Revision 2, new plug P5
        V2_Pin_P5_03 = 28,
        V2_Pin_P5_04 = 29,
        V2_Pin_P5_05 = 30,
        V2_Pin_P5_06 = 31,
    };
    public enum GPIOPinMask : uint
    {
        GPIO_NONE = uint.MaxValue,
        //Revision 1
        GPIO_00 = 0,
        GPIO_01 = 1,
        GPIO_04 = 1 << 4,
        GPIO_07 = 1 << 7,
        GPIO_08 = 1 << 8,
        GPIO_09 = 1 << 9,
        GPIO_10 = 1 << 10,
        GPIO_11 = 1 << 11,
        GPIO_14 = 1 << 14,
        GPIO_15 = 1 << 15,
        GPIO_17 = 1 << 17,
        GPIO_18 = 1 << 18,
        GPIO_21 = 1 << 21,
        GPIO_22 = 1 << 22,
        GPIO_23 = 1 << 23,
        GPIO_24 = 1 << 24,
        GPIO_25 = 1 << 25,
        Pin_P1_03 = 1 << 0,
        Pin_P1_05 = 1 << 1,
        Pin_P1_07 = 1 << 4,
        Pin_P1_08 = 1 << 14,
        Pin_P1_10 = 1 << 15,
        Pin_P1_11 = 1 << 17,
        Pin_P1_12 = 1 << 18,
        Pin_P1_13 = 1 << 21,
        Pin_P1_15 = 1 << 22,
        Pin_P1_16 = 1 << 23,
        Pin_P1_18 = 1 << 24,
        Pin_P1_19 = 1 << 10,
        Pin_P1_21 = 1 << 9,
        Pin_P1_22 = 1 << 25,
        Pin_P1_23 = 1 << 11,
        Pin_P1_24 = 1 << 8,
        Pin_P1_26 = 1 << 7,
        LED = 1 << 16,
        //Revision 2
        V2_GPIO_00 = 1 << 0,
        V2_GPIO_02 = 1 << 2,
        V2_GPIO_03 = 1 << 3,
        V2_GPIO_01 = 1 << 1,
        V2_GPIO_04 = 1 << 4,
        V2_GPIO_07 = 1 << 7,
        V2_GPIO_08 = 1 << 8,
        V2_GPIO_09 = 1 << 9,
        V2_GPIO_10 = 1 << 10,
        V2_GPIO_11 = 1 << 11,
        V2_GPIO_14 = 1 << 14,
        V2_GPIO_15 = 1 << 15,
        V2_GPIO_17 = 1 << 17,
        V2_GPIO_18 = 1 << 18,
        V2_GPIO_21 = 1 << 21,
        V2_GPIO_22 = 1 << 22,
        V2_GPIO_23 = 1 << 23,
        V2_GPIO_24 = 1 << 24,
        V2_GPIO_25 = 1 << 25,
        V2_GPIO_27 = 1 << 27,
        //Revision 2, new plug P5
        V2_GPIO_28 = 1 << 28,
        V2_GPIO_29 = 1 << 29,
        V2_GPIO_30 = 1 << 30,
        V2_GPIO_31 = (uint)1 << 31,
        V2_Pin_P1_03 = 1 << 2,
        V2_Pin_P1_05 = 1 << 3,
        V2_Pin_P1_07 = 1 << 4,
        V2_Pin_P1_08 = 1 << 14,
        V2_Pin_P1_10 = 1 << 15,
        V2_Pin_P1_11 = 1 << 17,
        V2_Pin_P1_12 = 1 << 18,
        V2_Pin_P1_13 = 1 << 27,
        V2_Pin_P1_15 = 1 << 22,
        V2_Pin_P1_16 = 1 << 23,
        V2_Pin_P1_18 = 1 << 24,
        V2_Pin_P1_19 = 1 << 10,
        V2_Pin_P1_21 = 1 << 9,
        V2_Pin_P1_22 = 1 << 25,
        V2_Pin_P1_23 = 1 << 11,
        V2_Pin_P1_24 = 1 << 8,
        V2_Pin_P1_26 = 1 << 7,
        V2_LED = 1 << 16,
        //Revision 2, new plug P5
        V2_Pin_P5_03 = 1 << 28,
        V2_Pin_P5_04 = 1 << 29,
        V2_Pin_P5_05 = 1 << 30,
        V2_Pin_P5_06 = (uint)1 << 31,
    };
}

使用 GPIOPins.cs来自 RaspberryPiDotNet 库

GPIOPIN VS GPIOMask Registers :

GPIO是嵌入式系统中的一个技术术语,意思是通用输入输出。该输入输出引脚用于控制继电器、执行器、LED发光或检测来自传感器或开关的输入。

每个控制器有多个输入输出,这些输出与控制器PIN相关联。详细信息可从相应的数据表中获得。

GPIOPins 引用此输入输出引脚。您可以使用它通过使用软件更改其值来控制/接口其他电子设备。这可以通过更改 GPIO 寄存器中的值来实现

value 1 to GPIOpins gets/sets high (+VCC) voltage on pin.
value 0 to GPIOpins gets/sets (0) voltage on pin.

有时开发人员只需要特定的引脚进行接口,而其他引脚则保持未连接。为了在这种情况下优化代码,请使用 GPIOPinMask。这利用了硬件功能,这使得引脚在 GPIO 寄存器更改期间的状态更改无效。

value 1 will mask the PIN for further changes in GPIOPins
value 0 will unmask the PIN, which will affect voltage on pin as above explanation.

编辑:

天气使用 GPIO_XX 或 PIN_XX_XX 用于 GPIOPins 枚举?

您可以使用任何,这是为了开发人员的方便。 如果您以物理位置作为参考而不是使用PIN_XX_XX,如果您使用的是功能参考(参见原理图中的引脚布局),那么您应该使用GPIO_XX。这取决于开发人员的选择,他在编写代码时需要什么参考。

相关文章:
  • 没有找到相关文章