示例#1
0
        public void RegisterInitialization(TestDevice testDevice)
        {
            // All pins should be set to input, all output latches should be low, and pullups should be disabled.
            Mcp23xxx device = testDevice.Device;

            if (testDevice.Controller.PinCount == 8)
            {
                Assert.Equal(0xFF, device.ReadByte(Register.IODIR));
                Assert.Equal(0x00, device.ReadByte(Register.OLAT));
                Assert.Equal(0x00, device.ReadByte(Register.IPOL));
            }
            else
            {
                Mcp23x1x device16 = (Mcp23x1x)device;
                Assert.Equal(0xFFFF, device16.ReadUInt16(Register.IODIR));
                Assert.Equal(0x0000, device16.ReadUInt16(Register.OLAT));
                Assert.Equal(0x00, device.ReadByte(Register.OLAT));
            }
        }
示例#2
0
        public void Write_GoodPin(TestDevice testDevice)
        {
            Mcp23xxx device = testDevice.Device;

            for (int pin = 0; pin < testDevice.Device.PinCount; pin++)
            {
                bool first = pin < 8;

                device.Write(pin, PinValue.High);
                byte expected = (byte)(1 << (first ? pin : pin - 8));

                Assert.Equal(expected,
                             first ? device.ReadByte(Register.OLAT) : ((Mcp23x1x)device).ReadByte(Register.OLAT, Port.PortB));

                device.Write(pin, PinValue.Low);
                Assert.Equal(0,
                             first ? device.ReadByte(Register.OLAT) : ((Mcp23x1x)device).ReadByte(Register.OLAT, Port.PortB));
            }
        }
示例#3
0
        public void CacheInvalidatesWhenReset(TestDevice testDevice)
        {
            Mcp23xxx device = testDevice.Device;

            // Check the output latches after enabling and setting
            // different bits.
            device.Enable();
            device.Write(0, PinValue.High);
            Assert.Equal(1, device.ReadByte(Register.OLAT));
            device.Write(1, PinValue.High);
            Assert.Equal(3, device.ReadByte(Register.OLAT));

            // Flush OLAT
            device.WriteByte(Register.OLAT, 0x00);
            Assert.Equal(0, device.ReadByte(Register.OLAT));

            // Now setting the next bit will pick back up our cached 3
            device.Write(2, PinValue.High);
            Assert.Equal(7, device.ReadByte(Register.OLAT));

            // Re-enabling will reset the cache
            device.WriteByte(Register.OLAT, 0x00);
            device.Disable();
            device.Enable();
            device.Write(3, PinValue.High);
            Assert.Equal(8, device.ReadByte(Register.OLAT));

            device.WriteByte(Register.OLAT, 0x02);
            device.Disable();
            device.Enable();
            device.Write(0, PinValue.High);
            Assert.Equal(3, device.ReadByte(Register.OLAT));
        }
示例#4
0
        public void CacheInvalidatesWhenReset(TestDevice testDevice)
        {
            Mcp23xxx       device     = testDevice.Device;
            GpioController controller = testDevice.Controller;

            // Check the output latches after enabling and setting
            // different bits.
            device.Enable();
            for (int i = 0; i < 4; i++)
            {
                controller.OpenPin(i, PinMode.Output);
            }

            controller.Write(0, PinValue.High);
            Assert.Equal(1, device.ReadByte(Register.OLAT));
            controller.Write(1, PinValue.High);
            Assert.Equal(3, device.ReadByte(Register.OLAT));

            // Flush OLAT
            device.WriteByte(Register.OLAT, 0x00);
            Assert.Equal(0, device.ReadByte(Register.OLAT));

            // Now setting the next bit will pick back up our cached 3
            controller.Write(2, PinValue.High);
            Assert.Equal(7, device.ReadByte(Register.OLAT));

            // Re-enabling will reset the cache
            device.WriteByte(Register.OLAT, 0x00);
            device.Disable();
            device.Enable();
            controller.Write(3, PinValue.High);
            Assert.Equal(8, device.ReadByte(Register.OLAT));

            device.WriteByte(Register.OLAT, 0x02);
            device.Disable();
            device.Enable();
            controller.Write(0, PinValue.High);
            Assert.Equal(3, device.ReadByte(Register.OLAT));
        }