Controlling a latching relay, like HFD2/012-S-L2 (datasheet [PDF]) with two MCU pins is straightforward:
And here is the corresponding code:
void switchRelayTx() {
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOA, GPIO_PIN_0, GPIO_PIN_RESET);
}
void switchRelayRx() {
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_SET);
HAL_Delay(10);
HAL_GPIO_WritePin(GPIOC, GPIO_PIN_15, GPIO_PIN_RESET);
}
But when you need >= 10 relays in the project you end up out of MCU pins very soon. Thus I wonder if it's possible to control such a relay with only one MCU pin, maybe by utilizing a High-Z pin state, and without too many additional external components? Off the top of my head, I couldn't come up with the schematic.
Simply putting an "I2C pin number extender" like PCF8574 is possible of course, but I'm curious if there is a little less brute-force solution. Using a regular relay is not an option in the project because of the extra current such relays consume. Using a single-coil latching relay could be an option though.