// C# binding for SPI device services in libsimpleio.so // Copyright (C)2017-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. using System.Runtime.InteropServices; namespace IO.Bindings { public static partial class libsimpleio { /// /// Use hardware slave select. /// public const int SPI_AUTO_CS = -1; /// /// Open a Linux SPI device. /// /// Device node name. /// SPI transfer mode (0 .. 3) /// SPI transfer word size (8, 16, or 32). /// SPI transfer speed in Hz. /// File descriptor. /// Error code. Zero upon success or an errno /// value upon failure. ///The Linux kernel create a device nodes for each SPI slave ///device, of the form ////dev/spidevX.Y where X is the SPI bus ///controller number and Y is the SPI slave select number. [DllImport("simpleio")] public static extern void SPI_open(string devname, int mode, int wordsize, int speed, out int fd, out int error); /// /// Send bytes to and/or receive bytes from a Linux SPI device. /// /// File descriptor. /// Chip select file descriptor. /// Source buffer. /// Source buffer size. /// Delay in microseconds between the write and read operations. /// Destination buffer. /// Destination buffer size. /// Error code. Zero upon success or an errno /// value upon failure. [DllImport("simpleio")] public static extern void SPI_transaction(int fd, int csfd, byte[] cmd, int cmdlen, int delayus, byte[] resp, int resplen, out int error); /// /// Close a Linux SPI device. /// /// File descriptor. /// Error code. Zero upon success or an errno /// value upon failure. [DllImport("simpleio")] public static extern void SPI_close(int fd, out int error); } }