I am trying to understand the concept of using ports and pins. I understood that smaller bit ports have priority that if the idea is driving a single device which needs 1 line I should take a 1 bit port as higher bit ports will send/receive data on more than 1 physical pins of the chip. Normally I need just 3 free single bit ports (I am integrating parts of the xcore200 MC Audio board with another device), but it got me interested and I thought:"hmmm if I understand this I could add a couple of headers connected to free pins, in case I decide to connect something in the future". Besides the regular unused pins from on the schematic I got rid of the ethernet, DAC, ADC, MIDI, the USB A, and complicated clock scheme ( using just a single oscillator now meaning there is no PLL select, no MCLK_FSEL). As I was freeing pins I noticed for example this:X0D28 4F0 8C2 16B2 USB_SEL0X0D29 4F1 8C3 16B3 USB_SEL1X0D30 4F2 8C4 16B4 VBUS_OUT_ENX0D31 4F3 8C5 16B5 PLL_SELECT

So 4 pins are physically connected to 2 different devices sending different signals. But it is a 4-bit port...... and all of these require just a single 0 or 1. How did they make this work. Or am I misunderstanding how ports and pins are used?

You have a 4 bit port that can be referenced as 4F block. The port pins do not care where they are connected but access to each pin can be as follows:

if you output a "0" to bit0 of 4F then X0D28 will be logic low.if you output a "1" to bit0 of 4F then X0D28 will be logic high.

if you output a "0" to bit1 of 4F then X0D29 will be logic low.if you output a "1" to bit1 of 4F then X0D29 will be logic high.

if you output a "0" to bit2 of 4F then X0D30 will be logic low.if you output a "1" to bit2 of 4F then X0D30 will be logic high.

if you output a "0" to bit3 of 4F then X0D31 will be logic low.if you output a "1" to bit3 of 4F then X0D31 will be logic high.

To isolate each and configure each port bit, there are many solutions and the methods are common to C programming. As my prof used to say, and probably still does, do not be fancy with the coding but make it work correctly.

Okay so I guess- using this library would allow to easily use a multiple-bit port's pins separately. That would mean that I could potentially connect all unused pins to headers (stress goes on "potentially"). So at whatever part of the code I am and whatever the current statues of the bit stream is, for example 1100, if i send the order "P4F <:= make_bit0_high;" - the output on the port would become 1101, keeping the other pins intact. That would be quite amazing.

I have not reviewed the GPIO library but suspecting that is the intent...to make bit level manipulation easier for the user.

In summary, you always start with a global value for that port and then either mask off a bit or bits to force that bit or bits to 0. Respectively you take the original global value and OR the proper bit weight to turn ON that bit. Yes, you should be fine to consider that library and review the example supplied with that download. It should be pretty straightforward to do your own but will save some brain cells and at least a few hours of coding to use a proven to work library.