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

Convert hello_interp.c:times_table to µPython #58

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

graeme-winter
Copy link

Not useful for efficient calculation of times-tables (it is not) but a nice way to show accessing hardware registers in the rp2040 from µPython.

Not useful for efficient calculation of times-tables (it is not) but a nice
way to show accessing hardware registers in the rp2040 from µPython
@graeme-winter
Copy link
Author

Not sure how useful this would be, but I thought it would be nice to show that you can access a lot of what is written in the data sheets from micropython without too much hassle.

interp/interp.py Outdated
from machine import mem32

# initialise lane 0 on interp: set that we are using all 32 bits
mem32[0xD0000000 | 0xAC] = 0x1F << 10
Copy link
Contributor

@lurch lurch Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not up to me whether this PR gets merged or not, but IMHO it'd be much easier to read if you had

SIO_BASE = 0xD0000000

INTERP0_ACCUM0 = 0x80
INTERP0_BASE0 = 0x88
INTERP0_POP_LANE0 = 0x94
INTERP0_CTRL_LANE0 = 0xAC

at the top of the file, and then this line could become:

mem32[SIO_BASE + INTERP0_CTRL_LANE0] = 0x1F << 10

(note that I've also changed the | to a +, which is probably more readable to most Python programmers?)

EDIT: I lifted those names directly from https://datasheets.raspberrypi.com/rp2040/rp2040-datasheet.pdf

Copy link
Author

@graeme-winter graeme-winter Jan 6, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent suggestion, thank you. Done.

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

Successfully merging this pull request may close these issues.

2 participants