write ((read() & ~ 0 ) | configuration_reg) = write (read() | configuration_reg)
write (configuration_reg)
So you leave the existing inputs as inputs while changing the other settings and
only make them outputs *after* this sequence. Pins already configured as output
are left as they are. And new inputs are set up before changing anything.
Ok, this avoids glitches while switching the output polarity and value.
Is this interpretation right?
BTW: line 161 seems to be redundant.
And while I look at it, we could suggest to optimize out the i2c_read() if mask = 0xff in tca642x_reg_write()...