Sometimes a couple more IOs are needed in a design. Often these are configuration or IOs that do not change very often. These can be handled by some simple TTL logic devices, many of which were designed in the 1970s. The fact that they are still in use indicates how valuable they still are in hardware design.
Pictured above is a 74HC151 which can select one of 8 inputs. So for 3 outputs and 1 input, you now have access to 8 inputs. Or for even more you can parallel the controls and then read 16 inputs with the use of 5 pins.
For the output side there are serial in to parallel out shift registers (below). This means that a string of outputs are shifted in, and then latched into an output register. Typical devices have 8 outputs, and then can be daisy chained for as many outputs as needed. The control typically have RESET lines that can be tied to the RESET of the controller board or just tied high. The serial data and serial clock can be controlled by SPI hardware of the ARM CPUs we use. By using that SPI hardware, you can write that 8/16 bit value that will be shifted out and the SPI MOSI and SCK. The SSEL pin can be used to clock the data into the output register. So once configured, a single write to the SPI peripheral can configure those 8/16 outputs.
If you are using one of these shift registers for output, instead of a data selector/multiplexer you can use a parallel in/ serial out shift register to read 8/16 inputs (like 74HC597). And all you need to add is a connection to MISO pin. So for those 4 pins with 1 write the CPU controls up to 16 outputs, followed by 1 read to get those 16 inputs.