GPIO
The amaranth_soc.gpio module provides a basic GPIO peripheral.
Introduction
GPIO peripherals are commonly used to interface a SoC (usually a microcontroller) with a variety of external circuitry. This module contains a GPIO peripheral which can be connected to a CSR bus.
Example
This example shows a GPIO peripheral being used to drive four LEDs:
class MySoC(wiring.Component):
def elaborate(self, platform):
m = Module()
m.submodules.led_gpio = led_gpio = gpio.Peripheral(pin_count=4, addr_width=8,
data_width=8)
for n in range(4):
led = io.Buffer("o", platform.request("led", n, dir="-"))
connect(m, led_gpio.pins[n], led)
m.submodules.csr_decoder = csr_decoder = csr.Decoder(addr_width=31, data_width=8)
csr_decoder.add(led_gpio.bus, addr=0x1000, name="led_gpio")
# ...
return m
Pin modes
- class amaranth_soc.gpio.PinMode
GPIO pin mode.
The 2-bit values of this enumeration can be written to a
Peripheral.Modefield to configure the pins of aPeripheral.- INPUT_ONLY = 0
Input-only mode.
The pin output is disabled but remains connected to its
Peripheral.Outputfield. ItsPeripheral.alt_modebit is wired to 0.
- PUSH_PULL = 1
Push-pull mode.
The pin output is enabled and connected to its
Peripheral.Outputfield. ItsPeripheral.alt_modebit is wired to 0.
- OPEN_DRAIN = 2
Open-drain mode.
The pin output is enabled when the value of its
Peripheral.Outputfield is 0, and is itself wired to 0. ItsPeripheral.alt_modebit is wired to 0.
- ALTERNATE = 3
Alternate mode.
The pin output is disabled but remains connected to its
Peripheral.Outputfield. ItsPeripheral.alt_modebit is wired to 1.
Pin interface
Peripheral
- class Peripheral.Mode
A CSR register.
- Parameters:
fields (
dictorlistorField) – Collection of register fields. IfNone(default), a dict is populated from Python variable annotations.fieldsis used to create aFieldActionMap,FieldActionArray, orFieldAction, depending on its type (dict, list, or Field).
Interface attributes
- element
Element Interface between this register and a CSR bus primitive.
- Attributes:
field (
FieldActionMaporFieldActionArrayorFieldAction) – Collection of field instances.f (
FieldActionMaporFieldActionArrayorFieldAction) – Shorthand forRegister.field.
- raises TypeError:
- raises ValueError:
If
fieldsis notNoneand at least one variable annotation is aField.- raises ValueError:
If
element.accessis not readable and at least one field is readable.- raises ValueError:
If
element.accessis not writable and at least one field is writable.
- class Peripheral.Input
A CSR register.
- Parameters:
fields (
dictorlistorField) – Collection of register fields. IfNone(default), a dict is populated from Python variable annotations.fieldsis used to create aFieldActionMap,FieldActionArray, orFieldAction, depending on its type (dict, list, or Field).
Interface attributes
- element
Element Interface between this register and a CSR bus primitive.
- Attributes:
field (
FieldActionMaporFieldActionArrayorFieldAction) – Collection of field instances.f (
FieldActionMaporFieldActionArrayorFieldAction) – Shorthand forRegister.field.
- raises TypeError:
- raises ValueError:
If
fieldsis notNoneand at least one variable annotation is aField.- raises ValueError:
If
element.accessis not readable and at least one field is readable.- raises ValueError:
If
element.accessis not writable and at least one field is writable.
- class Peripheral.Output
A CSR register.
- Parameters:
fields (
dictorlistorField) – Collection of register fields. IfNone(default), a dict is populated from Python variable annotations.fieldsis used to create aFieldActionMap,FieldActionArray, orFieldAction, depending on its type (dict, list, or Field).
Interface attributes
- element
Element Interface between this register and a CSR bus primitive.
- Attributes:
field (
FieldActionMaporFieldActionArrayorFieldAction) – Collection of field instances.f (
FieldActionMaporFieldActionArrayorFieldAction) – Shorthand forRegister.field.
- raises TypeError:
- raises ValueError:
If
fieldsis notNoneand at least one variable annotation is aField.- raises ValueError:
If
element.accessis not readable and at least one field is readable.- raises ValueError:
If
element.accessis not writable and at least one field is writable.
- class Peripheral.SetClr
A CSR register.
- Parameters:
fields (
dictorlistorField) – Collection of register fields. IfNone(default), a dict is populated from Python variable annotations.fieldsis used to create aFieldActionMap,FieldActionArray, orFieldAction, depending on its type (dict, list, or Field).
Interface attributes
- element
Element Interface between this register and a CSR bus primitive.
- Attributes:
field (
FieldActionMaporFieldActionArrayorFieldAction) – Collection of field instances.f (
FieldActionMaporFieldActionArrayorFieldAction) – Shorthand forRegister.field.
- raises TypeError:
- raises ValueError:
If
fieldsis notNoneand at least one variable annotation is aField.- raises ValueError:
If
element.accessis not readable and at least one field is readable.- raises ValueError:
If
element.accessis not writable and at least one field is writable.
- class amaranth_soc.gpio.Peripheral