diff -r 97757a798918 -r 458a6c3de579 Hardware/LPC/IT87XX.cs --- a/Hardware/LPC/IT87XX.cs Sun Oct 17 08:21:33 2010 +0000 +++ b/Hardware/LPC/IT87XX.cs Sun Oct 17 16:04:19 2010 +0000 @@ -45,6 +45,9 @@ private readonly Chip chip; private readonly byte version; + private readonly ushort gpioAddress; + private readonly int gpioCount; + private readonly ushort addressReg; private readonly ushort dataReg; @@ -77,16 +80,31 @@ byte value = WinRing0.ReadIoPortByte(dataReg); valid = register == WinRing0.ReadIoPortByte(addressReg); return value; - } + } - public IT87XX(Chip chip, ushort address, byte version) { + public byte? ReadGPIO(int index) { + if (index >= gpioCount) + return null; + + return WinRing0.ReadIoPortByte((ushort)(gpioAddress + index)); + } + + public void WriteGPIO(int index, byte value) { + if (index >= gpioCount) + return; + + WinRing0.WriteIoPortByte((ushort)(gpioAddress + index), value); + } + + public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version) { this.address = address; this.chip = chip; this.version = version; this.addressReg = (ushort)(address + ADDRESS_REGISTER_OFFSET); this.dataReg = (ushort)(address + DATA_REGISTER_OFFSET); - + this.gpioAddress = gpioAddress; + // Check vendor id bool valid; byte vendorId = ReadByte(VENDOR_ID_REGISTER, out valid); @@ -109,6 +127,20 @@ } else { voltageGain = 0.016f; } + + // Set the number of GPIO sets + switch (chip) { + case Chip.IT8712F: + case Chip.IT8716F: + case Chip.IT8718F: + case Chip.IT8726F: + gpioCount = 5; + break; + case Chip.IT8720F: + case Chip.IT8721F: + gpioCount = 8; + break; + } } public Chip Chip { get { return chip; } } @@ -126,6 +158,8 @@ version.ToString("X", CultureInfo.InvariantCulture)); r.Append("Base Address: 0x"); r.AppendLine( address.ToString("X4", CultureInfo.InvariantCulture)); + r.Append("GPIO Address: 0x"); r.AppendLine( + gpioAddress.ToString("X4", CultureInfo.InvariantCulture)); r.AppendLine(); if (!WinRing0.WaitIsaBusMutex(100)) @@ -150,6 +184,16 @@ } r.AppendLine(); + r.AppendLine("GPIO Registers"); + r.AppendLine(); + for (int i = 0; i < gpioCount; i++) { + r.Append(" "); + r.Append(ReadGPIO(i).Value.ToString("X2", + CultureInfo.InvariantCulture)); + } + r.AppendLine(); + r.AppendLine(); + WinRing0.ReleaseIsaBusMutex(); return r.ToString();