summaryrefslogtreecommitdiffstatshomepage
path: root/docs/library/rp2.PIO.rst
blob: f922456c8c4838d4d8954cb443c6d96c6ace82f1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
.. currentmodule:: rp2
.. _rp2.PIO:

class PIO -- advanced PIO usage
===============================

The :class:`PIO` class gives access to an instance of the RP2040's PIO
(programmable I/O) interface.

The preferred way to interact with PIO is using :class:`rp2.StateMachine`, the
PIO class is for advanced use.

For assembling PIO programs, see :func:`rp2.asm_pio`.


Constructors
------------

.. class:: PIO(id)

    Gets the PIO instance numbered *id*. The RP2040 has two PIO instances,
    numbered 0 and 1.

    Raises a ``ValueError`` if any other argument is provided.


Methods
-------

.. method:: PIO.gpio_base([base])

    Query and optionally set the current GPIO base for this PIO instance.

    If an argument is given then it must be a pin (or integer corresponding to a pin
    number), restricted to either GPIO0 or GPIO16.  The GPIO base will then be set to
    that pin.  Setting the GPIO base must be done before any programs are added or state
    machines created.

    Returns the current GPIO base pin.

.. method:: PIO.add_program(program)

    Add the *program* to the instruction memory of this PIO instance.

    The amount of memory available for programs on each PIO instance is
    limited. If there isn't enough space left in the PIO's program memory
    this method will raise ``OSError(ENOMEM)``.

.. method:: PIO.remove_program([program])

    Remove *program* from the instruction memory of this PIO instance.

    If no program is provided, it removes all programs.

    It is not an error to remove a program which has already been removed.

.. method:: PIO.state_machine(id, [program, ...])

    Gets the state machine numbered *id*. On the RP2040, each PIO instance has
    four state machines, numbered 0 to 3.

    Optionally initialize it with a *program*: see `StateMachine.init`.

    >>> rp2.PIO(1).state_machine(3)
    StateMachine(7)

.. method:: PIO.irq(handler=None, trigger=IRQ_SM0|IRQ_SM1|IRQ_SM2|IRQ_SM3, hard=False)

    Returns the IRQ object for this PIO instance.

    MicroPython only uses IRQ 0 on each PIO instance. IRQ 1 is not available.

    Optionally configure it.


Constants
---------

.. data:: PIO.IN_LOW
          PIO.IN_HIGH
          PIO.OUT_LOW
          PIO.OUT_HIGH

    These constants are used for the *out_init*, *set_init*, and *sideset_init*
    arguments to `asm_pio`.

.. data:: PIO.SHIFT_LEFT
          PIO.SHIFT_RIGHT

    These constants are used for the *in_shiftdir* and *out_shiftdir* arguments
    to `asm_pio` or `StateMachine.init`.

.. data:: PIO.JOIN_NONE
          PIO.JOIN_TX
          PIO.JOIN_RX

    These constants are used for the *fifo_join* argument to `asm_pio`.

.. data:: PIO.IRQ_SM0
          PIO.IRQ_SM1
          PIO.IRQ_SM2
          PIO.IRQ_SM3

    These constants are used for the *trigger* argument to `PIO.irq`.