Exemplo n.º 1
0
        public void spi_frequency(ref spi_t obj, int hz)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            ((SPI)uif).SetFrequency(hz);
        }
Exemplo n.º 2
0
        public int spi_master_write(ref spi_t obj, int value)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((SPI)uif).MasterWrite(value));
        }
Exemplo n.º 3
0
        public void spi_format(ref spi_t obj, int bits, int mode, int slave)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            ((SPI)uif).SetFormat(bits, mode, slave != 0);
        }
Exemplo n.º 4
0
        public int spi_master_block_write(ref spi_t obj,
                                          byte[] tx_buffer, int tx_length,
                                          byte[] rx_buffer, int rx_length, byte write_fill)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((SPI)uif).MasterBlockWrite(tx_buffer, tx_length,
                                               rx_buffer, rx_length, write_fill));
        }
Exemplo n.º 5
0
        private void DeleteSPI(ref spi_t obj)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                return;
            }

            pin_if.Remove(((SPI)uif).mosi);
            pin_if.Remove(((SPI)uif).miso);
            pin_if.Remove(((SPI)uif).sclk);
            pin_if.Remove(((SPI)uif).ssel);
            interfaces.Remove(obj.id);
        }
Exemplo n.º 6
0
        private IUnitInterface CreateSPI(ref spi_t obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
        {
            var p = PinMap.Peripheral(mosi, PinMap.PinMap_SPI_MOSI);

            if (p == (int)PinName.NC)
            {
                return(null);
            }
            var t = PinMap.Peripheral(miso, PinMap.PinMap_SPI_MISO);

            if ((t == (int)PinName.NC) || (t != p))
            {
                return(null);
            }
            t = PinMap.Peripheral(sclk, PinMap.PinMap_SPI_SCLK);
            if ((t == (int)PinName.NC) || (t != p))
            {
                return(null);
            }
            t = PinMap.Peripheral(ssel, PinMap.PinMap_SPI_SSEL);
            if ((t != (int)PinName.NC) && (t != p))
            {
                return(null);
            }

            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                if (pin_if.ContainsKey(mosi) || pin_if.ContainsKey(miso) || pin_if.ContainsKey(sclk) || pin_if.ContainsKey(ssel))
                {
                    throw new ArgumentException();
                }
                uif    = new SPI((SPIName)p, mosi, miso, sclk, ssel);
                obj.id = uif.GetHashCode();
                interfaces.Add(obj.id, uif);

                if ((mosi == PinName.P4_6) && (miso == PinName.P4_7) && (sclk == PinName.P4_4))
                {
                    obj.fthandle = fthandle;
                }
            }
            return(uif);
        }
Exemplo n.º 7
0
 public void spi_free(ref spi_t obj)
 {
     DeleteSPI(ref obj);
 }
Exemplo n.º 8
0
 public void spi_init(ref spi_t obj, PinName mosi, PinName miso, PinName sclk, PinName ssel)
 {
     CreateSPI(ref obj, mosi, miso, sclk, ssel);
 }