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

Button Configuration

Hi,

I need some details about the button configuration

To perform a Single Button configuration like

One click (BUTTON_RELEASE)

Double Click (BUTTON_RELEASE)

Button Press for 3 seconds

Button Press for 7 seconds.

all these configuration should apply for only one BUTTON

if this is case which one is better

app_button.c or bsp.c

2. how do i change the wake up button action.

   i.e -   by default while the system off state . when the button is pressed the system wake up. instead of that i need the

wake up action to be change it to BUTTON _RELEASE .

3. or wake up is to be done after the 3seconds of long press of a button.

  • i have a question that my application run with bootloader and hardware i have only one button.

    If i wakeup the device with pressing the button .it enter into DFU because that pin assigned as DFU button

    so. is it possible to have CONNECTION LIKE THIS

    P0.12 as OUTPUT

    P0.13 as INPUT

    when the controller receive command from the app as DFU

    the Pin

    P0.12 will get high

    and P0.13 will get high and enter into DFU process

    this will work ?

  • Hi,

    BSP module uses the app_button library. But the board support package (BSP) includes more things like control of LEDS, buttons, etc, are is mostly intended to be used with nordic development kits.

    BSP have single push and long push, but it doesn't have support for double push.

    I think you will need to make something custom using app_button and app_timer. You can look into the BSP module to see how it generates long pushes so you have a starting guide

    With app_button you will get events for both pushes and releases, so you can start a timer and stop it after each release, or when you detect more than 1 push inside one given interval.

    Best regards,

    Marjeris

  • Hi,

    Why don't disable the DFU button in the bootloader? Try to use the Buttonless DFU template application example in the SDK instead.

  • Hi msromero,

    I have create the C file to run by button application

    please conform that the work nature or it will not affect cpu life cycle when its applied in a large program

    Main Code:

    #include <stdbool.h>
    #include <stdint.h>
    #include "boards.h"
    #include "bsp.h"
    #include "app_timer.h"
    #include "nordic_common.h"
    #include "nrf_error.h"
    #include "nrf_gpio.h"
    #include "blc.h"
    #include "nrf_log.h"
    #include "nrf_log_ctrl.h"
    #include "nrf_log_default_backends.h"
    
    
    void clock_initialization()
    {
        NRF_CLOCK->LFCLKSRC            = (CLOCK_LFCLKSRC_SRC_Xtal << CLOCK_LFCLKSRC_SRC_Pos);
        NRF_CLOCK->EVENTS_LFCLKSTARTED = 0;
        NRF_CLOCK->TASKS_LFCLKSTART    = 1;
    
        while (NRF_CLOCK->EVENTS_LFCLKSTARTED == 0)
        {
            // Do nothing.
        }
    }
    
    
    int main(void)
    {   bool erase_bonds;
        clock_initialization();
      
        uint32_t err_code = app_timer_init();
        APP_ERROR_CHECK(err_code);
    
        APP_ERROR_CHECK(NRF_LOG_INIT(NULL));
        NRF_LOG_DEFAULT_BACKENDS_INIT();
        err_code = blc_init();
        APP_ERROR_CHECK(err_code);
        NRF_LOG_INFO("BSP example started.");
        
    
    
        while (true)
        {
            NRF_LOG_FLUSH();
            __SEV();
            __WFE();
            __WFE();
            // no implementation needed
        }
    }
    

    BLC.h

    #ifndef BLC_H__
    #define BLC_H__
    
    #include <stdint.h>
    #include <stdbool.h>
    #include "boards.h"
    #include "app_button.h"
    
    
    uint32_t blc_init(void);
    
    #endif

    BLC.c

    #include "blc.h"
    #include "boards.h"
    #include "bsp_config.h"
    #include "app_timer.h"
    #include "app_button.h"
    #include "app_error.h"
    #include "nrf_log.h"
    
    
    char flag = 0;
    bool first_click = false;
    APP_TIMER_DEF(m_button_action);
    
    #define BUTTON_STATE_POLL_INTERVAL_MS  100UL
    
    #define LONG_PRESS(MS)    (uint32_t)(MS)/BUTTON_STATE_POLL_INTERVAL_MS 
    
    
    
    void button_timeout_handler(void * p_context)
    { 
         uint32_t err_code;
         static uint32_t cnt;
    
         if (app_button_is_pushed(0))
         {
             cnt++;
              NRF_LOG_INFO("cnt: %d",cnt);
    
             if ( cnt >= LONG_PRESS(1300))
             {
                 cnt = 0;
                 bsp_board_leds_off();
                      bsp_board_led_on(BSP_LED_INDICATE_USER_LED3);
                      bsp_board_led_on(BSP_LED_INDICATE_USER_LED4);
                 NRF_LOG_INFO("Long Button press");
                 flag = 0;
             }
             else
             {
                  err_code = app_timer_start(m_button_action, 
                                             APP_TIMER_TICKS(BUTTON_STATE_POLL_INTERVAL_MS),
                                             NULL);
                  APP_ERROR_CHECK(err_code);
                  NRF_LOG_INFO("timer");
             }
         }
         else
         {
             if (cnt >= 4 )
             {
              
              }
    
              else
              {
              if(flag == 2)
                 {
                      bsp_board_leds_off();
                      bsp_board_led_on(BSP_LED_INDICATE_USER_LED2);
                      NRF_LOG_INFO("double click");
                      first_click = true;
            
                  }
                else if((flag == 1)&& (first_click == true))
                  {
                       bsp_board_leds_off();
                      bsp_board_led_on(BSP_LED_INDICATE_USER_LED1);
                      NRF_LOG_INFO("single click");
          
                  }
              }
              cnt = 0; // reset counter variable
                        
    
                flag = 0;
    
                }
    }
    
    void button_callback(uint8_t pin_no, uint8_t button_action)
    {
          uint32_t err_code;
    
          
          if ((pin_no == BUTTON_1) && (button_action == APP_BUTTON_PUSH))
          {
              err_code = app_timer_start(m_button_action, 
                                         APP_TIMER_TICKS(450),
                                         NULL);
              APP_ERROR_CHECK(err_code);
               flag++;
    
          }
         /* else if ((pin_no == BUTTON_1 ) && (button_action == APP_BUTTON_RELEASE))
          {
            app_timer_stop_all();
            cnt = 0;
          }*/
    }
    
    
    uint32_t blc_init()
    {
      uint32_t err_code = NRF_SUCCESS;
    
      static app_button_cfg_t  button_cfg;
    
          button_cfg.pin_no         = BUTTON_1;
          button_cfg.button_handler = button_callback;
          button_cfg.pull_cfg       = NRF_GPIO_PIN_PULLUP;
          button_cfg.active_state   = APP_BUTTON_ACTIVE_LOW;
          bsp_board_init(BSP_INIT_LEDS);
          err_code = app_button_init(&button_cfg, 1, 100);
          if (err_code == NRF_SUCCESS)
          {      
          err_code = app_button_enable();
          }
          
          if (err_code == NRF_SUCCESS)
          {
    
          /*Enable an app timer instance to detect long button press*/
          err_code = app_timer_create(&m_button_action, APP_TIMER_MODE_SINGLE_SHOT, button_timeout_handler);
          APP_ERROR_CHECK(err_code);
          }
           return err_code;
     }

    function of the code:

    First:

    Double click to access single click

    long press for 1.2 sec

    single click and double click function

    i want it to assign the same button for wake up and the wake up function must appear only when button is release .

    how to assign for this

    i will try buttonless dfu and i will reply

Related