Beispiel #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);
        }
Beispiel #2
0
        public int i2c_byte_write(ref i2c_t obj, int data)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((I2C)uif).ByteWrite(data));
        }
Beispiel #3
0
        public int i2c_byte_read(ref i2c_t obj, int ack)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((I2C)uif).ByteRead(ack));
        }
Beispiel #4
0
        public int i2c_stop(ref i2c_t obj)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((I2C)uif).Stop() ? 1 : 0);
        }
Beispiel #5
0
        public void i2c_frequency(ref i2c_t obj, int hz)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            ((I2C)uif).SetFrequency(hz);
        }
Beispiel #6
0
        public int i2c_write(ref i2c_t obj, int address,
                             byte[] data, int length, int repeated)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                throw new ArgumentException();
            }

            return(((I2C)uif).Write(address, data, length, repeated));
        }
Beispiel #7
0
        private void DeleteI2C(ref i2c_t obj)
        {
            if (!interfaces.TryGetValue(obj.id, out var uif))
            {
                return;
            }

            pin_if.Remove(((I2C)uif).sda);
            pin_if.Remove(((I2C)uif).scl);
            interfaces.Remove(obj.id);
        }
Beispiel #8
0
 public void i2c_init(ref i2c_t obj, PinName sda, PinName scl)
 {
     CreateI2C(ref obj, sda, scl);
 }