This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

About missing first button release event after power up if the key is pressed during power up

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.

static void buttons_leds_init(bool * p_erase_bonds)
{
    ret_code_t err_code;
    bsp_event_t startup_event;

    err_code = bsp_init(BSP_INIT_LEDS | BSP_INIT_BUTTONS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_event_to_button_action_assign(2, BSP_BUTTON_ACTION_RELEASE, BPS_EVENT_KEY_2_RLEASE);
    APP_ERROR_CHECK(err_code);

    err_code = bsp_btn_ble_init(NULL, &startup_event);
    APP_ERROR_CHECK(err_code);

    *p_erase_bonds = (startup_event == BSP_EVENT_CLEAR_BONDING_DATA);
}

The procedure to repeat the problem is as below:

  1. press the button #2
  2. power up / reset the nrf52832
  3. release the button 
  4. release event for button #2 is not triggered

However, if the button is not pressed when power up. The first button press event is triggered.

Just the first release event is missing but after the first one, everything works fine.

Any idea how to solve this? Or I can use other software module rather than the bsp? 

Thanks,

Jones

Parents
  • Hello,

    Have you by chance changed a few things in bsp.c/h?

    The reason I ask is that BPS_EVENT_KEY_2_RLEASE is not defined (and neither is BPS_EVENT_KEY_2_RELEASE). 

    On top of that, bsp_event_to_button_action_assign() checks if the parameter "action" is BSP_BUTTON_ACTION_PUSH, and if it is not, it will  set the event to BSP_EVENT_NOTHING, so it doesn't do anything if you use BSP_BUTTON_ACTION_RELEASE. 

    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. 

    Just curious: Does the release event for button #2 work for the next release events in your case?

    EDIT:

    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't work for the first event. An alternative is to use the app_button module, which the bsp uses below the hood.  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.

    BR,

    Edvin

  • Hi Edvin,

    Thanks for you reply. 

    In fact, the press and release event works in my code. Sorry I didn’t list them all out.

    My problem is that the first release event is missing if the button is press while reset/power up. 

    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? 

    Thanks,

    Jones

  • 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. 

    My point was that bsp doesn'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, BPS_EVENT_KEY_2_RLEASE is not defined by default. Where did you define it?

    I don't know why the first release doesn't work if I don't know what the library you are working with looks like. Can you send me your bsp.h and bsp.c?

    If you want to use the app_button directly, look at how bsp uses app_button.

    Some keywords to get started:

    app_button_init(), app_button_enable(), app_buttons[BUTTONS_NUMBER], and the event handler that you set in app_buttons[BUTTONS_NUMBER].button_handler.

    BR,

    Edvin

Reply
  • 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. 

    My point was that bsp doesn'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, BPS_EVENT_KEY_2_RLEASE is not defined by default. Where did you define it?

    I don't know why the first release doesn't work if I don't know what the library you are working with looks like. Can you send me your bsp.h and bsp.c?

    If you want to use the app_button directly, look at how bsp uses app_button.

    Some keywords to get started:

    app_button_init(), app_button_enable(), app_buttons[BUTTONS_NUMBER], and the event handler that you set in app_buttons[BUTTONS_NUMBER].button_handler.

    BR,

    Edvin

Children
No Data
Related