Skip to content

Commit 16c8466

Browse files
committed
Update PIOASMEmit and StateMachine type hints to use _PIO_ASM_Program
Signed-off-by: Jos Verlinde <Jos.Verlinde@microsoft.com>
1 parent ea64d35 commit 16c8466

File tree

4 files changed

+34
-31
lines changed

4 files changed

+34
-31
lines changed

reference/micropython/rp2/PIOASMEmit.pyi

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -117,23 +117,23 @@ class PIOASMEmit:
117117
"""
118118
...
119119

120-
def word(self, instr, label: Incomplete | None = ...) -> PIOASMEmit:
120+
def word(self, instr, label: Incomplete | None = ...) -> _PIO_ASM_Program:
121121
"""rp2.PIO instruction.
122122
123123
Stores a raw 16-bit value as an instruction in the program. This directive is
124124
invalid outside of a program.
125125
"""
126126
...
127127

128-
def nop(self) -> PIOASMEmit:
128+
def nop(self) -> _PIO_ASM_Program:
129129
"""rp2.PIO NOP instruction.
130130
131131
Assembles to mov y, y. "No operation", has no particular side effect, but a useful vehicle for a side-set
132132
operation or an extra delay.
133133
"""
134134
...
135135

136-
def jmp(self, condition, label: Incomplete | None = ...) -> PIOASMEmit:
136+
def jmp(self, condition, label: Incomplete | None = ...) -> _PIO_ASM_Program:
137137
"""rp2.PIO JMP instruction.
138138
139139
Set program counter to Address if Condition is true, otherwise no operation.
@@ -168,7 +168,7 @@ class PIOASMEmit:
168168
"""
169169
...
170170

171-
def wait(self, polarity: int, src: int, index: int, /) -> PIOASMEmit:
171+
def wait(self, polarity: int, src: int, index: int, /) -> _PIO_ASM_Program:
172172
"""rp2.PIO WAIT instruction.
173173
174174
Stall until some condition is met.
@@ -203,7 +203,7 @@ class PIOASMEmit:
203203
"""
204204
...
205205

206-
def in_(self, src: int, data) -> PIOASMEmit:
206+
def in_(self, src: int, data) -> _PIO_ASM_Program:
207207
"""rp2.PIO IN instruction.
208208
209209
Shift Bit count bits from Source into the Input Shift Register (ISR).
@@ -236,7 +236,7 @@ class PIOASMEmit:
236236
"""
237237
...
238238

239-
def out(self, destination: int, bit_count: int) -> PIOASMEmit:
239+
def out(self, destination: int, bit_count: int) -> _PIO_ASM_Program:
240240
"""rp2.PIO OUT instruction.
241241
242242
Shift Bit count bits out of the Output Shift Register (OSR), and write those bits to Destination.
@@ -274,7 +274,7 @@ class PIOASMEmit:
274274
"""
275275
...
276276

277-
def push(self, value: int = ..., value2: int = ...) -> PIOASMEmit:
277+
def push(self, value: int = ..., value2: int = ...) -> _PIO_ASM_Program:
278278
"""rp2.PIO PUSH instruction.
279279
280280
Push the contents of the ISR into the RX FIFO, as a single 32-bit word. Clear ISR to all-zeroes.
@@ -293,7 +293,7 @@ class PIOASMEmit:
293293
"""
294294
...
295295

296-
def pull(self, block: int = block, timeout: int = 0) -> PIOASMEmit:
296+
def pull(self, block: int = block, timeout: int = 0) -> _PIO_ASM_Program:
297297
"""rp2.PIO PULL instruction.
298298
299299
Load a 32-bit word from the TX FIFO into the OSR.
@@ -319,7 +319,7 @@ class PIOASMEmit:
319319
"""
320320
...
321321

322-
def mov(self, dest, src, operation: int | None = None) -> PIOASMEmit:
322+
def mov(self, dest, src, operation: int | None = None) -> _PIO_ASM_Program:
323323
"""rp2.PIO MOV instruction.
324324
325325
Copy data from Source to Destination.
@@ -365,7 +365,7 @@ class PIOASMEmit:
365365
"""
366366
...
367367

368-
def irq(self, mod, index: Incomplete | None = ...) -> PIOASMEmit:
368+
def irq(self, mod, index: Incomplete | None = ...) -> _PIO_ASM_Program:
369369
"""rp2.PIO instruction.
370370
371371
Set or clear the IRQ flag selected by Index argument.
@@ -384,7 +384,7 @@ class PIOASMEmit:
384384
which are running the same program. Bit 2 (the third LSB) is unaffected by this addition.
385385
If Wait is set, Delay cycles do not begin until after the wait period elapses."""
386386

387-
def set(self, destination: int, data) -> PIOASMEmit:
387+
def set(self, destination: int, data) -> _PIO_ASM_Program:
388388
"""rp2.PIO SET instruction.
389389
390390
Write immediate value Data to Destination.

