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

Set multiple pins at once? #122

Open
superlou opened this issue Jan 31, 2023 · 2 comments
Open

Set multiple pins at once? #122

superlou opened this issue Jan 31, 2023 · 2 comments
Assignees

Comments

@superlou
Copy link

Is it possible to set multiple pins at once, through something like GPIO register masking or a multiple set/multiple clear register? It sounds like the Python interface can set or clear multiple simultaneously. I am trying to write my own HUB75 driver, and it would be nice to be able to set and clear all 6 bits (R0, R1, G0, G1, B1, and B2) in a single write.

@golemparts
Copy link
Owner

Thanks for the suggestion! While RPPAL doesn't currently provide that functionality, It would technically be possible to combine register writes for multiple pins. I can imagine a batch_write function (and possibly a batch_read) that takes a list of OutputPins and states, and combines those into fewer writes.

The BCM2711 uses 4 registers to set/clear pin states (GPSET0, GPSET1, GPCLR0, GPCLR1). In the worst case scenario you'd go from writing 6 32-bit values to 4 (possibly as a single 128-bit write), plus the overhead (either in the library or the end-user code) of sorting through the list of pins. I think it's worth implementing as a convenience function for parallel interfaces, with any performance gains as a bonus.

I'll put this on the list of requested changes and see if we can get it into a future update.

@superlou
Copy link
Author

superlou commented Feb 2, 2023

Thanks for considering it. I'm actually getting pretty acceptable performance from what I can tell (though I don't have a logic analyzer at home for my hobby projects) setting them one at a time. If it's just a convenience function, I can just write a wrapper that takes an array of pins. In hindsight, trying to set them via the set/clear registers potentially adds a lot of support work since it might be unique to each Raspberry PI SOC.

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

No branches or pull requests

2 participants