public FtdiMpsseSPIResult ReadWrite(byte[] bufferSend, byte [] bufferReceive, FtSpiTransferOptions options)
        {
            EnforceRightConfiguration();
            int sizeTransferred;

            return(LibMpsse_AccessToCppDll.SPI_ReadWrite(_spiHandle, bufferReceive, bufferSend, bufferSend.Length, out sizeTransferred, options));
        }
 private void EnforceRightConfiguration()
 {
     if (_globalConfig.spiConfigOptions != _spiConfig.spiConfigOptions)
     {
         LibMpsse_AccessToCppDll.SPI_ChangeCS(_spiHandle, _spiConfig.spiConfigOptions);
         _globalConfig = _spiConfig;
     }
 }
        private int ReadGPIOMask()
        {
            int vals;
            var r = LibMpsse_AccessToCppDll.FT_ReadGPIO(_spiHandle, out vals);

            if (r == FtdiMpsseSPIResult.Ok)
            {
                return(vals);
            }
            else
            {
                return(-1);
            }
        }
        private void InitLibAndHandle()
        {
            if (_spiHandle != IntPtr.Zero)
            {
                return;
            }

            LibMpsse.Init();

            var result = CheckResult(LibMpsse_AccessToCppDll.SPI_OpenChannel(_ftdiMpsseChannelConfig.ChannelIndex, out _spiHandle));

            if (_spiHandle == IntPtr.Zero)
            {
                throw new SpiChannelNotConnectedException(FtdiMpsseSPIResult.InvalidHandle);
            }

            result        = CheckResult(LibMpsse_AccessToCppDll.SPI_InitChannel(_spiHandle, ref _spiConfig));
            _globalConfig = this._spiConfig;
        }
        public void SetPinMode(int pin, PinMode pinMode)
        {
            if (pinMode == PinMode.Output)
            {
                _directions |= PowerOf2[pin];
            }
            else
            {
                _directions &= ~PowerOf2[pin];
            }

            var r = LibMpsse_AccessToCppDll.FT_WriteGPIO(_spiHandle, _directions, _values);

            if (r != FtdiMpsseSPIResult.Ok)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                throw new GpioException(r, nameof(SetPinMode));
            }
        }
        public void DigitalWrite(int pin, PinState mode)
        {
            if (mode == PinState.High)
            {
                _values |= PowerOf2[pin];
            }
            else
            {
                _values &= ~PowerOf2[pin];
            }

            var r = LibMpsse_AccessToCppDll.FT_WriteGPIO(_spiHandle, _directions, _values);

            if (r != FtdiMpsseSPIResult.Ok)
            {
                if (Debugger.IsAttached)
                {
                    Debugger.Break();
                }
                throw new GpioException(r, nameof(DigitalWrite));
            }
        }
 public FtdiMpsseSPIResult Write(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtSpiTransferOptions options = FtSpiTransferOptions.ToogleChipSelect)
 {
     EnforceRightConfiguration();
     return(LibMpsse_AccessToCppDll.SPI_Write(_spiHandle, buffer, sizeToTransfer, out sizeTransfered, options));
 }
 public FtdiMpsseSPIResult Read(byte[] buffer, int sizeToTransfer, out int sizeTransfered, FtSpiTransferOptions options)
 {
     EnforceRightConfiguration();
     return(LibMpsse_AccessToCppDll.SPI_Read(_spiHandle, buffer, sizeToTransfer, out sizeTransfered, options));
 }
 private FtdiMpsseSPIResult WriteGPIOMask(byte directions, byte values)
 {
     _values     = values;
     _directions = directions;
     return(LibMpsse_AccessToCppDll.FT_WriteGPIO(_spiHandle, directions, values));
 }
 private FtdiMpsseSPIResult WriteGPIOMask(byte values)
 {
     return(LibMpsse_AccessToCppDll.FT_WriteGPIO(_spiHandle, values));
 }