Hardware/LPC/IT87XX.cs
changeset 228 458a6c3de579
parent 195 0ee888c485d5
child 236 763675f19ff4
     1.1 --- a/Hardware/LPC/IT87XX.cs	Sun Oct 17 08:21:33 2010 +0000
     1.2 +++ b/Hardware/LPC/IT87XX.cs	Sun Oct 17 16:04:19 2010 +0000
     1.3 @@ -45,6 +45,9 @@
     1.4      private readonly Chip chip;
     1.5      private readonly byte version;
     1.6  
     1.7 +    private readonly ushort gpioAddress;
     1.8 +    private readonly int gpioCount;
     1.9 +
    1.10      private readonly ushort addressReg;
    1.11      private readonly ushort dataReg;
    1.12  
    1.13 @@ -77,16 +80,31 @@
    1.14        byte value = WinRing0.ReadIoPortByte(dataReg);
    1.15        valid = register == WinRing0.ReadIoPortByte(addressReg);
    1.16        return value;
    1.17 -    } 
    1.18 +    }
    1.19  
    1.20 -    public IT87XX(Chip chip, ushort address, byte version) {
    1.21 +    public byte? ReadGPIO(int index) {
    1.22 +      if (index >= gpioCount)
    1.23 +        return null;
    1.24 +
    1.25 +      return WinRing0.ReadIoPortByte((ushort)(gpioAddress + index));
    1.26 +    }
    1.27 +
    1.28 +    public void WriteGPIO(int index, byte value) {
    1.29 +      if (index >= gpioCount)
    1.30 +        return;
    1.31 +
    1.32 +      WinRing0.WriteIoPortByte((ushort)(gpioAddress + index), value);
    1.33 +    }
    1.34 +
    1.35 +    public IT87XX(Chip chip, ushort address, ushort gpioAddress, byte version) {
    1.36        
    1.37        this.address = address;
    1.38        this.chip = chip;
    1.39        this.version = version;
    1.40        this.addressReg = (ushort)(address + ADDRESS_REGISTER_OFFSET);
    1.41        this.dataReg = (ushort)(address + DATA_REGISTER_OFFSET);
    1.42 -      
    1.43 +      this.gpioAddress = gpioAddress;
    1.44 +
    1.45        // Check vendor id
    1.46        bool valid;
    1.47        byte vendorId = ReadByte(VENDOR_ID_REGISTER, out valid);       
    1.48 @@ -109,6 +127,20 @@
    1.49        } else {
    1.50          voltageGain = 0.016f;
    1.51        }
    1.52 +
    1.53 +      // Set the number of GPIO sets
    1.54 +      switch (chip) {
    1.55 +        case Chip.IT8712F:
    1.56 +        case Chip.IT8716F:
    1.57 +        case Chip.IT8718F:
    1.58 +        case Chip.IT8726F:
    1.59 +          gpioCount = 5;
    1.60 +          break;
    1.61 +        case Chip.IT8720F:
    1.62 +        case Chip.IT8721F:
    1.63 +          gpioCount = 8;
    1.64 +          break;
    1.65 +      }
    1.66      }
    1.67  
    1.68      public Chip Chip { get { return chip; } }
    1.69 @@ -126,6 +158,8 @@
    1.70          version.ToString("X", CultureInfo.InvariantCulture));
    1.71        r.Append("Base Address: 0x"); r.AppendLine(
    1.72          address.ToString("X4", CultureInfo.InvariantCulture));
    1.73 +      r.Append("GPIO Address: 0x"); r.AppendLine(
    1.74 +        gpioAddress.ToString("X4", CultureInfo.InvariantCulture));
    1.75        r.AppendLine();
    1.76  
    1.77        if (!WinRing0.WaitIsaBusMutex(100))
    1.78 @@ -150,6 +184,16 @@
    1.79        }
    1.80        r.AppendLine();
    1.81  
    1.82 +      r.AppendLine("GPIO Registers");
    1.83 +      r.AppendLine();
    1.84 +      for (int i = 0; i < gpioCount; i++) {
    1.85 +        r.Append(" ");
    1.86 +        r.Append(ReadGPIO(i).Value.ToString("X2",
    1.87 +          CultureInfo.InvariantCulture));
    1.88 +      }
    1.89 +      r.AppendLine();
    1.90 +      r.AppendLine();
    1.91 +
    1.92        WinRing0.ReleaseIsaBusMutex();
    1.93  
    1.94        return r.ToString();