-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Description
Both Adafruit TFT Experiment board and for an unreleased pimoroni board use on-board I2C bus expanders.
Besides this, the Pico W has a special I/O pin that is on the CYW wifi coprocessor.
Usable for what tasks?
It is desirable for these "pins" to be able to be treated consistently by anything that doesn't require fast or accurate timing. This could include:
- digitalio.DigitalInOut
- bitbangio.SPI
- The CS and DC pins of an SPI device, SD card, or a 4-wire display
- keypad.Keys and friends
Some examples of things where this would not work well are:
- IncrementalEncoder, because every pin transition must be captured
- NeoPixel and OneWire, because the bit timing must be tight, relative to the time for an I2C transaction
Design
The design I have in mind is:
- Introduce an "abstract pin" protocol in the core
- Provide an implementation for microcontroller pin, cyw43 pin, and "generic I2C expander pin"
- Start switching things to use this protocol, beginning with bitbangio.SPI and digitalio.DigitalInOut
Generic I2C Expander
Generic I2C expander:
- Assumes that there are some simple registers full of bits:
- direction, pull-up, pull-down, out-value, in-value (all optional)
- registers may be 1 or 2 bytes
- Does not initially handle an interrupt pin, which could potentially optimize digital reads. maybe this could be done in the future.
- Does not batch digital writes; there's no plan for that
Locked bus problem
This presents a potential problem that didn't exist before: Maybe a digital pin can't be read or set "right now". For instance, suppose that an I2C bus contains a temperature sensor and a bus expander. The bus expander is the home of the CS pin of a SPI display. During an I2C transaction to read the temperature, a background display refresh occurs. But because of the ongoing transaction, CS can't be asserted and so the refresh can't actually occur. It's not clear how to discover and recover from such a problem within the current architecture.
Honestly that realization is enough to make me want to turn aside from the whole idea.
@ZodiusInfuser did you consider the locked I2C bus problem? What kinds of I/O tasks does your board need to do with expander pins? We have a SPI bus, TFT reset pin, some buttons, and I think the LCD back-light. We'd probably do fine with just a custom bitbang i2c implementation for our use case, and make the rest rely on a userspace implementation of a digital pin, like we have already for other expanders.