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 timeout to I2C calls #1524

Open
PocketPi opened this issue Jan 15, 2024 · 2 comments
Open

add timeout to I2C calls #1524

PocketPi opened this issue Jan 15, 2024 · 2 comments

Comments

@PocketPi
Copy link
Contributor

I would love to have an option for timeout in the I2C calls.

Generally I find it bad when code can stall in a while(1) loop.

@AndreCostaaa
Copy link

This has also bothered me recently.
How about a pointer to, let's say a 8 bit map, that we can set so the user can check for it in case he's interested ?
As a bonus we could also make the function return a boolean value (right now it has void as its return type)

I'll open a PR with this proposal

@mindnever
Copy link

mindnever commented May 23, 2024

My solution to this issue was to add weak function (i2c_is_timed_out() for example) that returns true to use instead of while(i2c_nack(i2c)) - while(i2c_nack(i2c) && !i2c_is_timed_out()) .. This by default does not change the behaviour, but if provided by user code, can check for whatever timeout or other condition to break the loop.
Obviously, the function does take some parameter to identify which i2c peripheral is in use, but thats implementation specific in my case.

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

3 participants