Hi, I am working on long press button interrupt in nrf52832 device & used NCS. I am unable to detect the long press from button.below is my functionality which is I am trying to implement.
press for 10 sec after that call a callback function.
void long_button_pressed(const struct device *dev, struct gpio_callback *cb, uint32_t pins) { // if (gpio_pin_get_dt(&button_0)) { if(pins & BIT(button_0.pin)){ LOG_INF("button pin detected"); k_timer_start(&button_timer, K_SECONDS(10), K_NO_WAIT); } else { LOG_INF("long_press not detected"); k_timer_stop(&button_timer); long_press_detected = false; // Reset flag if button is released } } void button_timer_expiry_handler(struct k_timer *timer_id) { printk("Button long-pressed for 10 seconds\n"); long_press_detected = true; Reset_Flag=1; eeprom_write(i2c_dev,EEPROM_RESET_FLAG_ADDRESS, &Reset_Flag, 1); eeprom_write(i2c_dev,EEPROM_RESET_TIME_FLAG, ¤t_epoch_time, 4); guide_flag=1; eeprom_write(i2c_dev,EEPROM_DEVICE_GUIDE_ADDRESS,&guide_flag,1); reset_hardware_locally(); //reset_hardware(); k_msleep(1000); NVIC_SystemReset(); // Add your action here } void long_press_button(){ if (!device_is_ready(button_0.port)) { printk("Button device not ready\n"); return; } gpio_init_callback(&button_cb_data,long_button_pressed, BIT(button_0.pin)); gpio_add_callback(button_0.port, &button_cb_data); k_timer_init(&button_timer, button_timer_expiry_handler, NULL); }
above is the code of long press button.
Pin configuration :-
gpio_pin_configure_dt(&button_0, GPIO_INPUT);
gpio_pin_interrupt_configure_dt(&button_0, GPIO_INT_EDGE_BOTH);
configuration in overlay file:-
button0
{
gpios = <&gpio0 21 GPIO_ACTIVE_LOW>;
label = "SW1";
};
Suggest a solution how can implement long press button interrupt in zephyr ncs.