control-gpio

CLI reference

glasgow run control-gpio

Sample and drive individual I/O pins via the CLI, the REPL, or a script.

CLI pin actions can be used to configure a pin to be driven strongly (A0=0 or A0=1), or to be driven weakly using a pull resistor (A0=H or A0=L). The actions are executed in the order they are provided on the command line.

usage: glasgow run control-gpio [-h] [-V SPEC] --pins PINS [PIN-ACTION ...]
pin-action

pins to drive or sample, e.g.: ‘A0=1’, ‘A1=L’, ‘B5’

-h, --help

show this help message and exit

-V <spec>, --voltage <spec>

configure I/O port voltage to SPEC (e.g.: ‘3.3’, ‘A=5.0,B=3.3’, ‘A=SA’)

--pins <pins>

bind the applet I/O lines ‘pins’ to PINS (required)

API reference

exception glasgow.applet.control.gpio.GPIOException
class glasgow.applet.control.gpio.GPIOInterface(logger: Logger, assembly: AbstractAssembly, *, pins: tuple[GlasgowPin])
property count: int

Number of pins.

async pull(index: int, state: PullState | str)

Configure pull-up or pull-down for pin index.

async input(index: int)

Configure pin index as input.

Raises:

IndexError – If index does not specify a valid pin index.

async output(index: int, value: bool)

Configure pin index as output, initially driving value.

Raises:

IndexError – If index does not specify a valid pin index.

async get(index: int) bool

Sample state of pin index.

Raises:

IndexError – If index does not specify a valid pin index.

async set(index: int, value: bool)

Update value driven by pin index to be value.

Raises:
  • IndexError – If index does not specify a valid pin index.

  • GPIOException – If pin index is not configured as an ouptut.

async get_all() int

Sample state of every pin simultaneously.

In the returned value, the least significant bit corresponds to the first pin in the port provided to the constructor.

async set_all(value: int)

Update value of every pin simultaneously.

In value, the least significant bit corresponds to the first pin in the port provided to the constructor. The bits corresponding to pins that are configured as inputs, as well as the bits that do not correspond to any pins, are ignored.