Pin sharing among tasks

Problem: I thought the dev board I bought had enough pins for my use-case, but I’m two short.

Could I share access to the pins between tasks by pinning them both to the same core or use a mutex to access them? Is there a better way?

One task runs infrequently to update an ePaper display. The other task runs frequently to to set control bits on a 32-channel ADG732 multiplexer.

The e-paper interface

ESP32 pinout

That will be more of a hardware question. Will both of the interfaces you want to share the pins not mind if the pins change while you aren’t actively talking on that interface.

If so, then hardware sharing is possible, you just will need something like a Mutex to control which way the interface is being used.

1 Like

Yeah, I have a little investigation to do on how the two IOs are set up. I just wanted a lil sanity check on the software side before I start banging away on the keyboard.

A mutex, with the code reseting the pins to the state needed after getting the mutex, should work if the hardware doesn’t mind the strange behavor of the pin when not operating the other pins.

is it just gpio pins you’re running short on?

If so, think about whether it’s worth moving “as many practicable” gpio pins onto an i2c gpio expander. You’ll still need 2 pins for the i2c bus but you might save more than that. Generally speaking, this is most useful for pins that you don’t need to read/write/detect a transition on “quickly”.