使用RaspberryPiDotNet库中的GPIOPins.cs

时间:2014-11-22 03:09:52

标签: c# raspberry-pi

this site,您可以下载Raspberry Pi的.NET库。

GPIOPins.cs包含以下代码。在命名空间RaspberryPiDotNet下,有两个公共枚举对象GPIOPinsGPIOPinMask。 GPIO(例如V2_GPIO_04)和pin(例如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,

    };

}

1 个答案:

答案 0 :(得分:0)

GPIOPIN VS GPIOMask寄存器:

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 。它是开发人员的选择,他在编写代码时所采用的参考。