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

matrix.wait doesn't block? #26

Open
BrianPugh opened this issue Jan 14, 2021 · 3 comments
Open

matrix.wait doesn't block? #26

BrianPugh opened this issue Jan 14, 2021 · 3 comments

Comments

@BrianPugh
Copy link

it seems like the C implementation of the matrix.wait method immediately returns, resulting in a super tight primary loop. The python matrix.py code does not have this issue.

Is the C implementation public anywhere?

@xiongyihui
Copy link
Contributor

The C implementation of the matrix.wait will return when a new event (keyup or keydown) occurs. The reason may be that C is faster than Python.

The source code is at https://github.com/xiongyihui/circuitpython/tree/m60

@BrianPugh
Copy link
Author

thanks, i'll check that out and raise an issue in that repo if my report is still valid.

@BrianPugh BrianPugh reopened this Jan 20, 2021
@BrianPugh
Copy link
Author

ok so I cannot open issues in that repo for some reason. Basically I believe the issue is this:

  1. When port_sleep_until_interrupt (or port_idle_until_interrupt in newer circuitpython) is called, sd_app_evt_wait blocks in lower power mode until an interrupt happens.
  2. We expect that interrupt to be the interrupt from the timer setup before hand to wake it up after 20mS or 1000mS (or whatever depending on the situation) or for the interrupt to be from a button press.
  3. However, I think USB and BT events also trigger this to unblock. I don't really have a way to debug this.
  4. Essentially, this results in unblocking nearly immediately, rather than after the expected timeout.
  5. wrapping this in a while loop and toggling a flag in the interrupts semi-solves this situation, but this causes a bunch of other issues, like with circuitpython operating properly.

Any thoughts? Another solution is to just wrap this wait code in a while loop in python, just might have battery life impacts.

You can see my circuitpython fork of @xiongyihui repo here:
https://github.com/BrianPugh/circuitpython/tree/m60
I merged (and fixed conflicts) upstream adafruit circuitpython/main into it for bugfixes and I was having linker issues that upstream resolved.

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

No branches or pull requests

2 participants