Esempio n. 1
0
        private bool EndTransaction(Configuration configuration)
        {
            SpiDevice spiDevice = this.Emulator.SpiBus.GetActiveDevice();

            if (configuration.ChipSelect_Port != Cpu.Pin.GPIO_NONE)
            {
                this.Emulator.ManagedHal.Gpio.SetPinState((uint)configuration.ChipSelect_Port, !configuration.ChipSelect_ActiveState);
            }

            if (!IsInTransaction)
            {
                Debug.Assert(false, "not in a SPI transaction");
                Trace.WriteLine("Error: Attempt to end a transaction when none is in place.");
                return(false);
            }
            if (_spiDeviceCurrent != spiDevice)
            {
                Debug.Assert(false, "wrong SPI device");
                Trace.WriteLine("Error: Attempt to end a transaction, but the SPI device does not match.");
                return(false);
            }

            _spiDeviceCurrent = null;

            return(true);
        }
Esempio n. 2
0
 private void SetConfiguration(Configuration configuration)
 {
     _chipSelectPin         = configuration.ChipSelect_Port;
     _chipSelectActiveState = configuration.ChipSelect_ActiveState;
     _chipSelectSetupTime   = configuration.ChipSelect_SetupTime;
     _chipSelectHoldTime    = configuration.ChipSelect_HoldTime;
     _clockIdleState        = configuration.Clock_IdleState;
     _clockEdge             = configuration.Clock_Edge;
     _clockRateKHz          = configuration.Clock_RateKHz;
     _spiModule             = configuration.SpiModule;
 }
Esempio n. 3
0
        private Configuration SpiConfigurationToConfiguration(SpiConfiguration configuration)
        {
            Configuration cfg = new Configuration(
                (Cpu.Pin)configuration.DeviceCS,
                configuration.CS_Active,
                configuration.CS_Setup_uSecs,
                configuration.CS_Hold_uSecs,
                configuration.MSK_IDLE,
                configuration.MSK_SampleEdge,
                configuration.Clock_RateKHz,
                (Hardware.Spi.SpiModule)configuration.SPI_mod);

            return(cfg);
        }
Esempio n. 4
0
        private bool StartTransaction(Configuration configuration)
        {
            if (IsInTransaction)
            {
                Debug.Assert(false, "already in a SPI transaction");
                Trace.WriteLine("Error: Attempt to start a transaction when another one is in place.");
                return(false);
            }

            if (configuration.ChipSelect_Port != Cpu.Pin.GPIO_NONE)
            {
                this.Emulator.ManagedHal.Gpio.SetPinState((uint)configuration.ChipSelect_Port, configuration.ChipSelect_ActiveState);
            }

            _spiDeviceCurrent = this.Emulator.SpiBus.GetActiveDevice();

            return(true);
        }
Esempio n. 5
0
        bool ISpiDriver.nWrite8_nRead8(ref SpiConfiguration Configuration, IntPtr Write8, int WriteCount, IntPtr Read8, int ReadCount, int ReadStartOffset)
        {
            Configuration configuration = SpiConfigurationToConfiguration(Configuration);

            bool res = false;

            try
            {
                if (StartTransaction(configuration))
                {
                    SpiXaction xaction = new SpiXaction(Write8, WriteCount, Read8, ReadCount, ReadStartOffset);

                    res = ((ISpiDriver)this).Xaction_nWrite8_nRead8(ref xaction);
                }
            }
            finally
            {
                res &= EndTransaction(configuration);
            }

            return(res);
        }
Esempio n. 6
0
 public SpiDevice(Configuration configuation)
 {
     SetConfiguration(configuation);
 }
Esempio n. 7
0
        bool ISpiDriver.Xaction_Stop(ref SpiConfiguration Configuration)
        {
            Configuration configuration = SpiConfigurationToConfiguration(Configuration);

            return(EndTransaction(configuration));
        }