<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/100636/nrf-desktop---how-to-add-soft-power-off</link><description>Hi, 
 I&amp;#39;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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Wed, 19 Jul 2023 13:12:45 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/100636/nrf-desktop---how-to-add-soft-power-off" /><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/437262?ContentTypeID=1</link><pubDate>Wed, 19 Jul 2023 13:12:45 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:14b5ed21-be99-49d3-80da-f488fa0d93f9</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Awesome! Thanks!!!&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/437249?ContentTypeID=1</link><pubDate>Wed, 19 Jul 2023 12:37:15 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:47040327-931d-4961-b9eb-2869dd431035</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Glen,&lt;/p&gt;
&lt;p&gt;&lt;a href="https://github.com/nrfconnect/sdk-nrf/pull/11759"&gt;You can already find your request available in NCS main&lt;/a&gt; &lt;span class="emoticon" data-url="https://devzone.nordicsemi.com/cfs-file/__key/system/emoji/1f642.svg" title="Slight smile"&gt;&amp;#x1f642;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/435477?ContentTypeID=1</link><pubDate>Mon, 10 Jul 2023 11:57:19 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:91991376-e99f-4841-846a-00249d1e6b5b</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;No problem, though sorry about the wait. Due to the summer vacation there can be some delays here on DevZone.&lt;/p&gt;
[quote user="Glen M"] 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?[/quote]
&lt;p&gt;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, &lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/caf/caf_overview.html#adding-custom-modules"&gt;though implementing these changes as a separate custom module might be the cleanest&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/434291?ContentTypeID=1</link><pubDate>Mon, 03 Jul 2023 18:11:49 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9d539c00-4add-4ed5-b676-7bd439406821</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;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?&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/434203?ContentTypeID=1</link><pubDate>Mon, 03 Jul 2023 12:01:02 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:8e9a8e24-7039-47a2-9dfc-248d3663034a</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello again, and hope you&amp;#39;ve had a good weekend.&lt;/p&gt;
&lt;p&gt;I had a talk with the R&amp;amp;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&amp;nbsp;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 (&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/caf/buttons.html"&gt;CAF buttons doc&lt;/a&gt;,&amp;nbsp;&lt;a href="https://developer.nordicsemi.com/nRF_Connect_SDK/doc/latest/nrf/libraries/caf/caf_overview.html#caf-power-events"&gt;CAF power management events&lt;/a&gt;).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;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.&lt;/p&gt;
&lt;p&gt;The team now has this on their to-do list, though I am not able to say anything about at what time they&amp;#39;ll be able to finish this. (Though due to the summer vacation etc&amp;nbsp;you should expect some delay).&lt;/p&gt;
[quote user="Glen M"]&lt;p&gt;Now my only issue is that it takes so long to wake up from&amp;nbsp;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&amp;#39;ll see what the customer says.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;[/quote]
&lt;p&gt;Hopefully this will be an acceptable workaround for both you and your customer in the meantime.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/433602?ContentTypeID=1</link><pubDate>Thu, 29 Jun 2023 07:34:11 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:668359df-7fed-46c9-8e8f-bbca1387eb0b</guid><dc:creator>Elfving</dc:creator><description>&lt;p&gt;Hello Glen, and sorry about the wait.&lt;/p&gt;
&lt;p&gt;Hung is on parental leave at the moment, so I&amp;#39;ll be taking over this case.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;I&amp;#39;m actually also&amp;nbsp;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&amp;#39;ve contacted the relevant R&amp;amp;D team&amp;nbsp;to hear what they would recommend. I&amp;#39;ll let you know once I hear from them.&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;Elfving&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/433334?ContentTypeID=1</link><pubDate>Tue, 27 Jun 2023 21:53:29 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6ff25ed6-3b82-400d-aa5b-fc300fdb1d7f</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Here&amp;#39;s the current state of things. I have gotten pretty decent power-off behavior with this code, and a check first-thing in main() to see if they are holding down the power button for my wakeup (if not then I jump straight back to PM_STATE_SOFT_OFF):&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;   force_power_down();		// This puts the device into the suspended state
   k_sleep(K_MSEC(1200));  // Wait longer than 1 second to make sure the system gets the power off event, which it checks for every 1 second
   pm_state_force(0u, &amp;amp;(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0}); // Force a hard off where the interrupt wakeup resets the processor&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;With the &amp;gt;1s delay, the system has time to send the force power down event around and get itself set up for sleep, and then the pm_state_force seems to do a good job of fully shutting it down.&lt;/p&gt;
&lt;p&gt;Now my only issue is that it takes so long to wake up from&amp;nbsp;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&amp;#39;ll see what the customer says.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I would still love it if I could get all interrupt sources except for my power button line disabled (power button is on its own pin... it&amp;#39;s not in the keyboard matrix), but so far I&amp;#39;ve been unsuccessful at that.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/432739?ContentTypeID=1</link><pubDate>Fri, 23 Jun 2023 15:04:13 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:0be95ce1-29a2-4101-b39f-97f1e4f8c8fb</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Hi Hung,&lt;/p&gt;
&lt;p&gt;I&amp;#39;ve continued to work on this and I&amp;#39;ve made some progress, but simply turning the device off and on is proving to me much harder than we imagined.&lt;/p&gt;
&lt;p&gt;The primary thing keeping it from going to sleep is the custom motion sensor that I added. I&amp;#39;ve just turned that off for the time being and I did get it to go to sleep - I&amp;#39;ll figure out how to disable it for sleep mode, but now I&amp;#39;m fighting a related issue I&amp;#39;m hoping you can help me with.&lt;/p&gt;
&lt;p&gt;Our device has a full keyboard including a power button, and we want to use the power button to turn on and off, not every key on the keyboard. Right now, no matter what I do, I haven&amp;#39;t been able to keep the other keys on the keyboard from waking the device up.&lt;/p&gt;
&lt;p&gt;I decided to just accept my failure to disable the wakeup interrupt for the row/column stuff and put in some code that would go immediately back to sleep when a button was pressed other than the power button - but that doesn&amp;#39;t work either. When it&amp;#39;s powered off and I press one of the normal keyboard buttons, the device wakes up, but my&amp;nbsp;is_button_event() check doesn&amp;#39;t get called. What&amp;#39;s up with that?&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;static bool app_event_handler(const struct app_event_header *aeh)
{
	static bool initialized;

	if (is_button_event(aeh)) 
   {
      // Check to see if a keyboard button other than the power button has been pressed while we&amp;#39;re off.
      // If so, go back to off mode.
		if (m_keyboard_is_on == false)
      {
         k_work_reschedule(&amp;amp;worker, K_MSEC(20));	// This fires off a worker task that calls force_power_down
         return true;
      }
      return false;
	}
}	

APP_EVENT_LISTENER(MODULE, app_event_handler);
APP_EVENT_SUBSCRIBE_FIRST(MODULE, button_event);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Instead it&amp;#39;s hitting this part of that same app_event_handler as if it&amp;#39;s starting up from scratch - which may make sense if&amp;nbsp;&lt;/p&gt;
&lt;div&gt;
&lt;div&gt;&lt;span&gt;force_power_down takes it to&amp;nbsp;&lt;/span&gt;it&amp;#39;s in PM_STATE_SOFT_OFF:&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;	if (is_module_state_event(aeh)) {
		const struct module_state_event *event = cast_module_state_event(aeh);

		if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
			__ASSERT_NO_MSG(!initialized);
			initialized = true;

			turn_board_on();
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I asked my customer if they were OK with using the power button to go to sleep and any key to wake up, and they said no - so I have to find a way to solve this problem. Any ideas?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I have a partial solution going, but it&amp;#39;s not great. I am forcing it into&amp;nbsp;&lt;span&gt;PM_STATE_SOFT_OFF and then when I get into main the very first thing I do it check to see if the button is still held, and only allow the device to power up if so (if not I jump back to SOFT_OFF), but it takes about a second to boot up from that state, so you have to hold down the power button for a second to get it to power up and the LEDs on the board flash on briefly during the boot process, so you can see a flicker every time you press a wrong button that shouldn&amp;#39;t wake it up.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for your help,&lt;/p&gt;
&lt;p&gt;Glen&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/430437?ContentTypeID=1</link><pubDate>Mon, 12 Jun 2023 10:46:14 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:74fb0309-bf23-43c9-b266-beb1532d5ab4</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Glen,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;You can read the &lt;a href="https://infocenter.nordicsemi.com/topic/ps_nrf52840/power.html?cp=5_0_0_4_2_6_10#register.RESETREAS"&gt;RESETREAS &lt;/a&gt;register at address 0x40000400 to know what trigger wakeup/reset. Most likely it would be wake up from system off.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;Could you try testing what I did on a Dev Kit ? From what I could see when testing with the DK it worked fine, the device enter deep sleep until I pressed on Button 3 or 4.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Have you checked if P0.24 and P0.25 is not connected to anything pulling it down ?&amp;nbsp;&lt;br /&gt;&lt;br /&gt;How do you configure your GPIO_INPUT in device tree? Did you use any pull up /down internally/externally ?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If you can test on a devkit and if it work as expected, then it must be something in the difference in the hardware causing the issue.&amp;nbsp;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/430291?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 16:31:47 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:542ad68d-c801-4a7d-a3a3-23fd82e36058</guid><dc:creator>Glen M</dc:creator><description>&lt;p&gt;Hmm - nice to know there&amp;#39;s just a force_power_down function to call. It&amp;#39;s still doing the same thing though, even when I put the call in main like you did so the button isn&amp;#39;t involved.&lt;/p&gt;
&lt;p&gt;Is there some way to see the cause of a powerup, or some way to see what interrupts are active before I call the shutdown function that might be causing it to wake? I can set a breakpoint in my shut down function if there are some registers I can look at.&lt;/p&gt;
&lt;p&gt;Maybe some other pin in my system is still configured as an interrupt without me realizing it, or maybe some module isn&amp;#39;t enabled for power management so it&amp;#39;s waking me up.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;None of the KEEP_ALIVE_EVENTS things in prj.conf are set to true.&lt;/p&gt;
&lt;p&gt;It might also be good if I can figure out how to disable parts of the code to see if it works up until I turn on the ADC or some other peripheral&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the code I&amp;#39;m using for the wakeup button. I added it to the init part of app_event_handler in board.c:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#define POWER_BTN_NODE	DT_ALIAS(powerbtn)
static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(POWER_BTN_NODE, gpios, {0});
static struct gpio_callback button_cb_data;


static bool app_event_handler(const struct app_event_header *aeh)
{
	static bool initialized;

	if (is_module_state_event(aeh)) {
		const struct module_state_event *event = cast_module_state_event(aeh);

		if (check_state(event, MODULE_ID(main), MODULE_STATE_READY)) {
			__ASSERT_NO_MSG(!initialized);
			initialized = true;

			turn_board_on();

         // Set up the power button interrupt
         gpio_pin_configure_dt(&amp;amp;button, GPIO_INPUT);
         gpio_pin_interrupt_configure_dt(&amp;amp;button, GPIO_INT_EDGE_TO_ACTIVE);
         gpio_init_callback(&amp;amp;button_cb_data, button_pressed, BIT(button.pin));
         gpio_add_callback(button.port, &amp;amp;button_cb_data);&lt;/pre&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrf desktop - how to add soft power off</title><link>https://devzone.nordicsemi.com/thread/430196?ContentTypeID=1</link><pubDate>Fri, 09 Jun 2023 10:51:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:84c08640-4296-42f0-87c2-ddb7b9961f72</guid><dc:creator>Hung Bui</dc:creator><description>&lt;p&gt;Hi Glen,&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Could you show how you put the device to system off and how you configure the wake up source ?&lt;br /&gt;There could be a chance that the wake up source is triggered right after the device enter deep sleep.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Maybe you can try to test using different buttons, one for putting the device to sleep and another one to wake the device up ?&amp;nbsp;&lt;br /&gt;I don&amp;#39;t think putting the device to deep sleep in an ISR could be the reason it wake up.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Have you tried to use&amp;nbsp;force_power_down()&amp;nbsp;&amp;nbsp;&lt;br /&gt;I tried this in the nRF Desktop code, compile with nRF52840 dk board and it seems to work:&amp;nbsp;&lt;br /&gt;&lt;pre class="ui-code" data-mode="text"&gt;void main(void)
{
	if (app_event_manager_init()) {
		LOG_ERR(&amp;quot;Application Event Manager not initialized&amp;quot;);
	} else {
		module_set_state(MODULE_STATE_READY);
	}
	k_sleep(K_SECONDS(3));
	force_power_down();
}
&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;The board enter deep sleep after awhile (more than 3 seconds, but I assume it&amp;#39;s because it takes time to shutdown). Pressing button 3 or 4 wakes the board up.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>