-
Notifications
You must be signed in to change notification settings - Fork 16
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
Feature request: Allow using secondary Wire buses #23
Comments
Sounds good; this is partly because all the interfaces in So this will require a little bit more thought on our end, or potentially just foregoing compatibility with |
Yeah, so maybe adding a function (i.e. Even though the existing index-based API isn't necessarily bad, I'm afraid it will be hard to implement fully portably Arduino, since there is no generic index -> Wire object API, or a standardized and documented way to figure out how many wire interfaces there are. Looking more closely, it does seem that there is a
(as an alternative implementation for |
The generic usage we thought of is quite similar but shifts more logic in to the i2c read and write functions based on the current context. A quick recap: The HAL implementation is aware of all three implementations: |
Ah, that would probably be even better, since then the code will even work when |
This makes the library work on the MJS2020 hardware. This is obviously a hack, but until the library supports configuring it dynamically (see Sensirion#23), this is the best we can do.
+1 |
The cleanest way forward would be to port this to https://github.com/Sensirion/arduino-core/ since that allows selecting Wire objects already. In the interest of time, maybe we could just modify |
Any further thoughts on this issue? Would be good if we could switch back to an unmodified arduino-sps library for our project. |
If it helps you in any way. We already have a newer driver for SCD30 that allows you to provide the Wire and I2C address on initialization. The driver is available on Arduino library and PlatformIO. |
On some boards, such as STM32 boards (and probably SAMD boards too), there are multiple I²C controllers available, typically named
Wire
,Wire1
, etc.Currently, this library always uses
Wire
hardcoded, but it would be convenient if a secondary bus could also be used.There is already a
sensirion_i2c_select_bus(uint8_t idx)
function declared, but it is never defined anywhere. Also, since I'm not sure whether there is a standard way to detect how much Wire objects are defined, this API might be hard to implement on Arduino. Therefore, I'd suggest implementing a selection function that actually passes theWire
,Wire1
, etc objects as a reference. The type of these seems to beTwoWire
on most cores, but just in case cores use other names, I'd suggest usingdecltype(Wire)
instead.So, that would be something like this (untested, should probably be split between .h and .cpp files as well, but just to get the general idea):
And then replace all other
Wire.
withSensirionWire->
too.This allows a sketch to do e.g.:
It can even switch between multiple buses at runtime, as long as it does call
sensiron_i2c_init()
once for each bus beforehand.The text was updated successfully, but these errors were encountered: