Ejemplo n.º 1
0
        /// +=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=+=
        /// <summary>
        /// Enables the SPI slave device. Will throw exceptions if it cannot open the
        /// device
        /// </summary>
        /// <returns>ssHandle - the handle for the Slave Device or null for fail</returns>
        /// <param name="spiSlaveDeviceIn">The SPI Slave Device we are configuring</param>
        /// <history>
        ///    21 Dec 14  Cynic - Originally written
        /// </history>
        public SPISlaveDeviceHandle EnableSPISlaveDevice(SPISlaveDeviceEnum spiSlaveDeviceIn)
        {
            string deviceFileName;

            // set up now
            deviceFileName = BBBDefinitions.SPIDEV_FILENAME;

            // set up the spi device number, this is based off the port
            // NOTE that SPI port 0 goes to /dev/spidev1.x and SPI port 1
            //      goes to /dev/spidev2.x. That is just the way it is
            if (SPIPort == SPIPortEnum.SPIPORT_0)
            {
                deviceFileName = deviceFileName.Replace("%device%", "1");
            }
            else if (SPIPort == SPIPortEnum.SPIPORT_1)
            {
                deviceFileName = deviceFileName.Replace("%device%", "2");
            }
            else
            {
                // should never happen
                throw new Exception("Unknown SPI Port:" + SPIPort.ToString());
            }

            // set up the spi slave number
            if (spiSlaveDeviceIn == SPISlaveDeviceEnum.SPI_SLAVEDEVICE_CS0)
            {
                deviceFileName = deviceFileName.Replace("%slave%", "0");
            }
            else if (spiSlaveDeviceIn == SPISlaveDeviceEnum.SPI_SLAVEDEVICE_CS1)
            {
                deviceFileName = deviceFileName.Replace("%slave%", "1");
            }
            else
            {
                // should never happen
                throw new Exception("Unknown SPI Slave Device:" + spiSlaveDeviceIn.ToString());
            }

            // we open the file. We have to have an open file descriptor
            // note this is an external call. It has to be because the
            // ioctl needs an open file descriptor it can use
            int fd = ExternalFileOpen(deviceFileName, O_RDWR | O_NONBLOCK);

            if (fd <= 0)
            {
                throw new Exception("Could not open spidev file:" + deviceFileName);
            }

            //Console.WriteLine("SPIPort Slave Device Enabled: "+ deviceFileName);

            // create a new slave device handle
            SPISlaveDeviceHandle outHandle = new SPISlaveDeviceHandle(spiSlaveDeviceIn, fd);

            // record that we opened this slave device (so we can close it later)
            openSlaveDevices.Add(outHandle);
            // return the slave device handle
            return(outHandle);
        }
        public async void Init(List<int> adc_channel, SPIPort spi,int clockfrequency, SpiMode mode)
        {
            try
            {
                InitChannel(adc_channel);
                var settings = new SpiConnectionSettings((int)spi);
                settings.ClockFrequency = clockfrequency;
                settings.Mode = mode;

                string spiAqs = SpiDevice.GetDeviceSelector(Enum.GetName(typeof(SPIPort), spi));
                var deviceInfo = await DeviceInformation.FindAllAsync(spiAqs);
                SpiDisplay = await SpiDevice.FromIdAsync(deviceInfo[0].Id, settings);
            }

            /* If initialization fails, display the exception and stop running */
            catch (Exception ex)
            {
                throw new Exception("SPI Initialization Failed", ex);
            }
        }
Ejemplo n.º 3
0
 public static int ReadAutoReceivedData(SPIPort port, uint *buffer, int numToRead, double timeout)
 {
     return(lowLevel.HAL_ReadSPIAutoReceivedData(port, buffer, numToRead, timeout));
 }
Ejemplo n.º 4
0
 public static int Read(SPIPort port, byte *buffer, int count)
 {
     return(lowLevel.HAL_ReadSPI(port, buffer, count));
 }
