コード例 #1
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));
        }
コード例 #2
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));
        }