It is odd, unless I have simply missed it, that I have never seen anything on the internet or in any documentation that a particular mcu may already have the means to clear a bus by use of the peripheral only, with no need to bit bang a solution. When writing an i2c driver for any particular mcu, the first thing I'm now going to find out is if it is able to generate a start (resulting in a clock) when the sda line is pulled low. If so, no need to create a bit banged bus clear solution. Although nothing inherently wrong with a bit banged solution, and may end up being the only option for the mcu, using the existing i2c peripheral that already handles timing, pin states, clock stretching, status, plus the functions are already in place, seems like a much better option.
There is one subtle situation when a slave is stuck in the ack phase of a master write (with sda pulled low), and if the mcu in use will generate a start condition when sda is pulled low- the master may put out a normal write transaction and the appearance will be that the address+rw was ack'd (by the wayward slave, assuming it is happy to receive more data), and the master will get the impression that its talking to the addressed slave. Although the intended addressed slave is not listening because there was no actual start produced, and what the confused slave is doing with that data is unknown, or whether the master thinking it has successfully talked to the intended slave ends up being a problem, eventually the master will get to a point where it produces a stop and everyone will be back in sync.
The first scenario I spelled out (referred to as scenario 1 in a previous post) there will be no indication there is a stuck sda (with the 2 mcu's I tested so far anyway), so one will go through a normal transaction and never realize you were talking to the wrong slave, and the previous paragraph describes what happens. Still end up with a stop and a slave back in sync, but may have missed doing something important without knowing that it did not actually happen.
One method with the mcu that has the 'semi idle' start feature, whether it is actually ever put to use for this one particular rare case, would be to start every transaction with a write to address 127- no write actually takes place, and does not matter whether it was ack'd/nack'd, but it will always result in a state where a valid restart will be produced for the actual transaction that follows. There then would be no possible phantom writes taking place as described above.
This same method, when always applied whether needed or not (just doing, no checking if needed), would also take care of scenario 2 at the same time. You would get an extra byte at the start of each series of transfers (or up to 9 attempts if arbitration errors due to scenario 2), and although the probabilities are quite low that they turn out to be necessary, it may be something to consider. Rather than continue the transaction, although the bus clear will have completed, it would probably be better to return an error that indicates some slave may have been confused so the user can re-init the slave(s) to make sure they are in some sane state. If the 127 address was ack'd there may have been scenario 1, if arb lost (and a single master) scenario 2, and if was nack'd the single time then all ok so continue the transaction.
For the gen2 avr, although the i2c (twi) peripheral takes over the pins when enabled, the pin inputs are still accessible to gpio so in that case simply monitoring the state of sda before any transaction is started would allow for making a decision first whether the need is there. But that is mcu specific, and the pin may get routed completely away from gpio.
My original goal was to see if the peripheral could handle this problem on its own, and my conclusion is it can but there remains one requirement- the mcu has to allow for a start from a 'semi idle' bus state (scl high/sda low).
I just tested an stm32g031, and it too will generate a start condition when sda is low- result is a single clock, and subsequent arbitration checking of sda on the first rising scl edge. So avr gen2, silabs efr32, and stm32 that I have tested have the ability to generate a clock when sda is low, so the peripheral is able to do a bus clear on its own.
Add PFET or smart power switch IC on the supply line of every I2C device
This is if you are making your own board, but you may not have made the board and have to deal with what you have so would have to come up with a plan where you do not have the ability to power cycle the device. For your own designs that are battery powered, the added benefit of controlling i2c device power is to be able to simply turn it off when not in use. Whether the device standby power is low enough to not care, or is higher than you would like, by simply turning it off when not in use you know what the power consumption is. The i2c devices I use can easily be powered by a gpio pin.