Exemplo n.º 1
0
        public async Task<bool> Init()
        {
            var config = new FtChannelConfig
            {
                ClockRate = ConnectionSpeed,
                LatencyTimer = LatencyTimer
            };

            _i2cConfig = _i2cConfig ?? I2CConfiguration.ChannelZeroConfiguration;
            _cfg = config;
           
            InitLibAndHandle();

            return true;
        }
Exemplo n.º 2
0
        private void InitLibAndHandle()
        {
            FtResult result;
            if (_handle != IntPtr.Zero)
                return;


            LibMpsse.Init();
            result = LibMpsseSpi.SPI_OpenChannel(_spiConfig.ChannelIndex, out _handle);

            CheckResult(result);

            if (_handle == IntPtr.Zero)
                throw new SpiChannelNotConnectedException(FtResult.InvalidHandle);

            result = LibMpsseSpi.SPI_InitChannel(_handle, ref _cfg);

            CheckResult(result);

            _currentGlobalConfig = _cfg;

        }
Exemplo n.º 3
0
 protected SpiDevice(FtChannelConfig config, SpiConfiguration spiConfig)
 {
     _spiConfig = spiConfig ?? SpiConfiguration.ChannelZeroConfiguration;
     _cfg = config;
     InitLibAndHandle();
 }
Exemplo n.º 4
0
        protected SpiDevice(FtChannelConfig config)
            : this(config, null)
        {

        }
Exemplo n.º 5
0
 private void EnforceRightConfiguration()
 {
     if (_currentGlobalConfig.configOptions != _cfg.configOptions)
     {
         LibMpsseSpi.SPI_ChangeCS(_handle, _cfg.configOptions);
         _currentGlobalConfig = _cfg;
     }
 }
Exemplo n.º 6
0
 public static extern FtResult I2C_InitChannel(System.IntPtr handle, ref FtChannelConfig config);
Exemplo n.º 7
0
 public extern static FtResult SPI_InitChannel(IntPtr handle, ref FtChannelConfig config);
Exemplo n.º 8
0
        void InitLibAndHandle()
        {
            FtResult result;

            if (_handle != IntPtr.Zero) 
                return;

            LibMpsse.Init();

            var num_channels = 0;

            var channels = LibMpsseI2C.I2C_GetNumChannels(out num_channels);

            CheckResult(channels);

            //if (num_channels > 0)
            //{
            //    for (var i = 0; i < num_channels; i++)
            //    {
            //        FtDeviceInfo cInfo;
            //        var channelInfoStatus = LibMpsseI2C.I2C_GetChannelInfo(i, out cInfo);
            //        CheckResult(channelInfoStatus);
            //        Debug.WriteLine($"Flags: {cInfo.Flags}");
            //        Debug.WriteLine($"Type: {cInfo.Type}");
            //        Debug.WriteLine($"ID: {cInfo.ID}");
            //        Debug.WriteLine($"LocId: {cInfo.LocId}");
            //        Debug.WriteLine($"SerialNumber: {cInfo.SerialNumber}");
            //        Debug.WriteLine($"Description: {cInfo.Description}");
            //        Debug.WriteLine($"ftHandle: {cInfo.ftHandle}");
            //    }
            //}

            result = LibMpsseI2C.I2C_OpenChannel(_i2cConfig.ChannelIndex, out _handle);

            CheckResult(result);

            if (_handle == IntPtr.Zero)
                throw new I2CChannelNotConnectedException(FtResult.InvalidHandle);

            result = LibMpsseI2C.I2C_InitChannel(_handle, ref _cfg);

            CheckResult(result);
            _currentGlobalConfig = _cfg;

        }