diff --git a/samples/boards/nrf/nrfx/src/main.c b/samples/boards/nrf/nrfx/src/main.c index 5c2f2a6b55..64e60d6534 100644 --- a/samples/boards/nrf/nrfx/src/main.c +++ b/samples/boards/nrf/nrfx/src/main.c @@ -17,9 +17,10 @@ #include LOG_MODULE_REGISTER(nrfx_sample, LOG_LEVEL_INF); -#define INPUT_PIN DT_GPIO_PIN(DT_ALIAS(sw0), gpios) #define OUTPUT_PIN DT_GPIO_PIN(DT_ALIAS(led0), gpios) +uint32_t m_input_pin; + static void button_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) { LOG_INF("GPIO input event callback"); @@ -27,7 +28,15 @@ static void button_handler(nrfx_gpiote_pin_t pin, nrf_gpiote_polarity_t action) void main(void) { - LOG_INF("nrfx_gpiote sample on %s", CONFIG_BOARD); + if (strcmp(DT_GPIO_LABEL(DT_ALIAS(sw0), gpios), "GPIO_1") == 0) { + m_input_pin = 32 + DT_GPIO_PIN(DT_ALIAS(sw0), gpios); + } + else { + m_input_pin = DT_GPIO_PIN(DT_ALIAS(sw0), gpios); + } + + LOG_INF("nrfx_gpiote sample on %s. Input pin is: %u", CONFIG_BOARD, m_input_pin); + nrfx_err_t err; @@ -56,7 +65,7 @@ void main(void) /* Initialize input pin to generate event on high to low transition * (falling edge) and call button_handler() */ - err = nrfx_gpiote_in_init(INPUT_PIN, &in_config, button_handler); + err = nrfx_gpiote_in_init(m_input_pin, &in_config, button_handler); if (err != NRFX_SUCCESS) { LOG_ERR("nrfx_gpiote_in_init error: %08x", err); return; @@ -77,7 +86,7 @@ void main(void) return; } - nrfx_gpiote_in_event_enable(INPUT_PIN, true); + nrfx_gpiote_in_event_enable(m_input_pin, true); nrfx_gpiote_out_task_enable(OUTPUT_PIN); LOG_INF("nrfx_gpiote initialized"); @@ -100,7 +109,7 @@ void main(void) * the button is pressed, the LED pin will be toggled. */ nrfx_gppi_channel_endpoints_setup(channel, - nrfx_gpiote_in_event_addr_get(INPUT_PIN), + nrfx_gpiote_in_event_addr_get(m_input_pin), nrfx_gpiote_out_task_addr_get(OUTPUT_PIN)); /* Enable (D)PPI channel. */