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),
to be driven weakly using a pull resistor (A0=H or A0=L), undriven (A0=Z), or
specified without a value (A0) to sample a pin. The actions are executed in the order they
are provided on the command line.
Socket pin actions may be used to interface with the applet from an external application.
Send each action over the socket in the same format as the CLI pin action described above,
terminating with a \n. (Spaces are ignored.) When sampling a pin, the value is sent back
over the socket terminated with a n`, otherwise no response is provided.
usage: glasgow run control-gpio [-h] [-V VOLTS] --pins PINS [--socket SOCKET]
[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 <volts>, --voltage <volts>¶
pin power (range: 1.8..5 V, or ‘S<port>’ to follow the voltage sensed on a port; default: unchanged)
- --pins <pins>¶
bind pins to sample and drive to PINS (required)
- --socket <socket>¶
listen at ENDPOINT, either unix:PATH or tcp:HOST:PORT
API reference¶
- exception glasgow.applet.control.gpio.GPIOException¶
- class glasgow.applet.control.gpio.ControlGPIOPorts(*, supply: glasgow.abstract.GlasgowSupply, pins: amaranth.lib.io.PortLike)¶
- supply: GlasgowSupply¶
pin power
- pins: PortLike¶
pins to sample and drive
- class glasgow.applet.control.gpio.GPIOInterface(logger: Logger, assembly: AbstractAssembly, port: PortLike, *, pins: Sequence[GlasgowPin] | None = None)¶
Sample and drive the pins of a port.
portis a port of any width; pin0is its first pin. Use it with, for example, thepinsof anControlGPIOPorts, or a single-pin field of another applet’s ports.pinsoptionally lists the pins that make upport, in order. It is required to change pulls at runtime withpull(); pulls that are fixed for the applet are better declared withpull=on the field.- async pull(index: int, state: PullState | str)¶
Configure pull-up or pull-down for pin
index.- Raises:
GPIOException – If the interface was constructed without
pins.
- async input(index: int)¶
Configure pin
indexas input.- Raises:
IndexError – If
indexdoes not specify a valid pin index.
- async output(index: int, value: bool)¶
Configure pin
indexas output, initially drivingvalue.- Raises:
IndexError – If
indexdoes not specify a valid pin index.
- async get(index: int) bool¶
Sample state of pin
index.- Raises:
IndexError – If
indexdoes not specify a valid pin index.
- async set(index: int, value: bool)¶
Update value driven by pin
indexto bevalue.- Raises:
IndexError – If
indexdoes not specify a valid pin index.GPIOException – If pin
indexis 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.