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

never call "app_button_is_pushed()" function in ble-lbs-master project

Hello Nordic,

I am trying debugging on following project [--ble_app_lbs_master--]. During debugging, I never reach at app_button_is_pushed function. I tried pressing the button while debugging and in connected state.

Actually I want to read the button_pin_status (value) in between when button pressed and button detected. How can I do that?

Please suggest valuable suggestions.

Thanks n Regards

Update1: @Aryan: Please find the attached app_button.x file.app_button.c

Update2: @Aryan:

image description

uint32_t app_button_init(app_button_cfg_t * p_buttons, uint8_t button_count, uint32_t detection_delay) image description

Parents
  • There was a PAN that on OUTINIT on some hardware IC rev and the workaround for it was removed from SDK from 8.0.0.

    in SDK9.0 and SDK 8.1, nrf_gpiote.h nrf_gpiote_task_configure needs a fix for the above to work. update it with this code and let me know if it works.

    __STATIC_INLINE void nrf_gpiote_task_configure(uint32_t idx, uint32_t pin,
                                                    nrf_gpiote_polarity_t polarity,
                                                    nrf_gpiote_outinit_t  init_val)
    {
        /* Check if the output desired is high or low */
        if (init_val == NRF_GPIOTE_INITIAL_VALUE_LOW)
        {
            /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
            on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 
            correct state in GPIOTE but not in the OUT register. */
            NRF_GPIO->OUTCLR = (1 << pin);
    
            /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */
            NRF_GPIOTE->CONFIG[idx] = (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos)     |
                                                 (31UL                          << GPIOTE_CONFIG_PSEL_Pos)     |
                                                 (GPIOTE_CONFIG_POLARITY_HiToLo << GPIOTE_CONFIG_POLARITY_Pos);                                    
        } 
        else 
        {
            /* Workaround for the OUTINIT PAN. When nrf_gpiote_task_config() is called a glitch happens
            on the GPIO if the GPIO in question is already assigned to GPIOTE and the pin is in the 
            correct state in GPIOTE but not in the OUT register. */
            NRF_GPIO->OUTSET = (1 << pin);
    
            /* Configure channel to Pin31, not connected to the pin, and configure as a tasks that will set it to proper level */
            NRF_GPIOTE->CONFIG[idx] = (GPIOTE_CONFIG_MODE_Task       << GPIOTE_CONFIG_MODE_Pos)     |
                                                 (31UL                          << GPIOTE_CONFIG_PSEL_Pos)     |
                                                 (GPIOTE_CONFIG_POLARITY_LoToHi << GPIOTE_CONFIG_POLARITY_Pos);
        }
    
        /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
        __NOP();
        __NOP();
        __NOP(); 
    
        /* Launch the task to take the GPIOTE channel output to the desired level */
        NRF_GPIOTE->TASKS_OUT[idx] = 1;
    
    
        /* Finally configure the channel as the caller expects. If OUTINIT works, the channel is configured properly. 
           If it does not, the channel output inheritance sets the proper level. */
        NRF_GPIOTE->CONFIG[idx] = (GPIOTE_CONFIG_MODE_Task << GPIOTE_CONFIG_MODE_Pos)     |
                                             ((uint32_t)pin    << GPIOTE_CONFIG_PSEL_Pos)     |
                                             ((uint32_t)polarity      << GPIOTE_CONFIG_POLARITY_Pos) |
                                             ((uint32_t)init_val << GPIOTE_CONFIG_OUTINIT_Pos);
    
        /* Three NOPs are required to make sure configuration is written before setting tasks or getting events */
        __NOP();
        __NOP();
        __NOP(); 
    }
    
  • app_button_is_pushed is not used by the example that is why it never gets called.

    bool m_is_pushed;
    static void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
    {
        uint32_t err_code;
     
        // Start detection timer. If timer is already running, the detection period is restarted.
        // NOTE: Using the p_context parameter of app_timer_start() to transfer the pin states to the
        //       timeout handler (by casting event_pins_mask into the equally sized void * p_context
        //       parameter).
        STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t));
    
        err_code = app_timer_stop(m_detection_delay_timer_id);
    
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
            return;
        }
        
        err_code = app_button_is_pushed(1,  &m_is_pushed);
            if (err_code != NRF_SUCCESS)
        {
            while(1); // you handle your error here
        }
        m_pin_transition.low_to_high = event_pins_low_to_high;
        m_pin_transition.high_to_low = event_pins_high_to_low;
        
        err_code = app_timer_start(m_detection_delay_timer_id,
                                   m_detection_delay,
                                   (void *)(event_pins_low_to_high | event_pins_high_to_low));
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
        }
    }
    

    in main.c you can access m_is_pushed by declaring it as extern.

    the first argument in the function app_button_is_pushed is the index of the button config you have used in app_button_init. For me it was 1.

Reply
  • app_button_is_pushed is not used by the example that is why it never gets called.

    bool m_is_pushed;
    static void gpiote_event_handler(uint32_t event_pins_low_to_high, uint32_t event_pins_high_to_low)
    {
        uint32_t err_code;
     
        // Start detection timer. If timer is already running, the detection period is restarted.
        // NOTE: Using the p_context parameter of app_timer_start() to transfer the pin states to the
        //       timeout handler (by casting event_pins_mask into the equally sized void * p_context
        //       parameter).
        STATIC_ASSERT(sizeof(void *) == sizeof(uint32_t));
    
        err_code = app_timer_stop(m_detection_delay_timer_id);
    
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
            return;
        }
        
        err_code = app_button_is_pushed(1,  &m_is_pushed);
            if (err_code != NRF_SUCCESS)
        {
            while(1); // you handle your error here
        }
        m_pin_transition.low_to_high = event_pins_low_to_high;
        m_pin_transition.high_to_low = event_pins_high_to_low;
        
        err_code = app_timer_start(m_detection_delay_timer_id,
                                   m_detection_delay,
                                   (void *)(event_pins_low_to_high | event_pins_high_to_low));
        if (err_code != NRF_SUCCESS)
        {
            // The impact in app_button of the app_timer queue running full is losing a button press.
            // The current implementation ensures that the system will continue working as normal. 
        }
    }
    

    in main.c you can access m_is_pushed by declaring it as extern.

    the first argument in the function app_button_is_pushed is the index of the button config you have used in app_button_init. For me it was 1.

Children
No Data
Related