Use a pushbutton switch with one side gounded. Drive the gate of a P channel mosfet with the other side through a resistor and diode (weak pullup between resistor and diode), use a pullup to Vin on the gate. Run the output of the switch through another resistor, then a diode, puller resistor and zener (to limit to 3.3v) and to a GPIO. Run a second GPIO to a NPN transister with the emitter connected to the gate of the P channel mosfet.
When the system is off, the only power consumption is leakage through the P channel mosfet. When the button is pressed, the mosfet is turned on, and the microproressor immediately turns on the npn transistor, keeping the mosfet gate low (active) when the pushbutton is released.
The microcontroller can sense the state of the pushbutton switch (sample before the diode, the pullup will keep the input high unless the button is pressed, the high level is Vin, so you will probably need a series resistor followed by a zener to limit the high level voltage). Once the microcontroller sees the switch go inactive after poweron, it can look for a 2s low pulse on the switch and disable the npn transistor on the mosfet. When the switch is released, neither the switch or npn are pulling the mosfet gate low so the system turns off.
If there is a shutdown sequence for any system components, on detecting the 2s low pulse on the switch the controller can initiate shutdown and release the gate / npn transistor when shutdown is completed.
Dean
Use a pushbutton switch with one side gounded. Drive the gate of a P channel mosfet with the other side through a resistor and diode (weak pullup between resistor and diode), use a pullup to Vin on the gate. Run the output of the switch through another resistor, then a diode, puller resistor and zener (to limit to 3.3v) and to a GPIO. Run a second GPIO to a NPN transister with the emitter connected to the gate of the P channel mosfet.
When the system is off, the only power consumption is leakage through the P channel mosfet. When the button is pressed, the mosfet is turned on, and the microproressor immediately turns on the npn transistor, keeping the mosfet gate low (active) when the pushbutton is released.
The microcontroller can sense the state of the pushbutton switch (sample before the diode, the pullup will keep the input high unless the button is pressed, the high level is Vin, so you will probably need a series resistor followed by a zener to limit the high level voltage). Once the microcontroller sees the switch go inactive after poweron, it can look for a 2s low pulse on the switch and disable the npn transistor on the mosfet. When the switch is released, neither the switch or npn are pulling the mosfet gate low so the system turns off.
If there is a shutdown sequence for any system components, on detecting the 2s low pulse on the switch the controller can initiate shutdown and release the gate / npn transistor when shutdown is completed.
Dean