// Mikroelektronika Expand Click MIKROE-951 (https://www.mikroe.com/expand-click) Services // Copyright (C)2020-2023, Philip Munts dba Munts Technologies. // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are met: // // * Redistributions of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE // ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE // LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR // CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF // SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS // INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN // CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE // POSSIBILITY OF SUCH DAMAGE. namespace IO.Devices.ClickBoards.RemoteIO.Expand { /// /// Encapsulates the Mikroelektronika Expand Click Board. /// public class Board { private readonly IO.Interfaces.GPIO.Pin myrst; private readonly IO.Devices.MCP23S17.Device mydev; /// /// Constructor for a single Expand click. /// /// mikroBUS socket number. /// Remote I/O server device object. public Board(int socknum, IO.Objects.RemoteIO.Device remdev = null) { // Create Remote I/O server device object, if one wasn't supplied if (remdev == null) remdev = new IO.Objects.RemoteIO.Device(); // Create a mikroBUS socket object IO.Objects.RemoteIO.mikroBUS.Socket S = new IO.Objects.RemoteIO.mikroBUS.Socket(socknum); // Configure hardware reset GPIO pin myrst = remdev.GPIO_Create(S.RST, IO.Interfaces.GPIO.Direction.Output, true); // Issue hardware reset Reset(); // Create MCP23S17 device object mydev = new IO.Devices.MCP23S17.Device(remdev.SPI_Create(S.SPIDev, IO.Devices.MCP23S17.Device.SPI_Mode, IO.Devices.MCP23S17.Device.SPI_WordSize, IO.Devices.MCP23S17.Device.SPI_Frequency)); } /// /// Returns the underlying MCP23S17 device object. /// public IO.Devices.MCP23S17.Device device { get { return mydev; } } /// /// Issue hardware reset to the MCP23S17. /// public void Reset() { myrst.state = false; System.Threading.Thread.Sleep(1); myrst.state = true; } /// /// Factory function for creating GPIO pins. /// /// MCP23S17 channel number (0 to 15). /// GPIO pin direction. /// Initial GPIO output state. /// GPIO pin object. public IO.Interfaces.GPIO.Pin GPIO(int channel, IO.Interfaces.GPIO.Direction dir, bool state = false) { return mydev.GPIO_Create(channel, dir, state); } } }