-
Notifications
You must be signed in to change notification settings - Fork 7
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
Setting inputs is rather slow #8
Comments
This is horrible, but it's fast, and more importantly it's atomic, so all the pins change value together: @micropython.native
def set_input_byte(val):
val = ((val & 0xF) << 9) | ((val & 0xF0) << 17-4)
val = (machine.mem32[0xd0000010] ^ val) & 0x1E1E00
machine.mem32[0xd000001c] = val |
I wouldn't say this is horrible - it gets the job done, while providing a nice interface for the user. One change that could potentially make it more "future-proof" would be to split it into two functions in a way that we could test that the pin numbers match the ui_in pins defined in the SDK code upon startup. |
Yeah, it's horrible in the sense that it's hard-coded and difficult to understand. |
Hey @MichaelBell: how is this working? I've replaced the default function with the @micropython.native stuff and I can't pass the boot-up stage (it fails to get the chip rom data etc). This is on a TT05 board, not sure how to debug it as it's pretty opaque. |
Looks like pilot error on my part. Testing... |
Well, it's an improvement, but I'm not clear on where the slowdown is... Sticking a straight call to the native stuff in the input_byte setter gives this:
So maybe twice as fast, but really far from sub 200us. |
ok, solved that mystery -- it's the indirection on the property... calling direct into the pins is surprisingly good (?)
|
Wow, that redirect is really slow! Maybe should document somewhere that And to explain that magic. It is just what the pico-sdk
The rest is just getting the values in the right place and XOR'ing and masking appropriately. |
I put in your set_input and did similar for other ports. The implementations are in ttboard.util.platform. I renamed things to try and make it clear: if your are getting values, it returns only bits for GPIO that are inputs, if you are setting values it sets all the output bits (but won't impact input gpio unless they are switched to outs). |
This code
takes 1.6 seconds to run - output at stock 125MHz RP2040 clock:
This seems extremely slow!
Using the Python gpio directly gets that down to 46ms:
The text was updated successfully, but these errors were encountered: