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

A library should never call begin() on a shared bus #9

Closed
TD-er opened this issue Aug 30, 2019 · 4 comments
Closed

A library should never call begin() on a shared bus #9

TD-er opened this issue Aug 30, 2019 · 4 comments

Comments

@TD-er
Copy link

TD-er commented Aug 30, 2019

See:

_i2c->begin();

The library for this sensor does call begin() on the I2C bus.
A library should never call functions like these on a shared medium without explicit call to do so.
A library should just add support for some sensor or device and should never change things on a shared medium.

This does cause undefined behavior when using the library together with other sensors on the same bus.

If you really need to have it done in the begin function of your library, then please either add an optional parameter to not call begin or use defines in the code to exclude it.

@ladyada
Copy link
Member

ladyada commented Aug 30, 2019

hiya, wontfix - this is 100% the standard operation procedure for arduino libaries and we've done it 200+ times for 10 years. Wire.begin() should be idempotent in the board support implementation, as it is in all official Arduino boards!

@ladyada ladyada closed this as completed Aug 30, 2019
@ladyada
Copy link
Member

ladyada commented Aug 30, 2019

its also what Arduino does for their libraries, in case you think we're doing it wrong ;)
https://github.com/arduino-libraries/Arduino_HTS221/blob/master/src/HTS.cpp#L47

@TD-er
Copy link
Author

TD-er commented Aug 30, 2019

That doesn't mean it is the right thing to do.

I'm not suggesting you should change it to all, only if you want to consider it for this one and future libraries.
If not, then other projects cannot use your libraries by linking to them but have to include them in a patched form.

@ladyada
Copy link
Member

ladyada commented Aug 30, 2019

nope, wontfix - if you have a 'fork' and its not compatible with arduino's official libraries, its your fork thats the issue :) Wire.begin() was designed to be callable as many times as you like, if that implementation is broken, it needs to be fixed, not a decade worth of libraries

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