So to compare:

Bela Button
Short P9.27 to ground
Short press action: by default stops running Bela program, this action can be changed or disabled
Long press (2 seconds): graceful shutdown, calls cleanup function
PWR_BUT
Short P9.09 to ground
Long press (8 seconds): graceful shutdown, calls cleanup function ??
Pressing while Bela is shutdown while power is connected starts it up again

Is this correct? Does the PWR_BUT also call cleanup() in render.cpp? I'd like to use that function to trigger autosaving of parameters when a gracefull shutdown is triggered.

Ideally I'd like to have a button that is able to both shut down and boot up the Bela. The PWR_BUT seems to be able to do this, however pressing 8 seconds is a bit too much. The TPS65217C datasheets mentions the 8 seconds, and it seems like that time cannot be changed.

I have a momentary DPDT switch with one side connecting P9.27 to ground when pressed. Now I wonder if I connect the other side of the switch to P9.09 I get the best of both behaviours:
- When the Bela is turned on pressing 2+ seconds triggers a graceful shutdown (if one where to press for more than 8 seconds, the Bela would already be shutting down anyway)
- When the Bela is turned off pressing will boot the Bela
alt text

    Ward Does the PWR_BUT also call cleanup() in render.cpp?

    Whether your running program calls it depends on how the program is stopped. When tapping on the Bela button, a flag (gShouldStop) is set in the program so that the audio thread stops calling render () and exits
    In turn, the main thread will call cleanup() and then exit. Any other threads should be exiting whenever Bela_stopRequested() returns true. If these are AuxiliaryTask s, main waits on them before calling cleanup(). When the program finally exits, all global objects will be destroyed by calling their destructors before the program finally terminates.

    When hold-pressing the Bela button, if you have a running program, it will be stopped as above and any new instance of the program which could attempt to start before the shutdown sequence is started and while the button is held down will fail to start (although I am not currently sure at what stage it will stop and whether it will call setup(), render() and/or cleanup ()).
    If the program is stopped via make stop, a SIGINT is sent to it. This signal is caught by the main thread, which sets gShouldStop and the program terminatea gracefully as above. Both SIGTERM and SIGINT are handled this way.

    I am not sure how the shutdown procedure (which is probably called by both PWR button and Bela button) attempts to stop the running program (it probably offloads the task to systemd). As long as this sends a SIGTERM or SIGINT, cleanup() should be called and a graceful project exit takes place (there may be some timeouts after which the program is forcibly terminated).

    In short: briefly tapping the Bela button or sending the program a SIGINT or SIGTERM immediately causes a graceful exit calling cleanup().

    2 months later

    So to report back, I implemented this on my PCB and it seems to work, it triggers the cleanup function, shuts down the Bela and if you press it while the Bela is shut down is wakes it up again and runs my project.

    2 years later

    Hi all, is there any specific pin for the external power button on the multichannel expander? Can't find P9.27 on the pin diagram. Thanks in advance!

    On the BelaMini and BelaMini Multichannel Expander The Bela Button is connected to P2.34 ("shutdown_req" here https://raw.githubusercontent.com/wiki/BelaPlatform/Bela/Images/BelaMiniPinout.png).

    if you want to power on the board, as Ward is doing above, use P2.12 "SYS PWR BTN".
    To clarify, the mapping is:

    Function     | Bela  | BelaMini
    Bela button  | P9.27 | P2.34
    Power button | P9.09 | P2.12

    The functions mean:

    • Bela button: short tap stops the currently running project, 2 second hold press triggers shutdown
    • Power button: when on, a short tap triggers shutdown; when off, a short tap triggers a boot