Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for the assembly instructions in @asm_pio functions #767

Open
DeflateAwning opened this issue Nov 15, 2024 · 6 comments
Open
Labels
WIP Work in progress

Comments

@DeflateAwning
Copy link

DeflateAwning commented Nov 15, 2024

Here's an example of what the type checking looks like currently (observe all the errors) for @asm_pio-decorated Programmable IO assembly code blocks:

image

Doing a bit of digging around, I found that the PIOASMEmit class seems to define these functions, but there's no way to move those member functions to imports.

I think the best solution would be to make them global functions, probably. Or maybe there's a way to highjack the @asm_pio decorator so that it considers the assembly functions only in that function.

@Josverl
Copy link
Owner

Josverl commented Nov 17, 2024

Can you share the code,
which type-stubs you had installed ?

@DeflateAwning
Copy link
Author

@Josverl
Copy link
Owner

Josverl commented Nov 18, 2024

I have already built it , but not (yet) included it as part of the rp2 stubs.
image
I plan to add this in the upcoming release , but it needed some significant restructuring

if you want it today - you need to add it manually to the stubs

  • rename or delete ..../rp2.pyi
  • create a rp2 folder
  • copy in the new rp2 & PIO stubs

See for more details :
https://github.com/Josverl/PIO_ASM_typing

@Josverl Josverl added the WIP Work in progress label Nov 18, 2024
@DeflateAwning
Copy link
Author

That's very neat, thank you very much! Looking forward to giving it a try.

In the final release, will we need to import anything? Or it'll work automatically?

@Josverl
Copy link
Owner

Josverl commented Nov 18, 2024

You'll need the somewhat ugly activation blurb

# -----------------------------------------------
# add type hints for the rp2.PIO Instructions
try: 
    from typing_extensions import TYPE_CHECKING # type: ignore
except ImportError:
    TYPE_CHECKING = False
if TYPE_CHECKING:
    from rp2.asm_pio import *
# -----------------------------------------------

before the first @asm_pio .
as there are a bunch of side effects that don't apply to pure python , I would not want to enable it by default,
and I have not found a way to have the type checkers enable it by default.

there is a cpython decorator @no_type_check , but that is not (yet) part of micropython ,
but can be loaded.
That suppresses errors, but offers no type-hints.
https://micropython-stubs.readthedocs.io/en/main/typing_mpy.html#using-the-no-type-check-decorator

@DeflateAwning
Copy link
Author

This is perfect as-is! Thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in progress
Projects
None yet
Development

No branches or pull requests

2 participants