Overview

This module contains functions for accessing the CPU's PIO (Programmable Input Output) pins. It contains two set of functions with identical names and behaviour. One set groups the functions used to access individual pins from ports, the other groups the functions used to access full ports.

With the pio module, you specifiy names of ports as they appear in your eLua's CPU datasheet. For example, if your CPU's ports are named PA, PB and PC, you can reffer to them using pio.PA, pio.PB and pio.PC, respectively. If your CPU uses P0, P1, P2 instead of PA, PB and PC, you can simply use pio.P0, pio.P1 and pio.P2 instead.

You can also reffer to individual pins instead of ports. With the same notation as above, pio.PA_0 refers to the first pin of port PA, P0_15 refers to the 16th pin of port P0 and so on.

Functions

pio.pin.setdir( direction, pin1, pin2, ..., pinn )

Set pin(s) direction

Arguments:

  • direction - the pin direction, can be either pio.INPUT or pio.OUTPUT
  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optional) - the n-th pin

Returns: nothing.

pio.pin.setpull( type, pin1, pin2, ..., pinn )

Enable/disable pullups/pulldowns on the specified pin(s)

Arguments:

  • type - 'pull' type, can be either pio.PULLUP to enable pullups, pio.PULLDOWN to enable pulldowns, or pio.NOPULL to disable both pullups and pulldowns
  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optional) - the n-th pin

Returns: nothing.

pio.pin.setval( value, pin1, pin2, ..., pinn )

Set pin(s) value

Arguments:

  • value - pin value, can be either 0 or 1
  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optional) - the n-th pin

Returns: nothing.

val1, val2, ..., valn = pio.pin.getval( pin1, pin2, ..., pinn )

Get value of pin(s)

Arguments:

  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optional) - the n-th pin

Returns: The value(s) of the pin(s), either 0 or 1

pio.pin.sethigh( pin1, pin2, ..., pinn )

Set pin(s) to 1 (high)

Arguments:

  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optinoal) - the n-th pin

Returns: nothing.

pio.pin.setlow( pin1, pin2, ..., pinn )

Set pin(s) to 0 (low)

Arguments:

  • pin1 - the first pin
  • pin2 (optional) - the second pin
  • pinn (optinoal) - the n-th pin

Returns: nothing.

pio.port.setdir( direction, port1, port2, ..., portn )

Set port(s) direction

Arguments:

  • direction - the port direction, can be either pio.INPUT or pio.OUTPUT
  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optional) - the n-th port

Returns: nothing.

pio.port.setpull( type, port1, port2, ..., portn )

Enable/disable pullups/pulldowns on the specified port(s)

Arguments:

  • type - 'pull' type, can be either pio.PULLUP to enable pullups, pio.PULLDOWN to enable pulldowns, or pio.NOPULL to disable both pullups and pulldowns
  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optional) - the n-th port

Returns: nothing.

pio.port.setval( value, port1, port2, ..., portn )

Set port(s) value

Arguments:

  • value - port value
  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optional) - the n-th port

Returns: nothing.

val1, val2, ..., valn = pio.port.getval( port1, port2, ..., portn )

Get value of port(s)

Arguments:

  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optional) - the n-th port

Returns: The value(s) of the port(s)

pio.port.sethigh( port1, port2, ..., portn )

Set port(s) to all 1 (high)

Arguments:

  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optinoal) - the n-th port

Returns: nothing.

pio.port.setlow( port1, port2, ..., portn )

Set port(s) to all 0 (low)

Arguments:

  • port1 - the first port
  • port2 (optional) - the second port
  • portn (optinoal) - the n-th port

Returns: nothing.