samples/boards/nrf/nrfx: Make the sample usable on all nRF SoCs
Conditionally use either DPPI or PPI channel in the sample so that
it can be built for all nRF SoCs. Update documentation accordingly.
Signed-off-by: Andrzej Głąbek <andrzej.glabek@nordicsemi.no>
diff --git a/samples/boards/nrf/nrfx/Kconfig b/samples/boards/nrf/nrfx/Kconfig
new file mode 100644
index 0000000..0d54067
--- /dev/null
+++ b/samples/boards/nrf/nrfx/Kconfig
@@ -0,0 +1,10 @@
+# Copyright (c) 2021 Nordic Semiconductor ASA
+# SPDX-License-Identifier: Apache-2.0
+
+config NRFX_DPPI
+ default HAS_HW_NRF_DPPIC
+
+config NRFX_PPI
+ default HAS_HW_NRF_PPI
+
+source "Kconfig.zephyr"
diff --git a/samples/boards/nrf/nrfx/README.rst b/samples/boards/nrf/nrfx/README.rst
index 4faac6f..c447335 100644
--- a/samples/boards/nrf/nrfx/README.rst
+++ b/samples/boards/nrf/nrfx/README.rst
@@ -1,17 +1,17 @@
-.. _nrf91_nrfx:
+.. _nrfx_sample:
-nRF91 nrfx example
-##################
+nrfx use example
+################
Overview
********
This sample demonstrates the usage of nrfx library in Zephyr.
-GPIOTE and DPPI are used as examples of nrfx drivers.
+GPIOTE and DPPI/PPI are used as examples of nrfx drivers.
The code shows how to initialize the GPIOTE interrupt in Zephyr
so that the nrfx_gpiote driver can use it. Additionally, it shows
-how the DPPI subsystem can be used to connect tasks and events of
+how the DPPI/PPI subsystem can be used to connect tasks and events of
nRF peripherals, enabling those peripherals to interact with each
other without any intervention from the CPU.
@@ -24,7 +24,7 @@
************
This sample has been tested on the NordicSemiconductor nRF9160 DK
-(nrf9160dk_nrf9160) board.
+(nrf9160dk_nrf9160) and nRF52840 DK (nrf52840dk_nrf52840) boards.
Building and Running
********************
diff --git a/samples/boards/nrf/nrfx/prj.conf b/samples/boards/nrf/nrfx/prj.conf
index 1aa92d9..32cbfc3 100644
--- a/samples/boards/nrf/nrfx/prj.conf
+++ b/samples/boards/nrf/nrfx/prj.conf
@@ -1,5 +1,4 @@
CONFIG_GPIO=n
CONFIG_NRFX_GPIOTE=y
-CONFIG_NRFX_DPPI=y
CONFIG_LOG=y
CONFIG_LOG_PROCESS_THREAD_SLEEP_MS=100
diff --git a/samples/boards/nrf/nrfx/sample.yaml b/samples/boards/nrf/nrfx/sample.yaml
index eda9020..329903b 100644
--- a/samples/boards/nrf/nrfx/sample.yaml
+++ b/samples/boards/nrf/nrfx/sample.yaml
@@ -1,6 +1,6 @@
sample:
- name: nrfx usage sample
+ name: nrfx use example
tests:
- sample.board.nrf91.nrfx:
- platform_allow: nrf9160dk_nrf9160
+ sample.boards.nrf.nrfx:
+ platform_allow: nrf52840dk_nrf52840 nrf9160dk_nrf9160
tags: board
diff --git a/samples/boards/nrf/nrfx/src/main.c b/samples/boards/nrf/nrfx/src/main.c
index 2e0fa18..fc732c5 100644
--- a/samples/boards/nrf/nrfx/src/main.c
+++ b/samples/boards/nrf/nrfx/src/main.c
@@ -7,7 +7,12 @@
#include <zephyr.h>
#include <nrfx_gpiote.h>
+#include <helpers/nrfx_gppi.h>
+#if defined(DPPI_PRESENT)
#include <nrfx_dppi.h>
+#else
+#include <nrfx_ppi.h>
+#endif
#include <logging/log.h>
LOG_MODULE_REGISTER(nrfx_sample, LOG_LEVEL_INF);
@@ -77,35 +82,39 @@
LOG_INF("nrfx_gpiote initialized");
- /* Initialize DPPI channel */
+ /* Allocate a (D)PPI channel. */
+#if defined(DPPI_PRESENT)
uint8_t channel;
-
err = nrfx_dppi_channel_alloc(&channel);
+#else
+ nrf_ppi_channel_t channel;
+ err = nrfx_ppi_channel_alloc(&channel);
+#endif
if (err != NRFX_SUCCESS) {
- LOG_ERR("nrfx_dppi_channel_alloc error: %08x", err);
+ LOG_ERR("(D)PPI channel allocation error: %08x", err);
return;
}
- /* Configure input pin to publish to the DPPI channel and output pin to
- * receive events from the DPPI channel. Note that output pin is
- * subscribed using the OUT task. This means that each time the button
- * is pressed, the LED pin will be toggled.
+ /* Configure endpoints of the channel so that the input pin event is
+ * connected with the output pin OUT task. This means that each time
+ * the button is pressed, the LED pin will be toggled.
*/
- nrf_gpiote_publish_set(
- NRF_GPIOTE,
- nrfx_gpiote_in_event_get(INPUT_PIN),
- channel);
- nrf_gpiote_subscribe_set(
- NRF_GPIOTE,
- nrfx_gpiote_out_task_get(OUTPUT_PIN),
- channel);
+ nrfx_gppi_channel_endpoints_setup(channel,
+ nrf_gpiote_event_address_get(NRF_GPIOTE,
+ nrfx_gpiote_in_event_get(INPUT_PIN)),
+ nrf_gpiote_task_address_get(NRF_GPIOTE,
+ nrfx_gpiote_in_event_get(OUTPUT_PIN)));
- /* Enable DPPI channel */
+ /* Enable (D)PPI channel. */
+#if defined(DPPI_PRESENT)
err = nrfx_dppi_channel_enable(channel);
+#else
+ err = nrfx_ppi_channel_enable(channel);
+#endif
if (err != NRFX_SUCCESS) {
- LOG_ERR("nrfx_dppi_channel_enable error: %08x", err);
+ LOG_ERR("Failed to enable (D)PPI channel, error: %08x", err);
return;
}
- LOG_INF("DPPI configured, leaving main()");
+ LOG_INF("(D)PPI configured, leaving main()");
}