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

Allow manual muxing? #28

Open
caternuson opened this issue Mar 25, 2021 · 3 comments
Open

Allow manual muxing? #28

caternuson opened this issue Mar 25, 2021 · 3 comments
Labels
enhancement New feature or request

Comments

@caternuson
Copy link
Contributor

Should we provide some mechanism to manually set the TCA mux? For use cases where this library is being used in conjunction with I2C devices that do not have a CircuitPython driver.

Example:
https://forums.adafruit.com/viewtopic.php?f=60&t=177241

Maybe something like a new channel property?

tca.channel = 3

Could probably add a new class variable to track this also, to provide a read of current channel.

@ladyada
Copy link
Member

ladyada commented Mar 27, 2021

yah im not against it!

@tannewt
Copy link
Member

tannewt commented Mar 29, 2021

I don't think you want a second way to change the channel because it'll lead to confusion when using both ways at the same time. Instead, they should just use the appropriate channel object like a busio.I2C for driverless use.

@caternuson
Copy link
Contributor Author

The current code only switches the mux via try_lock(), which works fine with BusDevice since it calls try_lock() as part of the context manager.
https://github.com/adafruit/Adafruit_CircuitPython_BusDevice/blob/c322a567512277cc94f152b7f359d7c011d51d96/adafruit_bus_device/i2c_device.py#L137

None of the other busio.I2C-like methods do this. So something like this would not do any mux changes:

tca[1].writeto(stuff)
tca[2].writeto(stuff)

One would have to do this:

tca[1].try_lock()
tca[1].writeto(stuff)
tca[1].unlock()
tca[2].try_lock()
tca[2].writeto(stuff)
tca[2].unlock()

For some 3rd party driver that does not use BusDevice, one would have to do this:

sensor = SomeSensor(tca[1])
tca[1].try_lock()
sensor.read_value()
tca[1].unlock()

Could maybe add mux changing code to all the busio.I2C methods, like writeto? Track current channel and only actually mux change if needed, to reduce unnecessary I2C traffic.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants