···100100resistor will make the line tend to high level unless one of the transistors on101101the rail actively pulls it down.102102103103+The level on the line will go as high as the VDD on the pull-up resistor, which104104+may be higher than the level supported by the transistor, achieveing a105105+level-shift to the higher VDD.106106+103107Integrated electronics often have an output driver stage in the form of a CMOS104108"totem-pole" with one N-MOS and one P-MOS transistor where one of them drives105109the line high and one of them drives the line low. This is called a push-pull···114110 OD ||--+115111 +--/ ---o|| P-MOS-FET116112 | ||--+117117-in --+ +----- out113113+IN --+ +----- out118114 | ||--+119115 +--/ ----|| N-MOS-FET120116 OS ||--+121117 |122118 GND123119124124-You see the little "switches" named "OD" and "OS" that enable/disable the120120+The desired output signal (e.g. coming directly from some GPIO output register)121121+arrives at IN. The switches named "OD" and "OS" are normally closed, creating122122+a push-pull circuit.123123+124124+Consider the little "switches" named "OD" and "OS" that enable/disable the125125P-MOS or N-MOS transistor right after the split of the input. As you can see,126126either transistor will go totally numb if this switch is open. The totem-pole127127is then halved and give high impedance instead of actively driving the line···136128hard-wired lines that will only support open drain or open source no matter137129what: there is only one transistor there. Some are software-configurable:138130by flipping a bit in a register the output can be configured as open drain139139-or open source, by flicking open the switches labeled "OD" and "OS" in the140140-drawing above.131131+or open source, in practice by flicking open the switches labeled "OD" and "OS"132132+in the drawing above.141133142134By disabling the P-MOS transistor, the output can be driven between GND and143135high impedance (open drain), and by disabling the N-MOS transistor, the output···154146If this state can not be configured in hardware, i.e. if the GPIO hardware does155147not support open drain/open source in hardware, the GPIO library will instead156148use a trick: when a line is set as output, if the line is flagged as open157157-drain, and the output value is negative, it will be driven low as usual. But158158-if the output value is set to positive, it will instead *NOT* be driven high,149149+drain, and the IN output value is low, it will be driven low as usual. But150150+if the IN output value is set to high, it will instead *NOT* be driven high,159151instead it will be switched to input, as input mode is high impedance, thus160152achieveing an "open drain emulation" of sorts: electrically the behaviour will161153be identical, with the exception of possible hardware glitches when switching