GPIO Type

Top  Previous  Next

As for as GPIO lines go, Tibbo devices fall into two categories:

Devices with unidirectional GPIO lines: such devices require explicit configuration of each GPIO line as input or output; and

Devices with bidirectional GPIO lines: GPIO lines of these devices work as outputs and inputs at the same time.

To find out the type of GPIO lines on your device, refer to its platform documentation (for example, EM1000's is here).

 

Devices with unidirectional GPIO lines

On such devices you need to explicitly enable or disable the output driver of each I/O line (controlled by the io. object). When the device boots up all pins are configured as inputs. If you want to use any particular I/O pin as the output, enable this pin's output driver first (set io.enabled= 1-YES):

 

 

...

io.num= PL_IO_NUM_5        'select the line

io.enabled= YES                'enable output driver (you need to do this only once)

io.state= LOW                'set the state

...

 

 

note_warning-wt

Make sure that your external circuitry does not attempt to drive the I/O lines that have their output drivers enabled. Severe damage to the device and/or your circuitry may occur if this happens!

 

When the driver is enabled (io.enabled= 1-YES) and you read the state of the pin, you get back the state of your own output driver. To turn the line into an input, switch the output driver off (ser.enabled= 0- NO). This will allow you to sense the state of the external signal applied to the I/O line:

 

 

...

io.num= PL_IO_NUM_4        'just to select some line as an example

io.enabled= NO                'now the output driver is off

x=io.state                        'read line state into x

...

 

 

There is the io.portenabled property as well. It allows simultaneous configuration of all GPIO lines in the 8-bit I/O port.

Serial port lines also require proper configuration. Depending on the mode of the serial port (see ser.mode) you need to set the following:

 

ser.mode

TX/W1out/dout output

RX/W1in/din input

RTS/W0out/cout output

CTS/W0&1in/cin input

0- PL_SER_MODE_UART

Will auto-configure as output(1)

Will auto-configure as input(1)

Requires configuration as output(2)

 

Requires configuration as input(2)

1- PL_SER_MODE_WIEGAND

Requires configuration as output

Requires configuration as input

2- PL_SER_MODE_CLOCKDATA

Notes:

1. When This line does not require configuration, it will be configured automatically as input or output when the port is opened. When the port is closed the line will return to the input/output and high/low state it had before the port was opened.

2.If RTS/CTS remapping is supported, you need to configure the I/O pin to which this line of the serial port is currently mapped.

 

Devices with bidirectional GPIO lines

I/O lines of these devices do not require explicit configuration as inputs or outputs. All lines are "quasi-bidirectional" and can be viewed as open collector outputs with weak pull-up resistors. To "measure" an external signal applied to an I/O line, set this line to HIGH first, then read the state of the line. It is OK to drive the line LOW externally when the same line outputs HIGH internally. Io.enabled and io.portenabled properties exist, but only for compatibility with other platforms. Writing to these properties has no effect and reading them always returns 1- YES and 255 (all lines enabled) correspondingly.

To sense the state of the external signal applied to the I/O line, set the line to HIGH first:

 

 

...

io.num= PL_IO_NUM        'just to select some line as an example

io.state= HIGH        'now we can read the line

x=io.state                'read line state into x

...

 

 

Serial port lines of devices with bidirectional GPIO do not require configuration as well.