コード例 #1
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        public void UpdatePins(I2CInterface i2c) //@TODO: We need to update VVAR directions on state change!
        {
            //Read inputs
            byte[] IN = this.ReadRegisters(i2c, Register.GPIOA, 2);
            //Update input pins
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit  = i % 8;
                if (this.Pins[i].Input)
                {
                    this.Pins[i].Value = (IN[bank] >> bit & 1) == 1;
                }
            }

            //Write outputs
            byte[] OUT = new byte[2];
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit  = i % 8;
                OUT[bank] |= (byte)((this.Pins[i].Value ? 1 : 0) << bit);
            }
            this.WriteRegisters(i2c, Register.GPIOA, OUT);
        }
コード例 #2
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        /// <summary>
        /// Write to a register on the MCP23017 via I2C
        /// </summary>
        /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
        /// <param name="register">Register Address</param>
        /// <param name="value">Value to write</param>
        private void WriteRegister(I2CInterface i2c, Register register, byte value)
        {
            byte opcode = (byte)(((this.Address % 8) << 1) | 0x40);

            byte[] data = { opcode, (byte)register, value };
            i2c.WriteThenRead(data, 0);
        }
コード例 #3
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        /// <summary>
        /// Read a register on the MCP23017 via I2C
        /// </summary>
        /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
        /// <param name="register">Register Address</param>
        /// <returns>Value Read</returns>
        private byte ReadRegister(I2CInterface i2c, Register register)
        {
            throw new NotImplementedException();

            /*byte opcode = (byte)(((this.Address % 8) << 1) | 0x41);
             * byte[] data = { opcode, (byte)register };
             * return i2c.WriteThenRead(data, 1)[0];*/
        }
コード例 #4
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        /// <summary>
        /// Write to sequential registers on the MCP23017 via I2C
        /// </summary>
        /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
        /// <param name="register">Base Register Address</param>
        /// <param name="value">Value to write</param>
        private void WriteRegisters(I2CInterface i2c, Register register, byte[] values)
        {
            byte        opcode = (byte)(((this.Address % 8) << 1) | 0x40);
            List <byte> data   = new List <byte> {
                opcode, (byte)register
            };

            data.AddRange(values);
            i2c.WriteThenRead(data.ToArray(), 0);
        }
コード例 #5
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
 internal void UpdateDirections(I2CInterface i2c)
 {
     byte[] IODIR = new byte[2];
     for (int i = 0; i < 16; i++)
     {
         int bank = i / 8;
         int bit  = i % 8;
         IODIR[bank] |= (byte)((this.Pins[i].Input ? 1 : 0) << bit);
     }
     //Write values out
     this.WriteRegisters(i2c, Register.IODIRA, IODIR);
 }
コード例 #6
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        /// <summary>
        /// Read from sequential registers on the MCP23017 via I2C
        /// </summary>
        /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
        /// <param name="register">Base Register Address</param>
        /// <returns>Values Read</returns>
        private byte[] ReadRegisters(I2CInterface i2c, Register register, uint registerstoread)
        {
            //Set address pointer
            byte opcode = (byte)(((this.Address % 8) << 1) | 0x40);

            byte[] data = { opcode, (byte)register };
            i2c.WriteThenRead(data, 0);

            //Read data
            opcode = (byte)(((this.Address % 8) << 1) | 0x41);
            return(i2c.WriteThenRead(new byte[] { opcode }, registerstoread));
        }
コード例 #7
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        public void Setup(I2CInterface i2c)
        {
            //Setup IOCON
            //Actually happy with default value.

            //Setup directions and pullups
            byte[] IODIR = new byte[2];
            byte[] GPPU = new byte[2];
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit = i % 8;
                IODIR[bank] |= (byte)((this.Pins[i].Input ? 1 : 0) << bit);
                GPPU[bank] |= (byte)((this.Pins[i].PullUp ? 1 : 0) << bit);
            }
            //Write values out
            this.WriteRegisters(i2c, Register.IODIRA, IODIR);
            this.WriteRegisters(i2c, Register.GPPUA, GPPU);
        }
