Skip to content

Commit cfdd0ab

Browse files
committed
docs/gpio: add documentation.
1 parent 0b0644e commit cfdd0ab

File tree

2 files changed

+61
-8
lines changed

2 files changed

+61
-8
lines changed

amaranth_soc/gpio.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ class Input(csr.Register, access="r"):
128128
"""Input register.
129129
130130
This :class:`~.csr.reg.Register` contains an array of ``pin_count`` read-only fields. Each
131-
field is 1-bit wide and is driven by the input of its associated pin in the
132-
:attr:`Peripheral.pins` array.
131+
field is 1-bit wide and is driven by the input of its associated pin in the ``pins`` array
132+
of the peripheral.
133133
134134
Values sampled from pin inputs go through :attr:`Peripheral.input_stages` synchronization
135135
stages (on a rising edge of ``ClockSignal("sync")``) before reaching the register.
@@ -170,8 +170,8 @@ class Output(csr.Register, access="rw"):
170170
"""Output register.
171171
172172
This :class:`~.csr.reg.Register` contains an array of ``pin_count`` read/write fields. Each
173-
field is 1-bit wide and drives the output of its associated pin in the
174-
:attr:`Peripheral.pins` array, depending on its associated :class:`~Peripheral.Mode` field.
173+
field is 1-bit wide and drives the output of its associated pin in the ``pins`` array of the
174+
peripheral, depending on its associated :class:`~Peripheral.Mode` field.
175175
176176
----
177177

docs/gpio.rst

+57-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,67 @@
11
GPIO
22
====
33

4-
.. warning::
5-
6-
This manual is a work in progress and is seriously incomplete!
7-
84
.. py:module:: amaranth_soc.gpio
95
106
The :mod:`amaranth_soc.gpio` module provides a basic GPIO peripheral.
117

8+
.. testsetup::
9+
10+
from amaranth import *
11+
from amaranth.lib import io, wiring
12+
from amaranth.lib.wiring import In, Out, flipped, connect
13+
14+
from amaranth_soc import csr, gpio
15+
16+
17+
Introduction
18+
------------
19+
20+
`GPIO <https://en.wikipedia.org/wiki/General-purpose_input/output>`_ peripherals are commonly used
21+
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 :ref:`CSR bus<csr-bus-introduction>`.
22+
23+
Example
24+
+++++++
25+
26+
This example shows a GPIO peripheral being used to drive four LEDs:
27+
28+
.. testcode::
29+
30+
class MySoC(wiring.Component):
31+
def elaborate(self, platform):
32+
m = Module()
33+
34+
m.submodules.led_gpio = led_gpio = gpio.Peripheral(pin_count=4, addr_width=8,
35+
data_width=8)
36+
37+
for n in range(4):
38+
led = io.Buffer("o", platform.request("led", n, dir="-"))
39+
connect(m, led_gpio.pins[n], led)
40+
41+
m.submodules.csr_decoder = csr_decoder = csr.Decoder(addr_width=31, data_width=8)
42+
csr_decoder.add(led_gpio.bus, addr=0x1000, name="led_gpio")
43+
44+
# ...
45+
46+
return m
47+
48+
Pin modes
49+
---------
50+
1251
.. autoclass:: PinMode()
52+
53+
Pin interface
54+
-------------
55+
1356
.. autoclass:: PinSignature()
57+
58+
Peripheral
59+
----------
60+
61+
.. autoclass:: amaranth_soc.gpio::Peripheral.Mode()
62+
.. autoclass:: amaranth_soc.gpio::Peripheral.Input()
63+
.. autoclass:: amaranth_soc.gpio::Peripheral.Output()
64+
.. autoclass:: amaranth_soc.gpio::Peripheral.SetClr()
65+
1466
.. autoclass:: Peripheral()
67+
:no-members:

0 commit comments

Comments
 (0)