// Abstract interface for a mikroBUS socket // Copyright (C)2025, 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.Interfaces.mikroBUS { /// /// Enumeration of mikroBUS socket pin designators. /// /// /// In principle, any of these pins may be used for GPIO. In practice, /// many of them will be configured for special functions and unavailable /// for GPIO. /// public enum SocketPins { /// /// Analog input. /// AN, /// /// Reset output. /// RST, /// /// SPI chip select (aka slave select) output. /// CS, /// /// SPI clock output. /// SCK, /// /// SPI MISO (Master In / Slave Out) data input. /// MISO, /// /// SPI MOSI (Master Out / Slave In) data output. /// MOSI, /// /// I2C bus bidirectional data signal. /// SDA, /// /// I2C bus bidirectional clock signal. /// SCL, /// /// Serial port transmit data output. /// TX, /// /// Serial port receive data input. /// RX, /// /// Interrupt input. /// INT, /// /// PWM (Pulse With Modulated) output. /// PWM } /// /// Abstract interface for mikroBUS sockets. /// public interface Socket { /// /// Create an analog input object instance for a given socket. /// /// Analog input object instance. IO.Interfaces.ADC.Sample CreateAnalogInput(); /// /// Create a GPIO pin object instance for a given pin of a given socket. /// /// mikroBUS socket pin designator. /// Data direction. /// Initial GPIO output state. /// Output drive setting. /// Input edge setting. /// /// Seldom are all of the mikroBUS socket pins available for GPIO. /// Usually many of them are configured for other special functions, /// including SPI bus, I2C bus, PWM output, etc. /// /// GPIO pin object instance. IO.Interfaces.GPIO.Pin CreateGPIOPin(SocketPins desg, IO.Interfaces.GPIO.Direction dir, bool state = false, IO.Interfaces.GPIO.Drive drive = IO.Interfaces.GPIO.Drive.PushPull, IO.Interfaces.GPIO.Edge edge = IO.Interfaces.GPIO.Edge.None); /// /// Create a GPIO output pin object instance for the RST pin of a /// given socket. /// /// Initial state for the reset output. /// Output drive setting. /// GPIO output pin object instance. IO.Interfaces.GPIO.Pin CreateResetOutput(bool state = false, IO.Interfaces.GPIO.Drive drive = IO.Interfaces.GPIO.Drive.PushPull); /// /// Create a SPI slave device object instance for a given socket. /// /// SPI slave device object instance. /// SPI transfer mode: 0 to 3. /// SPI transfer word size: 8, 16, or 32. /// SPI transfer speed in bits per second. IO.Interfaces.SPI.Device CreateSPIDevice(int mode, int wordsize, int speed); /// /// Create an I2C bus object instance for a given socket. /// /// I2C bus clock frequency in Hz. /// I2C bus object instance. IO.Interfaces.I2C.Bus CreateI2CBus(int speed = IO.Interfaces.I2C.Speeds.StandardMode); /// /// Create a GPIO input pin instance for the INT (interrupt) pin of a /// given socket. /// /// Interrupt edge setting. /// GPIO pin instance. IO.Interfaces.GPIO.Pin CreateInterruptInput( IO.Interfaces.GPIO.Edge edge = IO.Interfaces.GPIO.Edge.None); /// /// Create a PWM (Pulse Width Modulated) output instance for a given /// socket. /// /// PWM pulse frequency in Hz. /// Initial PWM output duty cycle. /// PWM output instance. IO.Interfaces.PWM.Output CreatePWMOutput(int freq, double duty = IO.Interfaces.PWM.DutyCycles.Minimum); } }