コード例 #1
0
 public UsbToSpiDevice()
 {
     _hidComHandler   = new HidSharpCommunicationHandler();
     _nvram           = new NonVolatileRam(_hidComHandler);
     _ram             = new VolatileRam(_hidComHandler);
     _extInterruptPin = new ExternalInterruptPin(_hidComHandler);
     _spiDataTransfer = new SpiDataTransfer(_hidComHandler);
     _eeprom          = new EepromMemory(_hidComHandler);
 }
コード例 #2
0
ファイル: Program.cs プロジェクト: namezis/MCP2210-Sharp
        static void TestNonVoltatileRam(INonVolatileRam nvram)
        {
            Console.Write("*** Test NVRAM: ");

            try {
                // read/write manufacters and product names
                string manufacterName = nvram.ManufacterName;
                string productName    = nvram.ProductName;

                nvram.ManufacterName = "Myself";
                nvram.ProductName    = "SomeProduct";

                string manufacterNameAfter = nvram.ManufacterName;
                string productNameAfter    = nvram.ProductName;

                nvram.ManufacterName = manufacterName;
                nvram.ProductName    = productName;

                // read USB settings
                UsbKeyPowerSettings usbPowerSettings0 = nvram.ReadUsbSettings();
                nvram.WriteUsbSettings(usbPowerSettings0);
                UsbKeyPowerSettings usbPowerSettings1 = nvram.ReadUsbSettings();

                // set the chip configuration
                ChipSettings chipSettings = new ChipSettings();
                chipSettings.InterruptBitMode    = DedicatedFunction.NoInterruptCounting;
                chipSettings.RemoteWakeUpEnabled = true;
                chipSettings.SpiBusReleaseEnable = true;
                chipSettings.AccessControl       = NramChipAccessControl.PasswordProtected;
                chipSettings.Password            = Password;
                chipSettings.PinDirections       = new PinDirection[] {
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output,
                    PinDirection.Output
                };

                chipSettings.PinModes = new PinMode[] {
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO,
                    PinMode.GPIO
                };

                chipSettings.DefaultOutput = new bool[] {
                    true,
                    true,
                    true,
                    true,
                    false,
                    false,
                    false,
                    true,
                    true
                };

                nvram.ConfigureChip(chipSettings);
                ChipSettings readSettings = nvram.ReadChipConfiguration();

                // configure SPI
                SpiSetup spiSetup = new SpiSetup();
                spiSetup.BitRate               = 300000;
                spiSetup.BytesToTransfer       = NumberOfBytes;
                spiSetup.ChipSelectToDataDelay = 3;
                spiSetup.BetweenDataDelay      = 3;
                spiSetup.DataToChipSelectDelay = 3;
                spiSetup.Mode = SpiModes.Spi0;
                spiSetup.ActiveChipSelectValues = new bool[] {
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true,
                    true
                };
                spiSetup.IdleChipSelectValues = new bool[] {
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false,
                    false
                };

                nvram.ConfigureSpi(spiSetup);

                // read spi configuration
                SpiSetup readSpiSetup = nvram.ReadSpiConfiguration();

                Console.WriteLine("completed successfully");
            } catch (Exception ex) {
                PrintException(ex);
            }
        }