Esempio n. 1
0
        /// <summary>
        /// Create a single MCP23S17 GPIO pin.
        /// </summary>
        /// <param name="dev">MCP23S17 device object.</param>
        /// <param name="channel">MCP23S17 I/O channel number.</param>
        /// <param name="dir">GPIO pin data direction.</param>
        /// <param name="state">Initial GPIO output state.</param>
        public Pin(IO.Devices.MCP23S17.Device dev, int channel,
                   IO.Interfaces.GPIO.Direction dir, bool state = false)
        {
            // Validate parameters

            if ((channel < IO.Devices.MCP23S17.Device.MinChannel) ||
                (channel > IO.Devices.MCP23S17.Device.MaxChannel))
            {
                throw new System.Exception("Invalid channel number.");
            }

            mask = (uint)(1 << channel);

            if (dir == IO.Interfaces.GPIO.Direction.Output)
            {
                dev.Direction |= mask;
            }
            else
            {
                dev.Direction &= ~mask;
            }

            this.dev   = dev;
            this.state = state;
        }
Esempio n. 2
0
        /// <summary>
        /// Constructor for a single Expand 2 click.
        /// </summary>
        /// <param name="socknum">mikroBUS socket number.</param>
        public Board(int socknum)
        {
            // Create a mikroBUS socket object

            IO.Objects.libsimpleio.mikroBUS.Socket S =
                new IO.Objects.libsimpleio.mikroBUS.Socket(socknum);

            // Configure hardware reset GPIO pin

            myrst = new IO.Objects.libsimpleio.GPIO.Pin(S.RST,
                                                        IO.Interfaces.GPIO.Direction.Output, true);

            // Issue hardware reset

            Reset();

            // Create MCP23S17 device object

            mydev = new IO.Devices.MCP23S17.Device(
                new IO.Objects.libsimpleio.SPI.Device(S.SPIDev,
                                                      IO.Devices.MCP23S17.Device.SPI_Mode,
                                                      IO.Devices.MCP23S17.Device.SPI_WordSize,
                                                      IO.Devices.MCP23S17.Device.SPI_Frequency));
        }