Пример #1
0
            public static int Setup(SpiChannelEnum channel, int speed)
            {
                if (speed < 500000 || speed > 32000000)
                {
                    throw new ArgumentOutOfRangeException(nameof(speed));
                }

                var spiPin = channel.ToPinNumber();

                Pins.Setup(spiPin, PinModeEnum.Output);
                Pins.Write(spiPin, true);

                var fileDescriptor = Unmanaged.Spi.Setup((int)channel, speed);

                if (fileDescriptor >= 0)
                {
                    return(fileDescriptor);
                }

                switch (fileDescriptor)
                {
                case -1:
                    throw new Exception("Could not setup SPI. Function open() or ioctl() did not execute correctly.");

                default:
                    throw new Exception($"Could not setup SPI. Result: {fileDescriptor}.");
                }
            }