title: Programming GPIO pins on a FINTEK F81866A chipset
body: <p>I have a <a href="http://www.cincoze.com/goods_info.php?id=10" rel="nofollow noreferrer">Cincoze DE-1000</a> industrial PC, that features a <a href="http://www.fintek.com.tw/index.php/i-o-controller-and-i-f-management/item/59-f81866a" rel="nofollow noreferrer">Fintek F81866A</a> chipset. I have to manage the DIO pins to read the input from a phisical button and to set on/off a LED. I have experience in C++ programming, but not at low/hardware level.</p>
  
  <p>On the documentation accompanying the PC, there is the following C code:</p>
  
  <pre><code>#define AddrPort 0x4E
  #define DataPort 0x4F
  
  //&lt;Enter the Extended Function Mode&gt;
  WriteByte(AddrPort, 0x87)
  WriteByte(AddrPort, 0x87) //Must write twice to entering Extended mode
  
  //&lt;Select Logic Device&gt;
  WriteByte(AddrPort, 0x07)
  WriteByte(DataPort, 0x06)
  //Select logic device 06h
  
  //&lt;Input Mode Selection&gt; //Set GP74 to GP77 input mode
  WriteByte(AddrPort, 0x80) //Select configuration register 80h
  WriteByte(DataPort, 0x0X)
  //Set (bit 4~7) = 0 to select GP 74~77 as Input mode.
  
  //&lt;input Value&gt;
  WriteByte(AddrPort, 0x82) // Select configuration register 82h
  ReadByte(DataPort, Value) // Read bit 4~7(0xFx)= GP74 ~77 as High.
  
  //&lt;Leave the Extended Function Mode&gt;
  WriteByte(AddrPort, 0xAA)
  </code></pre>
  
  <p>As far as I understood, the above code should read the value of the four input PINs (so it should read 1 for each PIN), but I am really struggling to understand how it actually works. I have understood the logic (selecting an address and reading/writing an hex value to it), but I cannot figure out what kind of C instructions <code>WriteByte()</code> and <code>ReadByte()</code> are. Also, I do not understand where <code>Value</code> in the line <code>ReadByte(DataPort, Value)</code> comes from. It should read the 4 PINs all together, so it should be some kind of "byte" type and it should contain 1 in its bits 4-7, but again I cannot really grasp the meaning of that line.</p>
  
  <p>I have found an <a href="https://stackoverflow.com/questions/24484193/fintek-f71869a-gpio-control">answer for a similar chip</a>, but it did not help me in understanding.</p>
  
  <p>Please advice me or point me to some relevant documentation.</p>