Sw2 button-dwm1001 dev

Hello,

It was previously said I could reconfigure the SW2 button on the DWM1001 Dev board. My question is, quite simply, how? Would I have to modify existing code (if so, where would that code be?)? Or would I have to write new code to overwrite the previous function?

Thanks.

Yes, definitely.
Below is a piece of my code using SW2 button to switch on/off LED depending of the button state. I skipped some code not related to the button usage.
Note that this button is not available if you configured DWM as a tag and enabled BLE (see 3.4.5 of the DWM1001-API-Guide.pdf). If so, the function dwm_gpio_value_get returns an error (can’t remember which error exactly). Strange for me, because concurrent reading such a resource should be safe, but…

[code]#define SLEEP_BTN_GPIO DWM_GPIO_IDX_2
#define LED_BTN_GPIO DWM_GPIO_IDX_14
#define SLEEP_BTN_CHECK_PERIOD_TICKS 2

/**

  • Check hardware button state
  • @return state
  • @retval true Button pressed
    */
    bool CheckButton(void)
    {
    bool value;
    int res = dwm_gpio_value_get( SLEEP_BTN_GPIO, &value);
    if ( res != DWM_OK ) {
    // in case of any error assuming button is not pressed
    return false;
    }
    // check pin value, light LED if pressed and return current button state
    if ( value == 0 ) {
    res = dwm_gpio_value_set( LED_BTN_GPIO, false);
    return true;
    }else{
    res = dwm_gpio_value_set( LED_BTN_GPIO, true);
    return false;
    }
    }

/**

  • Application thread
  • @param[in] data Pointer to user data
    /
    void app_thread_entry(uint32_t data)
    {

    // some initialisation
    // Config GPIO2(user wakeup button)
    dwm_gpio_cfg_input( SLEEP_BTN_GPIO, DWM_GPIO_PIN_PULLUP);
    // configure LED pin, blink twice
    dwm_gpio_cfg_output( LED_BTN_GPIO, false);

    // only task is to check User Button
    while (1) {
    /
    Thread loop */
    if ( CheckButton() ) {
    sleep_btn_counter++;
    }else{
    sleep_btn_counter = 0;
    }
    // delay 20ms
    dwm_thread_delay(SLEEP_BTN_CHECK_PERIOD_TICKS);
    }
    }

[/code]

i tried this code but i cant turn on and turn off the LED