コード例 #8
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        public void Setup(I2CInterface i2c)
        {
            //Setup IOCON
            //Actually happy with default value.

            //Setup directions and pullups
            byte[] IODIR = new byte[2];
            byte[] GPPU  = new byte[2];
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit  = i % 8;
                IODIR[bank] |= (byte)((this.Pins[i].Input ? 1 : 0) << bit);
                GPPU[bank]  |= (byte)((this.Pins[i].PullUp ? 1 : 0) << bit);
            }
            //Write values out
            this.WriteRegisters(i2c, Register.IODIRA, IODIR);
            this.WriteRegisters(i2c, Register.GPPUA, GPPU);
        }
コード例 #9
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        //@TODO: We need to update VVAR directions on state change!
        public void UpdatePins(I2CInterface i2c)
        {
            //Read inputs
            byte[] IN = this.ReadRegisters(i2c, Register.GPIOA, 2);
            //Update input pins
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit = i % 8;
                if (this.Pins[i].Input)
                {
                    this.Pins[i].Value = (IN[bank] >> bit & 1) == 1;
                }
            }

            //Write outputs
            byte[] OUT = new byte[2];
            for (int i = 0; i < 16; i++)
            {
                int bank = i / 8;
                int bit = i % 8;
                OUT[bank] |= (byte)((this.Pins[i].Value ? 1 : 0) << bit);
            }
            this.WriteRegisters(i2c, Register.GPIOA, OUT);
        }
コード例 #10
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
 /// <summary>
 /// Write to sequential registers on the MCP23017 via I2C
 /// </summary>
 /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
 /// <param name="register">Base Register Address</param>
 /// <param name="value">Value to write</param>
 private void WriteRegisters(I2CInterface i2c, Register register, byte[] values)
 {
     byte opcode = (byte)(((this.Address % 8) << 1) | 0x40);
     List<byte> data = new List<byte> { opcode, (byte)register };
     data.AddRange(values);
     i2c.WriteThenRead(data.ToArray(), 0);
 }
コード例 #11
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
 /// <summary>
 /// Write to a register on the MCP23017 via I2C
 /// </summary>
 /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
 /// <param name="register">Register Address</param>
 /// <param name="value">Value to write</param>
 private void WriteRegister(I2CInterface i2c, Register register, byte value)
 {
     byte opcode = (byte)(((this.Address % 8) << 1) | 0x40);
     byte[] data = { opcode, (byte)register, value };
     i2c.WriteThenRead(data, 0);
 }
コード例 #12
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
        /// <summary>
        /// Read from sequential registers on the MCP23017 via I2C
        /// </summary>
        /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
        /// <param name="register">Base Register Address</param>
        /// <returns>Values Read</returns>
        private byte[] ReadRegisters(I2CInterface i2c, Register register, uint registerstoread)
        {
            //Set address pointer
            byte opcode = (byte)(((this.Address % 8) << 1) | 0x40);
            byte[] data = { opcode, (byte)register };
            i2c.WriteThenRead(data, 0);

            //Read data
            opcode = (byte)(((this.Address % 8) << 1) | 0x41);
            return i2c.WriteThenRead(new byte[] {opcode}, registerstoread);
        }
コード例 #13
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
 /// <summary>
 /// Read a register on the MCP23017 via I2C
 /// </summary>
 /// <param name="i2c">I2C Interface, probabally the Bus Pirate</param>
 /// <param name="register">Register Address</param>
 /// <returns>Value Read</returns>
 private byte ReadRegister(I2CInterface i2c, Register register)
 {
     throw new NotImplementedException();
     /*byte opcode = (byte)(((this.Address % 8) << 1) | 0x41);
     byte[] data = { opcode, (byte)register };
     return i2c.WriteThenRead(data, 1)[0];*/
 }
コード例 #14
0
ファイル: MCP23017.cs プロジェクト: jcwa617/import
 internal void UpdateDirections(I2CInterface i2c)
 {
     byte[] IODIR = new byte[2];
     for (int i = 0; i < 16; i++)
     {
         int bank = i / 8;
         int bit = i % 8;
         IODIR[bank] |= (byte)((this.Pins[i].Input ? 1 : 0) << bit);
     }
     //Write values out
     this.WriteRegisters(i2c, Register.IODIRA, IODIR);
 }
コード例 #15
0
 internal IOWarrior40(IntPtr handle) : base(handle)
 {
     I2C = new I2CInterfaceImplementation(this, Pipe.SPECIAL_MODE, 6);
 }
コード例 #16
0
ファイル: MT2131.cs プロジェクト: g3gg0/rx-fft
 public MT2131(I2CInterface device)
 {
     I2cDevice = device;
     BusID     = defaultBusID;
 }