Ejemplo n.º 5
0
 public static void Initialize(SPIPort port)
 {
     lowLevel.HAL_InitializeSPI(port);
 }
Ejemplo n.º 6
0
 public static void StartAutoTrigger(SPIPort port, int digitalSourceHandle, AnalogTriggerType analogTriggerType, int triggerRising, int triggerFalling)
 {
     lowLevel.HAL_StartSPIAutoTrigger(port, digitalSourceHandle, analogTriggerType, triggerRising, triggerFalling);
 }
Ejemplo n.º 7
0
 public static void SetSpeed(SPIPort port, int speed)
 {
     lowLevel.HAL_SetSPISpeed(port, speed);
 }
Ejemplo n.º 8
0
 public static void SetHandle(SPIPort port, int handle)
 {
     lowLevel.HAL_SetSPIHandle(port, handle);
 }
Ejemplo n.º 9
0
 public static void ForceAutoRead(SPIPort port)
 {
     lowLevel.HAL_ForceSPIAutoRead(port);
 }
Ejemplo n.º 10
0
 public static void ConfigureAutoStall(SPIPort port, int csToSclkTicks, int stallTicks, int pow2BytesPerRead)
 {
     lowLevel.HAL_ConfigureSPIAutoStall(port, csToSclkTicks, stallTicks, pow2BytesPerRead);
 }
Ejemplo n.º 11
0
 public static void Close(SPIPort port)
 {
     lowLevel.HAL_CloseSPI(port);
 }
Ejemplo n.º 12
0
 public static int Write(SPIPort port, byte *dataToSend, int sendSize)
 {
     return(lowLevel.HAL_WriteSPI(port, dataToSend, sendSize));
 }
Ejemplo n.º 13
0
 public static int Transaction(SPIPort port, byte *dataToSend, byte *dataReceived, int size)
 {
     return(lowLevel.HAL_TransactionSPI(port, dataToSend, dataReceived, size));
 }
Ejemplo n.º 14
0
 public static void StopAuto(SPIPort port)
 {
     lowLevel.HAL_StopSPIAuto(port);
 }
Ejemplo n.º 15
0
 public static void SetAutoTransmitData(SPIPort port, byte *dataToSend, int dataSize, int zeroSize)
 {
     lowLevel.HAL_SetSPIAutoTransmitData(port, dataToSend, dataSize, zeroSize);
 }
Ejemplo n.º 16
0
 public static void SetChipSelectActiveLow(SPIPort port)
 {
     lowLevel.HAL_SetSPIChipSelectActiveLow(port);
 }
Ejemplo n.º 17
0
 public static void FreeAuto(SPIPort port)
 {
     lowLevel.HAL_FreeSPIAuto(port);
 }
Ejemplo n.º 18
0
 public static void SetOpts(SPIPort port, int msbFirst, int sampleOnTrailing, int clkIdleHigh)
 {
     lowLevel.HAL_SetSPIOpts(port, msbFirst, sampleOnTrailing, clkIdleHigh);
 }
Ejemplo n.º 19
0
 public static int GetAutoDroppedCount(SPIPort port)
 {
     return(lowLevel.HAL_GetSPIAutoDroppedCount(port));
 }
Ejemplo n.º 20
0
 public static void StartAutoRate(SPIPort port, double period)
 {
     lowLevel.HAL_StartSPIAutoRate(port, period);
 }
Ejemplo n.º 21
0
 public static int GetHandle(SPIPort port)
 {
     return(lowLevel.HAL_GetSPIHandle(port));
 }
Ejemplo n.º 22
0
 public static void SPIStatusCheck(int status, SPIPort port)
 {
     StatusCheckForce(status);
 }
Ejemplo n.º 23
0
 public static void InitAuto(SPIPort port, int bufferSize)
 {
     lowLevel.HAL_InitSPIAuto(port, bufferSize);
 }