Use the same pin to wake up and other uses

Hi to all!

I'm trying to use the same GPIO to wake up the nrf52810 from system off and also use it to execute some functions. I have this code that is based on the example from this link: https://developer.nordicsemi.com/nRF_Connect_SDK/doc/2.0.2/zephyr/samples/boards/nrf/system_off/README.html

// function to power off
static void power_off_system() {
	/* Configure to generate PORT event (wakeup) on button 1 press. */
	nrf_gpio_cfg_input(btn.pin, NRF_GPIO_PIN_PULLUP);
	nrf_gpio_cfg_sense_set(btn.pin, NRF_GPIO_PIN_SENSE_LOW);

	printk("Pwering off device\n");
	pm_state_force(0u, &(struct pm_state_info){PM_STATE_SOFT_OFF, 0, 0});

	/* Now we need to go sleep. This will let the idle thread runs and
	 * the pm subsystem will use the forced state. To confirm that the
	 * forced state is used, lets set the same timeout used previously.
	 */
	// k_sleep(2);
	k_msleep(2000);
}
/* Prevent deep sleep (system off) from being entered on long timeouts
 * or `K_FOREVER` due to the default residency policy.
 *
 * This has to be done before anything tries to sleep, which means
 * before the threading system starts up between PRE_KERNEL_2 and
 * POST_KERNEL.  Do it at the start of PRE_KERNEL_2.
 */
static int disable_ds_1(const struct device *dev)
{
	ARG_UNUSED(dev);

	pm_policy_state_lock_get(PM_STATE_SOFT_OFF);
	return 0;
}

SYS_INIT(disable_ds_1, PRE_KERNEL_2, 0);

This is executed when long press the button. Then in the wake up, it works but the button has some strange behavior like it us pulsed 2 times at the same time. The button is configured as an interrupt that enable a timer to test if is a long press or a simple press.

This is the configuration of the GPIO to use it as an interrupt:

gpio_init_callback(&button_cb_data, button_pressed, BIT(btn.pin));
gpio_add_callback(btn.port, &button_cb_data);

Also, there is a way to start the nrf with system off and wake it up with a long press?

Best regards

Parents Reply Children
No Data
Related