This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

app_button configure different pin sense & debounce time

Hi

I am using app_button library to sense button detect, it work fine.

static void button_init(void)
{
    uint32_t err_code;

    //The array must be static because a pointer to it will be saved in the button handler module.
    static app_button_cfg_t buttons[] =
    {
        	{button_1, false, NRF_GPIO_PIN_PULLUP, button_event_handler},
        	{button_2, false, NRF_GPIO_PIN_PULLUP, button_event_handler}
    }; 

    err_code = app_button_init(buttons, sizeof(buttons) / sizeof(buttons[0]),BUTTON_DETECTION_DELAY);
    APP_ERROR_CHECK(err_code);
}

now I'm try to detect difference sense and debounce time, like this

button_1, GPIOTE_SENSE_TOGGLE, debounce 1 second

button_2, GPIOTE_SENSE_LOTOHI, debounce 5 ticks

How do I configure it?

chip : nrf51822

SDK : 10

Softdevice : S110_V8

Parents
  • Hey, my first answer to a question so don't take everything for granted what i say but i had a similar question.

    Regarding TOGGLE, LOTOHI: I had a similar question which got answered. devzone.nordicsemi.com/.../

    so basically you can read what happened in your button_event_handler. Today I found an other way around. In the app_button.c

    there is this line of code

    nrf_drv_gpiote_in_config_t config = GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);

    So every button you configure is configured as toggle. If you want to have all buttons as HITOLO just change it to GPIOTE_CONFIG_IN_SENSE_HITOLO(false); I guess you can also write a litte if/else and give the app_button_init an extra argument if you want to not use the solution mentioned in the answer to my post.

    Regarding debounce: In your main you do app_button_init() the delay BUTTON_DETECTION_DELAY has to be given in ticks. To get ticks out of ms just write APP_TIMER_TICKS(50, APP_TIMER_PRESCALER) for 50ms delay The APP_TIMER_PRESCALER is the value you gave to APP_TIMER_INIT() earlier in your code.

    P.s. I use sdk12.2 so there could be differences in the code

  • You can achive the different behavior for TOGGLE and LOTOHI by configuring the gpiote_in_init for every button in a different way.

    in app_button.c all buttons are configured with TOGGLE if you add something like this

    			nrf_drv_gpiote_in_config_t config;
    				if(button_count == 1)
    				{
    					config = (nrf_drv_gpiote_in_config_t)GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    				}
    				else
    				{
    					config = (nrf_drv_gpiote_in_config_t)GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    				}
    

    the first button will fire on toggle the second only on high to low. For the Debounce time i guess you need to create different timers, but I am new to this so I don't have a solution for that.

Reply
  • You can achive the different behavior for TOGGLE and LOTOHI by configuring the gpiote_in_init for every button in a different way.

    in app_button.c all buttons are configured with TOGGLE if you add something like this

    			nrf_drv_gpiote_in_config_t config;
    				if(button_count == 1)
    				{
    					config = (nrf_drv_gpiote_in_config_t)GPIOTE_CONFIG_IN_SENSE_HITOLO(false);
    				}
    				else
    				{
    					config = (nrf_drv_gpiote_in_config_t)GPIOTE_CONFIG_IN_SENSE_TOGGLE(false);
    				}
    

    the first button will fire on toggle the second only on high to low. For the Debounce time i guess you need to create different timers, but I am new to this so I don't have a solution for that.

Children
No Data
Related