reference/micropython/rp2/StateMachine.pyi

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ from typing import Any, Optional
99
from _mpy_shed import _IRQ
1010
from _typeshed import Incomplete
1111
from machine import Pin # type: ignore
12+
from rp2 import _PIO_ASM_Program # type: ignore
1213

1314
class StateMachine:
1415
"""
@@ -22,9 +23,10 @@ class StateMachine:
2223

2324
def __init__(
2425
self,
25-
program: int,
26-
freq: int = 1,
26+
id :int,
27+
program: _PIO_ASM_Program,
2728
*,
29+
freq: int = 1,
2830
in_base: Pin | None = None,
2931
out_base: Pin | None = None,
3032
set_base: Pin | None = None,
@@ -35,11 +37,12 @@ class StateMachine:
3537
push_thresh: int | None = None,
3638
pull_thresh: int | None = None,
3739
) -> None: ...
40+
3841
def init(
3942
self,
40-
program: int,
41-
freq: int = 1,
43+
program: _PIO_ASM_Program,
4244
*,
45+
freq: int = 1,
4346
in_base: Pin | None = None,
4447
out_base: Pin | None = None,
4548
set_base: Pin | None = None,

reference/micropython/rp2/__init__.pyi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ from rp2.PIO import PIO
2727
from rp2.PIOASMEmit import PIOASMEmit
2828
from machine import Pin
2929

30-
_PIO_ASM_Program: TypeAlias = Callable
30+
_PIO_ASM_Program: TypeAlias = PIOASMEmit
3131

3232
class PIOASMError(Exception):
3333
"""
@@ -47,7 +47,7 @@ def asm_pio(
4747
push_thresh=32,
4848
pull_thresh=32,
4949
fifo_join=PIO.JOIN_NONE,
50-
) -> Callable[..., PIOASMEmit]:
50+
) -> Callable[..., _PIO_ASM_Program]:
5151
"""
5252
Assemble a PIO program.
5353

reference/micropython/rp2/asm_pio.pyi

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ from micropython import const # type: ignore
4545
if TYPE_CHECKING:
4646
# defined functions are all methods of the (frozen) class PIOASMEmit:
4747
# but also have a self method
48-
from rp2 import PIOASMEmit
48+
from rp2 import PIOASMEmit, _PIO_ASM_Program
4949

5050
# constants defined for PIO assembly
5151
# TODO: Make Final - or make const always return Final
@@ -110,15 +110,15 @@ if TYPE_CHECKING:
110110

111111
####################################################################################
112112

113-
def delay(delay: int) -> PIOASMEmit:
113+
def delay(delay: int) -> _PIO_ASM_Program:
114114
"""rp2.PIO delay modifier.
115115
116116
The delay method allows setting a delay for the current instruction,
117117
ensuring it does not exceed the maximum allowed delay.
118118
"""
119119
...
120120

121-
def side(value: int) -> PIOASMEmit:
121+
def side(value: int) -> _PIO_ASM_Program:
122122
"""rp2.PIO WRAP modifier.
123123
This is a modifier which can be applied to any instruction, and is used to control side-set pin values.
124124
value: the value (bits) to output on the side-set pins
@@ -167,23 +167,23 @@ if TYPE_CHECKING:
167167
"""
168168
...
169169

170-
def word(instr, label: Incomplete | None = ...) -> PIOASMEmit:
170+
def word(instr, label: Incomplete | None = ...) -> _PIO_ASM_Program:
171171
"""rp2.PIO instruction.
172172
173173
Stores a raw 16-bit value as an instruction in the program. This directive is
174174
invalid outside of a program.
175175
"""
176176
...
177177

178-
def nop() -> PIOASMEmit:
178+
def nop() -> _PIO_ASM_Program:
179179
"""rp2.PIO NOP instruction.
180180
181181
Assembles to mov y, y. "No operation", has no particular side effect, but a useful vehicle for a side-set
182182
operation or an extra delay.
183183
"""
184184
...
185185

186-
def jmp(condition, label: Incomplete | None = ...) -> PIOASMEmit:
186+
def jmp(condition, label: Incomplete | None = ...) -> _PIO_ASM_Program:
187187
"""rp2.PIO JMP instruction.
188188
189189
Set program counter to Address if Condition is true, otherwise no operation.
@@ -218,7 +218,7 @@ if TYPE_CHECKING:
218218
"""
219219
...
220220

221-
def wait(polarity: int, src: int, index: int, /) -> PIOASMEmit:
221+
def wait(polarity: int, src: int, index: int, /) -> _PIO_ASM_Program:
222222
"""rp2.PIO WAIT instruction.
223223
224224
Stall until some condition is met.
@@ -253,7 +253,7 @@ if TYPE_CHECKING:
253253
"""
254254
...
255255

256-
def in_(src, data) -> PIOASMEmit:
256+
def in_(src, data) -> _PIO_ASM_Program:
257257
"""rp2.PIO IN instruction.
258258
259259
Shift Bit count bits from Source into the Input Shift Register (ISR).
@@ -286,7 +286,7 @@ if TYPE_CHECKING:
286286
"""
287287
...
288288

289-
def out(destination: int, bit_count: int) -> PIOASMEmit:
289+
def out(destination: int, bit_count: int) -> _PIO_ASM_Program:
290290
"""rp2.PIO OUT instruction.
291291
292292
Shift Bit count bits out of the Output Shift Register (OSR), and write those bits to Destination.
@@ -324,7 +324,7 @@ if TYPE_CHECKING:
324324
"""
325325
...
326326

327-
def push(value: int = ..., value2: int = ...) -> PIOASMEmit:
327+
def push(value: int = ..., value2: int = ...) -> _PIO_ASM_Program:
328328
"""rp2.PIO PUSH instruction..
329329
330330
Push the contents of the ISR into the RX FIFO, as a single 32-bit word. Clear ISR to all-zeroes.
@@ -343,7 +343,7 @@ if TYPE_CHECKING:
343343
"""
344344
...
345345

346-
def pull(block: int = block, timeout: int = 0) -> PIOASMEmit:
346+
def pull(block: int = block, timeout: int = 0) -> _PIO_ASM_Program:
347347
"""rp2.PIO PULL instruction..
348348
349349
Load a 32-bit word from the TX FIFO into the OSR.
@@ -369,7 +369,7 @@ if TYPE_CHECKING:
369369
"""
370370
...
371371

372-
def mov(dest, src, operation: Optional[int] = None) -> PIOASMEmit:
372+
def mov(dest, src, operation: Optional[int] = None) -> _PIO_ASM_Program:
373373
"""rp2.PIO MOV instruction..
374374
375375
Copy data from Source to Destination.
@@ -415,7 +415,7 @@ if TYPE_CHECKING:
415415
"""
416416
...
417417

418-
def irq(mod, index: Incomplete | None = ...) -> PIOASMEmit:
418+
def irq(mod, index: Incomplete | None = ...) -> _PIO_ASM_Program:
419419
"""rp2.PIO instruction.
420420
421421
Set or clear the IRQ flag selected by Index argument.
@@ -435,7 +435,7 @@ if TYPE_CHECKING:
435435
If Wait is set, Delay cycles do not begin until after the wait period elapses."""
436436
...
437437

438-
def set(destination, data) -> PIOASMEmit:
438+
def set(destination, data) -> _PIO_ASM_Program:
439439
"""rp2.PIO SET instruction..
440440
441441
Write immediate value Data to Destination.

0 commit comments

Comments
 (0)