<?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>About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/66021/about-missing-first-button-release-event-after-power-up-if-the-key-is-pressed-during-power-up</link><description>Hi, 
 I have encounter a problem that the first button release event is missing if the key is pressed while powering up. 
 The SDK I am using is nRF5_SDK_17.0.0_9d13099. 
 Below is my code when initializing the buttons using the bsp. 
 
 
 
 
 The procedure</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Fri, 18 Sep 2020 08:00:37 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/66021/about-missing-first-button-release-event-after-power-up-if-the-key-is-pressed-during-power-up" /><item><title>RE: About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/thread/270250?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2020 08:00:37 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:58a877d4-357c-4db4-88aa-34915c6fa142</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Ok. My interpretation of the bsp_event_to_button_action_assign() implementation was wrong. I missed the line:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;if (event == BSP_EVENT_DEFAULT)&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;First of all, be careful by adding the&amp;nbsp;BPS_EVENT_KEY_2_RLEASE in the middle of the bsp_evt_t enum. It changes all the events after this. Perhaps you should add it after BSP_EVENT_KEY_7, and change BSP_EVENT_KEY_LAST to the last event that you have.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;The reason the first release event doesn&amp;#39;t occur is because of this:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;            case APP_BUTTON_RELEASE:
                (void)app_timer_stop(m_bsp_button_tmr);
                if (release_event_at_push[button] == m_events_list[button].release_event)
                {
                    event = m_events_list[button].release_event;
                }
                break;&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;Line 3 checks if the button was ever pushed before you receive the release event.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As I see it you have 3 options:&lt;/p&gt;
&lt;p&gt;1: Quick and dirty. Comment out line 3 of that snippet.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;2: Set the release_event_at_push[button 2]&amp;nbsp;&lt;strong&gt;if&lt;/strong&gt; button 2 is pressed at startup. This requires some modifications.&lt;/p&gt;
&lt;p&gt;3: Use the raw app_button module, as we discussed. As mentioned, bsp_button_event_handler() is the callback function for the app_button in this case, and it receives every push and release event. Even the first release even if there were no push.&lt;/p&gt;
&lt;p&gt;The debounce is part of the app_button, not bsp. You can either look at how the bsp uses app_button, or you can check out &lt;a href="https://github.com/edvinand/nRF52_peripherals_tutorial#3---buttons---button-handler-library" rel="noopener noreferrer" target="_blank"&gt;this guide&lt;/a&gt;. Note that you need to do section 2 (up and till app_timer_init(), if it is not done elsewhere in your project) before applying section 3(app_button).&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;br /&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/thread/270201?ContentTypeID=1</link><pubDate>Fri, 18 Sep 2020 02:23:52 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:9088a565-3d0c-4737-89e5-a5911b79fe5b</guid><dc:creator>Jones</dc:creator><description>&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/bsp.h"&gt;devzone.nordicsemi.com/.../bsp.h&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://devzone.nordicsemi.com/cfs-file/__key/communityserver-discussions-components-files/4/3731.bsp.c"&gt;devzone.nordicsemi.com/.../3731.bsp.c&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;In fact, I just added &amp;quot;BPS_EVENT_KEY_2_RLEASE&amp;quot; in the&amp;nbsp;bsp_event_t.&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/thread/270139?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2020 14:10:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:63a14e13-8220-456b-8b12-f9b104c5e57e</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;The debounce is part of the app_button module. The app timer that you see in bsp.c is used to separate long push from push.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;My point was that bsp doesn&amp;#39;t work with release out of the box. So if it works in your case, you must have done some changes. Is that correct? Also,&amp;nbsp;&lt;span&gt;BPS_EVENT_KEY_2_RLEASE is not defined by default. Where did you define it?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;I don&amp;#39;t know why the first release doesn&amp;#39;t work if I don&amp;#39;t know what the library you are working with looks like. Can you send me your bsp.h and bsp.c?&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;If you want to use the app_button directly, look at how bsp uses app_button.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Some keywords to get started:&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;app_button_init(), app_button_enable(), app_buttons[BUTTONS_NUMBER], and the event handler that you set in app_buttons[BUTTONS_NUMBER].button_handler.&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;BR,&lt;/span&gt;&lt;/p&gt;
&lt;p&gt;&lt;span&gt;Edvin&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/thread/270131?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2020 13:49:30 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:ea4d3d3d-3ae5-4470-8a95-b12745735770</guid><dc:creator>Jones</dc:creator><description>&lt;p&gt;Hi Edvin,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks for you reply.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;In fact, the press and release event works in my code. Sorry I didn&amp;rsquo;t list them all out.&lt;/p&gt;
&lt;p&gt;My problem is that the first release event is missing if the button is press while reset/power up.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;By the way, if bsp is not ideal, how I can remove it and how to implement those handling on my own? I want to keep those debouncing features for a key, what software module should I use?&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Jones&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: About missing first button release event after power up if the key is pressed during power up</title><link>https://devzone.nordicsemi.com/thread/270071?ContentTypeID=1</link><pubDate>Thu, 17 Sep 2020 12:02:04 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:1160bb90-e33e-499f-8a93-0352439bd0af</guid><dc:creator>Edvin</dc:creator><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Have you by chance changed a few things in bsp.c/h?&lt;/p&gt;
&lt;p&gt;The reason I ask is that&amp;nbsp;BPS_EVENT_KEY_2_RLEASE is not defined (and neither is&amp;nbsp;BPS_EVENT_KEY_2_RELEASE).&amp;nbsp;&lt;/p&gt;
&lt;p&gt;On top of that,&amp;nbsp;bsp_event_to_button_action_assign() checks if the parameter &amp;quot;action&amp;quot; is BSP_BUTTON_ACTION_PUSH, and if it is not, it will&amp;nbsp; set the event to BSP_EVENT_NOTHING, so it doesn&amp;#39;t do anything if you use&amp;nbsp;BSP_BUTTON_ACTION_RELEASE.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Actually, bsp is not ideal if you want to use all the events, because it masks away the release of buttons. Perhaps if you modify it enough, you can make it work, but then I need to know what changes you did to bsp.c/h.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Just curious: Does the release event for button #2 work for the next release events in your case?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;EDIT:&lt;/p&gt;
&lt;p&gt;I see that it is probably not too difficult to adjust it to accept release events, but let me have a look at the implementation, so I can look into why it doesn&amp;#39;t work for the first event. An alternative is to use the app_button module, which the bsp uses below the hood.&amp;nbsp; If you look at the function bsp_button_event_handler() in bsp.c, this is actually the app_button callback. The parameter button_action contains the parameter button_action, which says whther the button is pushed or released. If you debug here, you should see that the button event is probably registered. But the bsp filters out the event, because it is not set up correctly.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;BR,&lt;/p&gt;
&lt;p&gt;Edvin&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>