|
1 | 1 | GPIO
|
2 | 2 | ====
|
3 | 3 |
|
4 |
| -.. warning:: |
5 |
| - |
6 |
| - This manual is a work in progress and is seriously incomplete! |
7 |
| - |
8 | 4 | .. py:module:: amaranth_soc.gpio
|
9 | 5 |
|
10 | 6 | The :mod:`amaranth_soc.gpio` module provides a basic GPIO peripheral.
|
11 | 7 |
|
| 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 | + |
12 | 51 | .. autoclass:: PinMode()
|
| 52 | + |
| 53 | +Pin interface |
| 54 | +------------- |
| 55 | + |
13 | 56 | .. 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 | + |
14 | 66 | .. autoclass:: Peripheral()
|
| 67 | + :no-members: |
0 commit comments