示例#1
0
        private IUnitInterface CreateI2C(ref i2c_t obj, PinName sda, PinName scl)
        {
            var p = PinMap.Peripheral(sda, PinMap.PinMap_I2C_SDA);

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

            if ((t == (int)PinName.NC) || (p != t))
            {
                return(null);
            }

            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                if (pin_if.ContainsKey(sda) || pin_if.ContainsKey(scl))
                {
                    throw new ArgumentException();
                }
                uif    = new I2C((I2CName)p, sda, scl);
                obj.id = uif.GetHashCode();
                interfaces.Add(obj.id, uif);

                if ((sda == PinName.P1_7) && (scl == PinName.P1_6))
                {
                    obj.fthandle = fthandle;
                    obj.ftsda    = 5;
                    obj.ftscl    = 4;
                }
            }
            return(uif);
        }
示例#2
0
        private IUnitInterface CreateI2S(ref i2s_t obj, PinName tx, PinName rx, PinName sck, PinName ws, PinName audio_clk)
        {
            var p = PinMap.Peripheral(tx, PinMap.PinMap_I2S_TX);

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

            if ((t == (int)PinName.NC) || (t != p))
            {
                return(null);
            }
            t = PinMap.Peripheral(sck, PinMap.PinMap_I2S_SCK);
            if ((t == (int)PinName.NC) || (t != p))
            {
                return(null);
            }
            t = PinMap.Peripheral(ws, PinMap.PinMap_I2S_WS);
            if ((t == (int)PinName.NC) || (t != p))
            {
                return(null);
            }
            t = PinMap.Peripheral(audio_clk, PinMap.PinMap_I2S_AUDIO_CLK);
            if ((t != (int)PinName.NC) && (t != p))
            {
                return(null);
            }

            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                if (pin_if.ContainsKey(tx) || pin_if.ContainsKey(rx) || pin_if.ContainsKey(sck) || pin_if.ContainsKey(ws))
                {
                    throw new ArgumentException();
                }
                uif    = new I2S((I2SName)p, tx, rx, sck, ws, audio_clk);
                obj.id = uif.GetHashCode();
                interfaces.Add(obj.id, uif);
            }
            return(uif);
        }
示例#3
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);
        }
示例#4
0
        private IUnitInterface CreateAnalogIn(ref analogin_t obj, PinName pin)
        {
            var p = PinMap.Peripheral(pin, PinMap.PinMap_ADC);

            if (p == (int)PinName.NC)
            {
                return(null);
            }

            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                if (pin_if.ContainsKey(pin))
                {
                    throw new ArgumentException();
                }
                uif    = new AnalogIn((ADCName)p, pin);
                obj.id = uif.GetHashCode();
                interfaces.Add(obj.id, uif);
            }
            return(uif);
        }
示例#5
0
        private IUnitInterface CreateSerial(ref serial_t obj, PinName tx, PinName rx,
                                            PinName rts = PinName.NC, PinName cts = PinName.NC)
        {
            var p = PinMap.Peripheral(tx, PinMap.PinMap_UART_TX);

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

            if ((t == (int)PinName.NC) || (p != t))
            {
                return(null);
            }
            var r = PinMap.Peripheral(rts, PinMap.PinMap_UART_RTS);

            if ((rts != PinName.NC) && ((r == (int)PinName.NC) || (p != r)))
            {
                return(null);
            }
            var s = PinMap.Peripheral(cts, PinMap.PinMap_UART_CTS);

            if ((cts != PinName.NC) && ((s == (int)PinName.NC) || (p != s)))
            {
                return(null);
            }

            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                if (pin_if.ContainsKey(tx) || pin_if.ContainsKey(rx))
                {
                    throw new ArgumentException();
                }
                uif    = new Serial((UARTName)p, tx, rx, rts, cts);
                obj.id = uif.GetHashCode();
                interfaces.Add(obj.id, uif);
            }
            return(uif);
        }