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. UART GPIO Configuration provides the details.

 

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.