CHG is a dual state. CHG will be low or high impedance. CHG will be Low when the chip is charging and high impedance when the chip stops charging. When it's low, everything looks right. When its charging LED is ON, and the switch is open because CHG is low. Due to this, MCU will be getting voltage to the GPIO.
But when it's not charging but still connected to 5V, CHG is high impedance/open, LED is off, and the switch's gate terminal is open! Since the switch did not toggle to ON, how does microcontroller knows that the charging is already stopped? When the battery is not charging and not connected to 5V, the same scenario happens, I think. Please clarify how does the MCU know when the battery is not charging or stop charging?