nrf desktop - how to add soft power off

Hi,

I'm using nRF Connect v2.1.0.

How can I add a soft power off to nrf_desktop with a gpio interrupt wakeup? It looks like all of the demo hardware uses disconnecting switches, where I have a dedicated GPIO input with a momentary button for powering on/off.

I used the simple button example to add power button detection to board.c, and I used the code from the system_off example to shut it down from within my button callback, but it just reboots and turns right back on. I also tried creating and submitting a power_down_event to send to the power manager (I tried both "power_down_event" and "force_power_down_event"), with the same result. I also tried calling the turn_board_off() function that was already in board.c, which didn't do much.

I thought maybe it was failing because I was shutting down from within my button ISR so I added a worker function that I kick off with k_work_reschedule from the ISR, and then submit the powerdown event from the worker function, but I get the same result. It turns off and right back on.

Thanks,

Glen

  • Hello Glen, and sorry about the wait.

    Hung is on parental leave at the moment, so I'll be taking over this case. 

    I'm actually also finding it difficult getting only certain buttons to wake-up the board. CAF is doing a lot automatically, and can be a bit confusing at times. I've contacted the relevant R&D team to hear what they would recommend. I'll let you know once I hear from them.

    Regards,

    Elfving

  • Hello again, and hope you've had a good weekend.

    I had a talk with the R&D team responsible for nRF Desktop. It seems that the issue is that the CAF buttons module is being used, and it does not have selective wake up implemented at this point - any button press would wake up the system (see the callback_ctrl function implementation to check how GPIO interrupts are set up). You can also check how CAF buttons reacts on power down and wake up events and check the power management events documentation for further details (CAF buttons docCAF power management events). 

    If we want to allow waking up the system only by a given subset of buttons, we would need to slightly modify the implementation of CAF buttons module and add configuration for the subset of buttons.

    The team now has this on their to-do list, though I am not able to say anything about at what time they'll be able to finish this. (Though due to the summer vacation etc you should expect some delay).

    Glen M said:

    Now my only issue is that it takes so long to wake up from PM_STATE_SOFT_OFF that in order to determine that it was the power button that woke us up that I have to hold the power button for about a second to get it to successfully turn on. This might be acceptable - we'll see what the customer says.

    Hopefully this will be an acceptable workaround for both you and your customer in the meantime. 

    Regards,

    Elfving

  • Thanks Elfving - if I wanted to fiddle with the CAF buttons files myself, is there a way to make a local copy in my project and have the library use my version - or would I need to edit the files in the Zephyr library?

  • No problem, though sorry about the wait. Due to the summer vacation there can be some delays here on DevZone.

    Glen M said:
    if I wanted to fiddle with the CAF buttons files myself, is there a way to make a local copy in my project and have the library use my version - or would I need to edit the files in the Zephyr library?

    I guess there are multiple options available here. Unless you are planning on using the buttons module for another project as well you could just fiddle away, though implementing these changes as a separate custom module might be the cleanest.

    Regards,

    Elfving

Related