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

How can I use of unused button events while also using bsp_btn_ble_init()?

I'm trying to add a SPI driver to the ble_app_uart_c example. For now, I'm just trying to make this driver shoot out a SPI transaction every time I click a button on the dev kit. To do this I would like some control over the buttons/leds. I'm pretty sure I understand the button event handler and different events, and I roughly understand what bsp_btn_ble_init() does based off the API reference (it allows the board to wake up from button presses and read which button actually did the waking up, yea?) - BUT I don't understand how to add my own button/LED functionality in parallel with the existing BLE code.

If I call bsp_init() for the buttons (as I do in the snippet below), the example still seems to work (as in I can connect to a peripheral over via BLE), but the LEDs aren't responding. I can't set them to any values and LED1 isn't blinking while advertising. What am I missing? I feel like there is some hidden button handler that I keep overlooking. 

static void buttons_leds_init(void)
{
    ret_code_t err_code;
    bsp_event_t startup_event;

    err_code = bsp_init(BSP_INIT_LEDS, bsp_event_handler);
    APP_ERROR_CHECK(err_code);
    
    err_code = bsp_init(BSP_INIT_BUTTONS, bsp_event_handler); // this seems to remove the LED blinking
    APP_ERROR_CHECK(err_code);

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

}

Thank you for any help! I'm new to embedded/BLE development so I apologize for silly questions.

Parents
  • Hello,

    When you call bsp_init() two times like this, it messes up the internal event handlers. Mainly because m_indication_type inside bsp_init() will be wrong when you call it the second time. Only the buttons, and not the LEDs will be handled, but I haven't dug too deep into what behavior this causes. I just saw that it caused some weird behavior when I actually pressed a button after initializing it this way.

    The correct way to initialize both the LEDs and the buttons is:

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

    Try this and let me know if that doesn't work.

    Best regards,

    Edvin

Reply
  • Hello,

    When you call bsp_init() two times like this, it messes up the internal event handlers. Mainly because m_indication_type inside bsp_init() will be wrong when you call it the second time. Only the buttons, and not the LEDs will be handled, but I haven't dug too deep into what behavior this causes. I just saw that it caused some weird behavior when I actually pressed a button after initializing it this way.

    The correct way to initialize both the LEDs and the buttons is:

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

    Try this and let me know if that doesn't work.

    Best regards,

    Edvin

Children
No Data
Related